| 1 | class AntikingRules |
| 2 | { |
| 3 | // Path to pieces |
| 4 | static getPpath(b) |
| 5 | { |
| 6 | return b[1]=='a' ? "Antiking/"+b : b; |
| 7 | } |
| 8 | |
| 9 | static get ANTIKING() { return 'a'; } |
| 10 | |
| 11 | initVariables(fen) |
| 12 | { |
| 13 | super.initVariables(fen); |
| 14 | // TODO: initialize this.antikingPos[...] |
| 15 | } |
| 16 | |
| 17 | canTake(color1, color2, [x,y]) |
| 18 | { |
| 19 | const piece = this.getPiece(x,y); |
| 20 | return (piece != "a" && color1 != color2) || (piece == "a" && color1 == color2); |
| 21 | } |
| 22 | |
| 23 | getPotentialMovesFrom([x,y]) |
| 24 | { |
| 25 | let c = this.getColor(x,y); |
| 26 | switch (this.getPiece(x,y)) |
| 27 | { |
| 28 | case VariantRules.ANTIKING: |
| 29 | return this.getPotentialAntikingMoves(x,y,c); |
| 30 | default: |
| 31 | return super.getPotentielMovesFrom([x,y]); |
| 32 | } |
| 33 | } |
| 34 | |
| 35 | getPotentialAntikingMoves([x,y]) |
| 36 | { |
| 37 | // TODO |
| 38 | } |
| 39 | |
| 40 | isAttacked(sq, colors) |
| 41 | { |
| 42 | return (super.isAttacked(sq, colors) || this.isAttackedByAntiking(sq, colors)); |
| 43 | } |
| 44 | |
| 45 | isAttackedByAntiking(sq, color) |
| 46 | { |
| 47 | // TODO |
| 48 | } |
| 49 | |
| 50 | underCheck(move) |
| 51 | { |
| 52 | const c = this.turn; |
| 53 | this.play(move); |
| 54 | let res = this.isAttacked(this.kingPos[c], this.getOppCol(c)); |
| 55 | // TODO: also check that antiking is still in check |
| 56 | this.undo(move); |
| 57 | return res; |
| 58 | } |
| 59 | |
| 60 | getCheckSquares(move) |
| 61 | { |
| 62 | this.play(move); |
| 63 | const c = this.turn; |
| 64 | // TODO |
| 65 | let res = this.isAttacked(this.kingPos[c], this.getOppCol(c)) |
| 66 | ? [ JSON.parse(JSON.stringify(this.kingPos[c])) ] |
| 67 | : [ ]; |
| 68 | this.undo(move); |
| 69 | return res; |
| 70 | } |
| 71 | |
| 72 | // TODO: need antikingPos as well |
| 73 | updateVariables(move) |
| 74 | { |
| 75 | // ... |
| 76 | } |
| 77 | |
| 78 | unupdateVariables(move) |
| 79 | { |
| 80 | // TODO |
| 81 | } |
| 82 | |
| 83 | checkGameEnd(color) |
| 84 | { |
| 85 | // TODO |
| 86 | if (!this.isAttacked(this.kingPos[color], this.getOppCol(color))) |
| 87 | return "1/2"; |
| 88 | return color == "w" ? "0-1" : "1-0"; |
| 89 | } |
| 90 | |
| 91 | // Pieces values (TODO: use Object.assign() + ChessRules.VALUES ?) |
| 92 | static get VALUES() { |
| 93 | return { |
| 94 | 'p': 1, |
| 95 | 'r': 5, |
| 96 | 'n': 3, |
| 97 | 'b': 3, |
| 98 | 'q': 9, |
| 99 | 'k': 1000, |
| 100 | 'a': 1000 |
| 101 | }; |
| 102 | } |
| 103 | |
| 104 | static GenRandInitFen() |
| 105 | { |
| 106 | let randFen = ChessRules.GenRandInitFen(); |
| 107 | // TODO: just add an antiking at random on 3rd ranks |
| 108 | return randFen; |
| 109 | } |
| 110 | } |