1 const express = require("express");
2 const Game = require("./game.js");
4 class TicTacToe extends Game {
9 board: Array(9).fill(""),
12 this.teams = ["X", "O"];
15 /* Returns true if move was legal and added, false otherwise. */
16 add_move(player, square) {
18 const result = super.add_move(player, square);
20 /* If the generic Game class can reject this move, then we don't
21 * need to look at it any further. */
25 /* Cannot move to an occupied square. */
26 if (this.state.board[square])
28 return { legal: false,
29 message: "Square is already occupied" };
32 this.state.board[square] = this.state.team_to_play;
33 this.state.moves.push(square);
35 if (this.state.team_to_play === "X")
36 this.state.team_to_play = "O";
38 this.state.team_to_play = "X";
40 return { legal: true };
44 TicTacToe.router = express.Router();
48 identifier: "tictactoe"
51 exports.Game = TicTacToe;