J1 sale con doble X, J2 juega X:N, J3 se acuesta con doble N, J4 pasa

Escenario

J1 sale con doble X, J2 juega X:N, J3 se acuesta con doble N, J4 pasa


Resultados

Luego de correr 168 simulaciones con el escenario donde J1 sale con doble X, J2 juega X:N, J3 se acuesta con doble N, J4 pasa; la ocurrencia fue 1/168, es decir, 0,59%


¿Crees que es común este escenario?


Código python

scenario_counts_per_pair = {}

# Helper function to check if a double is present in a hand (re-defining for self-contained cell)
def has_double_in_hand(hand, target_number):
"""
Checks if the double piece (target_number, target_number) is present in the hand.
"""
return (target_number, target_number) in hand

# Helper function to check if a piece (num1, num2) or (num2, num1) is present in a hand (re-defining for self-contained cell)
def has_exact_piece_in_hand(hand, piece):
"""
Verifica si una ficha de dominó específica (ej. (3,5) o (5,3)) está presente en una mano.
Considera que (a,b) es lo mismo que (b,a).
"""
normalized_piece = tuple(sorted(piece))
for hand_piece in hand:
if tuple(sorted(hand_piece)) == normalized_piece:
return True
return False

# Helper function to count occurrences of a number in a hand (re-defining for self-contained cell)
def count_number_in_hand(hand, target_number):
"""
Counts the total occurrences of a specific number across all pieces in a player's domino hand.
"""
counter = 0
for piece in hand:
if piece[0] == target_number:
counter += 1
if piece[1] == target_number:
counter += 1
return counter

# Iterate through all possible pairs of distinct numbers (X, N)
for X in range(7):
for N in range(7):
if X == N: # Ensure X is distinct from N
continue

count_current_scenario = 0

# Iterate through each simulation
for simulation_hands in all_simulations_player_hands:
p1_hand = simulation_hands[0] # Player One's hand
p2_hand = simulation_hands[1] # Player Two's hand
p3_hand = simulation_hands[2] # Player Three's hand
p4_hand = simulation_hands[3] # Player Four's hand

# Condition 1: Player One has double X
p1_has_double_X = has_double_in_hand(p1_hand, X)

# Condition 2: Player Two has the piece (X,N)
p2_has_X_N_piece = has_exact_piece_in_hand(p2_hand, (X, N))

# Condition 3: Player Three has double N
p3_has_double_N = has_double_in_hand(p3_hand, N)

# Condition 4: Player Four has neither X nor N
p4_has_no_X = (count_number_in_hand(p4_hand, X) == 0)
p4_has_no_N = (count_number_in_hand(p4_hand, N) == 0)
p4_has_neither_X_nor_N = p4_has_no_X and p4_has_no_N

# If all four conditions are met, increment the counter
if p1_has_double_X and p2_has_X_N_piece and p3_has_double_N and p4_has_neither_X_nor_N:
count_current_scenario += 1

# Store the count for the current pair (X, N)
scenario_counts_per_pair[(X, N)] = count_current_scenario

print("Conteo de ocurrencias del escenario espec\u00edfico (J1 tiene doble X, J2 tiene X:N, J3 tiene doble N, J4 no tiene X ni N) para cada par (X, N):")
for pair, count in scenario_counts_per_pair.items():
print(f" Par (X={pair[0]}, N={pair[1]}): {count} veces")

total_global_scenario_count = sum(scenario_counts_per_pair.values())
print(f"\nConteo total global del escenario espec\u00edfico (sumando todos los pares X, N): {total_global_scenario_count} veces")

Comments

Popular Posts