X-Git-Url: https://git.auder.net/img/rock_paper_scissors_lizard_spock.gif?a=blobdiff_plain;f=client%2Fsrc%2Fvariants%2FPawnsking.js;fp=client%2Fsrc%2Fvariants%2FPawnsking.js;h=76d03efaf0406aeb5016c7b2242d6679a699c263;hb=737a5dafb39740ebe304b8d0a82df85070def571;hp=0000000000000000000000000000000000000000;hpb=1b56b73614509d1dca8c4353f18fb78349940cf8;p=vchess.git diff --git a/client/src/variants/Pawnsking.js b/client/src/variants/Pawnsking.js new file mode 100644 index 00000000..76d03efa --- /dev/null +++ b/client/src/variants/Pawnsking.js @@ -0,0 +1,56 @@ +import { ChessRules } from "@/base_rules"; + +export class PawnskingRules extends ChessRules { + static get PawnSpecs() { + return Object.assign( + {}, + ChessRules.PawnSpecs, + // The promotion piece doesn't matter, the game is won + { promotions: [V.QUEEN] } + ); + } + + static get HasFlags() { + return false; + } + + static GenRandInitFen() { + return "4k3/pppppppp/8/8/8/8/PPPPPPPP/4K3 w 0 -"; + } + + filterValid(moves) { + return moves; + } + + getCheckSquares() { + return []; + } + + getCurrentScore() { + const color = this.turn; + if (this.kingPos[color][0] < 0) return (color == "w" ? "0-1" : "1-0"); + const oppCol = V.GetOppCol(color); + const lastRank = (oppCol == 'w' ? 0 : 7); + if (this.board[lastRank].some(cell => cell[0] == oppCol)) + // The opposing edge is reached! + return (oppCol == "w" ? "1-0" : "0-1"); + if (this.atLeastOneMove()) return "*"; + return "1/2"; + } + + postPlay(move) { + super.postPlay(move); + if (move.vanish.length == 2 && move.vanish[1].p == V.KING) + this.kingPos[this.turn] = [-1, -1]; + } + + postUndo(move) { + super.postUndo(move); + if (move.vanish.length == 2 && move.vanish[1].p == V.KING) + this.kingPos[move.vanish[1].c] = [move.vanish[1].x, move.vanish[1].y]; + } + + static get SEARCH_DEPTH() { + return 4; + } +};