def main(): env = GomokuEnv(BOARD_SIZE, HISTORY) manager = HumanUI() result = {'Black': 0, 'White': 0, 'Draw': 0} for g in range(GAME): print('##### Game: {} #####'.format(g + 1)) state, board = env.reset() done = False idx = 0 while not done: env.render() # start simulations action = manager.get_action(state, board, idx) state, board, z, done = env.step(action) #print(board) idx += 1 if done: if z == 1: result['Black'] += 1 elif z == -1: result['White'] += 1 else: result['Draw'] += 1 # render & reset tree env.render() manager.ai.reset_tree() # result print('') print('=' * 20, " {} Game End ".format(g + 1), '=' * 20) blw, whw, drw = result['Black'], result['White'], result['Draw'] stat = ( 'Black Win: {} White Win: {} Draw: {} Winrate: {:0.1f}%'.format( blw, whw, drw, 1 / (1 + np.exp(whw / (g + 1)) / np.exp(blw / (g + 1))) * 100)) print(stat, '\n')
def play(): env = GomokuEnv(BOARD_SIZE, HISTORY) mcts = MCTS(BOARD_SIZE, HISTORY, N_SIMUL) result = {'Black': 0, 'White': 0, 'Draw': 0} for g in range(GAME): print('#' * (BOARD_SIZE - 4), ' GAME: {} '.format(g + 1), '#' * (BOARD_SIZE - 4)) # reset state state, board = env.reset() done = False while not done: env.render() # start simulations action = mcts.get_action(state, board) state, board, z, done = env.step(action) if done: if z == 1: result['Black'] += 1 elif z == -1: result['White'] += 1 else: result['Draw'] += 1 # render & reset tree env.render() mcts.reset_tree() # result print('') print('=' * 20, " {} Game End ".format(g + 1), '=' * 20) blw, whw, drw = result['Black'], result['White'], result['Draw'] stat = ( 'Black Win: {} White Win: {} Draw: {} Winrate: {:0.1f}%'.format( blw, whw, drw, 1 / (1 + np.exp(whw / (g + 1)) / np.exp(blw / (g + 1))) * 100)) print(stat, '\n')