const express = require("express");
const Game = require("./game.js");
-const engine_name = "tictactoe";
-
const router = express.Router();
class TicTacToe extends Game {
- constructor() {
- super(engine_name);
+ constructor(id) {
+ super(id);
this.moves = [];
- this.board = Array(9).fill(null);
+ this.board = Array(9).fill("");
+ this.next_player = "X";
}
/* Returns Boolean indicating whether move was legal and added. */
if (this.board[square])
return false;
- this.board[square] = 'X';
+ this.board[square] = this.next_player;
this.moves.push(square);
+ if (this.next_player === "X")
+ this.next_player = "O";
+ else
+ this.next_player = "X";
+
return true;
}
name: "Tic Tac Toe",
identifier: "tictactoe"
};
-
-exports.meta = TicTacToe.meta;