Optimized paths: a sliding search held to the grid, and how far to trust its answer
How the Solver's Automatically use optimized paths option works on boards of blocks, what its move counts prove, and why the normal full search takes so much longer
Summary
- What it does. On a board that divides into a grid of cells that its blocks fill, optimized paths lets a piece come to rest only on that grid. Pieces still slide through the places in between; they just may not stop there. On "Abe 1 to 6 Heart" this leaves 240 resting places out of 2,511.
- What is certain. The search is the same exhaustive search as a normal solve, over fewer arrangements. The path it finds is a real solution, and it is the shortest of all solutions that only rest on the grid.
- What is not certain. A solution that rests a piece off the grid could be shorter. So an (optimized) result is an upper limit on the fewest moves, not a proof of it, and "no solution" proves nothing.
- How good the limit is. On boards where every piece is made of whole cells it is exact: this can be proved, and a Klotski scaled up two and three times confirms it (81 moves either way). On boards with small pieces riding in the blocks' holes, such as the Heart puzzles, it has matched the full search on all five problems where the full search finished (14 to 40 moves). The longer results, 47, 50 and 56 moves, have not been checked by a full search. A small hand-made board shows that the grid can miss: no solution on the grid, four moves in full.
- Why the normal Solve is so much slower. It counts every resting place. On the same problem its levels were 207 times wider after 14 moves from each end, and the gap was still growing. On a 40-move problem the full search took 8,852 seconds and 5.09 billion arrangements; optimized paths took 2.3 seconds and 6.9 million.
- What the search counts
- The grid, and the stops it leaves
- How the search uses the grid
- How sure is the answer?
- How it differs from the normal Solve
- Which to use
1. What the search counts
In a sliding puzzle one move is one piece sliding anywhere it can reach while the others stay where they are. It may go any distance and turn any number of corners. With Allow Nested Slides, a piece may also carry the pieces nested inside its outline. The Solver looks for the fewest such moves from the start to the goal.
An arrangement is the position of every piece at once. The Solver searches level by level: every arrangement one move from the start, then every arrangement two moves away, and so on until the goal turns up. (The companion page describes that search and how it runs from both ends.) The work is the number of arrangements, so what matters is how many places each piece can come to rest. This page calls such a place a stop.
The boards are drawn on a grid of small cells, and a piece can rest at every cell position it fits. Many sliding puzzles are coarser than they are drawn. Figure 1 shows one: an 18 by 18 board of six blocks, each 6 cells high and 6 or 12 wide, with seven 4 by 4 pieces riding in the blocks' holes. Its solutions only ever move a block by a whole block's width. But as far as the search can tell, a block that slides into an empty space can also stop one, two, three, four or five cells of the way in, and each of those is a new arrangement with moves of its own.
2. The grid, and the stops it leaves
2.1 Finding the grid
The Solver works the grid out from the board. It takes the largest cell size, above one, for which all of these hold:
- the size divides the board's width and height;
- at least one piece measures a whole number of such cells each way (a block);
- every block starts on the grid's lines, and fills its goal on them;
- the grid leaves fewer stops than there were.
For Figure 1 that is a size of 6: a 3 by 3 grid. A board that fits no such grid has no optimized search; the option then does nothing and every stop is searched.
2.2 Where each piece may stop
A piece may rest only where its position within a cell of the grid, its offset, is one that the grid allows it:
- Blocks get the offsets at which they start and end, which by the rule above is the grid's lines. A block rests only in whole cells.
- Smaller pieces get every offset at which a piece of the same shape starts or fills a goal. Pieces that swap places therefore share their offsets, and so do copies.
- Holes. A piece also gets the offsets at which it lies wholly inside another piece's outline while that piece is on the grid. This covers a hole that no piece happens to start in.
- A piece with no offsets at all may stop anywhere, so the grid never freezes a piece it knows nothing about.
The seven small pieces of Figure 1 start and end in holes at three different offsets, so each of them has three stops in every cell of the grid.
| Pieces of Figure 1 | Stops each, full search | Stops each, on the grid | Fewer by |
|---|---|---|---|
| Five 6 by 6 blocks | 169 | 9 | 18.8× |
| One 12 by 6 block | 91 | 6 | 15.2× |
| Seven 4 by 4 pieces | 225 | 27 | 8.3× |
| All 13 pieces together | 2,511 | 240 | 10.5× |
These totals are the ones the Solver shows in its question before a solve. They count stops on the empty board; the number of arrangements is roughly what you get by combining a stop for every piece, so a tenfold cut for each piece is a far larger cut for the board as a whole (section 5).
3. How the search uses the grid
- Pieces pass through, they do not stop. When a piece moves, the search still follows it cell by cell through every position it can reach. It records an arrangement only where the piece is at a stop. So a block can cross an empty cell on its way to the next one, and a small piece can slide the length of the board, exactly as in a full search.
- A group stops only where all of it may. With nested slides, a block that carries small pieces can rest only where every piece of the group is at one of its own stops.
- Shorter keys. Each arrangement is stored as one number with a field for each piece. With the grid, a field only has to number the piece's stops, not all its positions. The Figure 1 board fits 64 bits this way and needs 128 in a full search. A larger board, "Abe 1 to 8 Heart", needs about 170 bits in full, which is more than the fast search can hold; with the grid it needs 100.
- Both ends. When every piece has a goal position the search runs from the start and from the goal until the two meet, with or without the grid.
- Stops of one cell searched as one. When the search has to run from the start alone, with nested slides, a small piece that could be at any of its stops in an otherwise empty cell is searched as a single arrangement, and put in the right place when a block arrives over it. This finds the same moves in about a third of the arrangements.
The result says how it was found. The problems list shows 47 moves (optimized) or no solution (optimized), and the file keeps that label. When the option's box is off, Solve asks first whenever the board fits a grid: Use Optimized Paths for this solve, or Full Search.
4. How sure is the answer?
The question has two halves, and they have different answers.
4.1 Within the grid: certain
Optimized paths is not a shortcut inside the search. It is the same exhaustive level search as a normal solve, run on a smaller set of arrangements. Everything that search guarantees still holds for that set:
- the path it returns is a real solution: every step is a legal move of the full puzzle;
- no solution that rests only at stops of the grid has fewer moves;
- if it reports no solution, then no solution rests only at stops of the grid.
The search itself is checked heavily. Its results are compared in the tests with an older, independent search on thousands of generated boards; the search from both ends was compared with the search from one end on 5,669 boards; and every path returned is replayed move by move.
4.2 Against the true minimum: an upper limit
What the grid cannot rule out is a solution that parks a piece off the grid and is shorter for it. So the honest reading of 47 moves (optimized) is "47 moves is possible, and the fewest is 47 or less". How often is it less? That depends on the kind of board.
4.3 Boards of whole-cell pieces: exact
If every piece is made of whole cells of the grid, the floor is too, every piece starts and ends on the grid's lines, and nested slides are off, then the grid loses nothing. The argument is short.
Take any solution of the full puzzle. At every moment, pull each piece back to the nearest grid line on its left and the nearest one above it. In other words, round both of its coordinates down to a whole number of cells.
- Nothing overlaps. Two whole cells that did not overlap were at least a cell apart in one direction. Rounding both down keeps them at least a cell apart. So pieces made of whole cells that did not overlap still do not.
- Nothing leaves the board. A cell of a piece that was inside the floor rounds to a floor cell it was already touching.
- A move stays a move. While one piece slides, the others do not move, so their rounded positions do not move either. The sliding piece's rounded position either stays put or steps one cell at a time through free cells. One move of the full solution becomes one move on the grid, or none.
The start and the goal are on the grid, so rounding leaves them alone. The rounded solution is therefore a solution on the grid with no more moves than the one we started from. Applied to a shortest solution, it shows the grid has one just as short.
This can be tested. Klotski is a board of whole-cell pieces whose fewest moves, counted the way ShapeLogic counts them, is known to be 81. Drawn at its usual size it has no grid to find. Drawn with every cell doubled or tripled, a full search has two or three times as many places to stop along every slide, and the Solver finds a grid of 2 or 3:
| Scale | Board | Grid found | Stops, full → grid | Full search: moves | arrangements | Optimized: moves | arrangements |
|---|---|---|---|---|---|---|---|
| 1× | 4 by 5 | none | 81 | 23,791 | 81 | 23,791 | |
| 2× | 8 by 10 | 2 cells | 528 → 171 | 81 | 107,021 | 81 | 23,791 |
| 3× | 12 by 15 | 3 cells | 1,081 → 171 | 81 | 302,909 | 81 | 23,791 |
The full search finds 81 moves at every scale, while its work grows from 23,791 arrangements to 302,909. Optimized paths finds 81 as well, and at every scale it visits exactly the 23,791 arrangements of the small board: the grid has undone the scaling and nothing else. (At 1× no grid is found, so the optimized run is the full search.)
4.4 Boards with small pieces: not proved, and it can fail
The argument above needs whole cells. The Heart boards break that in two ways: the small pieces are smaller than a cell, and the blocks have holes. Rounding a small piece to the grid can push it out of the hole it sits in or into a wall. So nothing guarantees that a part-way stop never helps there, and there are two ways it could:
- A small piece may need to wait somewhere that is not one of its offsets. Its stops are only the offsets at which pieces of its shape start, end or fit a hole. A pocket in the floor, or a spot half-way down a corridor, is not among them.
- A block parked part of the way changes which holes face each other and which gaps are open. That could let a small piece cross between two blocks that never line up on the grid.
The first is easy to show on a small board. Figure 3 is taken from the engine's tests. Two unit pieces have to change places along a corridor one cell wide. The only way is for one of them to step up into a pocket while the other passes. The corner block gives the board a grid of 2, and the pocket is one cell up, at an offset no unit piece starts or ends at. A full search solves the board in four moves. On the grid it has no solution.

