81c81607429aec0c8c8173d855e4f3c06cf160b2
1 import { ChessRules
} from "@/base_rules";
2 import { SuicideRules
} from "@/variants/Suicide";
4 export class KingletRules
extends ChessRules
{
6 static get HasFlags() {
10 static get PawnSpecs() {
14 { promotions: [V
.KING
] }
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
) {
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"]++;
32 const num
= parseInt(row
[i
], 10);
33 if (isNaN(num
)) return false;
37 if (sumElts
!= V
.size
.y
) return false;
39 if (Object
.values(pawns
).some(v
=> v
== 0)) return false;
53 // No variables update because no royal king + no castling
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'))
66 if (!pawnRemain
['w']) return "0-1";
67 if (!pawnRemain
['b']) return "1-0";
68 if (this.atLeastOneMove()) return "*";
73 static GenRandInitFen(randomness
) {
74 return SuicideRules
.GenRandInitFen(randomness
);
78 // TODO: no clue what correct values would be