diff --git a/js/pacosako.js b/js/pacosako.js index 474929c..91683c3 100644 --- a/js/pacosako.js +++ b/js/pacosako.js @@ -40,8 +40,9 @@ const COLUMNS = 'abcdefgh'; * effect when the game was started. * * Version 1: Initial version. (Default if version field is missing.) + * Version 2: Prohibit moving through check. */ -const CURRENT_VERSION = 1; +const CURRENT_VERSION = 2; function otherSide(side) { if (side === LIGHT) { @@ -622,7 +623,18 @@ class Game { board.isEmpty('f' + row) && board.isEmpty('g' + row)) { if (!this.isInCheck(side)) { - yield 'g' + row; + if (this._version < 2) { + yield 'g' + row; + } else { + /* Prohibit castling through check */ + const testGame = new Game(this); + testGame._board.putPiece(side, 'e' + row, EMPTY); + testGame._board.putPiece(side, 'f' + row, KING); + testGame._checkCache = {}; + if (!testGame.isInCheck(side)) { + yield 'g' + row; + } + } } } @@ -631,7 +643,18 @@ class Game { board.isEmpty('c' + row) && board.isEmpty('b' + row)) { if (!this.isInCheck(side)) { - yield 'c' + row; + if (this._version < 2) { + yield 'c' + row; + } else { + /* Prohibit castling through check */ + const testGame = new Game(this); + testGame._board.putPiece(side, 'e' + row, EMPTY); + testGame._board.putPiece(side, 'd' + row, KING); + testGame._checkCache = {}; + if (!testGame.isInCheck(side)) { + yield 'c' + row; + } + } } } }