Puzzle15
A lib for a sliding block puzzle game: https://en.wikipedia.org/wiki/15_puzzle.
Allows making custom width and height puzzles.
Puzzles can be randomly generated or given as input.
Functionality
- Create N x M puzzle
- Random puzzle from given width and height.
- Given puzzle from string. Giving unsolvable puzzle causes error.
- Note that one of the cells if blank so numbers start from 1 and end in NxM - 1.
- Check possible moves (up, right, down, left) in the current puzzle position.
- Make a move. If move is invalid no action is taken.
- See puzzle representation.
- Check if puzzle is solved.
Usage
from puzzle15.puzzle import Puzzle
# Create a 4x4 random puzzle
puzzle = Puzzle.from_dimensions(4, 4)
# Create a puzzle from a string (use -1 for the blank cell)
puzzle_str = '1 2 3 4|5 6 7 8|9 10 11 12|13 14 15 -1'
puzzle = Puzzle.from_string(puzzle_str)
# Check possible moves
moves = puzzle.possible_moves()
print('Possible moves: ', moves)
# Make a valid move
if 'up' in puzzle.possible_moves():
puzzle.move('up')
# Make a random valid move
import random
moves = puzzle.possible_moves()
if moves: # Make sure there are available moves
random_move = random.choice(moves)
puzzle.move(random_move)
# See puzzle representation
print(puzzle)
grid = puzzle.grid()
print(grid)
# Check if puzzle is solved
if puzzle.is_solved():
print('Puzzle is solved!')
else:
print('Puzzle is not solved.')
Caution
Please only use str(puzzle) method when printing.
Otherwise make use of puzzle.grid() method.
If you couple to str(puzzle) and this method will change by introducing different
formatting or showing the board in a different way, your code will break.
Metadata
Release files for puzzle15 1.0.2
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | |
|---|---|---|---|---|
| puzzle15-1.0.2.tar.gz | 16.6 kB | Without provenance | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| puzzle15-1.0.2-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 32.7 kB
Release files / puzzle15-1.0.2.tar.gz
| Download URL | puzzle15-1.0.2.tar.gz |
|---|---|
| Size | 16.6 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
0a167a4378d79f6f6344a37adb7b9089873c1978d23dfb15c3d81e86a7cfa77b
|
|
BLAKE2b-256 checksum How to use checksums |
7e42f9b4308b1cb1b23d2dcdc52fb07ee24be61ebb7bd08a66d20dec126b6ab9
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.1.0 CPython/3.12.9
|
Release files / puzzle15-1.0.2-py3-none-any.whl
| Download URL | puzzle15-1.0.2-py3-none-any.whl |
|---|---|
| Size | 16.1 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
f13a7f099ade3562d94df8ac296af26b5d51b57c1cc9daf5fe446d3449bceba2
|
|
BLAKE2b-256 checksum How to use checksums |
10a0f0db1555614c171cfd00390c33805a75b6c2852713366b3398a3e3c026b3
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.1.0 CPython/3.12.9
|
Security for puzzle15 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.