+export class AtomicRules extends ChessRules {
+
+ static get Options() {
+ return {
+ check: [
+ {
+ label: "Balanced",
+ defaut: false,
+ variable: "balanced"
+ }
+ ],
+ select: ChessRules.Options.select
+ };
+ }
+
+ static AbbreviateOptions(opts) {
+ return opts["balanced"] ? 'B' : '';
+ }
+
+ static GenRandInitFen(options) {
+ return ChessRules.GenRandInitFen(options) + (options.balanced ? " B" : "");
+ }
+
+ setOtherVariables(fen) {
+ super.setOtherVariables(fen);
+ this.balanced = !!V.ParseFen(fen).balanced;
+ }
+
+ static ParseFen(fen) {
+ return Object.assign(
+ { balanced: fen.split(" ")[5] },
+ ChessRules.ParseFen(fen)
+ );
+ }
+
+ static IsGoodFen(fen) {
+ if (!ChessRules.IsGoodFen(fen)) return false;
+ const balanced = V.ParseFen(fen).balanced;
+ return (!balanced || balanced == 'B');
+ }
+
+ getFen() {
+ return super.getFen() + (this.balanced ? " B" : "");
+ }
+
+ hoverHighlight([x, y]) {
+ return this.balanced && this.movesCount == 0 && [1, 6].includes(x);
+ }
+
+ canIplay(side, [x, y]) {
+ if (this.balanced && this.movesCount == 0)
+ return (this.turn == side && this.getPiece(x, y) == V.PAWN);
+ return super.canIplay(side, [x, y]);
+ }
+
+ doClick(square) {
+ if (!this.balanced || this.movesCount >= 1) return null;
+ const [x, y] = [square[0], square[1]];
+ if (![1, 6].includes(x)) return null;
+ return new Move({
+ appear: [],
+ vanish: [
+ new PiPo({
+ x: x,
+ y: y,
+ c: this.getColor(x, y),
+ p: V.PAWN
+ })
+ ],
+ start: { x: x, y: y },
+ end: { x: x, y: y }
+ });
+ }