+ hoverHighlight([x, y]) {
+ const c = this.turn;
+ return (
+ this.movesCount <= 3 &&
+ ((c == 'w' && x == 7) || (c == 'b' && x == 0))
+ );
+ }
+
+ // Special case of move 1 = choose squares, knight first, then bishop
+ doClick(square) {
+ if (this.movesCount >= 4) return null;
+ const color = this.turn;
+ const [x, y] = [square[0], square[1]];
+ if ((color == 'w' && x != 7) || (color == 'b' && x != 0)) return null;
+ const selectedPiece = this.board[x][y][1];
+ return new Move({
+ appear: [
+ new PiPo({
+ x: x,
+ y: y,
+ c: color,
+ p: this.getAugmented(selectedPiece)
+ })
+ ],
+ vanish: [
+ new PiPo({
+ x: x,
+ y: y,
+ c: color,
+ p: selectedPiece
+ })
+ ],
+ start: { x: x, y: y },
+ end: { x: x, y: y }
+ });
+ }
+
+ postPlay(move) {
+ if (this.movesCount > 4) super.postPlay(move);
+ }
+
+ postUndo(move) {
+ if (this.movesCount >= 4) super.postUndo(move);
+ }
+
+ evalPosition() {
+ let evaluation = 0;
+ 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) {
+ const sign = this.getColor(i, j) == "w" ? 1 : -1;
+ const piece = this.getPiece(i, j);
+ evaluation += sign * V.VALUES[piece];
+ const symbol = this.board[i][j][1];
+ if (V.AUGMENTED_PIECES.includes(symbol)) {
+ const extraPiece = this.getExtraPiece(symbol);
+ evaluation += sign * V.VALUES[extraPiece]
+ }
+ }
+ }
+ }
+ return evaluation;
+ }
+
+ getNotation(move) {
+ if (
+ move.appear[0].x != move.vanish[0].x ||
+ move.appear[0].y != move.vanish[0].y
+ ) {
+ if (
+ V.AUGMENTED_PIECES.includes(move.vanish[0].p) ||
+ (
+ move.appear.length >= 2 &&
+ move.vanish.length >= 2 &&
+ V.AUGMENTED_PIECES.includes(move.vanish[1].p)
+ )
+ ) {
+ // Simplify move before calling super.getNotation()
+ let smove = JSON.parse(JSON.stringify(move));
+ if (ChessRules.PIECES.includes(move.vanish[0].p)) {
+ // Castle with an augmented rook
+ smove.appear.pop();
+ smove.vanish[1].p = smove.appear[1].p;
+ }
+ else {
+ // Moving an augmented piece
+ smove.appear.pop();
+ smove.vanish[0].p = smove.appear[0].p;
+ if (
+ smove.vanish.length == 2 &&
+ smove.vanish[0].c == smove.vanish[1].c &&
+ V.AUGMENTED_PIECES.includes(move.vanish[1].p)
+ ) {
+ // Castle with an augmented rook
+ smove.appear.pop();
+ smove.vanish[1].p = smove.appear[1].p;
+ }
+ }
+ return super.getNotation(smove);
+ }
+ // Else, more common case:
+ return super.getNotation(move);
+ }
+ // First moves in game, placements:
+ const square = V.CoordsToSquare(move.appear[0]);
+ const reserve =
+ (['a','j','m','s','u'].includes(move.appear[0].p) ? 'N' : 'B');
+ return '+' + reserve + '@' + square;
+ }
+