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);
26 // TODO: graph with segments, as for cylindrical...
28 let res
= x
% this.size
.x
;
34 // TODO: rewrite in more elegant way
37 for (let c
of ["w", "b"]) {
38 for (let i
= 0; i
< 8; i
++)
39 flags
+= this.pawnFlags
[c
][i
] ? "1" : "0";
46 w: [...Array(8)], //pawns can move 2 squares?
49 for (let c
of ["w", "b"]) {
50 for (let i
= 0; i
< 8; i
++)
51 this.pawnFlags
[c
][i
] = fenflags
.charAt((c
== "w" ? 0 : 8) + i
) == "1";
55 genRandInitBaseFen() {
57 randomness: this.options
["randomness"],
60 const s
= FenUtil
.setupPieces(
61 ['r', 'n', 'b', 'q', 'k', 'b', 'n', 'r'], setupOpts
);
63 fen: "8/8/pppppppp/" + s
.b
.join("") + "/8/8/PPPPPPPP/" +
64 s
.w
.join("").toUpperCase(),
65 o: {flags: "11111111"}
70 const filteredMoves
= super.filterValid(moves
);
71 // If at least one full move made, everything is allowed:
72 if (this.movesCount
>= 2)
74 // Else, forbid checks:
75 const oppCol
= C
.GetOppTurn(this.turn
);
76 const oppKingPos
= this.searchKingPos(oppCol
);
77 return filteredMoves
.filter(m
=> {
79 const res
= !this.underCheck(oppKingPos
, [this.turn
]);
86 if (move.appear
.length
> 0 && move.vanish
.length
> 0) {
89 [2, 6].includes(move.start
.x
) &&
90 move.vanish
[0].p
== 'p' &&
91 Math
.abs(move.end
.x
- move.start
.x
) == 2
93 // This move turns off a 2-squares pawn flag
94 this.pawnFlags
[move.start
.x
== 6 ? "w" : "b"][move.start
.y
] = false;