X-Git-Url: https://git.auder.net/?a=blobdiff_plain;f=base_rules.js;h=9eb18fcfc66663d74a71086bc84f3da3a43661de;hb=99ea245370e6de1e3122f61fc18c2a557b8ae711;hp=a2cb95169f38767d837c4b7696c6d654915a6800;hpb=639afc982f9c3be3b4748ef10e8ef771a295712f;p=xogo.git diff --git a/base_rules.js b/base_rules.js index a2cb951..9eb18fc 100644 --- a/base_rules.js +++ b/base_rules.js @@ -1354,7 +1354,6 @@ export default class ChessRules { const lastRank = (color == "w" ? 0 : this.size.x - 1); const initPiece = this.getPiece(moves[0].start.x, moves[0].start.y); moves.forEach(m => { - let finalPieces = ["p"]; const [x1, y1] = [m.start.x, m.start.y]; const [x2, y2] = [m.end.x, m.end.y]; const promotionOk = ( @@ -1363,34 +1362,30 @@ export default class ChessRules { ); if (!promotionOk) return; //nothing to do - if (!this.options["pawnfall"]) { - if ( - this.options["cannibal"] && - this.board[x2][y2] != "" && - this.getColor(x2, y2) == oppCol - ) { - finalPieces = [this.getPieceType(x2, y2)]; - } - else - finalPieces = this.pawnPromotions; + if (this.options["pawnfall"]) { + m.appear.shift(); + return; + } + let finalPieces = ["p"]; + if ( + this.options["cannibal"] && + this.board[x2][y2] != "" && + this.getColor(x2, y2) == oppCol + ) { + finalPieces = [this.getPieceType(x2, y2)]; } + else + finalPieces = this.pawnPromotions; m.appear[0].p = finalPieces[0]; if (initPiece == "!") //cannibal king-pawn m.appear[0].p = C.CannibalKingCode[finalPieces[0]]; for (let i=1; i { + return this.castleFlags[c].some(val => val < this.size.y)}) ) { - // OK, not a drop move - if ( - this.hasCastle && - // If flags already off, no need to re-check: - Object.keys(this.castleFlags).some(c => { - return this.castleFlags[c].some(val => val < this.size.y)}) - ) { - this.updateCastleFlags(move); - } - const initSquare = C.CoordsToSquare(move.start); - if ( - this.options["crazyhouse"] && - (!this.options["rifle"] || !move.capture) - ) { + this.updateCastleFlags(move); + } + if (this.options["crazyhouse"]) { + move.vanish.forEach(v => { + const square = C.CoordsToSquare({x: v.x, y: v.y}); + if (this.ispawn[square]) + delete this.ispawn[square]; + }); + if (move.appear.length > 0 && move.vanish.length > 0) { + // Assumption: something is moving + const initSquare = C.CoordsToSquare(move.start); const destSquare = C.CoordsToSquare(move.end); - if (this.ispawn[initSquare]) { - delete this.ispawn[initSquare]; - this.ispawn[destSquare] = true; - } - else if ( - move.vanish[0].p == "p" && - move.appear[0].p != "p" + if ( + this.ispawn[initSquare] || + (move.vanish[0].p == "p" && move.appear[0].p != "p") ) { this.ispawn[destSquare] = true; } @@ -1987,6 +1978,10 @@ export default class ChessRules { } } } + + // TODO: robustify this by adding fields + // "captures" (capts?) and "births" (e.g...) to Move + // --> store only indices in appear/vanish ? const minSize = Math.min(move.appear.length, move.vanish.length); if (this.hasReserve && !move.pawnfall) { const color = this.turn; @@ -2002,6 +1997,12 @@ export default class ChessRules { this.updateReserve(color, piece, this.reserve[color][piece] + 1); } } + move.captures.forEach(capt => { + // TODO + }); + move.births.forEach(bth => { + // TODO + }); } play(move) {