Exemplo n.º 1
0
    def test_get_information(self):
        player = Player(1, 0, 4, Direction.up, 1, True, "")
        sut = PathfindingAI(player, 2, 10)
        expected = "max_speed=2, count_paths_to_check=10"

        result = sut.get_information()

        self.assertEqual(expected, result)
Exemplo n.º 2
0
    def test_create_action_should_return_None_if_given_action_list_is_none(self):
        player1 = Player(1, 0, 0, Direction.right, 2, True, "")
        player2 = Player(2, 0, 2, Direction.down, 3, True, "")
        players = [player1, player2]
        cells = [[Cell([player1]),  Cell(),             Cell()],
                 [Cell(),           Cell([player2]),    Cell()],
                 [Cell([player2]),  Cell(),             Cell()]]
        game = Game(3, 3, cells, players, 2, True, datetime.now())
        sut = PathfindingAI(player1, 2, 10)

        actions = sut.find_actions_by_best_path_connection(None, game)

        self.assertIsNone(actions)
Exemplo n.º 3
0
    def test_create_action_should_return_one_of_the_possible_action_with_best_connection(self):
        player1 = Player(1, 0, 0, Direction.right, 2, True, "")
        player2 = Player(2, 0, 2, Direction.down, 3, True, "")
        players = [player1, player2]
        cells = [[Cell([player1]),  Cell(),             Cell()],
                 [Cell(),           Cell([player2]),    Cell()],
                 [Cell([player2]),  Cell(),             Cell()]]
        game = Game(3, 3, cells, players, 2, True, datetime.now())
        sut = PathfindingAI(player1, 2, 10)

        actions = sut.find_actions_by_best_path_connection([Action.change_nothing, Action.slow_down], game)

        self.assertEqual(actions[0][0], Action.slow_down)
Exemplo n.º 4
0
    def test_create_action_should_return_action_with_best_connection(self):
        player1 = Player(1, 0, 0, Direction.down, 1, True, "")
        player2 = Player(2, 0, 2, Direction.down, 3, True, "")
        players = [player1, player2]
        cells = [[Cell([player1]),  Cell(),             Cell()],
                 [Cell(),           Cell([player2]),    Cell()],
                 [Cell([player2]),  Cell(),             Cell()]]
        game = Game(3, 3, cells, players, 2, True, datetime.now())
        sut = PathfindingAI(player1, 2, 10)

        result = Value('i')
        sut.create_next_action(game, result)

        self.assertEqual(Action.turn_left, Action.get_by_index(result.value))
Exemplo n.º 5
0
    def test_get_random_free_cells_from_playground_should_return_correct_number_of_free_cells(self):
        player1 = Player(1, 0, 0, Direction.up, 1, True, "")
        player2 = Player(2, 0, 1, Direction.down, 3, True, "")
        players = [player1, player2]
        cells = [[Cell([player1]), Cell(), Cell()],
                 [Cell([player2]), Cell(), Cell()],
                 [Cell(), Cell(), Cell()]]
        count_free_cells = 5
        game = Game(3, 3, cells, players, 2, True, datetime.now())
        sut = PathfindingAI(player1, 2, count_free_cells)

        free_cells_xy = sut.get_random_free_cells_from_playground(game)

        self.assertEqual(len(free_cells_xy), count_free_cells)
        for (x, y) in free_cells_xy:
            self.assertTrue(game.cells[y][x].players is None)
Exemplo n.º 6
0
    def __init__(self, player: Player, max_speed: int, count_paths_to_check: int, depth: int,
                 paths_tolerance: float = 0.75, distance_to_check: int = 0):
        """Creates a new object of the PathfindingSearchTreeAI.

        Args:
            player: The player assigned to the AI.
            max_speed: The maximum speed the AI can reach.
            count_paths_to_check: The number of paths used to avoid dead ends.
            depth: Depth pre-calculating actions.
            paths_tolerance: A tolerance, whereby more than just the best action is calculated. Actions which are
                worse, but within this tolerance, are also considered.
                depth: Number of player actions that are looked into the future.
            distance_to_check: Distance an enemy player is allowed to be at maximum distance, so that he is taken into
                account in the calculations.
        """
        PathfindingAI.__init__(self, player, max_speed, count_paths_to_check)
        SearchTreeAI.__init__(self, player, depth, max_speed, distance_to_check=distance_to_check)
        self.__paths_tolerance = paths_tolerance
Exemplo n.º 7
0
    def __init__(self,
                 player: Player,
                 max_speed: int,
                 count_paths_to_check: int,
                 depth: int,
                 distance_to_check: int = 0):
        """Creates a new object of the SearchTreePathfindingAI.

        Args:
            player: The player assigned to the AI.
            max_speed: The maximum speed the AI can reach.
            count_paths_to_check: The number of paths used to avoid dead ends.
            depth: Number of pre-calculating actions.
            distance_to_check:
                Distance an enemy player is allowed to be at maximum distance, so that he is taken into
                account in the calculations.
        """
        PathfindingAI.__init__(self, player, max_speed, count_paths_to_check)
        SearchTreeAI.__init__(self,
                              player,
                              depth,
                              max_speed,
                              distance_to_check=distance_to_check)