| 1 | import { ChessRules } from "@/base_rules"; |
| 2 | import { SuicideRules } from "@/variants/Suicide"; |
| 3 | |
| 4 | export class KingletRules extends ChessRules { |
| 5 | |
| 6 | static get HasFlags() { |
| 7 | return false; |
| 8 | } |
| 9 | |
| 10 | static get PawnSpecs() { |
| 11 | return Object.assign( |
| 12 | {}, |
| 13 | ChessRules.PawnSpecs, |
| 14 | { promotions: [V.KING] } |
| 15 | ); |
| 16 | } |
| 17 | |
| 18 | static IsGoodPosition(position) { |
| 19 | if (position.length == 0) return false; |
| 20 | const rows = position.split("/"); |
| 21 | if (rows.length != V.size.x) return false; |
| 22 | // Just check that at least one pawn of each color is there: |
| 23 | let pawns = { "w": 0, "b": 0 }; |
| 24 | for (let row of rows) { |
| 25 | let sumElts = 0; |
| 26 | for (let i = 0; i < row.length; i++) { |
| 27 | const lowerRi = row[i].toLowerCase(); |
| 28 | if (V.PIECES.includes(lowerRi)) { |
| 29 | if (lowerRi == 'p') pawns[row[i] == lowerRi ? "b" : "w"]++; |
| 30 | sumElts++; |
| 31 | } else { |
| 32 | const num = parseInt(row[i], 10); |
| 33 | if (isNaN(num)) return false; |
| 34 | sumElts += num; |
| 35 | } |
| 36 | } |
| 37 | if (sumElts != V.size.y) return false; |
| 38 | } |
| 39 | if (Object.values(pawns).some(v => v == 0)) return false; |
| 40 | return true; |
| 41 | } |
| 42 | |
| 43 | scanKings() {} |
| 44 | |
| 45 | filterValid(moves) { |
| 46 | return moves; |
| 47 | } |
| 48 | |
| 49 | getCheckSquares() { |
| 50 | return []; |
| 51 | } |
| 52 | |
| 53 | // No variables update because no royal king + no castling |
| 54 | prePlay() {} |
| 55 | postPlay() {} |
| 56 | preUndo() {} |
| 57 | postUndo() {} |
| 58 | |
| 59 | getCurrentScore() { |
| 60 | const pawnRemain = { |
| 61 | 'w': this.board.some(b => |
| 62 | b.some(cell => cell[0] == 'w' && cell[1] == 'p')), |
| 63 | 'b': this.board.some(b => |
| 64 | b.some(cell => cell[0] == 'b' && cell[1] == 'p')) |
| 65 | } |
| 66 | if (!pawnRemain['w']) return "0-1"; |
| 67 | if (!pawnRemain['b']) return "1-0"; |
| 68 | if (this.atLeastOneMove()) return "*"; |
| 69 | // Stalemate: draw |
| 70 | return "1/2"; |
| 71 | } |
| 72 | |
| 73 | static GenRandInitFen(randomness) { |
| 74 | return SuicideRules.GenRandInitFen(randomness); |
| 75 | } |
| 76 | |
| 77 | static get VALUES() { |
| 78 | // TODO: no clue what correct values would be |
| 79 | return { |
| 80 | p: 5, |
| 81 | r: 4, |
| 82 | n: 3, |
| 83 | b: 3, |
| 84 | q: 7, |
| 85 | k: 4 |
| 86 | }; |
| 87 | } |
| 88 | |
| 89 | }; |