Skip to main content

ParkingLotPuzzle

codecov PyPI version

This lib simulates a RushHour puzzle created by Nob Yoshigahara: https://en.wikipedia.org/wiki/Rush_Hour_(puzzle).

You can choose from lots of preconfigured puzzles or input your custom puzzle configuration.

Known clients: GitHub.

Board definition.

Hash (#) represents the walls. Vehicles cannot move into walls.

Dot (.) represents the empty spaces. Cars can move freely into empty spaces.

Other characters represent vehicles. However, for standartization using capital letters for vehicles are encouraged. Letter A represents the main vehicle.

Goal of the game.

Move the main vehicle (A) to the right side of the board: the vehicle must be on the rightmost cell.

Example of the solved puzzle:

..BB..
C.....
C...AA
C.EKOO
DDEK..

Functionality

  • Create puzzle:
    • Provide a number of moves. Get a random preconfigured puzzle solvable in provided number of moves. Note that there are no puzzles solvable in 56, 57, 59 moves. Inputting these numbers will cause error.
    • Provide a custom NxM puzzle. If invalid puzzle is provided an error will be thrown.
  • Get a list of vehicles and their positions on the puzzle.
  • Get width and height of the puzzle.
  • Show puzzle representation.
  • Get a copy of the puzzle.
  • Show valid moves.
  • Make a valid move. Making an invalid move will throw an error and will not result in any action.
  • Check if puzzle is solved.

Library restriction

Vehicles which have a length of a single cell are not allowed since it is not clear which direction it is facing.

Usage

from parkinglotpuzzle.lot import Lot
# Create puzzle solvable in 60 moves.
lot = Lot(60)

# Create a custom puzzle.
self.valid_layout = """
....O
FF..O
.AA..
..BB.
.CC..
.DD..
"""
lot = Lot(self.valid_layout)

print(lot.query_vehicles())
# Shows vehicles and their positions: (x, y) of each occupied cell.
# {
#     'A': [(1, 2), (2, 2)],
#     'O': [(4, 0), (4, 1)],
#     'F': [(0, 1), (1, 1)],
#     'B': [(2, 3), (3, 3)],
#     'C': [(1, 4), (2, 4)],
#     'D': [(1, 5), (2, 5)]
# }

print(lot.dimensions())
# Shows (width, height) of the puzzle.

print(lot)
# Prints the puzzle:
# ....O
# FF..O
# .AA..
# ..BB.
# .CC..
# .DD..

print(lot.grid())
# ['....O', 'FF..O', '.AA..', '..BB.', '.CC..', '.DD..']

print(lot.query_legal_moves())
# Shows legal moves. Given example, moves are:
# {
#     'A': (1, 2), # Main vehicle can move 1 step back and 2 forward. 
#     'O': (0, 4), # O vehicle cannot move back and can move 4 steps forward.
#     'F': (0, 2), # F vehicle cannot move back and can move 2 steps forward.
#     'B': (2, 1), # B vehicle can move 2 steps back and a step forward.
#     'C': (1, 2), # C vehicle can move a step back and a 2 steps forward.
#     'D': (1, 2) # D vehicle can move a step back and a 2 steps forward.
# }

# Check if puzzle is solved.
print(lot.is_solved())
#False

# Make a move which solves the puzzle.
lot.move('A', 2)

print(lot)
# ....O
# FF..O
# ...AA
# ..BB.
# .CC..
# .DD..

print(lot.is_solved())
#True

Caution

Please only use str(lot) method when printing. Otherwise make use of lot.grid() method.

If you couple to str(lot) and this method will change by introducing different formatting or showing the board in a different way, your code will break.

Game configuration database

The rush_sample.txt contains a modified sample from database of game configurations created by Michael Fogleman https://www.michaelfogleman.com/rush/. Modified means o is replaced with . and x with #.

Extra sources

A good analysis of the game: https://www.michaelfogleman.com/rush/.

Metadata

Release files for parkinglotpuzzle 1.0.2

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for parkinglotpuzzle 1.0.2
File Size Uploaded Provenance
parkinglotpuzzle-1.0.2.tar.gz 34.4 MB Without provenance Details

Built distribution (wheel)

Table of built distributions (wheels) for parkinglotpuzzle 1.0.2
File Interpreter ABI Platform
parkinglotpuzzle-1.0.2-py3-none-any.whl Python 3 none any Details

Total release size: 69.2 MB

Release files / parkinglotpuzzle-1.0.2.tar.gz

Download URL parkinglotpuzzle-1.0.2.tar.gz
Size 34.4 MB
Tags Source
SHA-256 checksum
How to use checksums
7f1df0998d8a603577d2944b582253d25a3f337b8704fe746bad562b511c8f47
BLAKE2b-256 checksum
How to use checksums
182dcc5e9240f0ebd5ec43f3128ae874799dc939d4eee4338fe46acdbb039a3a
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.12.9

Release files / parkinglotpuzzle-1.0.2-py3-none-any.whl

Download URL parkinglotpuzzle-1.0.2-py3-none-any.whl
Size 34.8 MB
Tags Python 3
SHA-256 checksum
How to use checksums
ad1b3da860a4ad9d6c6a05ad58693709937a8d6678e2d4192d7cadad6076ce02
BLAKE2b-256 checksum
How to use checksums
a3e041962c6b9c781dde2736380e22a8b780298e7d69844daa96247570e5ce3e
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.12.9

Security for parkinglotpuzzle 1.0.2

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page