X-Git-Url: https://git.auder.net/?a=blobdiff_plain;f=client%2Fsrc%2Fvariants%2FConvert.js;h=1180e375a26225b2266af7db0af2ce84a23bd115;hb=52bba5a41ea04d89922d4a039e5aa405b72aff00;hp=297d08dbd4a59e2e77d715ff2843f73f47dc65aa;hpb=1006b211894bdc0624e2fd332ac78322bf8ca0ee;p=vchess.git diff --git a/client/src/variants/Convert.js b/client/src/variants/Convert.js index 297d08db..1180e375 100644 --- a/client/src/variants/Convert.js +++ b/client/src/variants/Convert.js @@ -3,12 +3,27 @@ import { randInt } from "@/utils/alea"; export class ConvertRules extends ChessRules { + static get HasEnpassant() { + return false; + } + setOtherVariables(fen) { super.setOtherVariables(fen); // Stack of "last move" only for intermediate chaining this.lastMoveEnd = [null]; } + static GenRandInitFen(randomness) { + if (randomness == 0) + return "rnbqkbnr/8/pppppppp/8/8/PPPPPPPP/8/RNBQKBNR w 0 ahah"; + const baseFen = ChessRules.GenRandInitFen(randomness); + return ( + baseFen.substr(0, 8) + + "/8/pppppppp/8/8/PPPPPPPP/8/" + + baseFen.substr(35, 17) + ); + } + getBasicMove([sx, sy], [ex, ey], tr) { const L = this.lastMoveEnd.length; const lm = this.lastMoveEnd[L-1]; @@ -166,9 +181,23 @@ export class ConvertRules extends ChessRules { return []; } + prePlay(move) { + const c = this.turn; + // Extra conditions to avoid tracking converted kings: + if ( + move.appear[0].p == V.KING && + move.vanish.length >= 1 && + move.vanish[0].p == V.KING + ) { + this.kingPos[c][0] = move.appear[0].x; + this.kingPos[c][1] = move.appear[0].y; + } + } + play(move) { + this.prePlay(move); + const c = this.turn; move.flags = JSON.stringify(this.aggregateFlags()); - this.epSquares.push(this.getEpSquare(move)); V.PlayOnBoard(this.board, move); if (!move.end.converted) { // Not a capture: change turn @@ -181,29 +210,29 @@ export class ConvertRules extends ChessRules { Object.assign({}, move.end, { p: move.end.converted }) ); } - this.postPlay(move); - } - - postPlay(move) { - const c = (!move.end.converted ? V.GetOppCol(this.turn) : this.turn); - const piece = move.appear[0].p; - if (piece == V.KING) { - this.kingPos[c][0] = move.appear[0].x; - this.kingPos[c][1] = move.appear[0].y; - } - super.updateCastleFlags(move, piece, c); + super.updateCastleFlags(move, move.appear[0].p, c); } undo(move) { this.disaggregateFlags(JSON.parse(move.flags)); - this.epSquares.pop(); this.lastMoveEnd.pop(); V.UndoOnBoard(this.board, move); if (!move.end.converted) { this.turn = V.GetOppCol(this.turn); this.movesCount--; } - super.postUndo(move); + this.postUndo(move); + } + + postUndo(move) { + const c = this.getColor(move.start.x, move.start.y); + if ( + move.appear[0].p == V.KING && + move.vanish.length >= 1 && + move.vanish[0].p == V.KING + ) { + this.kingPos[c] = [move.start.x, move.start.y]; + } } getCurrentScore() { @@ -234,7 +263,7 @@ export class ConvertRules extends ChessRules { else break; } for (let i = mvArray.length - 1; i >= 0; i--) this.undo(mvArray[i]); - if (!mv.end.released) return (mvArray.length > 1 ? mvArray : mvArray[0]); + if (!mv.end.converted) return (mvArray.length > 1 ? mvArray : mvArray[0]); } return null; //never reached }