X-Git-Url: https://git.auder.net/?a=blobdiff_plain;f=client%2Fsrc%2Fvariants%2FCannibal.js;h=a0da0fd6c341cfe41af4cd1721a3609fa7245b44;hb=f52671e5b5b50b1421474f27dc9c18f701b559f3;hp=1d8469e2419be18c51c9a63bc5ecee03bbb03784;hpb=7301aa5ff93c6b0cf6b2c41a24d552597b689693;p=vchess.git diff --git a/client/src/variants/Cannibal.js b/client/src/variants/Cannibal.js index 1d8469e2..a0da0fd6 100644 --- a/client/src/variants/Cannibal.js +++ b/client/src/variants/Cannibal.js @@ -112,38 +112,9 @@ export class CannibalRules extends ChessRules { // Because of the disguised kings, getPiece() could be wrong: // use board[x][y][1] instead (always valid). getBasicMove([sx, sy], [ex, ey], tr) { - const initColor = this.getColor(sx, sy); - const initPiece = this.board[sx][sy].charAt(1); - let mv = new Move({ - appear: [ - new PiPo({ - x: ex, - y: ey, - c: tr ? tr.c : initColor, - p: tr ? tr.p : initPiece - }) - ], - vanish: [ - new PiPo({ - x: sx, - y: sy, - c: initColor, - p: initPiece - }) - ] - }); - - // The opponent piece disappears if we take it - if (this.board[ex][ey] != V.EMPTY) { - mv.vanish.push( - new PiPo({ - x: ex, - y: ey, - c: this.getColor(ex, ey), - p: this.board[ex][ey].charAt(1) - }) - ); + let mv = super.getBasicMove([sx, sy], [ex, ey], tr); + if (this.board[ex][ey] != V.EMPTY) { // If the captured piece has a different nature: take it as well if (mv.vanish[0].p != mv.vanish[1].p) { if ( @@ -151,7 +122,8 @@ export class CannibalRules extends ChessRules { Object.keys(V.KING_DECODE).includes(mv.vanish[0].p) ) { mv.appear[0].p = V.KING_CODE[mv.vanish[1].p]; - } else mv.appear[0].p = mv.vanish[1].p; + } + else mv.appear[0].p = mv.vanish[1].p; } } else if (!!tr && mv.vanish[0].p != V.PAWN)