+ this.tryChangeTurn(move, captureUndef);
+ }
+ }
+
+ // NOTE: not "try" here, we know the turn changes (TODO?)
+ tryChangeTurn(move, captureUndef) {
+ this.definition = null;
+ this.subTurn = captureUndef ? 0 : 1;
+ this.turn = C.GetOppCol(this.turn);
+ this.movesCount++;
+ }
+
+ computeNextMove(move) {
+ if (
+ !this.definition || this.playerColor != this.turn ||
+ this.board.some(row => row.some(cell =>
+ cell.charAt(0) == this.turn && cell.charAt(1) == 'u'))
+ ) {
+ return null;
+ }
+ const variety = (c) => {
+ return (
+ [...new Set(
+ Array.prototype.concat.apply([],
+ this.board.map(row =>
+ row.filter(cell =>
+ cell.charAt(0) == c && !['p', 'k'].includes(cell.charAt(1))
+ ).map(cell => cell.charAt(1))
+ )
+ )
+ )].length >= 2
+ );
+ };
+ this.playOnBoard(move);
+ let next = {start: move.end, end: move.end, vanish: [], appear: []};
+ for (let c of ['w', 'b']) {
+ if (variety(c)) {
+ for (let i=0; i<this.size.x; i++) {
+ for (let j=0; j<this.size.y; j++) {
+ const pieceIJ = this.getPiece(i, j);
+ if (
+ this.board[i][j] != "" &&
+ !['p', 'k', 'u'].includes(pieceIJ)
+ ) {
+ // NOTE: could also use a "flip" strategy similar to Benedict
+ next.vanish.push(new PiPo({c: c, p: pieceIJ, x: i, y: j}));
+ next.appear.push(new PiPo({c: c, p: 'u', x: i, y: j}));
+ this.reserve[c][pieceIJ]++;
+ }
+ }
+ }
+ super.re_drawReserve([c]);
+ }
+ }
+ this.undoOnBoard(move);
+ if (next.vanish.length >= 1) {
+ next.reset = true;
+ move.next = next;