]> git.cworth.org Git - lmno-server/blobdiff - tictactoe.js
tictactoe: Actually toggle between X and O as the current player
[lmno-server] / tictactoe.js
index aba043c65eba8c1dbe04ef6034c6d54b8fa8fee1..8efc70f8e791fe20d1aa68233667516a52ed5af0 100644 (file)
@@ -7,7 +7,8 @@ class TicTacToe extends Game {
   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. */
@@ -16,9 +17,14 @@ class TicTacToe extends Game {
     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;
   }
 
@@ -65,5 +71,3 @@ TicTacToe.meta = {
   name: "Tic Tac Toe",
   identifier: "tictactoe"
 };
-
-exports.meta = TicTacToe.meta;