- /* TODO: Need to enforce super-square matching mini-square from
- * previous move (if given super-square isn't full already). */
+ /* Ensure move is legal by Scribe rules. First, if this is only
+ * the first or second move, then any move is legal.
+ */
+ if (state.moves.length >= 2) {
+ const prev = state.moves.slice(-2, -1)[0];
+
+ /* Then check for mini-grid compatibility with move from two moves ago. */
+ if (move[0] != prev[1]) {
+ /* This can still be legal if the target mini grid is full. */
+ let count = 0;
+ for (let square of state.squares[prev[1]]) {
+ if (square)
+ count++;
+ }
+ if (count != 9) {
+ return { legal: false,
+ message: "Move is inconsistent with your previous move" };
+ }
+ }
+
+ }
+