Пример #1
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())
Пример #2
0
def helper_dropdown_select_player(g: ReversiGame, text: str) -> None:
    """HELPER FUNCTION: Select the players given the dropdown option selected."""

    if text == "Human vs. AI":
        g.start_game(human_player=1)
    elif text == "AI vs. Human":
        g.start_game(human_player=-1)
    else:
        g.start_game(human_player=0)
Пример #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[