X-Git-Url: https://git.auder.net/pieces/Cwda/n_black_rook.svg?a=blobdiff_plain;f=client%2Fsrc%2Fbase_rules.js;h=4b9a139f885cebdcd9ec122ac03fd2ee6a648051;hb=e3e2cc443054cfb273b28b3ba46f559117c5ceae;hp=7e4057bbe6b78f0266d4885fccbdef85fc2f3520;hpb=78d64531113d4b5045ff588dd43f301a332ebae8;p=vchess.git diff --git a/client/src/base_rules.js b/client/src/base_rules.js index 7e4057bb..4b9a139f 100644 --- a/client/src/base_rules.js +++ b/client/src/base_rules.js @@ -46,16 +46,18 @@ export const ChessRules = class ChessRules { 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"; } - - // Path to pieces - static getPpath(b) { - return b; //usual pieces in pieces/ folder + get showMoves() { + return V.ShowMoves; } // Turn "wb" into "B" (for FEN) @@ -160,6 +162,11 @@ export const ChessRules = class ChessRules { 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; @@ -267,12 +274,13 @@ export const ChessRules = class ChessRules { 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 @@ -357,9 +365,9 @@ export const ChessRules = class ChessRules { 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); } } @@ -379,7 +387,9 @@ export const ChessRules = class ChessRules { // 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 @@ -1252,7 +1262,7 @@ export const ChessRules = class ChessRules { // 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