]> git.cworth.org Git - empires-server/blobdiff - tictactoe.js
Add message string to the return value of add_move
[empires-server] / tictactoe.js
index a60eed600c9bdccde3736d56bf2b988dd1a9e892..da55c9f48e42c663f3e4016acaf6f4f083f15061 100644 (file)
@@ -11,11 +11,11 @@ class TicTacToe extends Game {
     };
   }
 
-  /* Returns Boolean indicating whether move was legal and added. */
+  /* Returns true if move was legal and added, false otherwise. */
   add_move(square) {
     /* Cannot move to an occupied square. */
     if (this.state.board[square])
-      return false;
+      return { legal: false, message: "Square is already occupied" };
 
     this.state.board[square] = this.state.next_player;
     this.state.moves.push(square);
@@ -25,7 +25,7 @@ class TicTacToe extends Game {
     else
       this.state.next_player = "X";
 
-    return true;
+    return { legal: true };
   }
 }