1 import { ChessRules
} from "@/base_rules";
2 import { SuicideRules
} from "@/variants/Suicide";
4 export class KingletRules
extends ChessRules
{
5 static get HasFlags() {
9 static get PawnSpecs() {
13 { promotions: [V
.KING
] }
17 static IsGoodPosition(position
) {
18 if (position
.length
== 0) return false;
19 const rows
= position
.split("/");
20 if (rows
.length
!= V
.size
.x
) return false;
21 // Just check that at least one pawn of each color is there:
22 let pawns
= { "w": 0, "b": 0 };
23 for (let row
of rows
) {
25 for (let i
= 0; i
< row
.length
; i
++) {
26 const lowerRi
= row
[i
].toLowerCase();
27 if (V
.PIECES
.includes(lowerRi
)) {
28 if (lowerRi
== 'p') pawns
[row
[i
] == lowerRi
? "b" : "w"]++;
31 const num
= parseInt(row
[i
], 10);
32 if (isNaN(num
)) return false;
36 if (sumElts
!= V
.size
.y
) return false;
38 if (Object
.values(pawns
).some(v
=> v
== 0)) return false;
52 // No variables update because no royal king + no castling
60 'w': this.board
.some(b
=>
61 b
.some(cell
=> cell
[0] == 'w' && cell
[1] == 'p')),
62 'b': this.board
.some(b
=>
63 b
.some(cell
=> cell
[0] == 'b' && cell
[1] == 'p'))
65 if (!pawnRemain
['w']) return "0-1";
66 if (!pawnRemain
['b']) return "1-0";
67 if (this.atLeastOneMove()) return "*";
72 static GenRandInitFen(randomness
) {
73 return SuicideRules
.GenRandInitFen(randomness
);
77 // TODO: no clue what correct values would be