def main(argv): size = 0 limit = -1 ordering = False caching = False minimax = False agent1 = None agent2 = None try: opts, args = getopt.getopt( argv, "hcmol:d:a:b:", ["limit=", "dimension=", "agent1=", "agent2="] ) except getopt.GetoptError: print( "othello_gui.py -d <dimension> [-a <agentA> -b <agentB> -l <depth-limit> -c -o -m]" ) sys.exit(2) for opt, arg in opts: if opt == "-h": print( "othello_gui.py -d <dimension> -a <agentA> [-b <agentB> -l <depth-limit> -c -o]" ) sys.exit() elif opt in ("-d", "--dimension"): size = int(arg) elif opt in ("-a", "--agentA"): agent1 = arg elif opt in ("-b", "--agentB"): agent2 = arg elif opt in ("-c", "--caching"): caching = True elif opt in ("-m", "--minimax"): minimax = True elif opt in ("-o", "--ordering"): ordering = True elif opt in ("-l", "--limit"): limit = int(arg) if size <= 0: # if no dimension provided print("Please provide a board size.") print( "othello_gui.py -d <dimension> [-a <agentA> -b <agentB> -l <depth-limit> -c -o]" ) sys.exit(2) if agent1 != None and agent2 != None and size > 0: p1 = AiPlayerInterface(agent1, 1, limit, minimax, caching, ordering) p2 = AiPlayerInterface(agent2, 2, limit, minimax, caching, ordering) elif agent1 != None and size > 0: p1 = Player(1) p2 = AiPlayerInterface(agent1, 2, limit, minimax, caching, ordering) else: p1 = Player(1) p2 = Player(2) game = OthelloGameManager(size) gui = OthelloGui(game, p1, p2) gui.run()
def __init__(self, game_manager=OthelloGameManager(dimension=8), player1='ap3901_ai.py', player2='Human'): self.game = game_manager self.players = [None, player1, player2] self.height = self.game.dimension self.width = self.game.dimension self.offset = 3 self.cell_size = 50 root = Tk() root.wm_title("Othello") root.lift() root.attributes("-topmost", True) self.root = root self.canvas = Canvas(root, height=self.cell_size * self.height + self.offset, width=self.cell_size * self.width + self.offset) self.move_label = Label(root) self.score_label = Label(root) self.text = scrolledtext.ScrolledText(root, width=70, height=10) self.move_label.pack(side="top") self.score_label.pack(side="top") self.canvas.pack() self.text.pack() self.draw_board()
def main(): if len(sys.argv) == 4: game = OthelloGameManager(dimension=int(sys.argv[1])) p1 = AiPlayerInterface(sys.argv[2], 1) p2 = AiPlayerInterface(sys.argv[3], 2) elif len(sys.argv) == 3: game = OthelloGameManager(dimension=int(sys.argv[1])) p1 = Player(1) p2 = AiPlayerInterface(sys.argv[2], 2) elif len(sys.argv) == 2: p1 = Player(1) p2 = Player(2) game = OthelloGameManager(dimension=int(sys.argv[1])) else: p1 = Player(1) p2 = Player(2) game = OthelloGameManager(dimension=8) gui = OthelloGui(game, p1, p2) gui.run()
def main(ai_player=None): if ai_player: p1 = Player(1) p2 = AiPlayerInterface(ai_player, 2) elif len(sys.argv) == 3: p1 = AiPlayerInterface(sys.argv[1], 1) p2 = AiPlayerInterface(sys.argv[2], 2) elif len(sys.argv) == 2: p1 = Player(1) p2 = AiPlayerInterface(sys.argv[1], 2) else: p1 = Player(1) p2 = Player(2) game = OthelloGameManager(dimension=8) gui = OthelloGui(game, p1, p2) gui.run()
print("Other played: ", otherI, otherJ) except AiTimeoutError: print("{} ({}) timed out!".format(player_obj.name, color)) print("FINAL: {} (dark) {}:{} {} (light)".format( player_obj.name, p1score, p2score, player2.name)) #player1.kill(game) #player2.kill(game) serverSocket.close() break if __name__ == "__main__": if len(sys.argv) == 4: game = OthelloGameManager(dimension=int(sys.argv[1])) p1 = AiPlayerInterface(sys.argv[2], 1) p2 = AiPlayerInterface(sys.argv[3], 2) elif len(sys.argv) == 3: game = OthelloGameManager(dimension=int(sys.argv[1])) p1 = Player(1) p2 = AiPlayerInterface(sys.argv[2], 2) elif len(sys.argv) == 2: p1 = Player(1) p2 = Player(2) game = OthelloGameManager(dimension=int(sys.argv[1])) else: p1 = Player(1) p2 = Player(2) game = OthelloGameManager(dimension=8) #gameManager = OthelloGameManager(game, p1, p2)
def main(): players = [] playerRanking = [] gameSize = int(sys.argv[1]) currentRound = 0 for arg in sys.argv[2:]: players.append(arg) while len(players) > 1: nextPlayers = [] print(" === Round {} : Current Contenders === ".format( str(currentRound))) currentAI = None for elem in players: currentAI = AiPlayerInterface(elem, 1) print(currentAI.name) currentAI.kill() print() while len(players) > 0: if len(players) == 1: nextPlayers.append(players.pop()) break print( "████████████████████████████████████████████████████████████████████████████████" ) random.shuffle(players) player1 = players.pop() player2 = players.pop() player1Interface = AiPlayerInterface(player1, 1) player1Name = player1Interface.name player1Interface.kill() player2Interface = AiPlayerInterface(player2, 2) player2Name = player2Interface.name player2Interface.kill() print("Now: {} vs. {}!".format(player1Name, player2Name)) time.sleep(5) game1 = OthelloGui(OthelloGameManager(dimension=gameSize), AiPlayerInterface(player1, 1), AiPlayerInterface(player2, 2)) scores1 = game1.run() print("Current Score: {} : {} ; {} : {}".format( game1.players[1].name, scores1[0], game1.players[2].name, scores1[1])) time.sleep(5) game2 = OthelloGui(OthelloGameManager(dimension=gameSize), AiPlayerInterface(player2, 1), AiPlayerInterface(player1, 2)) scores2 = game2.run() player1Score = scores1[0] + scores2[1] player2Score = scores1[1] + scores2[0] print("Final Score: {} : {} ; {} : {}".format( game1.players[1].name, player1Score, game1.players[2].name, player2Score)) winner = None winnerName = None loserName = None if player1Score > player2Score: winner = player1 winnerName = player1Name loserName = player2Name elif player2Score > player1Score: winner = player2 winnerName = player2Name loserName = player1Name if winner == None: print("Tie! Both go to next round...") nextPlayer.append(player1) nextPlayer.append(player2) else: print("{} wins! {} goes to the next round.".format( winnerName, winnerName)) nextPlayers.append(winner) playerRanking.insert(0, loserName) time.sleep(5) players = nextPlayers currentRound += 1 currentAI = AiPlayerInterface(players[0], 1) playerRanking.insert(0, currentAI.name) currentAI.kill() print("{} is the champion! Congratulations!!!".format(playerRanking[0])) print(" === Final rankings === ") for x in range(0, len(playerRanking)): print("{} : {}".format(x + 1, playerRanking[x]))