X-Git-Url: https://git.auder.net/?a=blobdiff_plain;f=client%2Fsrc%2Fvariants%2FConvert.js;h=c501c023a87b0f2ce7bf5059bafc52422b0e00df;hb=4313762da3237b04f204e121a20cab3ba7bb5dd2;hp=297d08dbd4a59e2e77d715ff2843f73f47dc65aa;hpb=1006b211894bdc0624e2fd332ac78322bf8ca0ee;p=vchess.git diff --git a/client/src/variants/Convert.js b/client/src/variants/Convert.js index 297d08db..c501c023 100644 --- a/client/src/variants/Convert.js +++ b/client/src/variants/Convert.js @@ -3,12 +3,25 @@ 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(options) { + const baseFen = ChessRules.GenRandInitFen(options); + 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 +179,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 +208,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 +261,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 }