| 1 | import { ChessRules } from "@/base_rules"; |
| 2 | |
| 3 | export class PawnskingRules extends ChessRules { |
| 4 | static get PawnSpecs() { |
| 5 | return Object.assign( |
| 6 | {}, |
| 7 | ChessRules.PawnSpecs, |
| 8 | // The promotion piece doesn't matter, the game is won |
| 9 | { promotions: [V.QUEEN] } |
| 10 | ); |
| 11 | } |
| 12 | |
| 13 | static get HasFlags() { |
| 14 | return false; |
| 15 | } |
| 16 | |
| 17 | static GenRandInitFen() { |
| 18 | return "4k3/pppppppp/8/8/8/8/PPPPPPPP/4K3 w 0 -"; |
| 19 | } |
| 20 | |
| 21 | filterValid(moves) { |
| 22 | return moves; |
| 23 | } |
| 24 | |
| 25 | getCheckSquares() { |
| 26 | return []; |
| 27 | } |
| 28 | |
| 29 | getCurrentScore() { |
| 30 | const color = this.turn; |
| 31 | if (this.kingPos[color][0] < 0) return (color == "w" ? "0-1" : "1-0"); |
| 32 | const oppCol = V.GetOppCol(color); |
| 33 | const lastRank = (oppCol == 'w' ? 0 : 7); |
| 34 | if (this.board[lastRank].some(cell => cell[0] == oppCol)) |
| 35 | // The opposing edge is reached! |
| 36 | return (oppCol == "w" ? "1-0" : "0-1"); |
| 37 | if (this.atLeastOneMove()) return "*"; |
| 38 | return "1/2"; |
| 39 | } |
| 40 | |
| 41 | postPlay(move) { |
| 42 | super.postPlay(move); |
| 43 | if (move.vanish.length == 2 && move.vanish[1].p == V.KING) |
| 44 | this.kingPos[this.turn] = [-1, -1]; |
| 45 | } |
| 46 | |
| 47 | postUndo(move) { |
| 48 | super.postUndo(move); |
| 49 | if (move.vanish.length == 2 && move.vanish[1].p == V.KING) |
| 50 | this.kingPos[move.vanish[1].c] = [move.vanish[1].x, move.vanish[1].y]; |
| 51 | } |
| 52 | |
| 53 | static get SEARCH_DEPTH() { |
| 54 | return 4; |
| 55 | } |
| 56 | }; |