static get CanAnalyze() {
return true;
}
+ // Patch: issues with javascript OOP, objects can't access static fields.
+ get canAnalyze() {
+ return V.CanAnalyze;
+ }
// Some variants show incomplete information,
// and thus show only a partial moves list or no list at all.
static get ShowMoves() {
return "all";
}
+ get showMoves() {
+ return V.ShowMoves;
+ }
- // Path to pieces
- static getPpath(b) {
- return b; //usual pieces in pieces/ folder
+ // Some variants always show the same orientation
+ static get CanFlip() {
+ return true;
+ }
+ get canFlip() {
+ return V.CanFlip;
}
// Turn "wb" into "B" (for FEN)
return V.CoordToColumn(coords.y) + (V.size.x - coords.x);
}
+ // Path to pieces
+ getPpath(b) {
+ return b; //usual pieces in pieces/ folder
+ }
+
// Aggregates flags into one object
aggregateFlags() {
return this.castleFlags;
pieces[c][knight2Pos] = "n";
pieces[c][rook2Pos] = "r";
}
+ // Add turn + flags + enpassant
return (
pieces["b"].join("") +
"/pppppppp/8/8/8/8/PPPPPPPP/" +
pieces["w"].join("").toUpperCase() +
" w 0 1111 -"
- ); //add turn + flags + enpassant
+ );
}
// "Parse" FEN: just return untransformed string data
for (let indexInRow = 0; indexInRow < rows[i].length; indexInRow++) {
const character = rows[i][indexInRow];
const num = parseInt(character);
+ // If num is a number, just shift j:
if (!isNaN(num)) j += num;
- //just shift j
- //something at position i,j
+ // Else: something at position i,j
else board[i][j++] = V.fen2board(character);
}
}
setFlags(fenflags) {
// white a-castle, h-castle, black a-castle, h-castle
this.castleFlags = { w: [true, true], b: [true, true] };
- if (!fenflags) return;
for (let i = 0; i < 4; i++)
this.castleFlags[i < 2 ? "w" : "b"][i % 2] = fenflags.charAt(i) == "1";
}
// INITIALIZATION
constructor(fen) {
- this.re_init(fen);
+ // In printDiagram() fen isn't supply because only getPpath() is used
+ if (fen)
+ this.re_init(fen);
}
// Fen string fully describes the game state
return { x: 8, y: 8 };
}
- // Color of thing on suqare (i,j). 'undefined' if square is empty
+ // Color of thing on square (i,j). 'undefined' if square is empty
getColor(i, j) {
return this.board[i][j].charAt(0);
}
////////////////////
// MOVES GENERATION
- // All possible moves from selected square (assumption: color is OK)
+ // All possible moves from selected square
getPotentialMovesFrom([x, y]) {
switch (this.getPiece(x, y)) {
case V.PAWN:
x + shiftX == lastRank
? [V.ROOK, V.KNIGHT, V.BISHOP, V.QUEEN]
: [V.PAWN];
- // One square forward
if (this.board[x + shiftX][y] == V.EMPTY) {
+ // One square forward
for (let piece of finalPieces) {
moves.push(
this.getBasicMove([x, y], [x + shiftX, y], {
// TODO: un-ambiguous notation (switch on piece type, check directions...)
getNotation(move) {
if (move.appear.length == 2 && move.appear[0].p == V.KING)
- //castle
+ // Castle
return move.end.y < move.start.y ? "0-0-0" : "0-0";
// Translate final square