| 1 | class ExtinctionRules extends ChessRules |
| 2 | { |
| 3 | initVariables(fen) |
| 4 | { |
| 5 | super.initVariables(fen); |
| 6 | const V = VariantRules; |
| 7 | this.material = |
| 8 | { |
| 9 | "w": |
| 10 | { |
| 11 | [V.KING]: 1, |
| 12 | [V.QUEEN]: 1, |
| 13 | [V.ROOK]: 2, |
| 14 | [V.KNIGHT]: 2, |
| 15 | [V.BISHOP]: 2, |
| 16 | [V.PAWN]: 8 |
| 17 | }, |
| 18 | "b": |
| 19 | { |
| 20 | [V.KING]: 1, |
| 21 | [V.QUEEN]: 1, |
| 22 | [V.ROOK]: 2, |
| 23 | [V.KNIGHT]: 2, |
| 24 | [V.BISHOP]: 2, |
| 25 | [V.PAWN]: 8 |
| 26 | } |
| 27 | }; |
| 28 | } |
| 29 | |
| 30 | // TODO: verify this assertion |
| 31 | atLeastOneMove() |
| 32 | { |
| 33 | return true; //always at least one possible move |
| 34 | } |
| 35 | |
| 36 | underCheck(move) |
| 37 | { |
| 38 | return false; //there is no check |
| 39 | } |
| 40 | |
| 41 | getCheckSquares(move) |
| 42 | { |
| 43 | return []; |
| 44 | } |
| 45 | |
| 46 | updateVariables(move) |
| 47 | { |
| 48 | super.updateVariables(move); |
| 49 | if (move.vanish.length==2 && move.appear.length==1) |
| 50 | this.material[move.vanish[1].c][move.vanish[1].p]--; |
| 51 | } |
| 52 | |
| 53 | unupdateVariables(move) |
| 54 | { |
| 55 | super.unupdateVariables(move); |
| 56 | if (move.vanish.length==2 && move.appear.length==1) |
| 57 | this.material[move.vanish[1].c][move.vanish[1].p]++; |
| 58 | } |
| 59 | |
| 60 | checkGameOver() |
| 61 | { |
| 62 | if (this.checkRepetition()) |
| 63 | return "1/2"; |
| 64 | |
| 65 | if (this.atLeastOneMove()) // game not over? |
| 66 | { |
| 67 | const color = this.turn; |
| 68 | if (Object.keys(this.material[color]).some( |
| 69 | p => { return this.material[color][p] == 0; })) |
| 70 | { |
| 71 | return this.checkGameEnd(); |
| 72 | } |
| 73 | return "*"; |
| 74 | } |
| 75 | |
| 76 | return this.checkGameEnd(); |
| 77 | } |
| 78 | |
| 79 | // Very negative (resp. positive) if white (reps. black) pieces set is incomplete |
| 80 | evalPosition() |
| 81 | { |
| 82 | if (this.missAkind()) |
| 83 | return (this.turn=="w"?-1:1) * VariantRules.INFINITY; |
| 84 | return super.evalPosition(); |
| 85 | } |
| 86 | } |