Twisty puzzles are a subset of combination puzzles, where the AI has to unscramble a three-dimensional puzzle by rotating (or twisting) the sides until each side is a solid block of colour. Most famously these include the Rubix Cube, (invented by Ernő Rubik in 1974,) a cube made of 26 smaller cubes that rotate around a central point; but the family of puzzles have expanded to include all sorts of shapes.
A lot of confusion for these puzzles is generated by the labelling of the moves and the different scoring systems available. Here (as far as possible) we have adopted the World Cube Association standards as set out in the WCA regulations, (section 12) and use the outer block turn metric (OBTM) to count moves.
Note – Although the WCA notes that dropping the “2” prefix for outer block moves when n=2 is optional, here it is done in all cases.
Although in theory all twisty puzzles could be solved by a simple search algorithm, (as all future states can be accurately predicted) in reality all but the smallest puzzles have far too many possible combinations actually do this.
smallTablePuzzle Type | Positions (Possible States) |
---|---|
Cube 2x2x2 | 3,674,160 |
Cube 3x3x3 | 43,252,003,274,489,856,000 |
Cube 4x4x4 | 7.4 × 1045 |
Cube 5x5x5 | 2.8 × 1074 |
Cube 6x6x6 | 1.6 × 10116 |
Cube 7x7x7 | 2.0 × 10160 |
Instead, you could try splitting the puzzle into several smaller tasks (i.e. top layer, sides, bottom corners, whole cube) with the solution to each sub-puzzle keeping the previous state intact.
Alternatively, it has been shown that by using a deep neural network to predict how many moves a state is away from a solution, existing search algorithms (such as A*) can be adapted to produce good results.
The Swagger specification for this API can be downloaded here.
The API is implemented as a single POST action which contains:
The response should be the desired move, expressed as a string.
To make multiple moves in the same network response, separate the moves by spaces. For example:
<move>R D' R' U2</move>
The history object of the next request will only show the last move made.
The state of the puzzle is encoded as a string, with each character representing the colour of a single face.
Character | Colour |
---|---|
‘W’ | White |
‘O’ | Orange |
‘G’ | Green |
‘R’ | Red |
‘B’ | Blue |
‘Y’ | Yellow |
Each face is encoded row by row, from top left to bottom right.
{
"history": {
"startState": "OYWYYBRYOYBYRRRWRRBRYGGYGGRGOBGOOYBGOOBGBBOORWWGWWWBWW",
"moves": "D'",
"endState": "OYWYYBRYOYBYRRRGGRBRYGGYYBGGOBGOOOOROOBGBBWRRGWWWWWWWB",
"success": false
},
"puzzleType": "Cube 3x3x3 (OTBM)",
"moves": [
"R", "L", "U","D","R'","L'"
],
"state": "OYWYYBRYOYBYRRRGGRBRYGGYYBGGOBGOOOOROOBGBBWRRGWWWWWWWB"
}
{
"move": "R D R'"
}
<?xml version="1.0" encoding="UTF-8"?>
<TwistyRequest>
<history>
<startState>OYWYYBRYOYBYRRRWRRBRYGGYGGRGOBGOOYBGOOBGBBOORWWGWWWBWW</startState>
<moves>D'</moves>
<endState>OYWYYBRYOYBYRRRGGRBRYGGYYBGGOBGOOOOROOBGBBWRRGWWWWWWWB</endState>
<success>false</success>
</history>
<puzzleType>Cube 3x3x3 (OTBM)</puzzleType>
<moves>R</moves>
<moves>L</moves>
<moves>U</moves>
<moves>D</moves>
<moves>R'</moves>
<moves>L'</moves>
<moves>U'</moves>
<moves>D'</moves>
<state>OYWYYBRYOYBYRRRGGRBRYGGYYBGGOBGOOOOROOBGBBWRRGWWWWWWWB</state>
</TwistyRequest>
<?xml version="1.0" encoding="UTF-8"?>
<TwistyResponse>
<move>R D R'</move>
</TwistyResponse>