Skip to main content

Gym library for training RL agents on Rush Hour game

Project description

ParkingLotGym

codecov PyPI version

A custom AI Gymnasium environment for the Rush hour puzzle: https://en.wikipedia.org/wiki/Rush_Hour_(puzzle).

Library used: GitHub.

Example solvable in 60 moves

Random moves are used for this demo. Click on .gif if still.

ParkingLot60

Example solvable in 5 moves

Random moves are used for this demo. Click if .gif if still.

ParkingLot5

Usage

Initiating the env via gym

import gymnasium as gym

env_6x6_random = gym.make('Puzzle6x6Moves15-v0')
env_4x4_random = gym.make('Puzzle6x6Moves30-v0')

env_6x6_fixed = gym.make('Puzzle6x6Moves13Fixed-v0')
env_6x6_fixed = gym.make('Puzzle6x6Moves6Fixed-v0')

Initiating the env directly

from parkinglotgym import ParkingLotEnv

env_random = ParkingLotEnv(15)
env_fixed = ParkingLotEnv
("""
    ....O
    FF..O
    .AA..
    ..BB.
    .CC..
    .DD..
""")

Making moves

import gymnasium as gym

env_3x3_fixed = gym.make('Puzzle6x6Moves13Fixed-v0')

# Reset the environment
observation, info = env_3x3_fixed.reset()

# Make a random valid move
import random

# Grab list of vehicles with their available moves.
available_moves = info["available_moves"]
# Drop moves from now, leave only vehicles.
movable_vehicles = [v for v, moves in available_moves.items()]
# Select a random vehicle to move.
vehicle = random.choice(movable_vehicles)
# Select a random move for the chosen vehicle.
move = random.choice(available_moves[vehicle])

# Render the environment. The only render mode is 'human' which renders visual output.
env_3x3_fixed.render()

# Close the environment
env_3x3_fixed.close()

Environment Details

  • Action Space: MultiDiscrete([num_vehicles, max_moves*2], start=[2, -max_moves]) - First value selects vehicle ID (starting at 2), second value indicates steps to move (negative for backward, positive for forward). Moving 0 steps is not allowed.
  • Observation Space: Box(0, num_vehicles+1, (height, width), int32). Contains values: 0 for empty cells, 1 for walls, 2 and up for vehicles. '2` represents the main vehicle.
  • Reward: 0 if the puzzle is solved, -1 if not solved yet, -2 if invalid move.
  • Done: True if the puzzle is solved, 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

parkinglotgym-1.1.3.tar.gz (18.0 kB view details)

Uploaded Source

Built Distribution

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

parkinglotgym-1.1.3-py3-none-any.whl (17.9 kB view details)

Uploaded Python 3

File details

Details for the file parkinglotgym-1.1.3.tar.gz.

File metadata

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

File hashes

Hashes for parkinglotgym-1.1.3.tar.gz
Algorithm Hash digest
SHA256 8982846533abe2c235ab1de8cb50f26a1510a4812f9e3b304f8297fece4cd48f
MD5 77e10101a2991178bea865aa3d34c8e5
BLAKE2b-256 9d705f870685ff55d51b3b3ca45d7807862af80ecdc319e161ece1087f90fe40

See more details on using hashes here.

File details

Details for the file parkinglotgym-1.1.3-py3-none-any.whl.

File metadata

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

File hashes

Hashes for parkinglotgym-1.1.3-py3-none-any.whl
Algorithm Hash digest
SHA256 5f1f9a7d8b960577007a04f96ebcb912a36a1f2b305053c6369fb98c9a91e38a
MD5 4310406a7c90ae0f1c95e717b1c2da5c
BLAKE2b-256 7f3e6905e6ce6a08bbf521dd4da76afddcae0aacaed512d1d2735d277c5f004a

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