X-Git-Url: https://git.auder.net/?a=blobdiff_plain;f=client%2Fsrc%2Fbase_rules.js;h=4f1478e17680fd5dde812d2f66bcd81319ebaed2;hb=0ba6420d3515e278b34c29e5afa1e58f6e08e9eb;hp=da9fab7837622a1dc3fc46ce452da10538d88c66;hpb=1cd3e362caa05b60f01cf8b1d4f6bfeafc0be55f;p=vchess.git diff --git a/client/src/base_rules.js b/client/src/base_rules.js index da9fab78..4f1478e1 100644 --- a/client/src/base_rules.js +++ b/client/src/base_rules.js @@ -60,6 +60,14 @@ export const ChessRules = class ChessRules { return V.ShowMoves; } + // Some variants always show the same orientation + static get CanFlip() { + return true; + } + get canFlip() { + return V.CanFlip; + } + // Turn "wb" into "B" (for FEN) static board2fen(b) { return b[0] == "w" ? b[1].toUpperCase() : b[1]; @@ -274,12 +282,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 @@ -377,7 +386,6 @@ export const ChessRules = class ChessRules { 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"; } @@ -459,7 +467,7 @@ export const ChessRules = class ChessRules { 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); } @@ -535,7 +543,7 @@ export const ChessRules = class ChessRules { //////////////////// // 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: @@ -626,8 +634,8 @@ export const ChessRules = class ChessRules { 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], {