Astera-org / minetest

Minetest is an open source voxel game engine with easy modding and game creation
https://www.minetest.net/
Other
0 stars 0 forks source link

Exposes some player attributes, player metadata, and hud strings #86

Closed mickvangelderen closed 1 week ago

mickvangelderen commented 1 week ago

Exposes some player attributes, player metadata, and hud strings (without processing) directly to python.

The gym environment uses that data to fill the info object:

{
  "hud_elements": [
    { "name": "", "text": "" },
    { "name": "", "text": "" },
    { "name": "score", "text": "Score: 0" },
    { "name": "health", "text": "Health: 20" },
    { "name": "food", "text": "Food: 600" },
    { "name": "water", "text": "Water: 600" }
  ],
  "player_health": 20,
  "player_health_max": 20,
  "player_breath": 10,
  "player_breath_max": 10,
  "player_is_dead": false,
  "player_metadata": {
    "hud_ids": "return {health=3,food=4,score=2,water=5}",
    "water": "600",
    "food": "600",
    "score": "0"
  }
}

Consumers of the environment can define additional observation spaces derived from this info like so:

additional_observation_spaces = {
    "health": minetest.minetest_env.AdditionalObservationSpace(
        space = gymnasium.spaces.Box(0, 20, (1,), dtype=np.int32),
        value_fn = lambda info: np.array(info["player_health"], dtype=np.int32)
    ),
    "food": minetest.minetest_env.AdditionalObservationSpace(
        space = gymnasium.spaces.Box(0, 1000, (1,), dtype=np.float32),
        value_fn = lambda info: np.array([float(info["player_metadata"]["food"])], dtype=np.float32)
    ),
    "water": minetest.minetest_env.AdditionalObservationSpace(
        space = gymnasium.spaces.Box(0, 1000, (1,), dtype=np.float32),
        value_fn = lambda info: np.array([float(info["player_metadata"]["water"])], dtype=np.float32)
    ),
}
mickvangelderen commented 1 week ago

@garymm I'm struggling to fix pytest tests/minetest_test.py::test_async_vector_env

FAILED tests/minetest_test.py::test_async_vector_env - ValueError: could not broadcast input array from shape (15,) into shape (1,)

Not even sure where the 15 is coming from. Don't have a call stack because the exception is re-raised on the main thread.

Using SyncVectorEnv to debug don't work because:

FAILED tests/minetest_test.py::test_async_vector_env - RuntimeError: minetest capnp error: kj/async.c++:1836: failed: expected threadLocalEventLoop == nullptr [5a91aa3aa030 == nullptr]; This thread already has an EventLoop.
garymm commented 1 week ago

I can sit with you to try to debug after lunch.