コード例 #1
0
 def test_syntax_checker_good_game8(self):
     game_internal = Game([[
         GameObject('starting_room', [], [
             GameObject('door', [GameObjectAttribute.IMMOBILE]),
             GameObject('keypart1'),
             GameObject('box', [GameObjectAttribute.IMMOBILE],
                        [GameObject('keypart2')])
         ]),
         GameObject('ending_room')
     ], [GameObject('key')],
                           [
                               GamePassage(11, 'starting_room',
                                           'ending_room', 'N', 'S',
                                           [GameObjectAttribute.INVISIBLE])
                           ],
                           [
                               GamePassageRevealAction('door', 'key', 11),
                               GameObjectUseAction('keypart1', 'keypart2',
                                                   'key')
                           ], [], 'ending_room', {}])
     verdict = GameSyntaxChecker().check(game_internal)
     assert (verdict == '')
     solution = GameSolver().solve(game_internal)
     assert (solution == [['take', 'keypart1'], ['open', 'box'],
                          ['take', 'keypart2'],
                          ['use', 'keypart1', 'keypart2'],
                          ['use', 'door', 'key'], ['go', 'N']])
コード例 #2
0
 def test_syntax_checker_good_game9(self):
     game_internal = Game(
         [[
             GameObject('starting_room', [], [
                 GameObject('door', [GameObjectAttribute.IMMOBILE]),
                 GameObject('key', [])
             ]),
             GameObject('ending_room')
         ], [GameObject('broken_key')],
          [
              GamePassage(11, 'starting_room', 'ending_room', 'N', 'S',
                          [GameObjectAttribute.INVISIBLE])
          ], [GameObjectUseAction('door', 'key', 'broken_key')],
          [GamePassageRevealAction('broken_key', '', 11)], 'ending_room',
          {}])
     verdict = GameSyntaxChecker().check(game_internal)
     assert (verdict == "")
     assert (GameSolver().solve(game_internal) == [['take', 'key'],
                                                   ['use', 'door', 'key'],
                                                   ['go', 'N']])
コード例 #3
0
 def test_syntax_checker_wrong_game28(self):
     game_internal = Game(
         [[
             GameObject('starting_room', [], [
                 GameObject('door', [GameObjectAttribute.IMMOBILE]),
                 GameObject('key', [])
             ]),
             GameObject('ending_room')
         ], [GameObject('broken_key')],
          [
              GamePassage(11, 'starting_room', 'strange_room', 'W', 'E',
                          []),
              GamePassage(12, 'strange_room', 'ending_room', 'N', 'S',
                          [GameObjectAttribute.INVISIBLE])
          ], [GameObjectUseAction('door', 'key', 'broken_key')],
          [GamePassageRevealAction('broken_key', '', 12)], 'ending_room',
          {}])
     verdict = GameSyntaxChecker().check(game_internal)
     assert (
         verdict == "found not existing room in a passage: strange_room")
コード例 #4
0
 def test_syntax_checker_wrong_game_19(self):
     game_internal = Game([[
         GameObject('roomA', [], [
             GameObject('button1', [GameObjectAttribute.IMMOBILE], []),
             GameObject('button2', [GameObjectAttribute.IMMOBILE], [])
         ]),
         GameObject('roomB')
     ], [GameObject('broken button')],
                           [
                               GamePassage(11, 'roomA', 'roomB', 'N', 'S',
                                           [GameObjectAttribute.INVISIBLE])
                           ],
                           [
                               GamePassageRevealAction('button1', '', 11),
                               GameObjectUseAction('', 'button1',
                                                   'broken button')
                           ], [], 'roomB', {}])
     verdict = GameSyntaxChecker().check(game_internal)
     assert (
         verdict == 'found multiple actions for the same actor, button1')
コード例 #5
0
 def test_syntax_checker_wrong_game_21(self):
     game_internal = Game([[
         GameObject('roomA', [], [
             GameObject('handle1', [GameObjectAttribute.IMMOBILE], []),
             GameObject('handle2', [GameObjectAttribute.IMMOBILE], []),
             GameObject('crowbar')
         ]),
         GameObject('roomB')
     ], [GameObject('handle1')],
                           [
                               GamePassage(11, 'roomA', 'roomB', 'N', 'S',
                                           [GameObjectAttribute.INVISIBLE])
                           ],
                           [
                               GamePassageRevealAction(
                                   'handle1', 'crowbar', 11),
                               GameObjectUseAction('handle2', 'crowbar',
                                                   'handle1')
                           ], [], 'roomB', {}])
     verdict = GameSyntaxChecker().check(game_internal)
     assert (verdict == 'found two objects with the same name, handle1')
コード例 #6
0
 def test_syntax_checker_wrong_game23(self):
     game_internal = Game([[
         GameObject('starting_room', [], [
             GameObject('door', [GameObjectAttribute.IMMOBILE]),
             GameObject('keypart1'),
             GameObject('box', [GameObjectAttribute.IMMOBILE],
                        [GameObject('keypart2')])
         ]),
         GameObject('ending_room')
     ], [GameObject('key', [GameObjectAttribute.INVISIBLE])],
                           [
                               GamePassage(11, 'starting_room',
                                           'ending_room', 'N', 'S',
                                           [GameObjectAttribute.INVISIBLE])
                           ],
                           [
                               GamePassageRevealAction('door', 'key', 11),
                               GameObjectUseAction('keypart1', 'keypart2',
                                                   'key')
                           ], [], 'ending_room', {}])
     verdict = GameSyntaxChecker().check(game_internal)
     assert (verdict == 'not top level stuffs cannot have attributes, key')
