From: Benjamin Auder Date: Wed, 28 Nov 2018 02:07:29 +0000 (+0100) Subject: Switching chess almost OK, Extinction seems OK, Crazyhouse advanced draft but to... X-Git-Url: https://git.auder.net/doc/html/assets/current/%7B%7B%20pkg.url%20%7D%7D?a=commitdiff_plain;h=1221ac47836806efb287b0323b92957d9129c653;p=vchess.git Switching chess almost OK, Extinction seems OK, Crazyhouse advanced draft but to be debugged --- diff --git a/TODO b/TODO index bcda2e84..fe7d8473 100644 --- a/TODO +++ b/TODO @@ -2,3 +2,5 @@ For animation, moves should contains "moving" and "fading" maybe... (But it's really just for Magnetic chess) setInterval "CRON" task in sockets.js to check connected clients (every 1hour maybe, or more) +Systematically show init+dest squares in PGN, maybe after short notation +(2 moves list, second for de-ambiguification) diff --git a/public/javascripts/base_rules.js b/public/javascripts/base_rules.js index f1188ab5..360f60c5 100644 --- a/public/javascripts/base_rules.js +++ b/public/javascripts/base_rules.js @@ -276,7 +276,8 @@ class ChessRules { let i = x + step[0]; let j = y + step[1]; - while (i>=0 && i=0 && j=0 && i=0 && j0 && this.canTake([x,y], [x+shift,y-1]) && this.board[x+shift][y-1] != V.EMPTY) + if (y>0 && this.canTake([x,y], [x+shift,y-1]) + && this.board[x+shift][y-1] != V.EMPTY) + { moves.push(this.getBasicMove([x,y], [x+shift,y-1])); - if (y0 && this.canTake([x,y], [x+shift,y-1]) && this.board[x+shift][y-1] != V.EMPTY) + if (y>0 && this.canTake([x,y], [x+shift,y-1]) + && this.board[x+shift][y-1] != V.EMPTY) + { moves.push(this.getBasicMove([x,y], [x+shift,y-1], {c:color,p:p})); - if (y + // 3 + { + let reservePiecesArray = []; + for (let i=0; i { + if (m.vanish.length == 2) + this.reserve[m.appear[0].c][m.vanish[1].p]++; + else if (m.vanish.length == 0) + this.reserve[m.appear[0].c][m.appear[0].p]--; + }); } // Used by the interface: - getReservePieces(color) + getReservePpath(color, index) { - return { - [color+V.PAWN]: this.reserve[color][V.PAWN], - [color+V.ROOK]: this.reserve[color][V.ROOK], - [color+V.KNIGHT]: this.reserve[color][V.KNIGHT], - [color+V.BISHOP]: this.reserve[color][V.BISHOP], - [color+V.QUEEN]: this.reserve[color][V.QUEEN], - }; + return color + VariantRules.RESERVE_PIECES[index]; } - getPotentialMovesFrom([x,y]) + // Put an ordering on reserve pieces + static get RESERVE_PIECES() { + const V = VariantRules; + return [V.PAWN,V.ROOK,V.KNIGHT,V.BISHOP,V.QUEEN]; + } + + getReserveMoves([x,y]) { - let moves = super.getPotentialMovesFrom([x,y]); - // Add landing moves: const color = this.turn; - Object.keys(this.reserve[color]).forEach(p => { - - moves.push(...); //concat... just appear - }); + const p = VariantRules.RESERVE_PIECES[y]; + if (this.reserve[color][p] == 0) + return []; + let moves = []; + for (let i=0; i special square !!! coordinates ?? - getPossibleMovesFrom(sq) + getPotentialMovesFrom([x,y]) { - // Assuming color is right (already checked) - return this.filterValid( this.getPotentialMovesFrom(sq) ); + const sizeX = VariantRules.size[0]; + if (x < sizeX) + return super.getPotentialMovesFrom([x,y]); + // Reserves, outside of board: x == sizeX + return this.getReserveMoves([x,y]); } - // TODO: add reserve moves getAllValidMoves() { - + let moves = super.getAllValidMoves(); + const color = this.turn; + const sizeX = VariantRules.size[0]; + for (let i=0; i 0) + return true; + } + return false; + } + return true; } - // TODO: update reserve updateVariables(move) { + super.updateVariables(move); + const color = this.turn; + if (move.vanish.length==2) + this.reserve[color][move.appear[0].p]++; + if (move.vanish.length==0) + this.reserve[color][move.appear[0].p]--; } + unupdateVariables(move) { + super.unupdateVariables(move); + const color = this.turn; + if (move.vanish.length==2) + this.reserve[color][move.appear[0].p]--; + if (move.vanish.length==0) + this.reserve[color][move.appear[0].p]++; } static get SEARCH_DEPTH() { return 2; } //high branching factor diff --git a/public/javascripts/variants/Extinction.js b/public/javascripts/variants/Extinction.js index db330d9e..9be4b0d7 100644 --- a/public/javascripts/variants/Extinction.js +++ b/public/javascripts/variants/Extinction.js @@ -27,6 +27,37 @@ class ExtinctionRules extends ChessRules }; } + getPotentialPawnMoves([x,y]) + { + let moves = super.getPotentialPawnMoves([x,y]); + // Add potential promotions into king + const color = this.turn; + const V = VariantRules; + const [sizeX,sizeY] = V.size; + const shift = (color == "w" ? -1 : 1); + const lastRank = (color == "w" ? 0 : sizeX-1); + + if (x+shift == lastRank) + { + // Normal move + if (this.board[x+shift][y] == V.EMPTY) + moves.push(this.getBasicMove([x,y], [x+shift,y], {c:color,p:V.KING})); + // Captures + if (y>0 && this.canTake([x,y], [x+shift,y-1]) + && this.board[x+shift][y-1] != V.EMPTY) + { + moves.push(this.getBasicMove([x,y], [x+shift,y-1], {c:color,p:V.KING})); + } + if (y { return this.material[color][p] == 0; })) + { + return (color=="w"?-1:1) * VariantRules.INFINITY; + } return super.evalPosition(); } } diff --git a/public/javascripts/variants/Magnetic.js b/public/javascripts/variants/Magnetic.js index 844cc689..03912e7e 100644 --- a/public/javascripts/variants/Magnetic.js +++ b/public/javascripts/variants/Magnetic.js @@ -112,7 +112,8 @@ class MagneticRules extends ChessRules // Scan move for pawn (max 1) on 8th rank for (let i=1; i=0 && i=0 && j=0 && i=0 && j=0 && i=0 && j=0 && i=0 && j