Skip to main content

A Gymnasium environment for maze-based reinforcement learning

Project description

MazeGym

codecov PyPI version

A Gymnasium env for training reinforcement learning agents to navigate mazes.

Library used: GitHub.

9x9 maze

Random moves are used for this demo.

Maze9x9

21x21 maze

Random moves are used for this demo.

Maze21x21

35x15 maze

Random moves are used for this demo.

Maze35x15

Usage

Initiating the env via gym

import gymnasium as gym

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()

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: 0 for empty paths, 1 for walls, 2 for the agent, 3 for the goal.
  • Reward: 100 if the goal is reached, -1 for each step taken.
  • Done: True if the agent reaches the goal, False otherwise.
  • Truncated: True if maximum steps (3 × width × height) are exceeded, False otherwise.

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

mazegym-1.0.2.tar.gz (19.7 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

mazegym-1.0.2-py3-none-any.whl (19.4 kB view details)

Uploaded Python 3

File details

Details for the file mazegym-1.0.2.tar.gz.

File metadata

  • Download URL: mazegym-1.0.2.tar.gz
  • Upload date:
  • Size: 19.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.12.9

File hashes

Hashes for mazegym-1.0.2.tar.gz
Algorithm Hash digest
SHA256 28b25ebb3ed0a4fd5f778e2f53ea103a264db9197c62829f6ed4479e6c50ff7d
MD5 b78cdaa85f453d9edf870f0c1220290f
BLAKE2b-256 5395436b96d4c9907d58f251084069311b436019ab6538edd32d3f2f7cb490e8

See more details on using hashes here.

File details

Details for the file mazegym-1.0.2-py3-none-any.whl.

File metadata

  • Download URL: mazegym-1.0.2-py3-none-any.whl
  • Upload date:
  • Size: 19.4 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.12.9

File hashes

Hashes for mazegym-1.0.2-py3-none-any.whl
Algorithm Hash digest
SHA256 06214bc92d4155d21475e3f9007a5612e82711c20e45fbd5f57f82cd2c6d625b
MD5 dd9eb8056477cf6e4038cd90215dfd2d
BLAKE2b-256 d8f1ac33be68d6419e6f01f3ebbf396c85e40e4234b774b812276140ac64d5b8

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page