Last active
April 25, 2021 22:07
-
-
Save jpark9013/08a45413386ef4220e7f5e7a7c0e7575 to your computer and use it in GitHub Desktop.
thing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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