+ genRandInitBaseFen() {
+ let res = super.genRandInitBaseFen();
+ res.o.flags += "1".repeat(16); //pawns flags
+ return res;
+ }
+
+ getPartFen(o) {
+ return Object.assign(
+ {
+ "cmove": o.init ? "-" : this.getCmoveFen(),
+ "stage": o.init ? "1" : this.getStageFen()
+ },
+ super.getPartFen(o)
+ );
+ }
+
+ getCmoveFen() {
+ if (!this.cmove)
+ return "-";
+ return (
+ C.CoordsToSquare(this.cmove.start) + C.CoordsToSquare(this.cmove.end)
+ );
+ }
+
+ getStageFen() {
+ return (this.stage + this.sideCheckered);
+ }
+
+ getFlagsFen() {
+ let fen = super.getFlagsFen();
+ // Add pawns flags
+ for (let c of ["w", "b"]) {
+ for (let i = 0; i < 8; i++)
+ fen += (this.pawnFlags[c][i] ? "1" : "0");
+ }
+ return fen;
+ }
+
+ getPawnShift(color) {
+ return super.getPawnShift(color == 'c' ? this.turn : color);
+ }
+
+ getOppCols(color) {
+ if (this.stage == 1)
+ return super.getOppCols(color).concat(['c']);
+ // Stage 2: depends if color is w+b or checkered
+ if (color == this.sideCheckered)
+ return ['w', 'b'];
+ return ['c'];
+ }
+
+ pieces(color, x, y) {
+ let baseRes = super.pieces(color, x, y);
+ if (this.getPiece(x, y) == 'p' && color == 'c') {
+ const pawnShift = this.getPawnShift(this.turn); //cannot trust color
+ const initRank = (
+ (this.stage == 2 && [1, 6].includes(x)) ||
+ (this.stage == 1 &&
+ ((x == 1 && this.turn == 'b') || (x == 6 && this.turn == 'w'))
+ )
+ );
+ // Checkered pawns on stage 2 are bidirectional
+ let moveSteps = [[pawnShift, 0]],
+ attackSteps = [[pawnShift, 1], [pawnShift, -1]];
+ if (this.stage == 2) {
+ moveSteps.push([-pawnShift, 0]);
+ Array.prototype.push.apply(attackSteps,
+ [[-pawnShift, 1], [-pawnShift, -1]]);
+ }
+ baseRes['p'] = {
+ "class": "pawn",
+ moves: [
+ {
+ steps: moveSteps,
+ range: (initRank ? 2 : 1)
+ }
+ ],
+ attack: [
+ {
+ steps: attackSteps,
+ range: 1
+ }
+ ]
+ };
+ }
+ const checkered = {
+ 's': {"class": "checkered-pawn", moveas: 'p'},
+ 'u': {"class": "checkered-rook", moveas: 'r'},
+ 'o': {"class": "checkered-knight", moveas: 'n'},
+ 'c': {"class": "checkered-bishop", moveas: 'b'},
+ 't': {"class": "checkered-queen", moveas: 'q'}
+ };
+ return Object.assign(baseRes, checkered);
+ }