Beispiel #1
0
 def get_valid_move(game_state: BotGameState, strategy: Strategy) -> BotMove:
     """
     Get a valid move for the bot using the specified game state and strategy.
     :param game_state: the BotGameState for the current turn.
     :param strategy: The Strategy to use to determine the valid move to return.
     :return: A valid move
     :rtype: BotMove
     """
     return strategy.choose_move(game_state, game_state.get_all_valid_moves())
Beispiel #2
0
    def take_turn(self):
        """
        Take a turn for the current active player, as determined by the GameState.
        """
        player = self.game_state.current_player
        player.can_play = True
        bot_game_state = BotGameState(self.game_state, player)

        drew = False
        played = False
        done = False
        first = player.turn == 0

        player.bot.start_turn(player.turn)
        while not done:
            valid_moves = bot_game_state.get_all_valid_moves()
            if len(valid_moves) == 0:
                if not played and not drew:
                    domino = self.game_state.draw_domino(player)
                    if not domino:
                        player.can_play = False
                        done = True
                    else:
                        bot_game_state.draw_domino(domino)
                    drew = True
                else:
                    done = True
            else:
                move = player.bot.get_move(bot_game_state)
                if not self.validate_move(move, player):
                    player.bot.report_invalid_move(move)
                    shuffle(valid_moves)
                    move = valid_moves.pop()
                if move.domino.is_double:
                    drew = False
                    played = False
                else:
                    played = True
                self.do_move(player, move)
                bot_game_state.do_move(move)
                if played and not first:
                    done = True
        player.turn += 1
Beispiel #3
0
 def get_move(self, game_state: BotGameState):
     return self.strategy.choose_move(game_state, game_state.get_all_valid_moves())