X-Git-Url: https://git.auder.net/?a=blobdiff_plain;f=public%2Fjavascripts%2Fvariants%2FDark.js;fp=public%2Fjavascripts%2Fvariants%2FDark.js;h=4031462cd53baf9172d8098d26bbf0444f49cef9;hb=388e4c401f05b1f6a4c54e33c9da9114969a53c0;hp=9cf50513f5ce06b3e2d97ef2cd091a648fa77d16;hpb=375ecdd1387e729f85ed114e82253469e4849869;p=vchess.git diff --git a/public/javascripts/variants/Dark.js b/public/javascripts/variants/Dark.js index 9cf50513..4031462c 100644 --- a/public/javascripts/variants/Dark.js +++ b/public/javascripts/variants/Dark.js @@ -1,25 +1,42 @@ -class Chess960Rules extends ChessRules +class DarkRules extends ChessRules { // Standard rules, in the shadow setOtherVariables(fen) { super.setOtherVariables(fen); - const [sizeX,sizeY] = {V.size.x,V.size.y}; + const [sizeX,sizeY] = [V.size.x,V.size.y]; this.enlightened = { - "w": doubleArray(sizeX,sizeY,false), - "b": doubleArray(sizeX,sizeY,false) + "w": doubleArray(sizeX,sizeY), + "b": doubleArray(sizeX,sizeY) }; - setup enlightened: squares reachable by each side (TODO: one side would be enough) + // Setup enlightened: squares reachable by each side + // (TODO: one side would be enough ?) + this.updateEnlightened(); } - isEnlightened(x, y, color) + updateEnlightened() { - //TODO: artificlaly change turn - } - - getAllPotentialMoves() - { - let moves = []; //TODO + // Initialize with pieces positions (which are seen) + for (let i=0; i but isEnlightened() should have its variable updated - // --> in fact an array is enough (no need for a function) - // recomputed after every play/undo (although there are no undo here for now) + updateVariables(move) + { + // Update kings positions + const piece = move.vanish[0].p; + const c = move.vanish[0].c; + if (piece == V.KING && move.appear.length > 0) + { + this.kingPos[c][0] = move.appear[0].x; + this.kingPos[c][1] = move.appear[0].y; + } + if (move.vanish.length >= 2 && move.vanish[1].p == V.KING) + { + // We took opponent king ! + const oppCol = this.getOppCol(c); + this.kingPos[oppCol] = [-1,-1]; + } + + // Update moves for both colors: + this.updateEnlightened(); + } + + unupdateVariables(move) + { + super.unupdateVariables(move); + const c = move.vanish[0].c; + const oppCol = this.getOppCol(c); + if (this.kingPos[oppCol][0] < 0) + { + // Last move took opponent's king + for (let psq of move.vanish) + { + if (psq.p == 'k') + { + this.kingPos[oppCol] = [psq.x, psq.y]; + break; + } + } + } + + // Update moves for both colors: + this.updateEnlightened(); + } checkGameEnd() {