Example #1
0
    def test_convert_json_to_ended_game(self):
        json = tests.read_test_file("service/game_ended.json")
        player1 = Player(1, 2, 2, Direction.up, 1, True, "")
        player2 = Player(2, 1, 0, Direction.down, 3, True, "")
        player3 = Player(3, 4, 3, Direction.left, 2, False, "Name 3")
        players = [player1, player2, player3]
        cells = [[Cell(), Cell([player2]),
                  Cell(), Cell(),
                  Cell()], [Cell(), Cell(),
                            Cell(), Cell(),
                            Cell()],
                 [Cell(),
                  Cell([player1]),
                  Cell([player1]),
                  Cell(),
                  Cell()], [Cell(),
                            Cell(),
                            Cell(),
                            Cell(),
                            Cell([player3])]]
        expected = Game(5, 4, cells, players, 2, False)

        result = self.sut.load(json)

        self.assertEqual(expected, result)
    def test_find_no_surviving_action(self):
        game = self.data_loader.load(tests.read_test_file("ai/game_5.json"))
        sut = SearchTreeAI(game.you, 2, 10, False, 10)

        result = sut.create_all_next_surviving_actions(game)

        self.assertEqual([], result)
Example #3
0
    def test_convert_json_to_running_game(self):
        json = tests.read_test_file("service/game.json")
        player1 = Player(1, 2, 2, Direction.up, 1, True, "")
        player2 = Player(2, 1, 0, Direction.down, 3, True, "")
        player3 = Player(3, 4, 3, Direction.left, 2, False, "Name 3")
        players = [player1, player2, player3]
        cells = [[Cell(), Cell([player2]),
                  Cell(), Cell(),
                  Cell()], [Cell(), Cell(),
                            Cell(), Cell(),
                            Cell()],
                 [Cell(),
                  Cell([player1]),
                  Cell([player1]),
                  Cell(),
                  Cell()], [Cell(),
                            Cell(),
                            Cell(),
                            Cell(),
                            Cell([player3])]]
        time = datetime(2020, 10, 1, 12, 5, 13, 0, timezone.utc)
        expected = Game(5, 4, cells, players, 2, True, time)

        result = self.sut.load(json)

        self.assertEqual(expected, result)
    def test_should_select_action_to_let_player_survive_next_two_rounds(self):
        game = self.data_loader.load(tests.read_test_file("ai/game_4.json"))

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

        self.assertEqual(Action.turn_left, Action.get_by_index(result.value))
Example #5
0
    def test_correctly_convert_game_with_collision_cells(self):
        json = tests.read_test_file("service/game_1.json")
        game = self.sut.load(json)

        players = game.cells[2][2].players

        self.assertIsNotNone(players)
        self.assertNotEqual(0, len(players))
    def test_get_information(self):
        game = self.data_loader.load(tests.read_test_file("ai/game_3.json"))
        sut = SearchTreeAI(game.you, 2, 3, True, 10)
        expected = "max_speed=3, depth=2, randomize=True, distance_to_check=10"

        result = sut.get_information()

        self.assertEqual(expected, result)
    def test_should_select_action_to_let_player_survive_next_two_rounds_2(self):
        game = self.data_loader.load(tests.read_test_file("ai/game_3.json"))
        sut = SearchTreeAI(game.you, 2, 2)

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

        self.assertEqual(Action.slow_down, Action.get_by_index(result.value))
    def test_should_select_action_to_let_player_survive_next_round(self):
        game = self.data_loader.load(tests.read_test_file("ai/game_1.json"))
        sut = SearchTreeAI(game.you, 1, 3, True)

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

        self.assertEqual(Action.turn_right, Action.get_by_index(result.value))
    def test_normalize_game_deadline_1(self):
        server_time = datetime(2020, 11, 20, 10, 33, 11, 0, timezone.utc)
        own_time = datetime(2020, 11, 20, 10, 33, 12, 941748, timezone.utc)
        game = JSONDataLoader().load(tests.read_test_file("model/game_1.json"))
        game.deadline = datetime(2020, 11, 20, 10, 33, 18, 0, timezone.utc)
        expected = datetime(2020, 11, 20, 10, 33, 19, 941748, timezone.utc)

        game.normalize_deadline(server_time, own_time)

        self.assertEqual(expected, game.deadline)