1 const express = require("express");
2 const Game = require("./game.js");
4 class TicTacToe extends Game {
18 board: Array(9).fill(""),
19 team_to_play: this.teams[0],
23 /* Returns true if move was legal and added, false otherwise. */
24 add_move(player, square) {
26 const state = this.state;
27 const result = super.add_move(player, square);
29 /* If the generic Game class can reject this move, then we don't
30 * need to look at it any further. */
34 /* Cannot move to an occupied square. */
35 if (state.board[square])
37 return { legal: false,
38 message: "Square is already occupied" };
41 state.board[square] = state.team_to_play;
42 state.moves.push(square);
44 if (state.team_to_play.id === 0)
45 state.team_to_play = this.teams[1];
47 state.team_to_play = this.teams[0];
49 return { legal: true };
53 TicTacToe.router = express.Router();
57 identifier: "tictactoe",
63 exports.Game = TicTacToe;