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 state = this.state;
19 const result = super.add_move(player, square);
21 /* If the generic Game class can reject this move, then we don't
22 * need to look at it any further. */
26 /* Cannot move to an occupied square. */
27 if (state.board[square])
29 return { legal: false,
30 message: "Square is already occupied" };
33 state.board[square] = state.team_to_play;
34 state.moves.push(square);
36 if (state.team_to_play === "X")
37 state.team_to_play = "O";
39 state.team_to_play = "X";
41 return { legal: true };
45 TicTacToe.router = express.Router();
49 identifier: "tictactoe"
52 exports.Game = TicTacToe;