X-Git-Url: https://git.auder.net/?a=blobdiff_plain;f=client%2Fsrc%2Fvariants%2FHoppelpoppel.js;fp=client%2Fsrc%2Fvariants%2FHoppelpoppel.js;h=c35046627f9cf65f83f2d232e6ee28b02ab4d847;hb=dbc79ee67847c36aad6b640b15d25d6fb7f361e5;hp=0000000000000000000000000000000000000000;hpb=95bc4bf5248120712946500416543bbfc6b7ae85;p=vchess.git diff --git a/client/src/variants/Hoppelpoppel.js b/client/src/variants/Hoppelpoppel.js new file mode 100644 index 00000000..c3504662 --- /dev/null +++ b/client/src/variants/Hoppelpoppel.js @@ -0,0 +1,64 @@ +import { ChessRules } from "@/base_rules"; + +export class HoppelpoppelRules extends ChessRules { + + getSlideNJumpMoves_([x, y], steps, oneStep, options) { + options = options || {}; + let moves = []; + outerLoop: for (let step of steps) { + let i = x + step[0]; + let j = y + step[1]; + while (V.OnBoard(i, j) && this.board[i][j] == V.EMPTY) { + if (!options.onlyTake) moves.push(this.getBasicMove([x, y], [i, j])); + if (!!oneStep) continue outerLoop; + i += step[0]; + j += step[1]; + } + if (V.OnBoard(i, j) && this.canTake([x, y], [i, j]) && !options.onlyMove) + moves.push(this.getBasicMove([x, y], [i, j])); + } + return moves; + } + + getPotentialKnightMoves(sq) { + // The knight captures like a bishop + return ( + this.getSlideNJumpMoves_( + sq, ChessRules.steps[V.KNIGHT], "oneStep", { onlyMove: true }) + .concat( + this.getSlideNJumpMoves_( + sq, ChessRules.steps[V.BISHOP], null, { onlyTake: true })) + ); + } + + getPotentialBishopMoves(sq) { + // The bishop captures like a knight + return ( + this.getSlideNJumpMoves_( + sq, ChessRules.steps[V.BISHOP], null, { onlyMove: true }) + .concat( + this.getSlideNJumpMoves_( + sq, ChessRules.steps[V.KNIGHT], "oneStep", { onlyTake: true })) + ); + } + + isAttackedByKnight([x, y], color) { + return super.isAttackedBySlideNJump( + [x, y], + color, + V.KNIGHT, + V.steps[V.BISHOP] + ); + } + + isAttackedByAntiking([x, y], color) { + return super.isAttackedBySlideNJump( + [x, y], + color, + V.BISHOP, + V.steps[V.KNIGHT], + "oneStep" + ); + } + +};