| 1 | import ChessRules from "/base_rules.js"; |
| 2 | |
| 3 | export default class DobutsuRules extends ChessRules { |
| 4 | |
| 5 | static get Options() { |
| 6 | return {}; |
| 7 | } |
| 8 | |
| 9 | get hasFlags() { |
| 10 | return false; |
| 11 | } |
| 12 | |
| 13 | get hasEnpassant() { |
| 14 | return false; |
| 15 | } |
| 16 | |
| 17 | pieces(color, x, y) { |
| 18 | const pawnShift = this.getPawnShift(color || 'w'); |
| 19 | // NOTE: classs change according to playerColor (orientation) |
| 20 | const mySide = (this.playerColor == color); |
| 21 | return { |
| 22 | 'p': { |
| 23 | "class": (mySide ? "" : "rev-") + "chick", |
| 24 | both: [{steps: [[pawnShift, 0]], range: 1}] |
| 25 | }, |
| 26 | 'h': { |
| 27 | "class": (mySide ? "" : "rev-") + "hen", |
| 28 | both: [ |
| 29 | { |
| 30 | steps: [ |
| 31 | [pawnShift, 1], [pawnShift, -1], |
| 32 | [0, 1], [0, -1], [1, 0], [-1, 0] |
| 33 | ], |
| 34 | range: 1 |
| 35 | } |
| 36 | ] |
| 37 | }, |
| 38 | 'e': { |
| 39 | "class": (mySide ? "" : "rev-") + "elephant", |
| 40 | both: [{steps: [[-1, 1], [-1, -1], [1, 1], [1, -1]], range: 1}] |
| 41 | }, |
| 42 | 'g': { |
| 43 | "class": (mySide ? "" : "rev-") + "giraffe", |
| 44 | both: [{steps: [[0, 1], [0, -1], [1, 0], [-1, 0]], range: 1}] |
| 45 | }, |
| 46 | 'k': { |
| 47 | "class": (mySide ? "" : "rev-") + "lion", |
| 48 | both: [{ |
| 49 | steps: [[-1, 1], [-1, -1], [1, 1], [1, -1], |
| 50 | [0, 1], [0, -1], [1, 0], [-1, 0]], |
| 51 | range: 1 |
| 52 | }] |
| 53 | } |
| 54 | }; |
| 55 | } |
| 56 | |
| 57 | static get ReserveArray() { |
| 58 | return ['p', 'h', 'e', 'g']; |
| 59 | } |
| 60 | |
| 61 | updateReserve(color, piece, count) { |
| 62 | if (piece != 'k') |
| 63 | super.updateReserve(color, piece, count); |
| 64 | } |
| 65 | |
| 66 | constructor(o) { |
| 67 | o.options = {crazyhouse: true, taking: true}; |
| 68 | super(o); |
| 69 | } |
| 70 | |
| 71 | get pawnPromotions() { |
| 72 | return ['h']; |
| 73 | } |
| 74 | |
| 75 | genRandInitBaseFen() { |
| 76 | return { |
| 77 | fen: "gke/1p1/1P1/EKG", |
| 78 | o: {} |
| 79 | }; |
| 80 | } |
| 81 | |
| 82 | get size() { |
| 83 | return {x: 4, y: 3}; |
| 84 | } |
| 85 | |
| 86 | getCurrentScore(move_s) { |
| 87 | const res = super.getCurrentScore(move_s); |
| 88 | if (res != '*') |
| 89 | return res; |
| 90 | for (let lastRank of [0, 3]) { |
| 91 | const color = (lastRank == 0 ? 'w' : 'b'); |
| 92 | for (let j=0; j < this.size.y; j++) { |
| 93 | if ( |
| 94 | this.board[lastRank][j] == color + 'k' && |
| 95 | !this.underAttack([lastRank, j], [C.GetOppTurn(color)]) |
| 96 | ) { |
| 97 | return (color == 'w' ? "1-0" : "0-1"); |
| 98 | } |
| 99 | } |
| 100 | } |
| 101 | return "*"; |
| 102 | } |
| 103 | |
| 104 | }; |