4.5 What the Heart boards show so far
An earlier version of the "Abe 1 to 6 Heart" file had five shorter problems, short enough for the full search to finish. Optimized paths found the same number of moves on all five.
| Problem | Fewest moves, full search | Moves, optimized | Arrangements, optimized |
|---|---|---|---|
| Mid 0 to Mid 1 | 14 | 14 | 82,456 |
| Mid 1 to Mid 2 | 14 | 14 | 177,100 |
| Mid to End | 16 | 16 | 215,063 |
| Start to Mid 0 | 31 | 31 | 3,115,279 |
| Start to End | 40 | 40 | 6,861,036 |
The file's three current problems come out at 50, 56 and 47 moves. No full search of them has finished, so those numbers are upper limits. The one-ended search of release 1.8.1 found the same 56 and 47 (it did not finish the 50). But both searches rest on the same grid, so their agreement checks the search and not the grid.
Putting it together:
| Claim about an (optimized) result | Standing |
|---|---|
| The moves shown solve the puzzle | Certain |
| No shorter solution rests only on the grid | Certain |
| No shorter solution exists at all, on a board of whole-cell pieces without nested slides | Certain: proved above, confirmed on Klotski at two scales |
| No shorter solution exists at all, on a board with small pieces in holes | Not proved. Held on 5 of 5 problems checked (14 to 40 moves); unchecked for 47, 50 and 56 |
| "No solution" means there is none | No. Figure 3 is a board where it is wrong |
Five agreements out of five is encouraging, and all five are on the same board with the same pieces as the longer problems. It is still a small sample, and a longer solution has more moves in which a part-way stop could pay off. We do not think a number can honestly be put on it. The only way to turn an (optimized) count into a proved minimum is to run the full search, and the next section shows what that costs.
5. How it differs from the normal Solve
The normal Solve, which the question before a solve calls Full Search, and optimized paths are the same search. Both go level by level, on every core, from both ends where the puzzle allows, writing to disk what outgrows memory, and both can be paused and continued. The one difference is the set of places a piece may rest. Everything else follows from that.
| Normal Solve (Full Search) | Optimized paths | |
|---|---|---|
| A piece may rest | At every position it fits | Only at its stops on the grid |
| Works on | Every sliding puzzle | Boards that fit a grid of blocks, with starts placed |
| The moves found | The fewest there are: proved | The fewest on the grid: an upper limit on the fewest there are |
| "No solution" | Proved | Proves nothing; a full search may find one |
| Stops, Figure 1 board | 2,511 | 240 |
| Key for one arrangement, Figure 1 board | 128 bits | 64 bits |
| Result shown as | 47 moves | 47 moves (optimized) |
5.1 Why the normal Solve takes so much longer
Every part-way position is an arrangement. When a block slides into an empty cell of the grid in Figure 1, optimized paths records one new arrangement. The full search records six: the block one cell in, two cells in, and so on. Each of the six is expanded in turn, and from each of them every other piece gets to make its own moves, part-way ones included. Two blocks each half-way into a cell, with a small piece at any of fifteen positions along a row, are all different arrangements that the search has to visit, sort and store. Almost none of them is on a shortest solution.
The effect multiplies across the pieces. The table in section 2 shows about ten times fewer stops for each piece. An arrangement is a stop for every piece at once, so the cut in arrangements is far larger than ten. Figure 4 measures it on Problem 3, the same search run both ways from both ends. One move from the start the full search has 36 arrangements and optimized paths 6. After five moves it is 36,655 against 434. After fourteen it is 29.5 million against 142,316: 207 times as many, with the ratio still rising at every level.
The levels also grow faster. At level 14 each level of the full search was 1.71 times the one before; for optimized paths the figure was 1.57, falling to 1.30 by the end. A higher growth rate compounds: it is why the ratio in Figure 4 keeps widening instead of settling.
Each arrangement costs more. The full search needs a 128-bit key for this board where the grid needs 64, so the same number of arrangements takes more memory and more disk. More arrangements at more bytes each means the search leaves memory sooner, and a search working from disk is slower again.
Large boards fall off the fast search. The level search can hold keys of up to 128 bits. A full search of a board the size of "Abe 1 to 8 Heart" needs about 170, so it drops to the original search: one core, memory only, about 11,000 arrangements a second where the level search does millions.
5.2 What it comes to
The one like-for-like pair measured to the end is the 40-move problem of the earlier file, before the search ran from both ends:
| "Start to End", 40 moves | Time | Arrangements |
|---|---|---|
| Normal Solve (full search) | 8,852 s | 5.09 billion |
| Optimized paths | 2.3 s | 6.9 million |
| Ratio | 3,800× | 740× |
For the 47-move Problem 3 there is no finished full search to compare with. The run in Figure 4 gives a rough idea of what one would take. It was 28 of the 47 moves deep after 134 million arrangements, with about ten more levels to build at each end. If its levels kept growing at 1.71 it would reach about 30 billion arrangements; if the growth eased the way the optimized search's did, about 5 billion. Either way that is hundreds to more than a thousand times the 18.4 million that optimized paths needed: hours of search and tens to hundreds of gigabytes of disk, against a few seconds. This is an estimate from the first 150 seconds, not a measurement.
6. Which to use
- To find a solution, or to see whether a design works: optimized paths. On a board of blocks it answers in seconds what a full search answers in hours or not at all.
- On a board where every piece is made of whole cells: optimized paths gives the true fewest moves (section 4.3).
- To claim a record or publish "the fewest moves" for a board with small pieces: say "at most", or run Full Search if the problem is short enough to finish. The Performance Analysis box under the solutions list forecasts how long each further move of a running search will take, which shows early whether a full search is within reach.
- When optimized paths says "no solution": do not believe it until a full search agrees.
Sources
- ShapeLogic sources: core/shapelogic/solve/sliding_search.cpp (slideGridFor, stopGridFor, StopGrid); decision records 0029 (optimized paths), 0031 (loose stops), 0032 (compact keys) and 0033 (both ends).
- The stop counts are the engine's own (sliding.gridAdvice), the ones the Solver shows before a solve.
- Figure 4: shapelogic_cli -d --nested-slides --slide-trace on Problem 3 of "Abe 1 to 6 Heart", with and without --optimized-paths; the full search was stopped after 150 seconds. The counts do not depend on the machine.
- The Klotski boards were built at each scale through the engine and solved with shapelogic_cli -d, with and without --optimized-paths. The start is the classic one, with the large block to be brought to the bottom center.
- The five shorter Heart problems, the 40-move timings and the test counts: decision records 0029, 0031 and 0033. Times are single runs of the release build on a MacBook Air M4.
- Figure 3: the board of the contract test sliding_grid_advice in tests/contract/test_engine.py.
