1 import { ChessRules
} from "@/base_rules";
2 import { CoregalRules
} from "@/variants/Coregal";
4 export class TwokingsRules
extends CoregalRules
{
5 static get PawnSpecs() {
9 { promotions: ChessRules
.PawnSpecs
.promotions
.concat([V
.KING
]) }
13 static IsGoodPosition(position
) {
14 if (position
.length
== 0) return false;
15 const rows
= position
.split("/");
16 if (rows
.length
!= V
.size
.x
) return false;
17 let kings
= { "w": 0, "b": 0 };
18 for (let row
of rows
) {
20 for (let i
= 0; i
< row
.length
; i
++) {
21 if (['K','k'].includes(row
[i
])) kings
[row
[i
]]++;
22 if (V
.PIECES
.includes(row
[i
].toLowerCase())) sumElts
++;
24 const num
= parseInt(row
[i
]);
25 if (isNaN(num
)) return false;
29 if (sumElts
!= V
.size
.y
) return false;
31 // Two kings (at least) per side should be present:
32 if (Object
.values(kings
).some(v
=> v
< 2)) return false;
36 // Not scanning king positions. In this variant, scan the board everytime.
39 getCheckSquares(color
) {
41 const oppCol
= V
.GetOppCol(color
);
42 for (let i
=0; i
<V
.size
.x
; i
++) {
43 for (let j
=0; j
<V
.size
.y
; j
++) {
45 this.getColor(i
, j
) == color
&&
46 this.getPiece(i
, j
) == V
.KING
&&
47 this.isAttacked([i
, j
], oppCol
)
56 static GenRandInitFen(randomness
) {
57 const fen
= CoregalRules
.GenRandInitFen(randomness
);
58 return fen
.replace("q", "k").replace("Q", "K");
62 const oppCol
= V
.GetOppCol(color
);
63 for (let i
=0; i
<V
.size
.x
; i
++) {
64 for (let j
=0; j
<V
.size
.y
; j
++) {
66 this.getColor(i
, j
) == color
&&
67 this.getPiece(i
, j
) == V
.KING
&&
68 this.isAttacked([i
, j
], oppCol
)
78 const piece
= move.vanish
[0].p
;
79 super.updateCastleFlags(move, piece
, "twoKings");