X-Git-Url: https://git.auder.net/variants/%24%7Bvname%7D/current/gitweb.css?a=blobdiff_plain;f=base_rules.js;h=0f950a240bb4b478d671d02ec9bb0dfe531ff00b;hb=c08a5e745db2b631bedf981d1ba685b312c7e3b5;hp=8c7d549469dcdd62c5670148227ae8a808ec698c;hpb=dcfaab5dc62ccd9701ff314ad4e3d40c40223d44;p=xogo.git diff --git a/base_rules.js b/base_rules.js index 8c7d549..0f950a2 100644 --- a/base_rules.js +++ b/base_rules.js @@ -324,7 +324,7 @@ export default class ChessRules { // Flags part of the FEN string getFlagsFen() { - return ["w", "b"].map(c => { + return ['w', 'b'].map(c => { return this.castleFlags[c].map(x => x.toString(36)).join(""); }).join(""); } @@ -340,7 +340,7 @@ export default class ChessRules { if (o.init) return "000000000000"; return ( - ["w","b"].map(c => Object.values(this.reserve[c]).join("")).join("") + ['w', 'b'].map(c => Object.values(this.reserve[c]).join("")).join("") ); } @@ -1686,6 +1686,10 @@ export default class ChessRules { getPotentialMovesOf(piece, [x, y]) { const color = this.getColor(x, y); const stepSpec = this.getStepSpec(color, x, y, piece); + + // TODO: pawns, coregal +console.log(stepSpec); + let squares = []; if (stepSpec.attack) { squares = this.findDestSquares( @@ -1792,7 +1796,10 @@ export default class ChessRules { continue outerLoop; const oldIJ = [i, j]; [i, j] = this.increment([i, j], step); - if (Math.abs(j - oldIJ[1]) > 1 || Math.abs(i - oldIJ[0]) > 1) { + if ( + Math.abs(i - oldIJ[0]) != Math.abs(step[0]) || + Math.abs(j - oldIJ[1]) != Math.abs(step[1]) + ) { // Boundary between segments (cylinder or circular mode) segments.push([[segStart[0], segStart[1]], oldIJ]); segStart = [i, j]; @@ -2236,7 +2243,7 @@ export default class ChessRules { } // NOTE: arg "castleFlags" for Coregal or Twokings - updateCastleFlags(move, castleFlags) { + updateCastleFlags(move, castleFlags, king) { castleFlags = castleFlags || this.castleFlags; // If flags already off, no need to re-check: if ( @@ -2247,7 +2254,7 @@ export default class ChessRules { } // Update castling flags if start or arrive from/at rook/king locations move.appear.concat(move.vanish).forEach(psq => { - if (this.isKing(0, 0, psq.p)) + if ((!!king && psq.p == king) || this.isKing(0, 0, psq.p)) castleFlags[psq.c] = [this.size.y, this.size.y]; // NOTE: not "else if" because king can capture enemy rook... let c = "";