def test_get_information(self):
        player = Player(1, 0, 4, Direction.up, 1, True, "")
        sut = NotKillingItselfAI(player, [], 3, 1, 3)
        expected = "max_speed=3, max_worse_distance=1, depth=3"

        result = sut.get_information()

        self.assertEqual(expected, result)
    def test_ai_should_choose_empty_list_with_depth_three_and_no_surviving_action(self):
        player1 = Player(1, 1, 2, Direction.up, 1, True, "")
        player2 = Player(2, 1, 1, Direction.down, 3, True, "")
        players = [player1, player2]
        cells = [[Cell(),           Cell(),          Cell(),            Cell(),             Cell()],
                 [Cell([player2]),  Cell([player2]), Cell([player2]),   Cell(),             Cell()],
                 [Cell(),           Cell([player1]), Cell(),            Cell([player2]),    Cell()],
                 [Cell([player2]),  Cell([player2]), Cell(),            Cell([player2]),    Cell()],
                 [Cell(),           Cell(),          Cell([player2]),   Cell(),             Cell()]]

        time = datetime(2020, 10, 1, 12, 5, 13, 0, timezone.utc)
        game = Game(5, 5, cells, players, 2, True, time)
        game_service = GameService(game)
        sut = NotKillingItselfAI(player1, [], 3, 0, 3)

        actions: List[Action] = sut.find_surviving_actions(game_service, 3)

        self.assertTrue(len(actions) == 0)
    def test_ai_should_choose_best_list_of_actions_by_depth(self):
        player1 = Player(1, 1, 2, Direction.up, 1, True, "")
        player2 = Player(2, 1, 1, Direction.down, 3, True, "")
        players = [player1, player2]
        cells = [[Cell(),           Cell(),          Cell(),            Cell(),             Cell()],
                 [Cell([player2]),  Cell([player2]), Cell([player2]),   Cell(),             Cell()],
                 [Cell(),           Cell([player1]), Cell(),            Cell([player2]),    Cell()],
                 [Cell([player2]),  Cell(), Cell(),            Cell([player2]),    Cell()],
                 [Cell(),           Cell(),          Cell([player2]),   Cell(),             Cell()]]

        time = datetime(2020, 10, 1, 12, 5, 13, 0, timezone.utc)
        game = Game(5, 5, cells, players, 2, True, time)
        game_service = GameService(game)
        sut = NotKillingItselfAI(player1, [], 3, 0, 5)

        actions: List[Action] = sut.find_surviving_actions_with_best_depth(game_service)

        self.assertTrue(Action.turn_right in actions)
        self.assertTrue(len(actions) == 1)
    def test_ai_should_not_choose_speed_up_if_max_speed_is_allready_reached(self):
        MAX_SPEED = 3
        player1 = Player(1, 0, 4, Direction.up, MAX_SPEED, True, "")
        player2 = Player(2, 0, 1, Direction.down, 3, True, "")
        players = [player1, player2]
        cells = [[Cell(), Cell(), Cell(), Cell(), Cell()],
                 [Cell([player2]), Cell(), Cell(), Cell(), Cell()],
                 [Cell(), Cell(), Cell(), Cell(), Cell()],
                 [Cell(), Cell(), Cell(), Cell(), Cell()],
                 [Cell([player1]), Cell(), Cell(), Cell(), Cell()]]
        time = datetime(2020, 10, 1, 12, 5, 13, 0, timezone.utc)
        game = Game(5, 5, cells, players, 2, True, time)
        game_service = GameService(game)
        sut = NotKillingItselfAI(player1, [], MAX_SPEED, 0, 3)

        actions: List[Action] = sut.find_surviving_actions(game_service, 1)

        self.assertTrue(Action.slow_down in actions)
        self.assertTrue(Action.turn_right in actions)
        self.assertTrue(len(actions) == 2)
    def test_ai_should_choose_the_correct_list_of_actions_non_killing_itself(self):
        player1 = Player(1, 0, 1, Direction.up, 1, True, "")
        player2 = Player(2, 4, 4, Direction.down, 3, True, "")
        players = [player1, player2]
        cells = [[Cell(), Cell(), Cell(), Cell(), Cell()],
                 [Cell([player1]), Cell(), Cell(), Cell(), Cell()],
                 [Cell(), Cell(), Cell(), Cell(), Cell()],
                 [Cell(), Cell(), Cell(), Cell(), Cell()],
                 [Cell(), Cell(), Cell(), Cell(), Cell([player2])]]

        time = datetime(2020, 10, 1, 12, 5, 13, 0, timezone.utc)
        game = Game(5, 5, cells, players, 2, True, time)
        game_service = GameService(game)
        sut = NotKillingItselfAI(player1, [], 3, 0, 3)

        actions: List[Action] = sut.find_surviving_actions(game_service, 3)

        self.assertTrue(Action.change_nothing in actions)
        self.assertTrue(Action.turn_right in actions)
        self.assertTrue(len(actions) == 2)
    def test_ai_should_calc_action_with_max_distance(self):
        player1 = Player(1, 0, 4, Direction.up, 1, True, "")
        player2 = Player(2, 0, 1, Direction.down, 3, True, "")
        players = [player1, player2]
        cells = [[Cell(), Cell(), Cell(), Cell(), Cell()],
                 [Cell([player2]), Cell(), Cell(), Cell(), Cell()],
                 [Cell(), Cell(), Cell(), Cell(), Cell()],
                 [Cell(), Cell(), Cell(), Cell(), Cell()],
                 [Cell([player1]), Cell(), Cell(), Cell(), Cell()]]
        time = datetime(2020, 10, 1, 12, 5, 13, 0, timezone.utc)
        game = Game(5, 5, cells, players, 2, True, time)
        game_service = GameService(game)
        sut = NotKillingItselfAI(player1, [], 3, 0, 3)

        actions: List[Action] = sut.calc_action_with_max_distance_to_visited_cells(game_service, [Action.speed_up,
                                                                                                  Action.change_nothing,
                                                                                                  Action.turn_right])

        self.assertTrue(Action.turn_right in actions)
        self.assertTrue(len(actions) == 1)