import { ChessRules, PiPo, Move } from "@/base_rules";
import { ArrayFun } from "@/utils/array";
+import { shuffle } from "@/utils/alea";
export class ShogiRules extends ChessRules {
static get HasFlags() {
);
}
- static GenRandInitFen() {
- // No randomization for now:
+ static GenRandInitFen(randomness) {
+ if (randomness == 0) {
+ return (
+ "lnsgkgsnl/1r5b1/ppppppppp/9/9/9/PPPPPPPPP/1B5R1/LNSGKGSNL " +
+ "w 0 00000000000000"
+ );
+ }
+ let pieces = { w: new Array(9), b: new Array(9) };
+ for (let c of ["w", "b"]) {
+ if (c == 'b' && randomness == 1) {
+ pieces['b'] = pieces['w'];
+ break;
+ }
+ let positions = shuffle(ArrayFun.range(9));
+ const composition = ['l', 'l', 'n', 'n', 's', 's', 'g', 'g', 'k'];
+ for (let i = 0; i < 9; i++) pieces[c][positions[i]] = composition[i];
+ }
return (
- "lnsgkgsnl/1r5b1/ppppppppp/9/9/9/PPPPPPPPP/1B5R1/LNSGKGSNL " +
- "w 0 00000000000000"
+ pieces["b"].join("") +
+ "/1r5b1/ppppppppp/9/9/9/PPPPPPPPP/1B5R1/" +
+ pieces["w"].join("").toUpperCase() +
+ " w 0 00000000000000"
);
}
let counts = new Array(14);
for (let i = 0; i < V.RESERVE_PIECES.length; i++) {
counts[i] = this.reserve["w"][V.RESERVE_PIECES[i]];
- counts[6 + i] = this.reserve["b"][V.RESERVE_PIECES[i]];
+ counts[7 + i] = this.reserve["b"][V.RESERVE_PIECES[i]];
}
return counts.join("");
}
// Modified to take promotions into account
getSlideNJumpMoves([x, y], steps, options) {
+ options = options || {};
const color = this.turn;
const oneStep = options.oneStep;
const forcePromoteOnLastRank = options.force;
return (
this.isAttackedBySlideNJump(sq, color, V.P_ROOK, V.steps[V.ROOK]) ||
this.isAttackedBySlideNJump(
- sq, color, V.DRAGON, V.steps[V.BISHOP], "oneStep")
+ sq, color, V.P_ROOK, V.steps[V.BISHOP], "oneStep")
);
}
return (
this.isAttackedBySlideNJump(sq, color, V.P_BISHOP, V.steps[V.BISHOP]) ||
this.isAttackedBySlideNJump(
- sq, color, V.DRAGON, V.steps[V.ROOK], "oneStep")
+ sq, color, V.P_BISHOP, V.steps[V.ROOK], "oneStep")
);
}