};
}
- pieces(color, x, y) {
- let fusions = {
- 'a': {
- "class": "amazon",
- both: [
- {
- steps: [
- [0, 1], [0, -1], [1, 0], [-1, 0],
- [1, 1], [1, -1], [-1, 1], [-1, -1]
- ]
- },
- {
- steps: [
- [1, 2], [1, -2], [-1, 2], [-1, -2],
- [2, 1], [-2, 1], [2, -1], [-2, -1]
- ],
- range: 1
- }
- ]
- },
- 'e': {
- "class": "empress",
- both: [
- {
- steps: [
- [1, 0], [-1, 0], [0, 1], [0, -1]
- ]
- },
- {
- steps: [
- [1, 2], [1, -2], [-1, 2], [-1, -2],
- [2, 1], [-2, 1], [2, -1], [-2, -1]
- ],
- range: 1
- }
- ]
- },
- 's': {
- "class": "princess",
- both: [
- {
- steps: [
- [1, 1], [1, -1], [-1, 1], [-1, -1]
- ]
- },
- {
- steps: [
- [1, 2], [1, -2], [-1, 2], [-1, -2],
- [2, 1], [-2, 1], [2, -1], [-2, -1]
- ],
- range: 1
- }
- ]
- }
+ pieceDef(piece, color, x, y) {
+ switch (piece) {
+ // Fusions
+ case 'a': return {
+ "class": "amazon",
+ both: [
+ {
+ steps: [
+ [0, 1], [0, -1], [1, 0], [-1, 0],
+ [1, 1], [1, -1], [-1, 1], [-1, -1]
+ ]
+ },
+ {
+ steps: [
+ [1, 2], [1, -2], [-1, 2], [-1, -2],
+ [2, 1], [-2, 1], [2, -1], [-2, -1]
+ ],
+ range: 1
+ }
+ ]
+ };
+ case 'e': return {
+ "class": "empress",
+ both: [
+ {
+ steps: [
+ [1, 0], [-1, 0], [0, 1], [0, -1]
+ ]
+ },
+ {
+ steps: [
+ [1, 2], [1, -2], [-1, 2], [-1, -2],
+ [2, 1], [-2, 1], [2, -1], [-2, -1]
+ ],
+ range: 1
+ }
+ ]
};
- return Object.assign(fusions, super.pieces(color, x, y));
+ case 's': return {
+ "class": "princess",
+ both: [
+ {
+ steps: [
+ [1, 1], [1, -1], [-1, 1], [-1, -1]
+ ]
+ },
+ {
+ steps: [
+ [1, 2], [1, -2], [-1, 2], [-1, -2],
+ [2, 1], [-2, 1], [2, -1], [-2, -1]
+ ],
+ range: 1
+ }
+ ]
+ };
+ }
+ return super.pieceDef(piece, color, x, y);
}
static get MergeComposed() {
}
// Triangles are rotated from opponent viewpoint (=> suffix "_inv")
- pieces(color, x, y) {
- const allSpecs = super.pieces(color, x, y);
- return {
- 'r': allSpecs['r'],
- 'q': allSpecs['q'],
- 'b': {
- "class": "bishop" + (this.playerColor != color ? "_inv" : ""),
- ...allSpecs['b']
- },
- 's': { //"square"
- "class": "babyrook",
- both: [
- {
- steps: [[0, 1], [0, -1], [1, 0], [-1, 0]],
- range: 1
- }
- ]
- },
- 'c': { //"circle"
- "class": "babyqueen",
- both: [
- {
- steps: [
- [0, 1], [0, -1], [1, 0], [-1, 0],
- [1, 1], [1, -1], [-1, 1], [-1, -1]
- ],
- range: 1
- }
- ]
- },
- 't': { //"triangle"
- "class": "babybishop" + (this.playerColor != color ? "_inv" : ""),
- both: [
- {
- steps: [[1, 1], [1, -1], [-1, 1], [-1, -1]],
- range: 1
- }
- ]
- }
+ pieceDef(piece, color, x, y) {
+ switch (piece) {
+ case 's': return { //"square"
+ "class": "babyrook",
+ both: [
+ {
+ steps: [[0, 1], [0, -1], [1, 0], [-1, 0]],
+ range: 1
+ }
+ ]
+ };
+ case 'c': return { //"circle"
+ "class": "babyqueen",
+ both: [
+ {
+ steps: [
+ [0, 1], [0, -1], [1, 0], [-1, 0],
+ [1, 1], [1, -1], [-1, 1], [-1, -1]
+ ],
+ range: 1
+ }
+ ]
};
+ case 't': return { //"triangle"
+ "class": "babybishop" + (this.playerColor != color ? "_inv" : ""),
+ both: [
+ {
+ steps: [[1, 1], [1, -1], [-1, 1], [-1, -1]],
+ range: 1
+ }
+ ]
+ };
+ }
+ let pd = super.pieceDef(piece, color, x, y);
+ if (piece == 'b')
+ pd["class"] = "bishop" + (this.playerColor != color ? "_inv" : "");
+ return pd;
}
get size() {
return ['k', 'l'].includes(p);
}
- pieces(color, x, y) {
- let alices = {
- 's': {"class": "alice-pawn", moveas: 'p'},
- 'u': {"class": "alice-rook", moveas: 'r'},
- 'o': {"class": "alice-knight", moveas: 'n'},
- 'c': {"class": "alice-bishop", moveas: 'b'},
- 't': {"class": "alice-queen", moveas: 'q'},
- 'l': {"class": "alice-king", moveas: 'k'}
- };
- return Object.assign(alices, super.pieces(color, x, y));
+ pieceDef(piece, color, x, y) {
+ switch (piece) {
+ case 's': return {"class": "alice-pawn", moveas: 'p'};
+ case 'u': return {"class": "alice-rook", moveas: 'r'};
+ case 'o': return {"class": "alice-knight", moveas: 'n'};
+ case 'c': return {"class": "alice-bishop", moveas: 'b'};
+ case 't': return {"class": "alice-queen", moveas: 'q'};
+ case 'l': return {"class": "alice-king", moveas: 'k'};
+ }
+ return super.pieceDef(piece, color, x, y);
}
fromSameWorld(p1, p2) {
};
}
- pieces(color, x, y) {
- const targets = {
- 's': {"class": "target-pawn"},
- 'u': {"class": "target-rook"},
- 'o': {"class": "target-knight"},
- 'c': {"class": "target-bishop"},
- 't': {"class": "target-queen"},
- 'l': {"class": "target-king"}
- };
- return Object.assign({ 'g': {"class": "target"} },
- targets, super.pieces(color, x, y));
+ pieceDef(piece, color, x, y) {
+ switch (piece) {
+ case 's': return {"class": "target-pawn"};
+ case 'u': return {"class": "target-rook"};
+ case 'o': return {"class": "target-knight"};
+ case 'c': return {"class": "target-bishop"};
+ case 't': return {"class": "target-queen"};
+ case 'l': return {"class": "target-king"};
+ case 'g': return {"class": "target"} };
+ }
+ return super.pieceDef(piece, color, x, y);
}
atLeastOneMove() {
return false;
}
- pieces(color, x, y) {
- let res = super.pieces(color, x, y);
- res['p'] = BerolinaPawnSpec(color); //no 2-squares moves
- return res;
+ pieceDef(piece, color, x, y) {
+ if (piece == 'p')
+ return BerolinaPawnSpec(color); //no 2-squares moves
+ return super.pieceDef(piece, color, x, y);
}
genRandInitBaseFen() {
// Allow pawns to move diagonally and capture vertically,
// because some of these moves might be valid a posteriori.
// They will be flagged as 'illegal' in a first time, however.
- pieces(color, x, y) {
- const pawnShift = (color == "w" ? -1 : 1);
- return {
- 'p': {
+ pieceDef(piece, color, x, y) {
+ if (piece == 'p') {
+ const pawnShift = (color == "w" ? -1 : 1);
+ return {
"class": "pawn",
both: [
{
range: 1
}
],
- },
- 'n': super.pieces(color, x, y)['n']
- };
+ };
+ }
+ return super.pieceDef('n', color, x, y);
}
// Allow self-captures, because they might be valid
return board;
}
- pieces(color, x, y) {
- let allSpecs = super.pieces(color, x, y);
- let pawnSpec = allSpecs['p'],
- queenSpec = allSpecs['q'],
- kingSpec = allSpecs['k'];
- const pawnShift = (color == "w" ? -1 : 1);
- Array.prototype.push.apply(pawnSpec.attack[0].steps,
- [[-pawnShift, 1], [-pawnShift, -1]]);
- queenSpec.both[0].range = 3;
- kingSpec.both[0].range = 3;
- return Object.assign({},
- allSpecs,
- {
- 'p': pawnSpec,
- 'q': queenSpec,
- 'k': kingSpec
- }
- );
+ pieceDef(piece, color, x, y) {
+ switch (piece) {
+ case 'p': {
+ const pawnShift = (color == "w" ? -1 : 1);
+ let pawnSpec = super.pieceDef('p', color, x, y);
+ pawnSpec.attack[0].steps.push(...[[-pawnShift, 1], [-pawnShift, -1]]);
+ return pawnSpec;
+ }
+ case 'q': {
+ let queenSpec = super.pieceDef('q', color, x, y);
+ queenSpec.both[0].range = 3;
+ return queenSpec;
+ }
+ case 'k': {
+ let kingSpec = super.pieceDef('k', color, x, y);
+ kingSpec.both[0].range = 3;
+ return kingSpec;
+ }
+ }
+ return super.pieceDef(piece, color, x, y);
}
static InArena(x) {
return false;
}
- pieces(color, x, y) {
- let res = super.pieces(color, x, y);
- const knightSpecMoves = res['n'].both;
- delete res['n'];
- res['m'] = {
- "class": "mammoth",
- both: [
- {
- steps: [
- [-2, -2], [-2, 0], [-2, 2],
- [0, -2], [0, 2], [2, -2],
- [2, 0], [2, 2]
- ],
- range: 1
- }
- ]
- };
- ['p', 'r', 'b', 'm', 'q'].forEach(p => {
- if (!res[p].moves)
- res[p].moves = [];
- Array.prototype.push.apply(res[p].moves, knightSpecMoves);
- });
+ pieceDef(piece, color, x, y) {
+ if (piece == 'm') {
+ return {
+ "class": "mammoth",
+ both: [
+ {
+ steps: [
+ [-2, -2], [-2, 0], [-2, 2],
+ [0, -2], [0, 2], [2, -2],
+ [2, 0], [2, 2]
+ ],
+ range: 1
+ }
+ ]
+ };
+ }
+ let res = super.pieceDef(piece, color, x, y);
+ const knightSpecMoves = super.pieceDef('n').both;
+ if (!res.moves)
+ res.moves = [];
+ res.moves.push(...knightSpecMoves);
return res;
}
return true;
}
- pieces(color, x, y) {
- return Object.assign(
- { 'u': {"class": "undefined"} },
- super.pieces(color, x, y)
- );
+ pieceDef(piece, color, x, y) {
+ if (piece == 'u')
+ return {"class": "undefined"};
+ return super.pieceDef(piece, color, x, y);
}
get clickOnly() {
const inReserve = Object.keys(this.reserve[oppCol])
.filter(k => this.reserve[oppCol][k] >= 1);
const allAttacks = Array.prototype.concat.apply(
- inReserve.map(p => this.pieces()[p].both[0]));
+ inReserve.map(p => this.pieceDef(p).both[0]));
const [x, y] = square_s[0];
for (let i=0; i<this.size.x; i++) {
for (let j=0; j<this.size.y; j++) {
};
}
- pieces() {
- return Object.assign({},
- super.pieces(),
- {
- 'p': {
- "class": "pawn", //pincer
- moves: [
- {steps: [[0, 1], [0, -1], [1, 0], [-1, 0]]}
- ]
- },
- 'r': {
- "class": "rook", //coordinator
- moves: [
- {
- steps: [
- [1, 0], [0, 1], [-1, 0], [0, -1],
- [1, 1], [1, -1], [-1, 1], [-1, -1]
- ]
- }
+ pieceDef(piece, color, x, y) {
+ switch (piece) {
+ case 'p': return {
+ "class": "pawn", //pincer
+ moves: [
+ {steps: [[0, 1], [0, -1], [1, 0], [-1, 0]]}
+ ]
+ };
+ case 'r': return {
+ "class": "rook", //coordinator
+ moves: [
+ {
+ steps: [
+ [1, 0], [0, 1], [-1, 0], [0, -1],
+ [1, 1], [1, -1], [-1, 1], [-1, -1]
]
- },
- 'n': {
- "class": "knight", //long-leaper
- moveas: 'r'
- },
- 'b': {
- "class": "bishop", //chameleon
- moveas: 'r'
- },
- 'q': {
- "class": "queen", //withdrawer
- moveas: 'r'
- },
- 'i': {
- "class": "immobilizer",
- moveas: 'r'
}
- }
- );
+ ]
+ };
+ case 'n': return {
+ "class": "knight", //long-leaper
+ moveas: 'r'
+ };
+ case 'b': return {
+ "class": "bishop", //chameleon
+ moveas: 'r'
+ };
+ case 'q': return {
+ "class": "queen", //withdrawer
+ moveas: 'r'
+ };
+ case 'i': return {
+ "class": "immobilizer",
+ moveas: 'r'
+ };
+ }
+ return {}; //never reached
}
// Is piece on square (x,y) immobilized?
const piece = this.getPiece(x, y);
const color = this.getColor(x, y);
const oppCol = C.GetOppTurn(color);
- const adjacentSteps = this.pieces()['k'].both[0].steps;
+ const adjacentSteps = this.pieceDef('k').both[0].steps;
for (let step of adjacentSteps) {
const [i, j] = [x + step[0], this.getY(y + step[1])];
if (
};
}
- pieces(color, x, y) {
- if (!this.options["cleopatra"])
- return super.pieces(color, x, y);
- const allSpecs = super.pieces(color, x, y);
- return Object.assign({},
- allSpecs,
- {'q': Object.assign({}, allSpecs['q'], {"class": "cleopatra"})}
- );
+ pieceDef(piece, color, x, y) {
+ if (this.options["cleopatra"] && piece == 'q') {
+ let pd = super.pieceDef('q', color, x, y);
+ pd["class"] = "cleopatra";
+ return pd;
+ }
+ return super.pieceDef(piece, color, x, y);
}
postProcessPotentialMoves(moves) {
export default class BerolinaRules extends ChessRules {
- pieces(color, x, y) {
- let res = super.pieces(color, x, y);
- const initRank = ((color == 'w' && x == 6) || (color == 'b' && x == 1));
- res['p'] = BerolinaPawnSpec(color, initRank);
- return res;
+ pieceDef(piece, color, x, y) {
+ if (piece == 'p') {
+ const initRank = ((color == 'w' && x == 6) || (color == 'b' && x == 1));
+ return BerolinaPawnSpec(color, initRank);
+ }
+ return super.pieceDef(piece, color, x, y);
}
};
return ['q', 'e', 's', 'r', 'n', 'b'];
}
- pieces(color, x, y) {
- let newPieces = {
- 'e': {
- "class": "empress",
- both: [
- {
- steps: [
- [1, 0], [-1, 0], [0, 1], [0, -1]
- ]
- },
- {
- steps: [
- [1, 2], [1, -2], [-1, 2], [-1, -2],
- [2, 1], [-2, 1], [2, -1], [-2, -1]
- ],
- range: 1
- }
- ]
- },
- 's': {
- "class": "princess",
- both: [
- {
- steps: [
- [1, 1], [1, -1], [-1, 1], [-1, -1]
- ]
- },
- {
- steps: [
- [1, 2], [1, -2], [-1, 2], [-1, -2],
- [2, 1], [-2, 1], [2, -1], [-2, -1]
- ],
- range: 1
- }
- ]
- }
+ pieceDef(piece, color, x, y) {
+ switch (piece) {
+ case 'e': return {
+ "class": "empress",
+ both: [
+ {
+ steps: [
+ [1, 0], [-1, 0], [0, 1], [0, -1]
+ ]
+ },
+ {
+ steps: [
+ [1, 2], [1, -2], [-1, 2], [-1, -2],
+ [2, 1], [-2, 1], [2, -1], [-2, -1]
+ ],
+ range: 1
+ }
+ ]
+ };
+ case 's': return {
+ "class": "princess",
+ both: [
+ {
+ steps: [
+ [1, 1], [1, -1], [-1, 1], [-1, -1]
+ ]
+ },
+ {
+ steps: [
+ [1, 2], [1, -2], [-1, 2], [-1, -2],
+ [2, 1], [-2, 1], [2, -1], [-2, -1]
+ ],
+ range: 1
+ }
+ ]
};
- return Object.assign(newPieces, super.pieces(color, x, y));
+ }
+ return super.pieceDef(piece, color, x, y);
}
get size() {
return this.egg == "kingboo" || this.getColor(x, y) == this.turn;
}
- pieces(color, x, y) {
- const specials = {
- 'i': {"class": "invisible"}, //queen
- '?': {"class": "mystery"}, //...initial square
- 'e': {"class": "egg"},
- 'm': {"class": "mushroom"},
- 'd': {"class": "banana"},
- 'w': {"class": "bomb"},
- 'z': {"class": "remote-capture"}
- };
- const bowsered = {
- 's': {"class": ["immobilized", "pawn"]},
- 'u': {"class": ["immobilized", "rook"]},
- 'o': {"class": ["immobilized", "knight"]},
- 'c': {"class": ["immobilized", "bishop"]},
- 't': {"class": ["immobilized", "queen"]},
- 'l': {"class": ["immobilized", "king"]}
- };
- return Object.assign(
- {
- 'y': {
- // Virtual piece for "king remote shell captures"
- attack: [
- {
- steps: [
- [0, 1], [0, -1], [1, 0], [-1, 0],
- [1, 1], [1, -1], [-1, 1], [-1, -1]
- ]
- }
+ pieceDef(piece, color, x, y) {
+ switch (piece) {
+ // Specials
+ case 'i': return {"class": "invisible"}; //queen
+ case '?': return {"class": "mystery"}; //...initial square
+ case 'e': return {"class": "egg"};
+ case 'm': return {"class": "mushroom"};
+ case 'd': return {"class": "banana"};
+ case 'w': return {"class": "bomb"};
+ case 'z': return {"class": "remote-capture"};
+ // Bowsered
+ case 's': return {"class": ["immobilized", "pawn"]};
+ case 'u': return {"class": ["immobilized", "rook"]};
+ case 'o': return {"class": ["immobilized", "knight"]};
+ case 'c': return {"class": ["immobilized", "bishop"]};
+ case 't': return {"class": ["immobilized", "queen"]};
+ case 'l': return {"class": ["immobilized", "king"]};
+ // Others
+ case 'y': return {
+ // Virtual piece for "king remote shell captures"
+ attack: [
+ {
+ steps: [
+ [0, 1], [0, -1], [1, 0], [-1, 0],
+ [1, 1], [1, -1], [-1, 1], [-1, -1]
]
}
- },
- specials, bowsered, super.pieces(color, x, y)
- );
+ ]
+ };
+ }
+ return super.pieceDef(piece, color, x, y);
}
isKing(x, y, p) {
return ['c'];
}
- pieces(color, x, y) {
- let baseRes = super.pieces(color, x, y);
- if (this.getPiece(x, y) == 'p' && color == 'c') {
+ pieceDef(piece, color, x, y) {
+ if (piece == 'p' && color == 'c') {
const pawnShift = this.getPawnShift(this.turn); //cannot trust color
const initRank = (
(this.stage == 2 && [1, 6].includes(x)) ||
Array.prototype.push.apply(attackSteps,
[[-pawnShift, 1], [-pawnShift, -1]]);
}
- baseRes['p'] = {
+ return {
"class": "pawn",
moves: [
{
]
};
}
- 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);
+ switch (piece) {
+ case 's': return {"class": "checkered-pawn", moveas: 'p'};
+ case 'u': return {"class": "checkered-rook", moveas: 'r'};
+ case 'o': return {"class": "checkered-knight", moveas: 'n'};
+ case 'c': return {"class": "checkered-bishop", moveas: 'b'};
+ case 't': return {"class": "checkered-queen", moveas: 'q'};
+ }
+ return super.pieceDef(piece, color, x, y);
}
setOtherVariables(fenParsed) {
return true;
}
- pieces(color, x, y) {
- let res = super.pieces(color, x, y);
- res['s'] = {"class": "nv-pawn", moveas: "p"};
- res['u'] = {"class": "nv-rook", moveas: "r"};
- res['o'] = {"class": "nv-knight", moveas: "n"};
- res['c'] = {"class": "nv-bishop", moveas: "b"};
- res['t'] = {"class": "nv-queen", moveas: "q"};
- return res;
+ pieceDef(piece, color, x, y) {
+ switch (piece) {
+ case 's': return {"class": "nv-pawn", moveas: "p"};
+ case 'u': return {"class": "nv-rook", moveas: "r"};
+ case 'o': return {"class": "nv-knight", moveas: "n"};
+ case 'c': return {"class": "nv-bishop", moveas: "b"};
+ case 't': return {"class": "nv-queen", moveas: "q"};
+ }
+ return super.pieceDef(piece, color, x, y);
}
static get V_PIECES() {
}
}
// Knights:
- this.pieces()['n'].both[0].steps.forEach(s => {
+ this.pieceDef('n').both[0].steps.forEach(s => {
const [i, j] = [x + s[0], y + s[1]];
if (
this.onBoard(i, j) &&
}
});
// Sliders:
- this.pieces()['q'].both[0].steps.forEach(s => {
+ this.pieceDef('q').both[0].steps.forEach(s => {
let [i, j] = [x + s[0], y + s[1]];
while (this.onBoard(i, j) && this.board[i][j] == "") {
i += s[0];
return res;
// Now check if the piece at x, y attack some friendly one (enhancement)
let movements = {};
- const steps = this.pieces()[piece].both[0].steps;
+ const steps = this.pieceDef(piece).both[0].steps;
steps.forEach(s => {
let [i, j] = [x + s[0], y + s[1]];
while (
});
Object.keys(movements).forEach(type => {
if ((piece != 'q' && type != piece) || (piece == 'q' && type == 'n'))
- res.both.push(this.pieces()[type].both[0]);
+ res.both.push(this.pieceDef(type).both[0]);
});
return res;
}
};
}
- pieces(color, x, y) {
- let res = super.pieces(color, x, y);
- res['l'] = JSON.parse(JSON.stringify(res['q']));
- // TODO: CSS royal queen symbol (with cross?)
- res['l']["class"] = "royal_queen";
- res['='] = {"class": "castle"}; //for castle display
- return res;
+ pieceDef(piece, color, x, y) {
+ if (piece == 'l') {
+ let pd = super.pieceDef('q', color, x, y);
+ // TODO: CSS royal queen symbol (with cross?)
+ pd["class"] = "royal_queen";
+ return pd;
+ }
+ else if (piece == '=')
+ return {"class": "castle"}; //for castle display
+ return super.pieceDef(piece, color, x, y);
}
setFlags(fenflags) {
};
}
- pieces(color, x, y) {
- const res = super.pieces(color, x, y);
+ pieceDef(piece, color, x, y) {
const backward = (color == 'w' ? 1 : -1);
const forward = -backward;
- return Object.assign(
- {
- 'd': {
- "class": "c_rook",
- both: [
- {steps: res['b'].both[0].steps},
- {steps: V.steps.d, range: 1}
- ]
- },
- 'w': {
- "class": "c_knight",
- both: [
- {steps: V.steps.a, range: 1},
- {steps: res['r'].both[0].steps, range: 1}
- ]
- },
- 'f': {
- "class": "c_bishop",
- both: [
- {steps: V.steps.d, range: 1},
- {steps: V.steps.a, range: 1},
- {steps: res['b'].both[0].steps, range: 1}
- ]
- },
- 'c': {
- "class": "c_queen",
- both: [
- {steps: res['b'].both[0].steps},
- {steps: res['n'].both[0].steps, range: 1}
- ]
- },
- 'm': { "class": "c_king", moveas: 'k' },
- 'z': { "class": "c_pawn", moveas: 'p' },
- 'g': {
- "class": "n_rook",
- both: [
- {steps: [[0, -1], [0, 1], [color == 'w' ? -1 : 1, 0]]},
- {steps: [[backward, -1], [backward, 0], [backward, 1]], range: 1}
- ]
- },
- 'i': {
- "class": "n_knight",
- both: [
- {steps: V.steps.$n, range: 1},
- {steps: V.steps.f, range: 1}
- ]
- },
- 't': {
- "class": "n_bishop",
- both: [
- {
- steps: [[0, -1], [0, 1], [backward, -1],
- [backward, 0], [backward, 1]],
- range: 1
- },
- {
- steps: [[2*forward, -1], [2*forward, 1],
- [forward, -2], [forward, 2]],
- range: 1
- }
- ]
- },
- 'l': {
- "class": "n_queen",
- both: [
- {steps: [[0, -1], [0, 1], [forward, 0]]},
- {steps: [[forward, -1], [forward, 1],
- [backward, -1], [backward, 0], [backward, 1]], range: 1},
- {steps: [[2*forward, -1], [2*forward, 1],
- [forward, -2], [forward, 2]], range: 1}
- ]
- },
- 'e': { "class": "n_king", moveas: 'k' },
- 'v': { "class": "n_pawn", moveas: 'p' },
- 's': {
- "class": "r_rook",
- both: [{steps: res['r'].both[0].steps, range: 4}]
- },
- 'y': {
- "class": "r_knight",
- both: [
- {steps: V.steps.d, range: 1},
- {steps: V.steps.w, range: 1}
- ]
- },
- 'h': {
- "class": "r_bishop",
- both: [
- {steps: V.steps.d, range: 1},
- {steps: V.steps.f, range: 1},
- {steps: V.steps.$3, range: 1}
- ]
- },
- 'o': {
- "class": "r_queen",
- both: [
- {steps: res['r'].both[0].steps},
- {steps: res['n'].both[0].steps, range: 1}
- ]
+ switch (piece) {
+ case 'd': return {
+ "class": "c_rook",
+ both: [
+ {steps: res['b'].both[0].steps},
+ {steps: V.steps.d, range: 1}
+ ]
+ };
+ case 'w': return {
+ "class": "c_knight",
+ both: [
+ {steps: V.steps.a, range: 1},
+ {steps: res['r'].both[0].steps, range: 1}
+ ]
+ };
+ case 'f': return {
+ "class": "c_bishop",
+ both: [
+ {steps: V.steps.d, range: 1},
+ {steps: V.steps.a, range: 1},
+ {steps: res['b'].both[0].steps, range: 1}
+ ]
+ };
+ case 'c': return {
+ "class": "c_queen",
+ both: [
+ {steps: res['b'].both[0].steps},
+ {steps: res['n'].both[0].steps, range: 1}
+ ]
+ };
+ case 'm': return { "class": "c_king", moveas: 'k' };
+ case 'z': return { "class": "c_pawn", moveas: 'p' };
+ case 'g': return {
+ "class": "n_rook",
+ both: [
+ {steps: [[0, -1], [0, 1], [color == 'w' ? -1 : 1, 0]]},
+ {steps: [[backward, -1], [backward, 0], [backward, 1]], range: 1}
+ ]
+ };
+ case 'i': return {
+ "class": "n_knight",
+ both: [
+ {steps: V.steps.$n, range: 1},
+ {steps: V.steps.f, range: 1}
+ ]
+ };
+ case 't': return {
+ "class": "n_bishop",
+ both: [
+ {
+ steps: [[0, -1], [0, 1], [backward, -1],
+ [backward, 0], [backward, 1]],
+ range: 1
},
- 'a': { "class": "r_king", moveas: 'k' },
- 'u': { "class": "r_pawn", moveas: 'p' }
- },
- res
- );
+ {
+ steps: [[2*forward, -1], [2*forward, 1],
+ [forward, -2], [forward, 2]],
+ range: 1
+ }
+ ]
+ };
+ case 'l': return {
+ "class": "n_queen",
+ both: [
+ {steps: [[0, -1], [0, 1], [forward, 0]]},
+ {steps: [[forward, -1], [forward, 1],
+ [backward, -1], [backward, 0], [backward, 1]], range: 1},
+ {steps: [[2*forward, -1], [2*forward, 1],
+ [forward, -2], [forward, 2]], range: 1}
+ ]
+ };
+ case 'e': return { "class": "n_king", moveas: 'k' };
+ case 'v': return { "class": "n_pawn", moveas: 'p' };
+ case 's': return {
+ "class": "r_rook",
+ both: [{steps: res['r'].both[0].steps, range: 4}]
+ };
+ case 'y': return {
+ "class": "r_knight",
+ both: [
+ {steps: V.steps.d, range: 1},
+ {steps: V.steps.w, range: 1}
+ ]
+ };
+ case 'h': return {
+ "class": "r_bishop",
+ both: [
+ {steps: V.steps.d, range: 1},
+ {steps: V.steps.f, range: 1},
+ {steps: V.steps.$3, range: 1}
+ ]
+ };
+ case 'o': return {
+ "class": "r_queen",
+ both: [
+ {steps: res['r'].both[0].steps},
+ {steps: res['n'].both[0].steps, range: 1}
+ ]
+ };
+ case 'a': return { "class": "r_king", moveas: 'k' };
+ case 'u': return { "class": "r_pawn", moveas: 'p' };
+ }
+ return super.pieceDef(piece, color, x, y);
}
pawnPromotions() {
return { fen: fen, o: {} };
}
- pieces(color, x, y) {
- let res = super.pieces(color, x, y);
- const pawnShift = this.getPawnShift(color || 'w');
- res['p'].moves = [{steps: [[pawnShift, pawnShift]], range: 1}];
- res['p'].attack = [{steps: [[0, pawnShift], [pawnShift, 0]], range: 1}];
- return res;
+ pieceDef(piece, color, x, y) {
+ if (piece == 'p') {
+ const pawnShift = this.getPawnShift(color || 'w');
+ return {
+ "class": "pawn",
+ moves: [{steps: [[pawnShift, pawnShift]], range: 1}],
+ attack: [{steps: [[0, pawnShift], [pawnShift, 0]], range: 1}]
+ };
+ }
+ return super.pieceDef(piece, color, x, y);
}
};
return false;
}
- pieces(color, x, y) {
- const pawnShift = this.getPawnShift(color || 'w');
+ pieceDef(piece, color, x, y) {
// NOTE: classs change according to playerColor (orientation)
const mySide = (this.playerColor == color);
- return {
- 'p': {
+ switch (piece) {
+ case 'p': {
+ const pawnShift = this.getPawnShift(color || 'w');
+ return {
"class": (mySide ? "" : "rev-") + "chick",
both: [{steps: [[pawnShift, 0]], range: 1}]
- },
- 'h': {
- "class": (mySide ? "" : "rev-") + "hen",
- both: [
- {
- steps: [
- [pawnShift, 1], [pawnShift, -1],
- [0, 1], [0, -1], [1, 0], [-1, 0]
- ],
- range: 1
- }
- ]
- },
- 'e': {
- "class": (mySide ? "" : "rev-") + "elephant",
- both: [{steps: [[-1, 1], [-1, -1], [1, 1], [1, -1]], range: 1}]
- },
- 'g': {
- "class": (mySide ? "" : "rev-") + "giraffe",
- both: [{steps: [[0, 1], [0, -1], [1, 0], [-1, 0]], range: 1}]
- },
- 'k': {
- "class": (mySide ? "" : "rev-") + "lion",
- both: [{
- steps: [[-1, 1], [-1, -1], [1, 1], [1, -1],
- [0, 1], [0, -1], [1, 0], [-1, 0]],
+ };
+ }
+ case 'h': return {
+ "class": (mySide ? "" : "rev-") + "hen",
+ both: [
+ {
+ steps: [
+ [pawnShift, 1], [pawnShift, -1],
+ [0, 1], [0, -1], [1, 0], [-1, 0]
+ ],
range: 1
- }]
- }
+ }
+ ]
};
+ case 'e': return {
+ "class": (mySide ? "" : "rev-") + "elephant",
+ both: [{steps: [[-1, 1], [-1, -1], [1, 1], [1, -1]], range: 1}]
+ };
+ case 'g': return {
+ "class": (mySide ? "" : "rev-") + "giraffe",
+ both: [{steps: [[0, 1], [0, -1], [1, 0], [-1, 0]], range: 1}]
+ };
+ case 'k': return {
+ "class": (mySide ? "" : "rev-") + "lion",
+ both: [{
+ steps: [[-1, 1], [-1, -1], [1, 1], [1, -1],
+ [0, 1], [0, -1], [1, 0], [-1, 0]],
+ range: 1
+ }]
+ };
+ }
+ return {}; //never reached
}
static get ReserveArray() {
};
}
- pieces(color, x, y) {
- let res = super.pieces(color, x, y);
- return Object.assign(
- {
- 'c': {
- "class": "commoner",
- moveas: 'k'
- }
- },
- res
- );
+ pieceDef(piece, color, x, y) {
+ if (piece == 'c') {
+ return {
+ "class": "commoner",
+ moveas: 'k'
+ };
+ }
+ return super.pieceDef(piece, color, x, y);
}
genRandInitBaseFen() {
// Slider
let steps = [];
if (['r', 'q'].includes(p))
- steps = steps.concat(this.pieces()['r'].both[0].steps);
+ steps = steps.concat(this.pieceDef('r').both[0].steps);
if (['b', 'q'].includes(p))
- steps = steps.concat(this.pieces()['b'].both[0].steps);
+ steps = steps.concat(this.pieceDef('b').both[0].steps);
for (let s of steps) {
let [i, j] = [x + s[0], y + s[1]];
while (this.onBoard(i, j) && this.board[i][j] == "") {
let movesHash = {};
moves.forEach(m => { movesHash[getMoveHash(m)] = true; });
// [x, y] is pushed by 'color'
- for (let step of this.pieces()['n'].both[0].steps) {
+ for (let step of this.pieceDef('n').both[0].steps) {
const [i, j] = [x + step[0], y + step[1]];
if (
this.onBoard(i, j) &&
addMoves(step, 1);
}
}
- for (let step of this.pieces()['r'].both[0].steps.concat(
- this.pieces()['b'].both[0].steps))
+ for (let step of this.pieceDef('r').both[0].steps.concat(
+ this.pieceDef('b').both[0].steps))
{
let [i, j] = [x + step[0], y + step[1]];
while (this.onBoard(i, j) && this.board[i][j] == "") {
const sq = square_s[0],
oppCol = oppCols[0];
// Look for every directions from kp
- const P = this.pieces(oppCol, 0, 0);
for (const piece of ['r', 'n', 'b', 'q', 'k', 'p']) {
- const stepArray = (P[piece].attack || P[piece].both);
+ const pd = this.pieceDef(piece, oppCol);
+ const stepArray = (pd.attack || pd.both);
for (const stepObj of stepArray) {
const range = stepObj.range || Math.max(this.size.x, this.size.y);
for (const s of stepObj.steps) {
}
}
return false;
- } //TODO: checks by pull!!
+ }
// Does m2 un-do m1 ? (to disallow undoing actions)
oppositeMoves(m1, m2) {
this.pushedTo = V.convertPush(fenParsed.pushedTo);
}
- pieces(color, x, y) {
+ pieceDef(piece, color, x, y) {
const mirror = (this.playerColor == 'b');
- return {
- 'j': {
- "class": "jailer",
- moves: [
- {steps: [[0, 1], [0, -1], [1, 0], [-1, 0]]}
- ]
- },
- 's': {
- "class": "sentry",
- indirectAttack: true,
- both: [
- {steps: [[1, 1], [1, -1], [-1, 1], [-1, -1]]}
- ]
- },
- 'c': {
- "class": mirror ? "lancer_S" : "lancer_N",
- both: [
- {steps: [[-1, 0]]}
- ]
- },
- 'd': {
- "class": mirror ? "lancer_SO" : "lancer_NE",
- both: [
- {steps: [[-1, 1]]}
- ]
- },
- 'e': {
- "class": mirror ? "lancer_O" : "lancer_E",
- both: [
- {steps: [[0, 1]]}
- ]
- },
- 'f': {
- "class": mirror ? "lancer_NO" : "lancer_SE",
- both: [
- {steps: [[1, 1]]}
- ]
- },
- 'g': {
- "class": mirror ? "lancer_N" : "lancer_S",
- both: [
- {steps: [[1, 0]]}
- ]
- },
- 'h': {
- "class": mirror ? "lancer_NE" : "lancer_SO",
- both: [
- {steps: [[1, -1]]}
- ]
- },
- 'm': {
- "class": mirror ? "lancer_E" : "lancer_O",
- both: [
- {steps: [[0, -1]]}
- ]
- },
- 'o': {
- "class": mirror ? "lancer_SE" : "lancer_NO",
- both: [
- {steps: [[-1, -1]]}
- ]
- },
- ...super.pieces(color, x, y)
+ switch (piece) {
+ case 'j': return {
+ "class": "jailer",
+ moves: [
+ {steps: [[0, 1], [0, -1], [1, 0], [-1, 0]]}
+ ]
};
+ case 's': return {
+ "class": "sentry",
+ indirectAttack: true,
+ both: [
+ {steps: [[1, 1], [1, -1], [-1, 1], [-1, -1]]}
+ ]
+ };
+ case 'c': return {
+ "class": mirror ? "lancer_S" : "lancer_N",
+ both: [
+ {steps: [[-1, 0]]}
+ ]
+ };
+ case 'd': return {
+ "class": mirror ? "lancer_SO" : "lancer_NE",
+ both: [
+ {steps: [[-1, 1]]}
+ ]
+ };
+ case 'e': return {
+ "class": mirror ? "lancer_O" : "lancer_E",
+ both: [
+ {steps: [[0, 1]]}
+ ]
+ };
+ case 'f': return {
+ "class": mirror ? "lancer_NO" : "lancer_SE",
+ both: [
+ {steps: [[1, 1]]}
+ ]
+ };
+ case 'g': return {
+ "class": mirror ? "lancer_N" : "lancer_S",
+ both: [
+ {steps: [[1, 0]]}
+ ]
+ };
+ case 'h': return {
+ "class": mirror ? "lancer_NE" : "lancer_SO",
+ both: [
+ {steps: [[1, -1]]}
+ ]
+ };
+ case 'm': return {
+ "class": mirror ? "lancer_E" : "lancer_O",
+ both: [
+ {steps: [[0, -1]]}
+ ]
+ };
+ case 'o': return {
+ "class": mirror ? "lancer_SE" : "lancer_NO",
+ both: [
+ {steps: [[-1, -1]]}
+ ]
+ };
+ }
+ return super.pieceDef(piece, color, x, y);
}
canIplay(x, y) {
)
||
(
- this.pieces()['j'].moves[0].steps.some(s => {
+ this.pieceDef('j').moves[0].steps.some(s => {
const [i, j] = [coords.x + s[0], coords.y + s[1]];
return (
this.onBoard(i, j) &&
});
if (V.LANCERS.includes(p)) {
// Allow all other directions without reorient
- const ls = this.pieces()[p].both[0].steps[0];
+ const ls = this.pieceDef(p).both[0].steps[0];
for (const lCode of V.LANCERS) {
- const s = this.pieces()[lCode].both[0].steps[0];
+ const s = this.pieceDef(lCode).both[0].steps[0];
if (s[0] != ls[0] || s[1] != ls[1]) {
this.board[x][y] = color + lCode;
super.findDestSquares([x, y], {}).forEach(r => {
if (V.LANCERS.includes(p)) {
pmoves.forEach(m => m.noReorient = true);
// Allow all other steps by 1 square (nudge)
- const ls = this.pieces()[p].both[0].steps[0];
+ const ls = this.pieceDef(p).both[0].steps[0];
let nextP = p;
for (const lCode of V.LANCERS) {
- const s = this.pieces()[lCode].both[0].steps[0];
+ const s = this.pieceDef(lCode).both[0].steps[0];
if (
(s[0] != ls[0] || s[1] != ls[1]) &&
this.onBoard(x + s[0], y + s[1]) &&
const p = this.getPiece(r.sq[0], r.sq[1]);
if (['j', 's'].includes(p))
continue;
- const specs = this.pieces(oppCol, r.sq[0], r.sq[1])[p];
+ const specs = this.pieceDef(p, oppCol, r.sq[0], r.sq[1]);
const steps = (specs.both || specs.attack)[0].steps;
let res = false;
for (const s of steps) {
max = z;
explored[index] = true;
component[index] = true;
- for (let [dx, dy] of super.pieces()['k'].both[0].steps) {
+ for (let [dx, dy] of super.pieceDef('k').both[0].steps) {
const [nx, ny] = [x + dx, y + dy];
const nidx = getIndex(nx, ny);
if (
return !this.options["logical"];
}
- pieces(color, x, y) {
- let res = super.pieces(color, x, y);
- if (this.options["logical"]) {
+ pieceDef(piece, color, x, y) {
+ if (this.options["logical"] && piece == 'p') {
const pawnShift = (color == "w" ? -1 : 1);
- res["p"].moves[0] = {
+ let res = super.pieceDef('p', color, x, y);
+ res.moves[0] = {
steps: [[pawnShift, 0]],
range: 1 //always
};
+ return res;
}
- return res;
+ return super.pieceDef(piece, color, x, y);
}
};
};
}
- pieces(color, x, y) {
- return {
- 's': {"class": "sleepy-pawn"},
- 'u': {"class": "sleepy-rook"},
- 'o': {"class": "sleepy-knight"},
- 'c': {"class": "sleepy-bishop"},
- 't': {"class": "sleepy-queen"},
- ...super.pieces(color, x, y)
- };
+ pieceDef(piece, color, x, y) {
+ switch (piece) {
+ case 's': return {"class": "sleepy-pawn"};
+ case 'u': return {"class": "sleepy-rook"};
+ case 'o': return {"class": "sleepy-knight"};
+ case 'c': return {"class": "sleepy-bishop"};
+ case 't': return {"class": "sleepy-queen"};
+ }
+ return super.pieceDef(piece, color, x, y);
}
static get M_PIECES() {
passBtn_arr[0].removeEventListener("click", this.passListener);
}
- pieces(color, x, y) {
+ pieceDef(piece, color, x, y) {
let classe_s = ["stone"];
- if (this.options["onecolor"] && color == 'w')
+ if (this.options["onecolor"] && color == 'w') //'w' is black! (First move)
classe_s.push("one-color");
- return {
- 's': {
- "class": classe_s,
- moves: []
- }
- };
+ return {"class": classe_s};
}
doClick(coords) {
};
}
- pieces(color, x, y) {
- let antikingSpec = super.pieces(color, x, y)['k'];
- antikingSpec["class"] = "antiking";
- return Object.assign({'a': antikingSpec}, super.pieces(color, x, y));
+ pieceDef(piece, color, x, y) {
+ if (piece == 'a') {
+ let antikingSpec = super.pieceDef('k', color, x, y);
+ antikingSpec["class"] = "antiking";
+ return antikingSpec;
+ }
+ return super.pieceDef(piece, color, x, y);
}
isKing(x, y, p) {
return false;
}
- pieces() {
- return Object.assign({},
- super.pieces(),
- {
- '+': {"class": "push-action"},
- '-': {"class": "pull-action"}
- }
- );
+ pieceDef(piece, color, x, y) {
+ if (['+', '-'].includes(piece))
+ // When a move is ambiguous ("pushme-pullyou")
+ return {"class": (piece == '+' ? "push" : "pull" + "-action")};
+ super.pieceDef(piece, color, x, y);
}
// Modify capturing moves among listed pincer moves
addPincerCaptures(moves, byChameleon) {
- const steps = this.pieces()['p'].moves[0].steps;
+ const steps = this.pieceDef('p').moves[0].steps;
const color = moves[0].vanish[0].c;
const oppCol = C.GetOppTurn(color);
moves.forEach(m => {
getLeaperCaptures([x, y], byChameleon, onlyOne) {
// Look in every direction for captures
- const steps = this.pieces()['r'].moves[0].steps;
+ const steps = this.pieceDef('r').moves[0].steps;
const color = this.getColor(x, y);
const oppCol = C.GetOppTurn(color);
let moves = [];
// type: nothing (freely, capture all), or pull or push, or "exclusive"
addPushmePullyouCaptures(moves, byChameleon, type) {
const [sx, sy] = [moves[0].start.x, moves[0].start.y];
- const adjacentSteps = this.pieces()['r'].moves[0].steps;
+ const adjacentSteps = this.pieceDef('r').moves[0].steps;
let capturingPullDir = {};
const color = moves[0].vanish[0].c;
const oppCol = C.GetOppTurn(color);