def test_players(player1: Player, player2: Player, iterations: int) -> None: """ test_players is a function that runs <iterations> number of games between player1 and player2 """ white = 0 black = 0 ties = 0 for _ in range(iterations): game = ReversiGame() prev_move = (-1, -1) while game.get_winner() is None: move = player1.make_move(game, prev_move) game.try_make_move(move) if game.get_winner() is None: prev_move = player2.make_move(game, move) game.try_make_move(prev_move) if game.get_winner() == 'white': print('White WINS') white += 1 elif game.get_winner() == 'black': print('Black WINS') black += 1 else: print('TIE') ties += 1 print("Player 1 Wins: " + str(black)) print("Player 2 Wins: " + str(white))
def check_same(player1: Player, player2: Player) -> None: """ check_same is a function that determines if two players return the same move throughout a game. this is particularly useful for comparison between MinimaxPlayer and MinimaxABPlayer. It also gives the time that each player takes to find a move. You must comment out the random.shuffle() line of code in both players before testing """ game = ReversiGame() prev_move = (-1, -1) while game.get_winner() is None: start_time = time.time() print("Player 1 CHOOSING") move1 = player1.make_move(game, prev_move) print("--- %s seconds ---" % (time.time() - start_time)) start_time = time.time() print("Player 2 CHOOSING") move2 = player2.make_move(game, prev_move) print("--- %s seconds ---" % (time.time() - start_time)) print("Player 1 chose: ", move1, " Player 2 chose: ", move2) assert move1 == move2 game.try_make_move(move1) prev_move = move1
results.append(winner) ui_handler.update_games_stored_text(len(results), window) increment_player_score(winner, window) game.start_game(human_player=game.get_human_player()) # If the game is not paused, look for mouse clicks and process moves. if not ui_handler.get_game_paused(): if game.get_human_player() == game.get_current_player(): # Look at the mouse clicks and see if they are in the board. for event in window.get_events(): if event[0] == pygame.MOUSEBUTTONUP: square = board_manager.check_mouse_press( event[1], game.get_board()) if square != (-1, -1): if game.try_make_move(square): moves_made.append(square) elif game.get_winner() is None: next_move = colour_to_player[ game.get_current_player()].make_move(game, moves_made[-1]) game.try_make_move(next_move) moves_made.append(next_move) # Update the window's clock window.update_clock() """ DRAW STUFF """ # Draw the background first!!!! window.draw_background() # Draw the board.