コード例 #1
0
    def test_return_no_player_who_is_not_reachable(self):
        player1 = Player(1, 4, 4, Direction.up, 0, True, "Name 1")
        player2 = Player(2, 2, 3, Direction.up, 0, True, "Name 2")
        player3 = Player(3, 1, 4, Direction.up, 0, True, "Name 3")
        players = [player1, player2, player3]
        cells = [[Cell(), Cell(),
                  Cell([player2]),
                  Cell(), Cell()],
                 [Cell(), Cell(),
                  Cell([player2]),
                  Cell(), Cell()],
                 [Cell(), Cell(),
                  Cell([player2]),
                  Cell(), Cell()],
                 [Cell(), Cell(),
                  Cell([player2]),
                  Cell(), Cell()],
                 [
                     Cell(),
                     Cell([player3]),
                     Cell([player2]),
                     Cell(),
                     Cell([player1])
                 ]]
        game = Game(5, 5, cells, players, 1, True, datetime.now())

        result = game.get_other_player_ids(player1, 3)

        self.assertEqual([2], result)
コード例 #2
0
    def test_return_all_players_except_one_within_distance_2(self):
        player1 = Player(1, 4, 4, Direction.up, 0, True, "Name 1")
        player2 = Player(2, 2, 3, Direction.up, 0, True, "Name 2")
        player3 = Player(3, 1, 4, Direction.up, 0, True, "Name 3")
        players = [player1, player2, player3]
        cells = [[Cell(), Cell(), Cell(),
                  Cell(), Cell()], [Cell(),
                                    Cell(),
                                    Cell(),
                                    Cell(),
                                    Cell()],
                 [Cell(), Cell(), Cell(),
                  Cell(), Cell()],
                 [Cell(), Cell(),
                  Cell([player2]),
                  Cell(), Cell()],
                 [
                     Cell(),
                     Cell([player3]),
                     Cell([player2]),
                     Cell(),
                     Cell([player1])
                 ]]
        game = Game(5, 5, cells, players, 1, True, datetime.now())

        result = game.get_other_player_ids(player1, 3)

        self.assertEqual([2], result)
コード例 #3
0
    def create_all_next_surviving_actions(self, game: Game) -> List[Action]:
        """Calculates not only one but all actions that will let the player survive for the next rounds.

        Args:
            game: The current state of the game.

        Returns:
            A list of actions which will let the player survive for the next rounds.
        """

        root = SearchTreeRoot(game.copy())
        player_ids_to_watch = game.get_other_player_ids(
            self.player, self.__distance_to_check, True)
        combinations = Action.get_combinations(len(player_ids_to_watch))

        search_tree_actions = []

        for action in Action.get_actions():
            if root.calculate_action(self.player, player_ids_to_watch,
                                     combinations, self.__depth,
                                     self._turn_ctr, True, [action],
                                     self._max_speed, True) is not None:
                search_tree_actions.append(action)

        return search_tree_actions
コード例 #4
0
    def test_return_all_other_active_players(self):
        player1 = Player(1, 1, 1, Direction.up, 0, True, "Name 1")
        player2 = Player(2, 1, 0, Direction.up, 0, False, "Name 2")
        player3 = Player(3, 0, 0, Direction.up, 0, True, "Name 3")
        players = [player1, player2, player3]
        cells = [[Cell([player3]), Cell([player2])],
                 [Cell([]), Cell([player1])]]
        game = Game(2, 2, cells, players, 1, True, datetime.now())

        result = game.get_other_player_ids(player1, check_active=True)

        self.assertEqual([3], result)
コード例 #5
0
    def create_next_action(self, game: Game, return_value: Value):
        """See base class."""
        self._turn_ctr += 1

        root = SearchTreeRoot(game.copy())
        player_ids_to_watch = game.get_other_player_ids(
            self.player, self.__distance_to_check, True)
        combinations = Action.get_combinations(len(player_ids_to_watch))

        action = root.calculate_action(self.player, player_ids_to_watch,
                                       combinations, self.__depth,
                                       self._turn_ctr, True, [],
                                       self._max_speed, self.__randomize)
        return_value.value = (action if action is not None else
                              Action.get_random_action()).get_index()