| 1 | import { ChessRules } from "@/base_rules"; |
| 2 | |
| 3 | export const VariantRules = class ChaturangaRules extends ChessRules { |
| 4 | static get HasFlags() { |
| 5 | return false; |
| 6 | } |
| 7 | |
| 8 | static get HasEnpassant() { |
| 9 | return false; |
| 10 | } |
| 11 | |
| 12 | static get ElephantSteps() { |
| 13 | return [ |
| 14 | [-2, -2], |
| 15 | [-2, 2], |
| 16 | [2, -2], |
| 17 | [2, 2] |
| 18 | ]; |
| 19 | } |
| 20 | |
| 21 | static GenRandInitFen() { |
| 22 | return ChessRules.GenRandInitFen().replace("w 1111 -", "w"); |
| 23 | } |
| 24 | |
| 25 | getPotentialPawnMoves([x, y]) { |
| 26 | const color = this.turn; |
| 27 | let moves = []; |
| 28 | const [sizeX, sizeY] = [V.size.x, V.size.y]; |
| 29 | const shiftX = color == "w" ? -1 : 1; |
| 30 | const startRank = color == "w" ? sizeX - 2 : 1; |
| 31 | const lastRank = color == "w" ? 0 : sizeX - 1; |
| 32 | // Promotion in minister (queen) only: |
| 33 | const finalPiece = x + shiftX == lastRank ? V.QUEEN : V.PAWN; |
| 34 | |
| 35 | if (this.board[x + shiftX][y] == V.EMPTY) { |
| 36 | // One square forward |
| 37 | moves.push( |
| 38 | this.getBasicMove([x, y], [x + shiftX, y], { |
| 39 | c: color, |
| 40 | p: finalPiece |
| 41 | }) |
| 42 | ); |
| 43 | } |
| 44 | // Captures |
| 45 | for (let shiftY of [-1, 1]) { |
| 46 | if ( |
| 47 | y + shiftY >= 0 && |
| 48 | y + shiftY < sizeY && |
| 49 | this.board[x + shiftX][y + shiftY] != V.EMPTY && |
| 50 | this.canTake([x, y], [x + shiftX, y + shiftY]) |
| 51 | ) { |
| 52 | moves.push( |
| 53 | this.getBasicMove([x, y], [x + shiftX, y + shiftY], { |
| 54 | c: color, |
| 55 | p: finalPiece |
| 56 | }) |
| 57 | ); |
| 58 | } |
| 59 | } |
| 60 | |
| 61 | return moves; |
| 62 | } |
| 63 | |
| 64 | getPotentialBishopMoves(sq) { |
| 65 | let moves = this.getSlideNJumpMoves(sq, V.ElephantSteps, "oneStep"); |
| 66 | // Complete with "repositioning moves": like a queen, without capture |
| 67 | let repositioningMoves = this.getSlideNJumpMoves( |
| 68 | sq, |
| 69 | V.steps[V.BISHOP], |
| 70 | "oneStep" |
| 71 | ).filter(m => m.vanish.length == 1); |
| 72 | return moves.concat(repositioningMoves); |
| 73 | } |
| 74 | |
| 75 | getPotentialQueenMoves(sq) { |
| 76 | return this.getSlideNJumpMoves( |
| 77 | sq, |
| 78 | V.steps[V.BISHOP], |
| 79 | "oneStep" |
| 80 | ); |
| 81 | } |
| 82 | |
| 83 | getPotentialKingMoves(sq) { |
| 84 | return this.getSlideNJumpMoves( |
| 85 | sq, |
| 86 | V.steps[V.ROOK].concat(V.steps[V.BISHOP]), |
| 87 | "oneStep" |
| 88 | ); |
| 89 | } |
| 90 | |
| 91 | isAttackedByBishop(sq, colors) { |
| 92 | return this.isAttackedBySlideNJump( |
| 93 | sq, |
| 94 | colors, |
| 95 | V.BISHOP, |
| 96 | V.ElephantSteps, |
| 97 | "oneStep" |
| 98 | ); |
| 99 | } |
| 100 | |
| 101 | isAttackedByQueen(sq, colors) { |
| 102 | return this.isAttackedBySlideNJump( |
| 103 | sq, |
| 104 | colors, |
| 105 | V.QUEEN, |
| 106 | V.steps[V.BISHOP], |
| 107 | "oneStep" |
| 108 | ); |
| 109 | } |
| 110 | |
| 111 | static get VALUES() { |
| 112 | return { |
| 113 | p: 1, |
| 114 | r: 5, |
| 115 | n: 3, |
| 116 | b: 2.5, |
| 117 | q: 2, |
| 118 | k: 1000 |
| 119 | }; |
| 120 | } |
| 121 | }; |