1 const express = require("express");
2 const Game = require("./game.js");
4 class Scribe extends Game {
7 this.teams = [{id:0, name:"+"}, {id:1, name:"o"}];
10 squares: Array(9).fill(null).map(() => Array(9).fill(null)),
11 team_to_play: this.teams[0],
15 /* Returns true if move was legal and added, false otherwise. */
16 add_move(player, move) {
18 const state = this.state;
21 const result = super.add_move(player, move);
23 /* If the generic Game class can reject this move, then we don't
24 * need to look at it any further. */
28 /* Ensure move is legal by Scribe rules. First, if this is only
29 * the first or second move, then any move is legal.
31 if (state.moves.length >= 2) {
32 const prev = state.moves.slice(-2, -1)[0];
34 /* Then check for mini-grid compatibility with move from two moves ago. */
35 if (move[0] != prev[1]) {
36 /* This can still be legal if the target mini grid is full. */
38 for (let square of state.squares[prev[1]]) {
43 return { legal: false,
44 message: "Move is inconsistent with your previous move" };
51 /* Cannot move to an occupied square. */
52 if (state.squares[i][j])
54 return { legal: false,
55 message: "Square is already occupied" };
58 state.squares[i][j] = state.team_to_play;
59 state.moves.push(move);
61 if (state.team_to_play.id === 0)
62 state.team_to_play = this.teams[1];
64 state.team_to_play = this.teams[0];
66 return { legal: true };
70 Scribe.router = express.Router();
80 exports.Game = Scribe;