1 import ChessRules
from "/base_rules.js";
2 import {FenUtil
} from "/utils/setupPieces.js";
4 export default class CircularRules
extends ChessRules
{
13 // Everypawn is going up!
17 isPawnInitRank(x
, color
) {
18 return (color
== 'w' && x
== 6) || (color
== 'b' && x
== 2);
27 let res
= x
% this.size
.x
;
33 // TODO: rewrite in more elegant way
36 for (let c
of ["w", "b"]) {
37 for (let i
= 0; i
< 8; i
++)
38 flags
+= this.pawnFlags
[c
][i
] ? "1" : "0";
45 w: [...Array(8)], //pawns can move 2 squares?
48 for (let c
of ["w", "b"]) {
49 for (let i
= 0; i
< 8; i
++)
50 this.pawnFlags
[c
][i
] = fenflags
.charAt((c
== "w" ? 0 : 8) + i
) == "1";
54 genRandInitBaseFen() {
56 randomness: this.options
["randomness"],
59 const s
= FenUtil
.setupPieces(
60 ['r', 'n', 'b', 'q', 'k', 'b', 'n', 'r'], setupOpts
);
62 fen: "8/8/pppppppp/" + s
.b
.join("") + "/8/8/PPPPPPPP/" +
63 s
.w
.join("").toUpperCase(),
64 o: {flags: "11111111"}
69 const filteredMoves
= super.filterValid(moves
);
70 // If at least one full move made, everything is allowed:
71 if (this.movesCount
>= 2)
73 // Else, forbid checks:
74 const oppCol
= C
.GetOppTurn(this.turn
);
75 const oppKingPos
= this.searchKingPos(oppCol
);
76 return filteredMoves
.filter(m
=> {
78 const res
= !this.underCheck(oppKingPos
, [this.turn
]);
85 if (move.appear
.length
> 0 && move.vanish
.length
> 0) {
88 [2, 6].includes(move.start
.x
) &&
89 move.vanish
[0].p
== 'p' &&
90 Math
.abs(move.end
.x
- move.start
.x
) == 2
92 // This move turns off a 2-squares pawn flag
93 this.pawnFlags
[move.start
.x
== 6 ? "w" : "b"][move.start
.y
] = false;