I’m writing a 4D 4-in-a-row game in javascript. You can see it here. I’d like to implement checking of a win.
To save time, I intend to build a list of all posible winning patterns beforehand, which makes checking for a win the trivial job of iterating over this list.
The trouble I’m having is how to construct this list. The sets of winning lines include:
[[0, x, y, z], [1, x, y, z], [2, x, y, z], [3, x, y, z]] for all x, y, and z
[[w, 0, y, z], [w, 1, y, z], [w, 2, y, z], [w, 3, y, z]] for all w, y, and z
[[w, x, 0, z], [w, x, 1, z], [w, x, 2, z], [w, x, 3, z]] for all w, x, and z
[[w, x, y, 0], [w, x, y, 1], [w, x, y, 2], [w, x, y, 3]] for all w, x, and y
And then
[[0, 0, y, z], [1, 1, y, z], [2, 2, y, z], [3, 3, y, z]] for all y, and z
[[0, 3, y, z], [1, 2, y, z], [2, 1, y, z], [3, 0, y, z]] for all y, and z
As you can guess, the list goes on and on. Essentially, the rule is that one set of ordinates (for example, the x-ordinate) in the set must be the sequence [1, 2, 3, 4], and the others are either the sequence [1, 2, 3, 4], [4, 3, 2, 1], or [n, n, n, n].
How the heck can I construct this list?
….
Solved!