I managed to solve this problem with a brute force with RNG it takes around 4-5 seconds to find the best solution even though the working grid is a 3x3.
I want to know how do I make it possible to generate the same moves the brute force finds without the brute force.
I'll list 2 examples and the solutions brute force found. I tried to analyze the solutions to figure out why it picked them and I can't figure anything out.
This game works by using cyclic rotation in both directions (left to right) and (right to left)
Left to right cyclic rotation does this
If [a, b, c] then [b, c, a]
Right to left cyclic rotation does this
If [a, b, c] then [c, a, b]
Game Data lets say is this (it can be any permutation of 1 to 9)
For example
Data = 7, 2, 6, 1, 5, 4, 3, 8, 9
I can move the pieces on the table in 8 different ways.
1) Cyclic Rotation (Left To Right) based on Row.
2) Cyclic Rotation (Right to Left) based on Row.
3) Top To Bottom based on Column.
4) Bottom To Top based on Column.
Now 5 to 8 don't require Column or Row since they are set diagonally.
5) Top Left To Bottom Right (Left To Right).
6) Top Left To Bottom Right (Right To Left).
7) Top Right To Bottom Left (Left To Right).
8) Top Right To Bottom Left (Right To Left).
The data is loaded as following
- 007 | 002 | 006
- 001 | 005 | 004
- 003 | 008 | 009
Solution brute forced:
1). [Top-Right] To [Bottom-Left] (Right To Left)
2). Bottom to Top, Column : 0
3). Left To Right, Row : 1
Here is the solution simlutated
1). [Top-Right] To [Bottom-Left] (Right To Left)
- 007 | 002 | 003
- 001 | 006 | 004
- 005 | 008 | 009
2). Bottom to Top, Column : 0
- 001 | 002 | 003
- 005 | 006 | 004
- 007 | 008 | 009
3). Left To Right, Row : 1
- 001 | 002 | 003
- 004 | 005 | 006
- 007 | 008 | 009
Here is example 2 which takes 6 moves to solve
- 009 | 008 | 007
- 006 | 005 | 004
- 003 | 002 | 001
Solve with: (6 moves)
1). [Top-Right] To [Bottom-Left] (Right To Left)
2). Top to Bottom, Column:1
3). Bottom to Top, Column:0
4). [Top-Left] To [Bottom-Right] (Left To Right)
5). Left To Right, Row:1
6). Right to Left, Row:2
So it's a pretty simple puzzle but finding efficient solutions is not a simple task.
Can someone guide me in a right direction.