In [1]:
import sys
import os
sys.path.append("../") # include the root directory as the main
import pandas as pd
import numpy as np
In [3]:
from aind.isolation import Board
from aind.sample_players import RandomPlayer
from aind.sample_players import GreedyPlayer
In [4]:
# create an isolation board (by default 7x7)
player1 = RandomPlayer()
player2 = GreedyPlayer()
game = Board(player1, player2)
In [6]:
# place player 1 on the board at row 2, column 3, then place player 2 on
# the board at row 0, column 5; display the resulting board state. Note
# that the .apply_move() method changes the calling object in-place.
game.apply_move((2, 3))
game.apply_move((0, 5))
print(game.to_string())
In [7]:
# players take turns moving on the board, so player1 should be next to move
assert(player1 == game.active_player)
# get a list of the legal moves available to the active player
print(game.get_legal_moves())
In [8]:
# get a successor of the current state by making a copy of the board and
# applying a move. Notice that this does NOT change the calling object
# (unlike .apply_move()).
new_game = game.forecast_move((1, 1))
assert(new_game.to_string() != game.to_string())
print("\nOld state:\n{}".format(game.to_string()))
print("\nNew state:\n{}".format(new_game.to_string()))
In [9]:
# play the remainder of the game automatically -- outcome can be "illegal
# move", "timeout", or "forfeit"
winner, history, outcome = game.play()
print("\nWinner: {}\nOutcome: {}".format(winner, outcome))
print(game.to_string())
print("Move history:\n{!s}".format(history))
Reading the data from the file
In [2]:
import pandas as pd
In [3]:
l_data = []
with open('../data/data_test.txt', 'r') as fr:
for row in fr:
if 'Win Rate:' in row:
l_data.append([float(x.replace('%', '')) for x in row.strip().split()[2:]])
In [4]:
df_tests = pd.DataFrame(l_data, columns=['AB_Improved', 'AB_Custom', 'AB_Custom_2', 'AB_Custom_3'])
In [5]:
df_tests
Out[5]:
In [14]:
import pandas as pd
from scipy.stats import ttest_ind
#performs t-test
b = df_tests.AB_Improved
a = df_tests.AB_Custom
tval, p_value = ttest_ind(a, b, equal_var=False)
print("t-value = {:0.6f}, p-value = {:0.8f}".format(tval, p_value/2))
In [19]:
(a>b).sum()
Out[19]:
In [18]:
b = df_tests.AB_Improved
a = df_tests.AB_Custom_2
tval, p_value = ttest_ind(a, b, equal_var=False)
print("t-value = {:0.6f}, p-value = {:0.8f}".format(tval, p_value/2))
In [13]:
b = df_tests.AB_Improved
a = df_tests.AB_Custom_3
tval, p_value = ttest_ind(a, b, equal_var=False)
print("t-value = {:0.6f}, p-value = {:0.8f}".format(tval, p_value/2))
In [ ]: