X-Git-Url: https://git.auder.net/?p=vchess.git;a=blobdiff_plain;f=client%2Fsrc%2Fvariants%2FKnightrelay.js;h=8ccd0e2188a97d1a55bc35d8a5b6841b7ea3490e;hp=79688e2a09f120da9e4ea55e3841c1655f2f9166;hb=1c5bfdf23707e893735f185786e9774b2270ace1;hpb=c322a84434326dff1291a57e82dbd995817a5423 diff --git a/client/src/variants/Knightrelay.js b/client/src/variants/Knightrelay.js index 79688e2a..8ccd0e21 100644 --- a/client/src/variants/Knightrelay.js +++ b/client/src/variants/Knightrelay.js @@ -24,11 +24,7 @@ export const VariantRules = class KnightrelayRules extends ChessRules { V.OnBoard(x+step[0],y+step[1]) && this.getColor(x+step[0],y+step[1]) != color ) { - let m = this.getBasicMove([x,y], [x+step[0],y+step[1]]); - if (!m.appear[0].c || !m.vanish[0].c) - debugger; - moves.push(m); - //moves.push(this.getBasicMove([x,y], [x+step[0],y+step[1]])); + moves.push(this.getBasicMove([x,y], [x+step[0],y+step[1]])); } } } @@ -37,6 +33,37 @@ export const VariantRules = class KnightrelayRules extends ChessRules { return moves; } + isAttacked(sq, colors) { + if (super.isAttacked(sq, colors)) + return true; + + // Check if a (non-knight) piece at knight distance + // is guarded by a knight (and thus attacking) + const x = sq[0], + y = sq[1]; + for (const step of V.steps[V.KNIGHT]) { + if ( + V.OnBoard(x+step[0],y+step[1]) && + colors.includes(this.getColor(x+step[0],y+step[1])) && + this.getPiece(x+step[0],y+step[1]) != V.KNIGHT + ) { + for (const step2 of V.steps[V.KNIGHT]) { + const xx = x+step[0]+step2[0], + yy = y+step[1]+step2[1]; + if ( + V.OnBoard(xx,yy) && + colors.includes(this.getColor(xx,yy)) && + this.getPiece(xx,yy) == V.KNIGHT + ) { + return true; + } + } + } + } + + return false; + } + getNotation(move) { if (move.appear.length == 2 && move.appear[0].p == V.KING) // Castle