Skip to content

Commit

Permalink
📝 Make examples doc more clear and exaustive
Browse files Browse the repository at this point in the history
  • Loading branch information
MathisFederico committed Aug 19, 2024
1 parent 5a8934b commit b161183
Show file tree
Hide file tree
Showing 2 changed files with 56 additions and 22 deletions.
57 changes: 44 additions & 13 deletions src/hcraft/examples/__init__.py
Original file line number Diff line number Diff line change
@@ -1,31 +1,62 @@
"""#HierarchyCraft environement examples.
Here is the table of available HierarchyCraft environments examples.
Here is the list of available HierarchyCraft environments examples.
If you built one of your own, send us a pull request so we can add it to the list!
##Minecraft inspired
See `hcraft.examples.minecraft` for more details.
[CLI keyword: `minecraft`]
| Gym name | Task description |
|:---------------------------------|:-----------------------------------------------------------------------|
| MineHcraft-NoReward-v1 | No task (Sandbox) |
| MineHcraft-Stone-v1 | Get the cobblestone item mining it with a wooden pickaxe |
| MineHcraft-Iron-v1 | Get the iron-ingot item smelting raw ore gathered with a stone pickage |
| MineHcraft-Diamond-v1 | Get the diamond item mining it with an iron pickaxe |
| MineHcraft-EnchantingTable-v1 | Craft the enchanting table from a book, obsidian and diamonds |
| MineHcraft-Dragon-v1 | Get the ender-dragon-head by killing it in the ender |
| MineHcraft-[name]-v1 | Get one of the Item of given `name` where Item is in env.world.items |
| MineHcraft-v1 | Get all items at least once |
##Minigrid inspired
[CLI keyword: `minicraft`]
| Gym name | Documentation reference |
|:---------------------------------|:------------------------------------------------|
| MiniHCraftEmpty-v1 | `hcraft.examples.minicraft.empty` |
| MiniHCraftFourRooms-v1 | `hcraft.examples.minicraft.fourrooms` |
| MiniHCraftMultiRoom-v1 | `hcraft.examples.minicraft.multiroom` |
| MiniHCraftCrossing-v1 | `hcraft.examples.minicraft.crossing` |
| MiniHCraftKeyCorridor-v1 | `hcraft.examples.minicraft.keycorridor` |
| MiniHCraftDoorKey-v1 | `hcraft.examples.minicraft.doorkey` |
| MiniHCraftUnlock-v1 | `hcraft.examples.minicraft.unlock` |
| MiniHCraftUnlockPickup-v1 | `hcraft.examples.minicraft.unlockpickup` |
| MiniHCraftBlockedUnlockPickup-v1 | `hcraft.examples.minicraft.unlockpickupblocked` |
##Parametrised toy structures
| Gym name | CLI name | Reference |
|:---------------------------------|:------------------|:------------------------------------------------|
| MineHcraft-v1 | `minecraft` | `hcraft.examples.minecraft` |
| MiniHCraftEmpty-v1 | `minicraft` | `hcraft.examples.minicraft.empty` |
| MiniHCraftFourRooms-v1 | `minicraft` | `hcraft.examples.minicraft.fourrooms` |
| MiniHCraftMultiRoom-v1 | `minicraft` | `hcraft.examples.minicraft.multiroom` |
| MiniHCraftCrossing-v1 | `minicraft` | `hcraft.examples.minicraft.crossing` |
| MiniHCraftKeyCorridor-v1 | `minicraft` | `hcraft.examples.minicraft.keycorridor` |
| MiniHCraftDoorKey-v1 | `minicraft` | `hcraft.examples.minicraft.doorkey` |
| MiniHCraftUnlock-v1 | `minicraft` | `hcraft.examples.minicraft.unlock` |
| MiniHCraftUnlockPickup-v1 | `minicraft` | `hcraft.examples.minicraft.unlockpickup` |
| MiniHCraftBlockedUnlockPickup-v1 | `minicraft` | `hcraft.examples.minicraft.unlockpickupblocked` |
| TowerHcraft-v1 | `tower` | `hcraft.examples.tower` |
| RecursiveHcraft-v1 | `recursive` | `hcraft.examples.recursive` |
| LightRecursiveHcraft-v1 | `light-recursive` | `hcraft.examples.light_recursive` |
| Treasure-v1 | `treasure` | `hcraft.examples.treasure` |
##Stochastic parametrised toy structures
| Gym name | CLI name | Reference |
|:---------------------------------|:------------------|:------------------------------------------------|
| RandomHcraft-v1 | `random` | `hcraft.examples.random_simple` |
##Other examples
| Gym name | CLI name | Reference |
|:---------------------------------|:------------------|:------------------------------------------------|
| Treasure-v1 | `treasure` | `hcraft.examples.treasure` |
"""


