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.

Методичка

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.tar.gz (5.7 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-py3-none-any.whl (5.6 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: polyominator-1.0.tar.gz
  • Upload date:
  • Size: 5.7 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.tar.gz
Algorithm Hash digest
SHA256 a39c56ea4d36411089d09895a9366d0df49036b0569f7696d9bdc2c97d23ad1b
MD5 556eadd230ebb24feddf49a090123752
BLAKE2b-256 fdfb99149c43f9233f53ba4e023388c38bb4a1f5b3eeaa27735451833b392745

See more details on using hashes here.

File details

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

File metadata

  • Download URL: polyominator-1.0-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-py3-none-any.whl
Algorithm Hash digest
SHA256 f71eec47ac88143aa0892653a8b6c40443c593480e848250ff904b119c9293ee
MD5 7da9172843e7b14303d40c356de5176e
BLAKE2b-256 f5103463590e15def489311676a048e777d686385f1965809a08dceab792f159

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