def fitness(indv): y, z = indv.solution print(y, z) ccgame = ChineseChecker(10, 4) simpleGreedyAgent = SimpleGreedyAgent(ccgame) randomAgent = RandomAgent(ccgame) teamAgent = TeamNameMinimaxAgent(ccgame) teamAgent.HeruDefine(y, z) agents_dict_1 = {1: teamAgent, 2: simpleGreedyAgent} agents_dict_2 = {1: teamAgent, 2: randomAgent} win_times_P1 = 0 win_times_P2 = 0 tie_times = 0 for i in range(10): run_result = runGame_vir(ccgame, agents_dict_1) #print(run_result) if run_result == 1: win_times_P1 += 1 elif run_result == 2: win_times_P2 += 1 elif run_result == 0: tie_times += 1 ''' run_result = runGame_vir(ccgame, agents_dict_2) print(run_result) if run_result == 1: win_times_P1 += 1 elif run_result == 2: win_times_P2 += 1 elif run_result == 0: tie_times += 1 ''' rate = win_times_P1 / 10 print("win rate:", rate) return rate
print(run_result) if run_result == 1: win_times_P1 += 1 elif run_result == 2: win_times_P2 += 1 elif run_result == 0: tie_times += 1 print('game', i + 1, 'finished', 'winner is player ', run_result) print('In', simulation_times, 'simulations:') print('winning times: for player 1 is ', win_times_P1) print('winning times: for player 2 is ', win_times_P2) print('Tie times:', tie_times) def callback(ccgame): B.destroy() simpleGreedyAgent = SimpleGreedyAgent(ccgame) randomAgent = RandomAgent(ccgame) teamAgent = Frappuccino(ccgame) simulateMultipleGames({1: simpleGreedyAgent, 2: teamAgent}, 10, ccgame) if __name__ == '__main__': ccgame = ChineseChecker(10, 4) root = tk.Tk() board = GameBoard(root, ccgame.size, ccgame.size * 2 - 1, ccgame.board) board.pack(side="top", fill="both", expand="true", padx=4, pady=4) B = tk.Button(board, text="Start", command=lambda: callback(ccgame=ccgame)) B.pack() root.mainloop()
print(run_result) if run_result == 1: win_times_P1 += 1 elif run_result == 2: win_times_P2 += 1 elif run_result == 0: tie_times += 1 print('game', i + 1, 'finished', 'winner is player ', run_result) print('In', simulation_times, 'simulastions:') print('winning times: for player 1 is ', win_times_P1) print('winning times: for player 2 is ', win_times_P2) print('Tie times:', tie_times) def callback(ccgame): B.destroy() simpleGreedyAgent = SimpleGreedyAgent(ccgame) simpleGreedyAgent1 = SimpleGreedyAgent(ccgame) randomAgent = RandomAgent(ccgame) teamAgent = Alpha_beta(ccgame) simulateMultipleGames({1: teamAgent, 2: simpleGreedyAgent}, 10, ccgame) if __name__ == '__main__': ccgame = ChineseChecker(10, 4) # the shape of checker game root = tk.Tk() board = GameBoard(root, ccgame.size, ccgame.size * 2 - 1, ccgame.board) board.pack(side="top", fill="both", expand="true", padx=4, pady=4) B = tk.Button(board, text="Start", command=lambda: callback(ccgame=ccgame)) B.pack() root.mainloop()