コード例 #1
0
 def test_create_observer_game_state(self):
     game_state = create_basic_game_state()
     actual = StateExporter.create_observer_game_state(game_state)
     expected_level_map = "........................................\n" + \
         ".....WWWWWWW............................\n" + \
         ".....WP    W......WWWWW.................\n" + \
         ".....W     D------DZ  W.................\n" + \
         ".....W     W......W   W.................\n" + \
         ".....WWWWWWW......W   W.................\n" + \
         "..................W   W.................\n" + \
         "..................W   W.................\n" + \
         "..................W   W.................\n" + \
         "..................WWDWW.................\n" + \
         "...WWWWWWWWWWWW.....-...................\n" + \
         "...W          W.....-...................\n" + \
         "...W   K      D------...................\n" + \
         "...W   E      W.........................\n" + \
         "...WWWWWWWWWWWW.........................\n" + \
         "........................................"
     expected = {
         "is_exit_unlocked": False,
         "is_game_over": False,
         "current_turn": "p1",
         "level_count": 1,
         "current_level_number": 0,
         "moves_elapsed": 0,
         "latest_player_message": "",
         "level_map": expected_level_map,
         "exited_players_count": 0,
         "dead_players_count": 0
     }
     self.assertEqual(actual, expected)
コード例 #2
0
 def test_create_adversary_game_state(self):
     game_state = create_basic_game_state()
     actual = StateExporter.create_adversary_game_state(game_state, "a1")
     expected_level_map = "........................................\n" + \
         ".....WWWWWWW............................\n" + \
         ".....WP    W......WWWWW.................\n" + \
         ".....W     D------DZ  W.................\n" + \
         ".....W     W......W   W.................\n" + \
         ".....WWWWWWW......W   W.................\n" + \
         "..................W   W.................\n" + \
         "..................W   W.................\n" + \
         "..................W   W.................\n" + \
         "..................WWDWW.................\n" + \
         "...WWWWWWWWWWWW.....-...................\n" + \
         "...W          W.....-...................\n" + \
         "...W   K      D------...................\n" + \
         "...W   E      W.........................\n" + \
         "...WWWWWWWWWWWW.........................\n" + \
         "........................................"
     actual_level_map = "\n".join(["".join(x) for x in actual["level_map"]])
     self.assertEqual(actual_level_map, expected_level_map)
     self.assertEqual(actual["type"], "adversary-update")
     self.assertEqual(actual["available_moves"], [(3, 19), (3, 20),
                                                  (4, 19)])
     self.assertEqual(actual["player_locations"], [(2, 6)])
     self.assertEqual(actual["position"], (3, 19))
コード例 #3
0
 def test_create_end_level_state(self):
     game_state = create_basic_game_state()
     actual = StateExporter.create_end_level_state(game_state, 1)
     expected = {
         "type": "end-level",
         "key": None,
         "exits": [],
         "ejects": [],
     }
     self.assertEqual(actual, expected)
コード例 #4
0
 def test_create_end_game_state(self):
     game_state = create_basic_game_state()
     actual = StateExporter.create_end_game_state(game_state)
     expected_scores = [{
         'ejects': 0,
         'exits': 0,
         'keys': 0,
         'name': 'p1',
         'type': 'player-score'
     }]
     self.assertEqual(actual["type"], "end-game")
     self.assertEqual(actual["scores"], expected_scores)
コード例 #5
0
 def test_create_player_update(self):
     game_state = create_basic_game_state()
     actual = StateExporter.create_player_update(game_state, "p1")
     expected_layout = [[0, 0, 0, 0, 0], [0, 0, 0, 0, 0], [0, 0, 1, 1, 1],
                        [0, 0, 1, 1, 1], [0, 0, 1, 1, 1]]
     self.assertEqual(actual["type"], "player-update")
     self.assertEqual(actual["layout"], expected_layout)
     self.assertEqual(actual["objects"], [])
     self.assertEqual(actual["actors"], [])
     self.assertEqual(actual["position"], (2, 6))
     self.assertEqual(actual["message"], "Current Turn: 0\n")
     self.assertEqual(actual["health"], 50)
コード例 #6
0
    def test_valid_move(self):
        state = create_basic_game_state()

        with self.assertRaises(InvalidOccupantIdError):
            RuleChecker.validate_move(state, "p0", [6,4])

        with self.assertRaises(InvalidDestinationError):
            RuleChecker.validate_move(state, "p1", [10,2])

        with self.assertRaises(NonTraversableTileError):
            RuleChecker.validate_move(state, "p1", [16,4])

        RuleChecker.validate_move(state, "p1", state.occupants["p1"].current_location)
コード例 #7
0
    def test_game_over_when_player_wins(self):
        state = create_basic_game_state()
        self.assertFalse(RuleChecker.is_game_over(state))
        self.assertFalse(RuleChecker.is_level_over(state))
        RuleChecker.validate_game_state(state)

        # move player to key
        state.update("p1", (7, 12))
        # move player to exit
        state.update("p1", (7, 13))

        self.assertTrue(RuleChecker.is_game_over)
        self.assertTrue(RuleChecker.is_level_over)
        self.assertEqual(RuleChecker.get_game_winner(state), constants.PLAYER_STRING)
コード例 #8
0
    def test_game_and_level_over_when_players_die(self):
        state = create_basic_game_state()
        self.assertFalse(RuleChecker.is_game_over(state))
        self.assertFalse(RuleChecker.is_level_over(state))
        RuleChecker.validate_game_state(state)

        a1_location = state.occupants["a1"].current_location
        p1_location = state.occupants["p1"].current_location

        with self.assertRaises(InvalidDestinationError):
            RuleChecker.validate_move(state, "p1", a1_location)

        for _ in range(5):
            state.update("a1", p1_location)

        self.assertTrue(RuleChecker.is_game_over)
        self.assertTrue(RuleChecker.is_level_over)
        self.assertEqual(RuleChecker.get_game_winner(state), constants.ADVERSARY_STRING)
コード例 #9
0
 def create_basic_game_state(self):
     return create_basic_game_state(), level_1()