def AI_vs_AI(): # power is the max depth of the game tree searched B_POWER = 6 W_POWER = 6 moves = [] game_field = OthelloAI() while True: winner = game_field.isGameOver() if winner != 0: game_field.displayBoard() print(f"{'Black' if winner == BLACK else 'White'} wins!") break # Black plays game_field.displayBoard() try: ai_power = B_POWER if game_field.player == BLACK else W_POWER x, y = game_field.aiPlay(ai_power) except TypeError: print(game_field.board) break move = getHumanReadableNotation(x, y) moves.append(('W' if game_field.player == BLACK else 'B', move)) # for move in moves: print(moves)
def singlePlayerMode(humanFirst=True): AI_POWER = 4 game_field = OthelloAI(humanFirst) if not humanFirst: game_field.displayBoard() game_field.aiPlay(AI_POWER) while True: # Player's chance game_field.displayBoard() print("Enter move (eg. 'a6')") x, y = getComputerReadableNotation(input(">>> ")) game_field.checkValidAndMove(x, y) # A.I.'s chance game_field.displayBoard() print("Computer's turn ...") x, y = game_field.aiPlay(AI_POWER) winner = game_field.isGameOver() if winner: game_field.displayBoard() print( f"{'You' if winner == game_field.HUMAN else 'Computer'} won!")