import ChessRules from "/base_rules.js";
import GiveawayRules from "/variants/Giveaway/class.js";
-import { ArrayFun } from "/utils/array.js";
-import { Random } from "/utils/alea.js";
+import {ArrayFun} from "/utils/array.js";
+import {Random} from "/utils/alea.js";
import PiPo from "/utils/PiPo.js";
import Move from "/utils/Move.js";
);
}
- genRandInitFen(seed) {
+ genRandInitBaseFen() {
const options = Object.assign({mode: "suicide"}, this.options);
const gr = new GiveawayRules({options: options, genFenOnly: true});
- const baseFen = gr.genRandInitFen(seed);
- const fenParts = baseFen.split(" ");
- let others = JSON.parse(fenParts[3]);
- delete others["enpassant"];
- others["flags"] = "1111"; //Peach + Mario flags
- return fenParts.slice(0, 3).join(" ") + " " + JSON.stringify(others);
+ let res = gr.genRandInitBaseFen();
+ res.o["flags"] = "1111"; //Peach + Mario flags
+ return res;
}
fen2board(f) {
play(move) {
const color = this.turn;
const oppCol = C.GetOppCol(color);
- if (
- move.appear.length > 0 &&
- move.appear[0].p == 'p' &&
- (
- (color == 'w' && move.end.x == 0) ||
- (color == 'b' && move.end.x == this.size.x - 1)
- )
- ) {
- // "Forgotten" promotion, which occurred after some effect
- let moves = [move];
- super.pawnPostProcess(moves, color, oppCol);
- super.showChoices(moves);
- return false;
- }
- this.postPlay(move, color, oppCol);
- return true;
- }
-
- postPlay(move, color, oppCol) {
this.egg = move.egg;
if (move.egg == "toadette") {
this.reserve = { w: {}, b: {} };
this.displayBonus(move);
}
+ buildMoveStack(move, r) {
+ const color = this.turn;
+ if (
+ move.appear.length > 0 &&
+ move.appear[0].p == 'p' &&
+ (
+ (color == 'w' && move.end.x == 0) ||
+ (color == 'b' && move.end.x == this.size.x - 1)
+ )
+ ) {
+ // "Forgotten" promotion, which occurred after some effect
+ let moves = [move];
+ super.pawnPostProcess(moves, color, C.GetOppCol(color));
+ super.showChoices(moves, r);
+ }
+ else
+ super.buildMoveStack(move, r);
+ }
+
computeNextMove(move) {
// Set potential random effects, so that play() is deterministic
// from opponent viewpoint:
let bagOfPieces = [];
for (let i=0; i<this.size.x; i++) {
for (let j=0; j<this.size.y; j++) {
- if (this.getColor(i, j) == c && this.getPiece(i, j) != 'k')
+ const pieceIJ = this.getPiece(i, j);
+ if (
+ this.getColor(i, j) == c && pieceIJ != 'k' &&
+ (
+ // The color will change, so pawns on first rank are ineligible
+ pieceIJ != 'p' ||
+ (c == 'w' && i < this.size.x - 1) || (c == 'b' && i > 0)
+ )
+ ) {
bagOfPieces.push([i, j]);
+ }
}
}
if (bagOfPieces.length >= 1)