X-Git-Url: https://git.auder.net/?a=blobdiff_plain;f=client%2Fsrc%2Fvariants%2FAntiking.js;h=94c8af6d021dc09ba401c8432bb6ad31f19dfeba;hb=68e19a449db7a12e0a168e99cd750d985c983ba1;hp=3b1b36e3ab0ee14a576281802f51ad90fbab28fa;hpb=78d64531113d4b5045ff588dd43f301a332ebae8;p=vchess.git diff --git a/client/src/variants/Antiking.js b/client/src/variants/Antiking.js index 3b1b36e3..94c8af6d 100644 --- a/client/src/variants/Antiking.js +++ b/client/src/variants/Antiking.js @@ -3,10 +3,6 @@ import { ArrayFun } from "@/utils/array"; import { randInt } from "@/utils/alea"; export const VariantRules = class AntikingRules extends ChessRules { - static getPpath(b) { - return b[1] == "a" ? "Antiking/" + b : b; - } - static get ANTIKING() { return "a"; } @@ -15,6 +11,10 @@ export const VariantRules = class AntikingRules extends ChessRules { return ChessRules.PIECES.concat([V.ANTIKING]); } + getPpath(b) { + return b[1] == "a" ? "Antiking/" + b : b; + } + setOtherVariables(fen) { super.setOtherVariables(fen); this.antikingPos = { w: [-1, -1], b: [-1, -1] }; @@ -68,28 +68,31 @@ export const VariantRules = class AntikingRules extends ChessRules { ); } - isAttacked(sq, colors) { + isAttacked(sq, color) { return ( - super.isAttacked(sq, colors) || this.isAttackedByAntiking(sq, colors) + super.isAttacked(sq, color) || + this.isAttackedByAntiking(sq, color) ); } - isAttackedByKing([x, y], colors) { - if (this.getPiece(x, y) == V.ANTIKING) return false; //antiking is not attacked by king + isAttackedByKing([x, y], color) { + // Antiking is not attacked by king: + if (this.getPiece(x, y) == V.ANTIKING) return false; return this.isAttackedBySlideNJump( [x, y], - colors, + color, V.KING, V.steps[V.ROOK].concat(V.steps[V.BISHOP]), "oneStep" ); } - isAttackedByAntiking([x, y], colors) { - if ([V.KING, V.ANTIKING].includes(this.getPiece(x, y))) return false; //(anti)king is not attacked by antiking + isAttackedByAntiking([x, y], color) { + // (Anti)King is not attacked by antiking + if ([V.KING, V.ANTIKING].includes(this.getPiece(x, y))) return false; return this.isAttackedBySlideNJump( [x, y], - colors, + color, V.ANTIKING, V.steps[V.ROOK].concat(V.steps[V.BISHOP]), "oneStep" @@ -99,20 +102,20 @@ export const VariantRules = class AntikingRules extends ChessRules { underCheck(color) { const oppCol = V.GetOppCol(color); let res = - this.isAttacked(this.kingPos[color], [oppCol]) || - !this.isAttacked(this.antikingPos[color], [oppCol]); + this.isAttacked(this.kingPos[color], oppCol) || + !this.isAttacked(this.antikingPos[color], oppCol); return res; } getCheckSquares(color) { let res = super.getCheckSquares(color); - if (!this.isAttacked(this.antikingPos[color], [V.GetOppCol(color)])) + if (!this.isAttacked(this.antikingPos[color], V.GetOppCol(color))) res.push(JSON.parse(JSON.stringify(this.antikingPos[color]))); return res; } - updateVariables(move) { - super.updateVariables(move); + postPlay(move) { + super.postPlay(move); const piece = move.vanish[0].p; const c = move.vanish[0].c; // Update antiking position @@ -122,8 +125,8 @@ export const VariantRules = class AntikingRules extends ChessRules { } } - unupdateVariables(move) { - super.unupdateVariables(move); + postUndo(move) { + super.postUndo(move); const c = move.vanish[0].c; if (move.vanish[0].p == V.ANTIKING) this.antikingPos[c] = [move.start.x, move.start.y]; @@ -136,8 +139,8 @@ export const VariantRules = class AntikingRules extends ChessRules { const color = this.turn; const oppCol = V.GetOppCol(color); if ( - !this.isAttacked(this.kingPos[color], [oppCol]) && - this.isAttacked(this.antikingPos[color], [oppCol]) + !this.isAttacked(this.kingPos[color], oppCol) && + this.isAttacked(this.antikingPos[color], oppCol) ) { return "1/2"; } @@ -145,13 +148,27 @@ export const VariantRules = class AntikingRules extends ChessRules { } static get VALUES() { - return Object.assign(ChessRules.VALUES, { a: 1000 }); + return Object.assign( + { a: 1000 }, + ChessRules.VALUES + ); } - static GenRandInitFen() { + static GenRandInitFen(randomness) { + if (randomness == 0) + return "rnbqkbnr/pppppppp/3A4/8/8/3a4/PPPPPPPP/RNBQKBNR w 0 ahah -"; + let pieces = { w: new Array(8), b: new Array(8) }; + let flags = ""; let antikingPos = { w: -1, b: -1 }; for (let c of ["w", "b"]) { + if (c == 'b' && randomness == 1) { + pieces['b'] = pieces['w']; + antikingPos['b'] = antikingPos['w']; + flags += flags; + break; + } + let positions = ArrayFun.range(8); // Get random squares for bishops, but avoid corners; because, @@ -189,6 +206,7 @@ export const VariantRules = class AntikingRules extends ChessRules { pieces[c][bishop2Pos] = "b"; pieces[c][knight2Pos] = "n"; pieces[c][rook2Pos] = "r"; + flags += V.CoordToColumn(rook1Pos) + V.CoordToColumn(rook2Pos); } const ranks23_black = "pppppppp/" + @@ -208,7 +226,11 @@ export const VariantRules = class AntikingRules extends ChessRules { ranks23_white + "/" + pieces["w"].join("").toUpperCase() + - " w 0 1111 -" + " w 0 " + flags + " -" ); } + + static get SEARCH_DEPTH() { + return 2; + } };