1 import { ChessRules
} from "@/base_rules";
2 import { SuicideRules
} from "@/variants/Suicide";
4 export class Squatter2Rules
extends ChessRules
{
6 static get HasFlags() {
10 static get PawnSpecs() {
14 { promotions: ChessRules
.PawnSpecs
.promotions
.concat([V
.KING
]) }
33 static IsGoodPosition(position
) {
34 if (position
.length
== 0) return false;
35 const rows
= position
.split("/");
36 if (rows
.length
!= V
.size
.x
) return false;
37 // Just check that at least one piece of each color is there:
38 let pieces
= { "w": 0, "b": 0 };
39 for (let row
of rows
) {
41 for (let i
= 0; i
< row
.length
; i
++) {
42 const lowerRi
= row
[i
].toLowerCase();
43 if (V
.PIECES
.includes(lowerRi
)) {
44 pieces
[row
[i
] == lowerRi
? "b" : "w"]++;
48 const num
= parseInt(row
[i
], 10);
49 if (isNaN(num
)) return false;
53 if (sumElts
!= V
.size
.y
) return false;
55 if (Object
.values(pieces
).some(v
=> v
== 0)) return false;
69 // No variables update because no royal king + no castling
76 const oppCol
= V
.GetOppCol(this.turn
);
77 const goal
= (oppCol
== 'w' ? 0 : 7);
78 if (this.board
[goal
].slice(3, 5).some(b
=> b
[0] == oppCol
))
79 return oppCol
== 'w' ? "1-0" : "0-1";
80 if (this.atLeastOneMove()) return "*";
84 static GenRandInitFen(randomness
) {
85 return SuicideRules
.GenRandInitFen(randomness
);