Exemplo n.º 1
0
def player_to_string(game: reversi.ReversiGame, player_colour: str, player: ai_players.Player) \
        -> str:
    """ Returns the string representation of the type of the player.

    Preconditions:
        - player_colour in {'white', 'black'}
    """
    if game.get_human_player() == 1 and player_colour == 'black':
        return 'Human'
    elif game.get_human_player() == -1 and player_colour == 'white':
        return 'Human'
    else:
        # the player is one of the AI players
        if isinstance(player, ai_players.RandomPlayer):
            return 'Random Moves'
        elif (isinstance(player, ai_players.MinimaxPlayer)
              or isinstance(player, ai_players.MinimaxABPlayer)):
            return 'Minimax ' + str(player.depth)
Exemplo n.º 2
0
def helper_dropdown_select_board_size(g: ReversiGame, colour_to_player: Dict,
                                      text: str) -> None:
    """
    Set the board size given the text.
    Preconditions:
        - text is of the form '<int>x<int>' where the two
          integers are the same and greater than 0.
    """
    global board_size_current

    # Update the current board size (why?)
    board_size_current = int(text.split('x')[0])

    # Set new heuristics for players
    colour_to_player[1].set_heuristic(board_size_current)

    colour_to_player[-1].set_heuristic(board_size_current)

    # Update game board size
    g.set_board_size(board_size_current)

    # Start new game.
    g.start_game(human_player=g.get_human_player())
Exemplo n.º 3
0
    results = []

    # Add UI to the window
    ui_handler.add_ui(window, game, results, colour_to_player)

    # Window loop
    while window.is_running():
        """ UPDATE STUFF """

        # Get game winner
        winner = game.get_winner()
        if winner is not None:
            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[