コード例 #1
0
def test_warning_no_player():
    expect_msg = "There is no player in the game. You can't call step method"
    with pytest.warns(Warning) as record:
        build_game.build_game(['    ', '  # '],
                              {'#': static.Static((255, 0, 0))}, 2)

    assert expect_msg in str(record[0].message)
コード例 #2
0
def test_too_much_information():
    expect_msg = "Some of the objects are not in the map."
    with pytest.raises(build_game.ObjectInfoException) as excinfo:
        build_game.build_game(['    ', '    '],
                              {'#': static.Static((255, 0, 0))}, 2)

    assert expect_msg in str(excinfo.value)
コード例 #3
0
def test_element_not_in_object_information():
    expect_msg = "There is no information for the object."
    with pytest.raises(build_game.ObjectInfoException) as excinfo:
        build_game.build_game(['    ', ' #  '],
                              {"?": static.Static((255, 0, 0))}, 2)

    assert expect_msg in str(excinfo.value)
コード例 #4
0
ファイル: game.py プロジェクト: Phu-archive/GridWorld
    def __init__(self, objs_lookup, map_size):
        self.objs_lookup = objs_lookup
        self.map_size = map_size

        # Just get the size of the object in the scene
        self._obj_size = list(self.objs_lookup.items())[0][1][0].size

        # Just create an object of the same size.
        _empty_tile = static.Static((255, 255, 255))
        _empty_tile.size = self._obj_size

        self.empty_tile_numpy = _empty_tile.numpy_tile
        self.reward = 0
        self.terminate = False

        # For reset the game - safe the start state
        self._start_state = copy.deepcopy(self.objs_lookup)

        # just to init everything
        self._list_players = self.get_list_players()
コード例 #5
0
            self._north()
        elif action == 1:
            self._south()

class GoldObj(interactive.Interactive):
    def __init__(self, color):
        super().__init__(color)

    def touch(self, env):
        env.add_reward(100)

    def consume(self, env):
        """Still Under developement"""

obj_information= {
    'P': DemoPlayer((0, 0, 255)),
    '#': static.Static((0, 0, 0)),
    'I': GoldObj((0, 255, 0))
}

env = build_game(ascii_art_world, obj_information, 2)
obs = env.reset()
env.display_map()

obs, reward, done = env.step(1)
print("Reward is {}".format(reward))
env.display_map()

obs, reward, done = env.step(1)
env.display_map()
コード例 #6
0
def test_finish_game():
    game = build_game.build_game(ascii_art_test, obj_information_test, 2)

    expected_objs_look_up = {
        (0, 0): [static.Static((0, 0, 0))],
        (1, 0): [static.Static((0, 0, 0))],
        (2, 0): [static.Static((0, 0, 0))],
        (3, 0): [static.Static((0, 0, 0))],
        (0, 1): [static.Static((0, 0, 0))],
        (3, 1): [static.Static((0, 0, 0))],
        (0, 2): [static.Static((0, 0, 0))],
        (3, 2): [static.Static((0, 0, 0))],
        (0, 3): [static.Static((0, 0, 0))],
        (1, 3): [static.Static((0, 0, 0))],
        (2, 3): [static.Static((0, 0, 0))],
        (3, 3): [static.Static((0, 0, 0))],
        (2, 1): [player.NormalPlayer((0, 255, 0))]
    }

    # Checking for types.
    assert len(game.objs_lookup.items()) == len(expected_objs_look_up.items())

    # Some how this works
    assert expected_objs_look_up == game.objs_lookup

    assert game.map_size == (4, 4)