import hcraft.examples.minecraft as minecraft
import hcraft.examples.minicraft as minicraft
import hcraft.examples.random_simple as random_simple
Expand Down
21 changes: 12 additions & 9 deletions tests/examples/minecraft/test_gym_make.py
Original file line number Diff line number Diff line change
@@ -1,49 +1,52 @@
from typing import List, Type, TypeVar
from typing import TYPE_CHECKING, List, Type, TypeVar
import pytest
import pytest_check as check


from hcraft.examples.minecraft.env import MineHcraftEnv
from hcraft.task import GetItemTask, GoToZoneTask, PlaceItemTask, Task

gym = pytest.importorskip("gym")
if TYPE_CHECKING:
import gym

gym_module: "gym" = pytest.importorskip("gym")


def test_no_reward_gym_make():
env: MineHcraftEnv = gym.make("MineHcraft-NoReward-v1")
env: MineHcraftEnv = gym_module.make("MineHcraft-NoReward-v1")
check.equal(env.purpose.tasks, [])


def test_stone_gym_make():
env: MineHcraftEnv = gym.make("MineHcraft-Stone-v1")
env: MineHcraftEnv = gym_module.make("MineHcraft-Stone-v1")
check.equal(len(env.purpose.tasks), 1)
task = env.purpose.tasks[0]
check.equal(task.name, "Get cobblestone")


def test_iron_gym_make():
env: MineHcraftEnv = gym.make("MineHcraft-Iron-v1")
env: MineHcraftEnv = gym_module.make("MineHcraft-Iron-v1")
check.equal(len(env.purpose.tasks), 1)
task = env.purpose.tasks[0]
check.equal(task.name, "Get iron_ingot")


def test_diamond_gym_make():
env: MineHcraftEnv = gym.make("MineHcraft-Diamond-v1")
env: MineHcraftEnv = gym_module.make("MineHcraft-Diamond-v1")
check.equal(len(env.purpose.tasks), 1)
task = env.purpose.tasks[0]
check.equal(task.name, "Get diamond")


def test_enchanting_table_gym_make():
env: MineHcraftEnv = gym.make("MineHcraft-EnchantingTable-v1")
env: MineHcraftEnv = gym_module.make("MineHcraft-EnchantingTable-v1")
check.equal(len(env.purpose.tasks), 1)
task = env.purpose.tasks[0]
check.equal(task.name, "Get enchanting_table")


def test_all_items_gym_make():
env: MineHcraftEnv = gym.make("MineHcraft-v1")
env: MineHcraftEnv = gym_module.make("MineHcraft-v1")

TaskOfType = TypeVar("TaskOfType")

Expand Down Expand Up @@ -76,7 +79,7 @@ def _task_names_of_type(


def test_dragon_gym_make():
env: MineHcraftEnv = gym.make("MineHcraft-Dragon-v1")
env: MineHcraftEnv = gym_module.make("MineHcraft-Dragon-v1")
env.reset()
expected_tasknames = {
"Go to meadow",
Expand Down

0 comments on commit b161183

Please sign in to comment.