Summer is coming, but it’s too hot outside, so let’s have fun inside. I googled around to see how the rush hour game is implemented in Prolog, and I wonder how a 6x6 rectangular game should be represented.
like this?
[ [-, -, -, -, -, -],
[-, -, -, -, b, -],
[-, -, r, r, b, -],
[-, -, -, -, b, -],
[-, -, -, -, -, -],
[-, -, -, -, -, -] ]
I would need to define moves by moving the list elements, which is easy horizontally, see docs for nth0/4 (I guess this works both ways, left and right):
edge(List, Index, OldElem, NewElem, NewList) :-
nth0(Index, List, OldElem, Transfer),
OldElem = [-, R2, R3, R4, R5, R6],
NewElem = [R2, R3, R4, R5, R6, -],
nth0(Index, NewList, NewElem, Transfer).
How do I do this vertically? Does it make sense to structure the array in matrix form at all (and use some of the matrix packs to transpose the matrix), or should I use a flat list and implement the moves with indices?
Efficiency is not needed. I found some solutions in the internet, but they are not pretty (and I want to solve it myself).