+ return true;
+ }
+ }
+ }
+ return false;
+ }
+
+ getRandPiece(color) {
+ // Find pieces which can move and roll a dice
+ let canMove = {};
+ for (let i=0; i<8; i++) {
+ for (let j=0; j<8; j++) {
+ if (this.board[i][j] != V.EMPTY && this.getColor(i, j) == color) {
+ const piece = this.getPiece(i, j);
+ if (!canMove[piece] && this.canMove(piece, color, [i, j]))
+ canMove[piece] = [i, j];
+ }
+ }
+ }
+ const options = Object.keys(canMove);
+ const randPiece = options[randInt(options.length)];
+ return [randPiece, canMove[randPiece]];
+ }
+
+ getPotentialMovesFrom([x, y]) {
+ const color = this.turn;
+ let moves = undefined;
+ if (this.movesCount == 0) moves = super.getPotentialMovesFrom([x, y]);
+ else {
+ const L = this.p2play.length; //L is >= 1
+ const piece = this.getPiece(x, y);
+ if (
+ piece == V.PAWN &&
+ this.p2play[L-1] != V.PAWN &&
+ ((color == 'w' && x == 1) || (color == 'b' && x == 6))
+ ) {
+ // The piece is a pawn about to promote
+ const destX = (color == 'w' ? 0 : 7);
+ moves = [];
+ if (this.board[destX][y] == V.EMPTY) {