X-Git-Url: https://git.auder.net/js/rpsls.js?a=blobdiff_plain;ds=sidebyside;f=base_rules.js;h=85666e209bd361f7de93df1afb92f6874705299f;hb=bc97fdd1302473b774cfb19e65dc3ed3ed388901;hp=ec2571a85c820a86ae5a74bb44cd11d3e6ff90be;hpb=616a8d7ae5ee96fe23d393cf6e4554b2cf3b9245;p=xogo.git diff --git a/base_rules.js b/base_rules.js index ec2571a..85666e2 100644 --- a/base_rules.js +++ b/base_rules.js @@ -1849,9 +1849,7 @@ export default class ChessRules { { captureTarget: [x, y], captureSteps: [{steps: [s], range: a.range}], - segments: o.segments, - attackOnly: true, - one: false //one and captureTarget are mutually exclusive + segments: o.segments }, allowed ); @@ -1989,7 +1987,7 @@ export default class ChessRules { oppCols.includes(this.getColor(x, this.epSquare.y)) ) { const [epx, epy] = [this.epSquare.x, this.epSquare.y]; - this.board[epx][epy] = this.board[x][this.epSquares.y]; + this.board[epx][epy] = this.board[x][this.epSquare.y]; let enpassantMove = this.getBasicMove([x, y], [epx, epy]); this.board[epx][epy] = ""; const lastIdx = enpassantMove.vanish.length - 1; //think Rifle @@ -2167,36 +2165,30 @@ export default class ChessRules { color = this.turn; const oppCols = this.getOppCols(color); let kingPos = this.searchKingPos(color); - let filtered = {}; //avoid re-checking similar moves (promotions...) return moves.filter(m => { - const key = m.start.x + m.start.y + '.' + m.end.x + m.end.y; - if (!filtered[key]) { - this.playOnBoard(m); - let newKingPP = null, - sqIdx = 0, - res = true; //a priori valid - const oldKingPP = - m.vanish.find(v => this.isKing(0, 0, v.p) && v.c == color); - if (oldKingPP) { - // Search king in appear array: - newKingPP = - m.appear.find(a => this.isKing(0, 0, a.p) && a.c == color); - if (newKingPP) { - sqIdx = kingPos.findIndex(kp => - kp[0] == oldKingPP.x && kp[1] == oldKingPP.y); - kingPos[sqIdx] = [newKingPP.x, newKingPP.y]; - } - else - res = false; //king vanished + this.playOnBoard(m); + let newKingPP = null, + sqIdx = 0, + res = true; //a priori valid + const oldKingPP = + m.vanish.find(v => this.isKing(0, 0, v.p) && v.c == color); + if (oldKingPP) { + // Search king in appear array: + newKingPP = + m.appear.find(a => this.isKing(0, 0, a.p) && a.c == color); + if (newKingPP) { + sqIdx = kingPos.findIndex(kp => + kp[0] == oldKingPP.x && kp[1] == oldKingPP.y); + kingPos[sqIdx] = [newKingPP.x, newKingPP.y]; } - res &&= !this.underCheck(kingPos, oppCols); - if (oldKingPP && newKingPP) - kingPos[sqIdx] = [oldKingPP.x, oldKingPP.y]; - this.undoOnBoard(m); - filtered[key] = res; - return res; + else + res = false; //king vanished } - return filtered[key]; + res &&= !this.underCheck(kingPos, oppCols); + if (oldKingPP && newKingPP) + kingPos[sqIdx] = [oldKingPP.x, oldKingPP.y]; + this.undoOnBoard(m); + return res; }); } @@ -2328,7 +2320,7 @@ export default class ChessRules { tryChangeTurn(move) { if (this.isLastMove(move)) { - this.turn = (this.turn == 'w' ? 'b' : 'w'); + this.turn = C.GetOppTurn(this.turn); this.movesCount++; this.subTurn = 1; } @@ -2400,9 +2392,9 @@ export default class ChessRules { if (kingPos[this.turn].length == 0 && kingPos[oppTurn].length == 0) return "1/2"; if (kingPos[this.turn].length == 0) - return (color == "w" ? "0-1" : "1-0"); + return (this.turn == "w" ? "0-1" : "1-0"); if (kingPos[oppTurn].length == 0) - return (color == "w" ? "1-0" : "0-1"); + return (this.turn == "w" ? "1-0" : "0-1"); if (this.atLeastOneMove(this.turn)) return "*"; // No valid move: stalemate or checkmate? @@ -2414,7 +2406,8 @@ export default class ChessRules { playVisual(move, r) { move.vanish.forEach(v => { - this.g_pieces[v.x][v.y].remove(); + if (this.g_pieces[v.x][v.y]) //can be null (e.g. Apocalypse) + this.g_pieces[v.x][v.y].remove(); this.g_pieces[v.x][v.y] = null; }); let chessboard = @@ -2483,6 +2476,10 @@ export default class ChessRules { animateMoving(start, end, drag, segments, cb) { let initPiece = this.getDomPiece(start.x, start.y); + if (!initPiece) { //TODO: shouldn't occur! + cb(); + return; + } // NOTE: cloning often not required, but light enough, and simpler let movingPiece = initPiece.cloneNode(); initPiece.style.opacity = "0";