X-Git-Url: https://git.auder.net/?a=blobdiff_plain;f=public%2Fjavascripts%2Fvariants%2FCheckered.js;h=a74143b9c21e89424d96318981d4ef1d71fc8053;hb=cd4cad0468612cf00c6e6879554e3cee58d4b1f9;hp=322d8fc0d398627501c931f5388005d6abeb37fb;hpb=1d184b4c016a645228251ce984d4c980e60420b0;p=vchess.git diff --git a/public/javascripts/variants/Checkered.js b/public/javascripts/variants/Checkered.js index 322d8fc0..a74143b9 100644 --- a/public/javascripts/variants/Checkered.js +++ b/public/javascripts/variants/Checkered.js @@ -32,24 +32,6 @@ class CheckeredRules extends ChessRules return ChessRules.fen2board(f); } - initVariables(fen) - { - super.initVariables(fen); - // Decode last non-capturing checkered move (if any) - const cmove = fen.split(" ")[4]; - if (cmove != "-") - { - const piece = cmove.charAt(0); - const startEnd = cmove.substr(1).split(";"); - const start = startEnd[0].split(","); - const end = startEnd[1].split(","); - this.moves.push(new Move({ - appear: [ new PiPo({c:"c", p:piece, x:end[0], y:end[1]}) ], - vanish: [ new PiPo({c:"c", p:piece, x:start[0], y:start[1]}) ] - })); - } - } - static GetFlags(fen) { let flags = [ @@ -294,8 +276,8 @@ class CheckeredRules extends ChessRules canIplay(color, sq) { - return ((color=='w' && this.movesCount%2==0) || color=='c' - || (color=='b' && this.movesCount%2==1)) + return ((color=='w' && this.moves.length%2==0) || color=='c' + || (color=='b' && this.moves.length%2==1)) && [color,'c'].includes(this.getColor(sq[0], sq[1])); } @@ -353,6 +335,20 @@ class CheckeredRules extends ChessRules return res; } + getCheckSquares(move, c) + { + this.play(move); + this.moves.push(move); //artifically change turn, for checkered pawns (TODO) + const kingAttacked = this.isAttacked(this.kingPos[c], this.getOppCol(c)) + || this.isAttacked(this.kingPos[c], 'c'); + let res = kingAttacked + ? [ JSON.parse(JSON.stringify(this.kingPos[c])) ] //need to duplicate! + : [ ]; + this.moves.pop(); + this.undo(move); + return res; + } + updateVariables(move) { const piece = this.getPiece(move.start.x,move.start.y); @@ -391,19 +387,6 @@ class CheckeredRules extends ChessRules this.flags[1][move.start.x==6 ? "w" : "b"][move.start.y] = false; } - play(move, ingame) - { - super.play(move, ingame); - if (!ingame) - this.moves.push(move); //needed for turn indication for checkered pieces - } - - undo(move) - { - super.undo(move); - this.moves.pop(); - } - checkGameEnd(color) { if (!this.isAttacked(this.kingPos[color], this.getOppCol(color)) @@ -437,23 +420,7 @@ class CheckeredRules extends ChessRules static GenRandInitFen() { - let fen = ChessRules.GenRandInitFen(); - return fen.replace(/ - 0$/, "1111111111111111 - 0 -"); - } - - getFen() - { - let fen = super.getFen() + " "; - const L = this.moves.length; - if (L > 0 && this.moves[L-1].vanish.length==1 && this.moves[L-1].appear[0].c=="c") - { - // Ok, un-cancellable checkered move - fen += this.moves[L-1].appear[0].p - + this.moves[L-1].start.x + "," + this.moves[L-1].start.y + ";" - + this.moves[L-1].end.x + "," + this.moves[L-1].end.y; - } - else fen += "-"; - return fen; + return ChessRules.GenRandInitFen() + "1111111111111111"; //add 16 pawns flags } getFlagsFen()