Skip to main content

Lib to make NxM - 1 sliding puzzles

Project description

Puzzle15

codecov

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.
  • Check possible moves (up, right, down, left) in the current puzzle position.
  • Make a move.
  • 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)
print(puzzle)

# Create a puzzle from a string (use -1 for the blank)
puzzle_another = "1 2 3 4|5 6 7 8|9 10 11 12|13 14 15 -1"
puzzle = Puzzle.from_string(puzzle_another)
print(puzzle)

# Check possible moves
moves = puzzle.possible_moves()
print("Possible moves: ", moves)

# Make a move
if 'up' in puzzle.possible_moves():
    puzzle.move('up')
    print(puzzle)

# 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.

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

puzzle15-1.0.0.tar.gz (16.3 kB view details)

Uploaded Source

Built Distribution

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

puzzle15-1.0.0-py3-none-any.whl (15.8 kB view details)

Uploaded Python 3

File details

Details for the file puzzle15-1.0.0.tar.gz.

File metadata

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

File hashes

Hashes for puzzle15-1.0.0.tar.gz
Algorithm Hash digest
SHA256 6765d2fbb7b279c0f68abe5a2165552632ec2670a104dc23242b34e83e833a5b
MD5 876d51594788cfb872e0da28f36f916f
BLAKE2b-256 2b8e6b0d589c6d60d4eda0b124dcaf4de757a8cca2e260c91848ead863376453

See more details on using hashes here.

File details

Details for the file puzzle15-1.0.0-py3-none-any.whl.

File metadata

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

File hashes

Hashes for puzzle15-1.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 7c08994d7b8113268af88115c93a0bbe10379d4e7a10515b5ceaf27831ef244a
MD5 2acd0a8a1c6633d8561d433d4597b60a
BLAKE2b-256 15a23f36c3e4327ba8318aaf5d1e62a76cb76379fdbc06e1b88527e3004d0fbb

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