if num_humans == 1: if human_is_x: player2 = player.AI_ABPruning(heuristics.game_heuristic1, show_thought_level) elif human_is_o: player1 = player.AI_ABPruning(heuristics.game_heuristic1, show_thought_level) else: if random.randint(0,1) == 0: player1 = player.AI_ABPruning(heuristics.game_heuristic1, show_thought_level) else: player2 = player.AI_ABPruning(heuristics.game_heuristic1, show_thought_level) elif num_humans == 0: player1 = player.AI_ABPruning(heuristics.game_heuristic1, show_thought_level) player2 = player.AI_ABPruning(heuristics.game_heuristic1, show_thought_level) if random.randint(0,1) == 0: player1 = player.RandomAI() print "Player 1 is random" else: player2 = player.RandomAI() print "Player 2 is random" if watch: movie = watcher.Watcher(game_file) movie.set_heuristic(heuristics.game_heuristic1) movie.set_show_eval(True) movie.watch() else: if not test: game = Board(player1, player2, game_file, history, load, show=show_board) game.play() else:
def on_pre_enter(self, *args): self.add_widget( GraphicalCoup(players=(player.HumanPlayer(), player.ThinkingAI(), player.RandomAI(), player.RandomAI())))
#for y in range(1,6): # for x in range(1,6): # print "y = " + str(y) + "; x = " + str(x) # B = Board(y,x) # B.opg() # print if __name__ == "__main__": num_games = 10000 # hp = player.Human() # B = Board(4,6,hp, player.GreedyAI()) # B.play() p1r = player.RandomAI() p2r = player.RandomAI() p1g = player.GreedyAI() p2g = player.GreedyAI() win_counts = [[0, 0, 0], [0, 0, 0], [0, 0, 0], [0, 0, 0]] for x in range(num_games): B = Board(4, 4, p1r, p2r, True) w = B.play() win_counts[0][w] += 1 # for x in range(num_games): # B = Board(10,12,p1r,p1g, True) # w = B.play() # win_counts[1][w] += 1
else: team1 = team.get_team_from_file(team1file) if team2file == '': team2 = team.make_random_team(2) else: team2 = team.get_team_from_file(team2file) player1 = team1player player2 = team2player singlebattle = battle.Battle(team1, team2, player1, player2) result = singlebattle.battle() print("Winner: " + str(result)) # Inits game with desired players/AI players if (__name__ == "__main__"): argv = sys.argv player2 = player.RandomAI("player 2") if len(argv) > 1: ai = argv[1].lower() if ai == 'minimax': player2 = player.MinimaxAI("player 2") elif ai == 'expectimax': player2 = player.ExpectimaxAI("player 2") main( "", #./tests/testteam.txt "", player.HumanPlayer("player 1"), player2)
import team import player import battle def main(team1file, team2file, team1player, team2player): team1 = team.get_team_from_file(team1file) team2 = team.get_team_from_file(team2file) player1 = team1player player2 = team2player singlebattle = battle.Battle(team1, team2, player1, player2) result = singlebattle.battle() print("Winner: " + str(result)) if (__name__ == "__main__"): main("./tests/testteam.txt", "./tests/testteam.txt", player.RandomAI("player 1"), player.RandomAI("player 2")) # main("./tests/testteam.txt", "./tests/testteam.txt", player.RandomAI("player 1"), player.RandomAI("player 2")) # main("./tests/testteam.txt", "./tests/testteam.txt", player.RandomAI("player 1"), player.RandomAI("player 2")) # main("./tests/testteam.txt", "./tests/testteam.txt", player.RandomAI("player 1"), player.RandomAI("player 2")) # main("./tests/testteam.txt", "./tests/testteam.txt", player.RandomAI("player 1"), player.RandomAI("player 2"))
print str(int(self.progress)) + '%' winners = [0] * 4 total = input("Amount of runs?") prog = ProgressBar(total) crashing_seeds = list() seed = None if input("seed to crash?"): with open("seeds.txt") as seed_file: crashing_seeds = seed_file.readlines() seed = crashing_seeds[0] seed = literal_eval(seed) for i in xrange(total): game = Coup(players=(player.RandomAI(), player.RandomAI(), player.RandomAI(), player.ThinkingAI()), seed=seed, should_print=False) try: game.run_game() except RuntimeError as r: print r.message crashing_seeds.append(game.seed) continue winners[game.winner.num - 1] += 1 prog.update() with open("seeds.txt", 'wb') as file: for seed in crashing_seeds: print >> file, seed print winners