コード例 #7
0
    def setUp(self):
        # Test game1, just to start with something

        self.game1_text_blueprints = """
            [
            [{"obj_content": {"attributes": [],
                              "childObjects": [{"obj_content": {"attributes": ["immobile"], "childObjects": [], "name": "table"}, "obj_name": "GameObject"},
                                               {"obj_content": {"attributes": [], "childObjects": [], "name": "candle"}, "obj_name": "GameObject"},
                                               {"obj_content": {"attributes": [], "childObjects": [], "name": "match"}, "obj_name": "GameObject"},
                                               {"obj_content": {"attributes": [], "childObjects": [], "name": "bird"}, "obj_name": "GameObject"},
                                               {"obj_content": {"attributes": [], "childObjects": [], "name": "stone"}, "obj_name": "GameObject"},
                                               {"obj_content": {"attributes": ["immobile", "invisible"], "childObjects": [], "name": "picture"}, "obj_name": "GameObject"}],
                              "name": "dark_room"},
              "obj_name": "GameObject"},
             {"obj_content": {"attributes": [],
                              "childObjects": [{"obj_content": {"attributes": ["immobile"],
                                                                "childObjects": [{"obj_content": {"attributes": [], "childObjects": [], "name": "knife"}, "obj_name": "GameObject"}],
                                                                "name": "cabinet"},
                                                "obj_name": "GameObject"}],
                              "name": "bathroom"},
              "obj_name": "GameObject"},
             {"obj_content": {"attributes": [],
                              "childObjects": [],
                              "name": "secret_room"},
              "obj_name": "GameObject"}],
            [{"obj_content": {"attributes": [],
                              "childObjects": [],
                              "name": "burning_candle"},
              "obj_name": "GameObject"},
             {"obj_content": {"attributes": [],
                              "childObjects": [],
                              "name": "injured_bird"},
              "obj_name": "GameObject"}],
            [{"obj_content": {"room_name2": "bathroom", "room_name1": "dark_room", "direction2": "S", "attributes": [], "direction1": "N", "identifier": 11},
              "obj_name": "GamePassage"},
             {"obj_content": {"room_name2": "secret_room", "room_name1": "dark_room", "direction2": "E", "attributes": ["invisible"], "direction1": "W", "identifier": 12},
              "obj_name": "GamePassage"}],
            [{"obj_content": {"subjectname": "candle", "toolname": "match", "resultname": "burning_candle"},
              "obj_name": "GameObjectUseAction"},
             {"obj_content": {"subjectname": "bird", "toolname": "stone", "resultname": "injured_bird"},
              "obj_name": "GameObjectUseAction"},
             {"obj_content": {"subjectname": "picture", "toolname": "", "identifier": 12},
              "obj_name": "GamePassageRevealAction"}],
            [{"obj_content": {"subjectname": "picture", "toolname": "burning_candle"},
              "obj_name": "GameObjectRevealAction"}],
            "secret_room",
            {"go#dark_room": "dark_room", "go#bathroom": "bathroom"}
            ]
      """

        self.game1 = Game([[
            GameObject('dark_room', [], [
                GameObject('table', [GameObjectAttribute.IMMOBILE], []),
                GameObject('candle'),
                GameObject('match'),
                GameObject('bird'),
                GameObject('stone'),
                GameObject('picture', [
                    GameObjectAttribute.IMMOBILE, GameObjectAttribute.INVISIBLE
                ])
            ]),
            GameObject('bathroom', [], [
                GameObject('cabinet', [GameObjectAttribute.IMMOBILE],
                           [GameObject('knife')])
            ]),
            GameObject('secret_room')
        ], [GameObject('burning_candle'),
            GameObject('injured_bird')],
                           [
                               GamePassage(11, 'dark_room', 'bathroom', 'N',
                                           'S'),
                               GamePassage(12, 'dark_room', 'secret_room', 'W',
                                           'E',
                                           [GameObjectAttribute.INVISIBLE])
                           ],
                           [
                               GameObjectUseAction('candle', 'match',
                                                   'burning_candle'),
                               GameObjectUseAction('bird', 'stone',
                                                   'injured_bird'),
                               GamePassageRevealAction('picture', '', 12)
                           ],
                           [
                               GameObjectRevealAction('picture',
                                                      'burning_candle')
                           ], 'secret_room', {
                               'go#dark_room': 'dark_room',
                               'go#bathroom': 'bathroom'
                           }])
        assert (self.game1.look() == 'dark_room')
        assert (self.game1.has('burning_candle') is None)
        assert (self.game1.has('candle') is None)
        assert (self.game1.has('match') is None)
        assert ('candle' in self.game1.stuffs())
        assert ('match' in self.game1.stuffs())
        assert ('table' in self.game1.stuffs())
        assert (not 'picture' in self.game1.stuffs())
        assert (self.game1.directions() == [['N', 'bathroom']])
        assert (self.game1.won() == 0)