const s = FenUtil.setupPieces(
['r', 'n', 'b', 'q', 'k', 'b', 'n', 'r'],
{
+ randomness: this.options["randomness"],
between: {p1: 'k', p2: 'r'},
diffCol: ['b'],
flags: ['r']
chessboard.style.top = spaceTop + "px";
// Give sizes instead of recomputing them,
// because chessboard might not be drawn yet.
- this.setupPieces({
+ this.setupVisualPieces({
width: cbWidth,
height: cbHeight,
x: spaceLeft,
return board;
}
- setupPieces(r) {
+ setupVisualPieces(r) {
let chessboard =
document.getElementById(this.containerId).querySelector(".chessboard");
if (!r)
flags += i;
});
}
- if (o.diffCol) {
- o.diffCol.forEach(p => {
- // Pieces of type p on different colors:
- const firstP = res.indexOf(p),
- lastP = res.lastIndexOf(p);
- if ((firstP - lastP) % 2 != 0) {
- const choice1 = Random.randBool() ? firstP : lastP;
- let choice2;
- do {
- choice2 = Random.randInt(arr.length);
+ if (o.randomness >= 1) {
+ if (o.diffCol) {
+ o.diffCol.forEach(p => {
+ // Pieces of type p on different colors:
+ const firstP = res.indexOf(p),
+ lastP = res.lastIndexOf(p);
+ if ((firstP - lastP) % 2 != 0) {
+ const choice1 = Random.randBool() ? firstP : lastP;
+ let choice2;
+ do {
+ choice2 = Random.randInt(arr.length);
+ }
+ while (
+ choice2 == choice1 ||
+ o.diffCol.includes(choice2) ||
+ (choice2 - choice1) % 2 != 0
+ );
+ res[choice1] = res[choice2];
+ res[choice2] = p;
}
- while (
- choice2 == choice1 ||
- o.diffCol.includes(choice2) ||
- (choice2 - choice1) % 2 != 0
- );
- res[choice1] = res[choice2];
- res[choice2] = p;
+ });
+ }
+ if (o.between) {
+ // Locate p1. If appearing first, exchange with first p2.
+ // If appearing last, exchange with last p2.
+ const p1 = res.indexOf(o.between["p1"]);
+ const firstP2 = res.indexOf(o.between["p2"]),
+ lastP2 = res.lastIndexOf(o.between["p2"]);
+ if (p1 < firstP2 || p1 > lastP2) {
+ res[p1] = o.between["p2"];
+ if (p1 < firstP2)
+ res[firstP2] = o.between["p1"];
+ else //p1 > lastP2
+ res[lastP2] = o.between["p1"];
}
- });
- }
- if (o.between) {
- // Locate p1. If appearing first, exchange with first p2.
- // If appearing last, exchange with last p2.
- const p1 = res.indexOf(o.between["p1"]);
- const firstP2 = res.indexOf(o.between["p2"]),
- lastP2 = res.lastIndexOf(o.between["p2"]);
- if (p1 < firstP2 || p1 > lastP2) {
- res[p1] = o.between["p2"];
- if (p1 < firstP2)
- res[firstP2] = o.between["p1"];
- else //p1 > lastP2
- res[lastP2] = o.between["p1"];
}
}
return {fen: res, flags: flags};
}
genRandInitBaseFen() {
- const s =
- FenUtil.setupPieces(['r', 'b', 'q', 'q', 'b', 'r'], {diffCol: ['b']});
+ const s = FenUtil.setupPieces(
+ ['r', 'b', 'q', 'q', 'b', 'r'],
+ {
+ randomness: this.options["randomness"],
+ diffCol: ['b']
+ }
+ );
const piece2pawn = {
r: 't',
q: 's',
genRandInitBaseFen() {
const s = FenUtil.setupPieces(
- ['r', 'n', 'b', 'q', 'k', 'b', 'n', 'r'], {diffCol: ['b']});
+ ['r', 'n', 'b', 'q', 'k', 'b', 'n', 'r'],
+ {
+ randomness: this.options["randomness"],
+ diffCol: ['b']
+ }
+ );
return {
fen: s.b.join("") + "/pppppppp/8/8/8/8/PPPPPPPP/" +
s.w.join("").toUpperCase(),
genRandInitBaseFen() {
const s = FenUtil.setupPieces(
- ['r', 'm', 'b', 'q', 'k', 'b', 'm', 'r'], {diffCol: ['b']});
+ ['r', 'm', 'b', 'q', 'k', 'b', 'm', 'r'],
+ {
+ randomness: this.options["randomness"],
+ diffCol: ['b']
+ }
+ );
return {
fen: s.b.join("") + "/pppppppp/8/8/8/8/PPPPPPPP/" +
s.w.join("").toUpperCase(),
genRandInitBaseFen() {
const s = FenUtil.setupPieces(
- ['r', 'n', 'b', 'q', 'k', 'b', 'n', 'i'], {diffCol: ['b']});
+ ['r', 'n', 'b', 'q', 'k', 'b', 'n', 'i'],
+ {
+ randomness: this.options["randomness"],
+ diffCol: ['b']
+ }
+ );
if (this.options["randomness"] <= 1) {
// Fix immobilizers/rooks pattern
const toExchange1 = s.w.indexOf('r'),
const s = FenUtil.setupPieces(
['r', 'n', 's', 'b', 'q', 'k', 'b', 'e', 'n', 'r'],
{
+ randomness: this.options["randomness"],
between: {p1: 'k', p2: 'r'},
diffCol: ['b'],
flags: ['r']
genRandInitBaseFen() {
const s = FenUtil.setupPieces(
- ['r', 'n', 'b', 'q', 'k', 'b', 'n', 'r'], {diffCol: ['b']});
+ ['r', 'n', 'b', 'q', 'k', 'b', 'n', 'r'],
+ {
+ randomness: this.options["randomness"],
+ diffCol: ['b']
+ }
+ );
return {
fen: s.b.join("") + "/pppppppp/8/8/8/8/PPPPPPPP/" +
s.w.join("").toUpperCase(),
}
genRandInitBaseFen() {
- let setupOpts = {diffCol: ['b']};
+ let setupOpts = {
+ randomness: this.options["randomness"],
+ diffCol: ['b']
+ };
if (this.options["mode"] == "losers") {
setupOpts["between"] = ['k', 'r'];
setupOpts["flags"] = ['r'];
genRandInitBaseFen() {
const s = FenUtil.setupPieces(
- ['r', 'n', 'b', 'q', 'k', 'b', 'n', 'r'], {diffCol: ['b']});
+ ['r', 'n', 'b', 'q', 'k', 'b', 'n', 'r'],
+ {
+ randomness: this.options["randomness"],
+ diffCol: ['b']
+ }
+ );
return {
fen: s.b.join("") + "/pppppppp/8/8/8/8/PPPPPPPP/" +
s.w.join("").toUpperCase(),
return ['k', 'a'].includes(p);
}
- // NOTE: canTake includes (wrong) captures of antiking,
- // to detect attacks on antikings.
+ // NOTE: canTake includes (wrong) captures of (anti)king,
+ // to detect attacks on (anti)kings.
canTake([x1, y1], [x2, y2]) {
const piece1 = this.getPiece(x1, y1);
const color1 = this.getColor(x1, y1);
);
}
- // Remove captures of antiking (see above)
+ // Remove captures of (anti)king (see above)
getPotentialMovesFrom([x, y]) {
return super.getPotentialMovesFrom([x, y]).filter(m =>
- m.vanish.length == 1 || m.vanish[1].p != 'a');
+ m.vanish.length == 1 || !['k', 'a'].includes(m.vanish[1].p));
}
underCheck(square_s, color) {
return {}
}
- setupPieces() {
+ setupVisualPieces() {
for (let i=0; i<this.size.x; i++) {
for (let j=0; j<this.size.y; j++) {
const markHere =