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']])
def test_syntax_checker_wrong_game_18(self): game_internal = Game([[ GameObject('roomA', [], [ GameObject('button1', [GameObjectAttribute.IMMOBILE], []), GameObject('button2', [GameObjectAttribute.IMMOBILE], []) ]), GameObject('roomB') ], [], [ GamePassage(11, 'roomA', 'roomB', 'N', 'S', [GameObjectAttribute.INVISIBLE]) ], [ GamePassageRevealAction('button1', '', 11), GamePassageRevealAction('button1', '', 11) ], [], 'roomB', {}]) verdict = GameSyntaxChecker().check(game_internal) assert ( verdict == 'found multiple actions for the same actor, button1')
def test_syntax_checker_wrong_game16(self): game_internal = Game([[ GameObject('starting_room', [], [GameObject('door', [GameObjectAttribute.IMMOBILE])]), GameObject('ending_room') ], [], [ GamePassage(11, 'starting_room', 'ending_room', 'N', 'S', [GameObjectAttribute.INVISIBLE]) ], [GamePassageRevealAction('', '', 11)], [], 'ending_room', {}]) verdict = GameSyntaxChecker().check(game_internal) assert (verdict == 'found an action without actors')
def test_syntax_checker_wrong_game_12(self): game_internal = Game([[ GameObject( 'roomA', [], [GameObject('button', [GameObjectAttribute.IMMOBILE], [])]), GameObject('roomB') ], [], [ GamePassage(11, 'roomA', 'roomB', 'N', 'S', [GameObjectAttribute.INVISIBLE]) ], [GamePassageRevealAction('button', '', 13)], [], 'roomB', {}]) assert (GameSyntaxChecker().check(game_internal) == 'invalid passage identifiers in an action, 13')
def test_syntax_checker_good_game3(self): game_internal = Game([[ GameObject('starting_room', [], [GameObject('door', [GameObjectAttribute.IMMOBILE])]), GameObject('ending_room') ], [], [ GamePassage(11, 'starting_room', 'ending_room', 'N', 'S', [GameObjectAttribute.INVISIBLE]) ], [GamePassageRevealAction('door', '', 11)], [], 'ending_room', {}]) verdict = GameSyntaxChecker().check(game_internal) assert (verdict == '') assert (GameSolver().solve(game_internal) == [['use', '', 'door'], ['go', 'N']])
def test_syntax_checker_wrong_game27(self): game_internal = Game([[ GameObject('starting_room', [], [ GameObject('door', [GameObjectAttribute.IMMOBILE]), GameObject('key', []) ]), GameObject('ending_room') ], [], [ GamePassage(11, 'starting_room', 'ending_room', 'N', 'S', [GameObjectAttribute.INVISIBLE]) ], [GamePassageRevealAction('key', 'door', 11)], [], 'ending_room', {}]) verdict = GameSyntaxChecker().check(game_internal) assert (verdict == "action actor door must be mobile")
def test_syntax_checker_wrong_game22(self): game_internal = Game([[ GameObject('starting_room', [], [ GameObject('door', [GameObjectAttribute.IMMOBILE]), GameObject('box', [GameObjectAttribute.IMMOBILE], [GameObject('key', [GameObjectAttribute.IMMOBILE])]) ]), GameObject('ending_room') ], [], [ GamePassage(11, 'starting_room', 'ending_room', 'N', 'S', [GameObjectAttribute.INVISIBLE]) ], [GamePassageRevealAction('door', 'key', 11)], [], 'ending_room', {}]) verdict = GameSyntaxChecker().check(game_internal) assert (verdict == 'not top level stuffs cannot have attributes, key')
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")
def test_syntax_checker_wrong_game26(self): game_internal = Game([[ GameObject('starting_room', [], [ GameObject('door', [ GameObjectAttribute.IMMOBILE, GameObjectAttribute.INVISIBLE ]), GameObject('key') ]), GameObject('ending_room') ], [], [ GamePassage(11, 'starting_room', 'ending_room', 'N', 'S', [GameObjectAttribute.INVISIBLE]) ], [GamePassageRevealAction('door', 'key', 11)], [], 'ending_room', {}]) verdict = GameSyntaxChecker().check(game_internal) assert ( verdict == 'there must be exactly one action for each invisible object which reveals it, door' )
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')
def test_syntax_checker_wrong_game_20(self): game_internal = Game([[ GameObject('roomA', [], [ GameObject('handle1', [GameObjectAttribute.IMMOBILE], []), GameObject('handle2', [GameObjectAttribute.IMMOBILE], []), GameObject('crowbar') ]), GameObject('roomB') ], [GameObject('broken handle')], [ GamePassage(11, 'roomA', 'roomB', 'N', 'S', [GameObjectAttribute.INVISIBLE]) ], [ GamePassageRevealAction( 'handle1', 'crowbar', 11), GameObjectUseAction('handle2', 'crowbar', 'broken handle') ], [], 'roomB', {}]) verdict = GameSyntaxChecker().check(game_internal) assert ( verdict == 'found multiple actions for the same actor, crowbar')
def test_syntax_checker_good_game10(self): game_internal = Game( [[ GameObject('starting_room', [], [ GameObject('door', [GameObjectAttribute.IMMOBILE]), GameObject('key', []) ]), GameObject('strange_room'), 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 == "") assert (GameSolver().solve(game_internal) == [['take', 'key'], ['use', 'door', 'key'], ['go', 'W'], ['go', 'N']])
def test_syntax_checker_wrong_game24(self): game_internal = Game( [[ GameObject( 'starting_room', [], [GameObject('key', [GameObjectAttribute.INVISIBLE])]), GameObject('middle_room', [], [ GameObject('burning_candle'), GameObject('door', [GameObjectAttribute.IMMOBILE]) ]), GameObject('ending_room') ], [], [ GamePassage(11, 'middle_room', 'ending_room', 'N', 'S', [GameObjectAttribute.INVISIBLE]), GamePassage(12, 'starting_room', 'middle_room', 'N', 'S') ], [GamePassageRevealAction('door', 'key', 11)], [GameObjectRevealAction('burning_candle', 'key')], 'ending_room', {}]) verdict = GameSyntaxChecker().check(game_internal) assert ( verdict == 'subjects of revealing actions must be invisible initially, burning_candle' )
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)