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 /* Cannot move if you are not on a team. */
19 if (player.team === "")
21 return { legal: false,
22 message: "You must be on a team to take a turn" };
25 /* Cannot move if it's not this player's team's turn. */
26 if (player.team !== this.state.team_to_play)
28 return { legal: false,
29 message: "It's not your turn to move" };
32 /* Cannot move to an occupied square. */
33 if (this.state.board[square])
35 return { legal: false,
36 message: "Square is already occupied" };
39 this.state.board[square] = this.state.team_to_play;
40 this.state.moves.push(square);
42 if (this.state.team_to_play === "X")
43 this.state.team_to_play = "O";
45 this.state.team_to_play = "X";
47 return { legal: true };
51 TicTacToe.router = express.Router();
55 identifier: "tictactoe"
58 exports.Game = TicTacToe;