| 1 | import { ChessRules } from "@/base_rules"; |
| 2 | |
| 3 | // NOTE: a lot copy-pasted from Hoppelpoppel |
| 4 | export class NewzealandRules extends ChessRules { |
| 5 | |
| 6 | // TODO: merge with base_rules.js |
| 7 | getSlideNJumpMoves_([x, y], steps, oneStep, options) { |
| 8 | options = options || {}; |
| 9 | let moves = []; |
| 10 | outerLoop: for (let step of steps) { |
| 11 | let i = x + step[0]; |
| 12 | let j = y + step[1]; |
| 13 | while (V.OnBoard(i, j) && this.board[i][j] == V.EMPTY) { |
| 14 | if (!options.onlyTake) moves.push(this.getBasicMove([x, y], [i, j])); |
| 15 | if (oneStep) continue outerLoop; |
| 16 | i += step[0]; |
| 17 | j += step[1]; |
| 18 | } |
| 19 | if (V.OnBoard(i, j) && this.canTake([x, y], [i, j]) && !options.onlyMove) |
| 20 | moves.push(this.getBasicMove([x, y], [i, j])); |
| 21 | } |
| 22 | return moves; |
| 23 | } |
| 24 | |
| 25 | getPotentialKnightMoves(sq) { |
| 26 | // The knight captures like a rook |
| 27 | return ( |
| 28 | this.getSlideNJumpMoves_( |
| 29 | sq, ChessRules.steps[V.KNIGHT], "oneStep", { onlyMove: true }) |
| 30 | .concat( |
| 31 | this.getSlideNJumpMoves_( |
| 32 | sq, ChessRules.steps[V.ROOK], null, { onlyTake: true })) |
| 33 | ); |
| 34 | } |
| 35 | |
| 36 | getPotentialRookMoves(sq) { |
| 37 | // The rook captures like a knight |
| 38 | return ( |
| 39 | this.getSlideNJumpMoves_( |
| 40 | sq, ChessRules.steps[V.ROOK], null, { onlyMove: true }) |
| 41 | .concat( |
| 42 | this.getSlideNJumpMoves_( |
| 43 | sq, ChessRules.steps[V.KNIGHT], "oneStep", { onlyTake: true })) |
| 44 | ); |
| 45 | } |
| 46 | |
| 47 | isAttackedByKnight([x, y], color) { |
| 48 | return super.isAttackedBySlideNJump( |
| 49 | [x, y], color, V.KNIGHT, V.steps[V.ROOK]); |
| 50 | } |
| 51 | |
| 52 | isAttackedByRook([x, y], color) { |
| 53 | return super.isAttackedBySlideNJump( |
| 54 | [x, y], color, V.ROOK, V.steps[V.KNIGHT], 1); |
| 55 | } |
| 56 | |
| 57 | }; |