| 1 | import { ChessRules } from "@/base_rules"; |
| 2 | |
| 3 | export class KnightpawnsRules 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 | scanKings() {} |
| 18 | |
| 19 | static GenRandInitFen() { |
| 20 | return "8/ppp5/8/8/8/8/8/6N1 w 0 -"; |
| 21 | } |
| 22 | |
| 23 | filterValid(moves) { |
| 24 | return moves; |
| 25 | } |
| 26 | |
| 27 | getCheckSquares() { |
| 28 | return []; |
| 29 | } |
| 30 | |
| 31 | getCurrentScore() { |
| 32 | // If all pieces of some color vanished, the opponent wins: |
| 33 | for (let c of ['w', 'b']) { |
| 34 | if (this.board.every(b => b.every(cell => !cell || cell[0] != c))) |
| 35 | return (c == 'w' ? "0-1" : "1-0"); |
| 36 | } |
| 37 | // Did a black pawn promote? Can the knight take it? |
| 38 | const qIdx = this.board[7].findIndex(cell => cell[1] == V.QUEEN); |
| 39 | if ( |
| 40 | qIdx >= 0 && |
| 41 | (this.turn == 'b' || !super.isAttackedByKnight([7, qIdx], 'w')) |
| 42 | ) { |
| 43 | return "0-1"; |
| 44 | } |
| 45 | if (!this.atLeastOneMove()) return "1/2"; |
| 46 | return "*"; |
| 47 | } |
| 48 | |
| 49 | postPlay() {} |
| 50 | postUndo() {} |
| 51 | }; |