Skip to main content

Polyomino task solver.

Project description

Polyomino-solver

Solving the problem of accurately paving polyominoes with a given set of shapes. The program translates the polymino problem into the language of the X-algorithm. The algorithm-x library is used to solve Algorithm X.

Training manual

In general, using the package looks like this:

  1. Connect the package and numpy
import numpy as np
from polyominator import polyomino
  1. Set the field as an array, where 1 is a cell for paving, 0 is not for paving (like a Boolean array). For example, a 3x3 square field will look like this:
area = np.array([
    [1,1,1],
    [1,1,1],
    [1,1,1]
])
  1. Set the shapes as arrays, where 1 is the element of the shape, 0 is the free space (again a Boolean array). For example, here is a 3-segment corner, a 2-segment stick, and a single segment, respectively:
corner = np.array([
    [1,1],
    [1,0],
])
stick = np.array([
    [1,1]
])
ceil = np.array([
    [1]
])

Please note that there is no fixed size of the array for the shapes. The main thing is that the shape fits into the array.

  1. Pass the field and the list of shapes to the `polyomino' class.
figures = [corner,corner,stick,ceil]
pm = polyomino(figures=figures,area=area)
  1. Get a single solution (with the argument get_only_one_solve = True) or a generator of all solutions (get_only_one_solve = False) using the solve method.

By default, get_only_one_solve = True.

solution = pm.solve()
#solutions_generator = pm.solve(False)

>>> [[0 0 2]
>>>  [0 1 2]
>>>  [3 1 1]]

What does the solution look like

The solution that (or which) the program will return to you, they look like an array with the same dimension as the field, and filled with numbers. If it seems to you that these numbers form shapes, it doesn't seem to you. When transferring figures to a class, they are numbered in the order of transfer (from 0). In this case:

  • 0: corner,
  • 1: corner,
  • 2: stick,
  • 3: ceil.

And these numbers form the silhouette of the figure in the place of the field in which this figure should be inserted.

Example

The field and the shapes for paving are given:

Paving field

Paving shapes

Then the search for the correct paving is presented in the file examples\example from readme.py . The solution looks like this:

>>> [[0 0 0 5]
>>>  [1 0 5 5]
>>>  [1 1 5 4]
>>>  [1 4 4 4]
>>>  [3 2 2 2]
>>>  [3 3 3 2]]

That is, the final arrangement of the shapes is:

Paved field

Notes

  • Theoretically, holes and protrusions in the fields are allowed, but they have not been tested for operability. For example:
example_area = [
    [1,1,1,0],
    [1,0,1,1],
    [1,1,1,0]
]
  • There is an 'is_rotate` flag in the class. In theory, it regulates whether the pieces can rotate. By default, rotates are allowed, but I have not tested how the program behaves when it is forbidden.

Thanks

Thanks to the Talos Principle and its beautiful puzzles, in particular the last yellow one, for inspiring the development. I sent rays of goodness to Elohim and Milton, may they be healthy forever and ever.

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

polyominator-1.0.1.tar.gz (5.6 kB view details)

Uploaded Source

Built Distribution

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

polyominator-1.0.1-py3-none-any.whl (5.6 kB view details)

Uploaded Python 3

File details

Details for the file polyominator-1.0.1.tar.gz.

File metadata

  • Download URL: polyominator-1.0.1.tar.gz
  • Upload date:
  • Size: 5.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.1

File hashes

Hashes for polyominator-1.0.1.tar.gz
Algorithm Hash digest
SHA256 0ca926476d480f5bd8cfd4db9f3fa85bd7bfd627c489aa78da63f6d145196f35
MD5 fa72ae0453aadae0173595e20a777d11
BLAKE2b-256 b6a285e2c6c9b40c9a9b89e55fee11ef65a25f1551b1f395d34a12cc398bb1b1

See more details on using hashes here.

File details

Details for the file polyominator-1.0.1-py3-none-any.whl.

File metadata

  • Download URL: polyominator-1.0.1-py3-none-any.whl
  • Upload date:
  • Size: 5.6 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.1

File hashes

Hashes for polyominator-1.0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 6ee613f2e8d5006e91f562d62632bd406a9391d53d3b6d995f8b1bcecc83c4be
MD5 abe41b53fb5f1e272a0ad727055b80c4
BLAKE2b-256 b1b4ba3366c03d04a58a6bf0735dd05d4b0bab7fee210dcda4d64670107e09d2

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