oldfartdeveloper / citysolve

Solve a wooden puzzle using Minisync

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

README

Purpose

I have a wooden puzzle that consists of a square base and buildings that are to be arranged on it. All of the buildings only fit on it if they are arranged precisely; the object of the puzzle is to figure out what the arrangement needs to be.

Needless to say, I suck at this puzzle, and this is my attempt to write a computer program to solve it.

Description of Puzzle Pieces

Here are the puzzle pieces grouped by piece shape:

piece shapes

Here are the same pieces with names added:

piece parts

Description of Puzzle Parts

The puzzle consists of the board and 12 pieces:

Board

The board defines a 7 x 7 cell matrix upon which the pieces must all be arranged.

Tee

A tee is shaped like a flattend "T" character and occupies 4 places in the matrix as follows:

tee

There are 3 of these.

Ell

An ell looks like an "L":

ell

There are 3 of these.

LEll

A lell looks like a reversed "L" (i.e. the 'foot' is facing left):

lell

There is only 1 of these.

Left

A left looks like it zigzags left then straightens out:

left

There are 2 of these.

Rite

A right looks like it zigzags right then straightens out:

rite

There are 2 of these.

Plus

A plus has a center and 4 spokes:

plus

There is only 1 of these and it is unusual in that it only has one unique position.

Strategy

After thinking about this A LOT, here's my my approach:

Rules

  1. Preorder the list of pieces to try in order.

  2. Find the first piece that fits in the top-left cell of the board. If rotating the piece's orientation helps it to fit, then do so.

  3. Similarly find the next piece that fits the next cell to the right without violating the board's boundary, nor overlap the previously-placed piece to its left

  4. Repeat this process for the remainder of the first row so that:

    1. All the cells in the first row are filled.

    2. No pieces overlap each other.

    3. None of the pieces placements spill outside the board's boundary.

  5. Repeat for the remaining rows.

  6. When you cannot find a piece to play, backup to the previous piece (including the previous row) and see if any of the following work:

    1. Can the previous piece be reoriented successfully? If so, keep it in its new orientation and solve the next piece.

    2. If not, select the next available piece type and see if you can replace the current piece with it. If so, keep the replacement. If not, repeat this process for the "previous previous" piece.

  7. The currently played pieces are on a stack. When you get stuck, you back up the stack to a piece orientation or type that you haven't tried yet in that stack position and try that.

  8. When the stack contains all the pieces and no cells are left unoccupied, then the game is solved.

I get the idea above, but it needs polishing.

Rules Implications

For each piece, it is always placed on the board in the topmost leftmost open square. That means that, for each of a piece's orientations, the piece's top square must be the one placed in the board's current topmost leftmost open square. This is because all other squares in the piece cannot be placed there because they will possibly:

  1. Overlap a board square that has already been filled by a previous-placed piece.

  2. Spill outside the board's playing area.

If the piece has more than one topmost square for a given orientation, then the only one that can be used is the leftmost top square. This is because any other top square, by definition, would either overlap a previous piece's square or would spill outside the board's playing area.

Each stack position defines a piece type and its orientation

So we need to define the notion of how orientation is used.

  • Should we just associate and enumeration with each possible orientation for the piece type?

    1. The "T's", "L's" and "Z's" each have 4 possible orientations. So when we need to update a type, before we do we have to step through the existing candidate through each of its candidate orientations first.

    2. Each orientation needs to have the associated topleft position to determine how to assign the piece.

Here are the orientation candidates for each of the pieces:

Left Orientations

1 2
leftPos1 leftPos2

Rite Orientations

1 2
rightPos1 rightPos2

Tee Orientations

1 2 3 4
tee1 tee2 tee3 tee4

Plus Orientation

Only one:

plus

Ell Orientations

1 2 3 4
ell1 ell2 ell3 ell4

LEll Orientations

1 2 3 4
lell1 lell2 lell3 lell4

About

Solve a wooden puzzle using Minisync

License:MIT License


Languages

Language:Shell 100.0%