A Gymnasium environment for maze-based reinforcement learning
Project description
MazeGym
A Gymnasium env for training reinforcement learning agents to navigate mazes.
9x9 maze
Random moves are used for this demo.
21x21 maze
Random moves are used for this demo.
35x15 maze
Random moves are used for this demo.
Usage
Initiating the env via gym
import gymnasium as gym
import mazegym
env_9x9_random = gym.make('Maze9x9Random-v0')
env_35x15_random = gym.make('Maze35x15Random-v0')
env_5x5_fixed = gym.make('Maze5x5Fixed-v0')
env_3x7_fixed = gym.make('Maze3x7Fixed-v0')
Initiating the env directly
from mazegym import MazeEnvironment
#Random env
env_random = MazeEnvironment(width=10, height=5)
# Fixed env
fixed_grid = np.ones((3, 7), dtype=np.int8)
fixed_grid[1, :] = 0
fixed_grid[1, 0] = 2
fixed_grid[1, 6] = 3
env_fixed = MazeEnvironment(grid=grid)
Making moves
import gymnasium as gym
env_35x15_random = gym.make('Maze35x15Random-v0')
# Reset the environment
observation, info = env_35x15_random.reset()
# Make a random valid move
valid_moves = info.get("valid_moves")
move = random.choice(valid_moves)
observation, reward, done, truncated, info = env_35x15_random.step(move)
# Render the environment. The only render mode is 'human' which renders visual output.
env_35x15_random.render()
# Close the environment
env_35x15_random.close()
Configurable parameters:
- width: width of maze.
- height: height of maze.
- grid: User for custom mazes.
- vision_range: Range of tiles your agent can see forward. Agent only sees forward and remembers previously visited tiles. If vision_range is not specified all map is visible. -- wall_path_swap: Tuple accepting two elements. Allows environment randomness making a wall become a path and a path become a wall. First value is the transformation chance. The second value is the frequency of transformations. No effects if tuple value is None.
Either width and height or grid is required. Width ang height are used for random mazes while grid is used for custom mazes.
Environment Details
- Action Space: Discrete(4) - Four possible actions:
0(up),1(right),2(down),3(left). Invalid moves (moving into walls) results in an error. - Observation Space:
Box(0, 3, (height, width), int8). Contains values:0for empty paths,1for walls,2for the agent,3for the goal. - Reward:
100if the goal is reached,-1for each step taken. - Done:
Trueif the agent reaches the goal,Falseotherwise. - Truncated:
Trueif maximum steps(3 × width × height)are exceeded,Falseotherwise.
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file mazegym-1.2.1.tar.gz.
File metadata
- Download URL: mazegym-1.2.1.tar.gz
- Upload date:
- Size: 20.8 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.12.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
588b676d04b79b1fab4e3b75b2a35f3e63ad197bd59eca0a685bd3232f616bdb
|
|
| MD5 |
10d1eacfb4a6aa4048a41f75cfa7e0ca
|
|
| BLAKE2b-256 |
d496097ae6458508300a0608b486b199e5f7a22bb7a5697e5325fcea922ad92d
|
File details
Details for the file mazegym-1.2.1-py3-none-any.whl.
File metadata
- Download URL: mazegym-1.2.1-py3-none-any.whl
- Upload date:
- Size: 19.1 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.12.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
7546920fdd3a2961e37b21585f6e19df1262728af530740248883fc8d37bc439
|
|
| MD5 |
36ae063702c4d0f4c1841f1f48e2366c
|
|
| BLAKE2b-256 |
50638d689fcbb00071eadcfc30f3c247a26ad08c97373d0937ab15fd6fb29939
|