I'm looking at solving the Puzzle 15 game. Example.
Basically at each position, valid positions can only come vertically or horizontally. I am looking for an algorithm that can determine it at any given position in a board of 16 elements, 4 by 4.
Currently I have the positions hard coded
var rules = [
{ "0": [1, 4]},{ "1": [0, 2, 5] },{ "2": [1, 3, 6] },{ "3": [2, 7] },
{ "4": [0, 5, 8] },{ "5": [1, 4, 6, 9] },{ "6": [2, 5, 7, 10] },{ "7": [3, 6, 11] },
{ "8": [4, 9, 12] },{ "9": [5, 8, 10, 13]},{ "10": [6, 9, 11, 14] },{ "11": [7, 10, 15] },
{ "12": [8, 13] },{ "13": [12, 9, 14] },{ "14": [10, 13, 15] },{ "15": [11, 14] },
]
For example at position "0", only positions [1, 4] are valid to move from.
[ _, 1, 2, 3 ]
[ 4, 5, 6, 7 ]
[ 8, 9, 10, 11 ]
[ 0, 12, 13, 14 ]
What's a better way?