+ getAllValidMoves(computer)
+ {
+ const color = this.turn;
+ const oppCol = this.getOppCol(color);
+ let potentialMoves = [];
+ for (let i=0; i<V.size.x; i++)
+ {
+ for (let j=0; j<V.size.y; j++)
+ {
+ if (this.board[i][j] != V.EMPTY && this.getColor(i,j) == color)
+ {
+ Array.prototype.push.apply(potentialMoves,
+ this.getPotentialMovesFrom([i,j], computer));
+ }
+ }
+ }
+ return this.filterValid(potentialMoves);
+ }
+
+ updateVariables(move)
+ {
+ super.updateVariables(move);
+ if (move.appear.length == 2 && move.vanish.length == 2
+ && move.appear[1].p == V.KING)
+ {
+ // Switch with the king; not castle, and not handled by main class
+ const color = move.vanish[0].c;
+ this.kingPos[color] = [move.appear[1].x, move.appear[1].y];
+ }
+ }
+
+ unupdateVariables(move)
+ {
+ super.unupdateVariables(move);
+ if (move.appear.length == 2 && move.vanish.length == 2
+ && move.appear[1].p == V.KING)
+ {
+ const color = move.vanish[0].c;
+ this.kingPos[color] = [move.appear[0].x, move.appear[0].y];
+ }
+ }
+
+ static get SEARCH_DEPTH() { return 2; } //high branching factor
+
+ getNotation(move)
+ {
+ if (move.appear.length == 1)
+ return super.getNotation(move); //no switch
+ // Switch or castle
+ if (move.appear[0].p == V.KING && move.appear[1].p == V.ROOK)
+ return (move.end.y < move.start.y ? "0-0-0" : "0-0");
+ // Switch:
+ return "S" + V.CoordsToSquare(move.start) + V.CoordsToSquare(move.end);
+ }