Skip to content

Instantly share code, notes, and snippets.

@jpark9013
Last active April 25, 2021 22:07
Show Gist options
  • Save jpark9013/08a45413386ef4220e7f5e7a7c0e7575 to your computer and use it in GitHub Desktop.
Save jpark9013/08a45413386ef4220e7f5e7a7c0e7575 to your computer and use it in GitHub Desktop.
thing
import math
import statistics
import random
import pyspiel
game = pyspiel.load_game("breakthrough")
trials = int(1e4)
white_wins = 0
black_wins = 0
lst = []
for _ in range(trials):
state = game.new_initial_state()
while not state.is_terminal():
action = random.choice(state.legal_actions())
state.apply_action(action)
rewards = state.rewards()
if rewards[0] == 1:
white_wins += 1
else:
black_wins += 1
lst.append(1 if rewards[0] == 1 else -1)
print(f"Percentage of white winning: {round(white_wins/trials*100, 3)}%\n"
f"Percentage of black winning: {round(black_wins/trials*100, 3)}%")
stdev = statistics.stdev(lst)
mean = white_wins/trials
z = (mean-0.5)/(stdev/math.sqrt(trials))
if z >= 1.96:
print("Statistically Significant; White wins more when making random moves.")
elif z <= -1.96:
print("Statistically Significant: Black wins more when making random moves.")
else:
print("Statistically Insignificant.")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment