1 import { ChessRules
} from "@/base_rules";
3 export const VariantRules
= class ExtinctionRules
extends ChessRules
{
4 setOtherVariables(fen
) {
5 super.setOtherVariables(fen
);
6 const pos
= V
.ParseFen(fen
).position
;
7 // NOTE: no need for safety "|| []", because each piece type must be present
8 // (otherwise game is already over!)
11 [V
.KING
]: pos
.match(/K
/g
).length
,
12 [V
.QUEEN
]: pos
.match(/Q
/g
).length
,
13 [V
.ROOK
]: pos
.match(/R
/g
).length
,
14 [V
.KNIGHT
]: pos
.match(/N
/g
).length
,
15 [V
.BISHOP
]: pos
.match(/B
/g
).length
,
16 [V
.PAWN
]: pos
.match(/P
/g
).length
19 [V
.KING
]: pos
.match(/k
/g
).length
,
20 [V
.QUEEN
]: pos
.match(/q
/g
).length
,
21 [V
.ROOK
]: pos
.match(/r
/g
).length
,
22 [V
.KNIGHT
]: pos
.match(/n
/g
).length
,
23 [V
.BISHOP
]: pos
.match(/b
/g
).length
,
24 [V
.PAWN
]: pos
.match(/p
/g
).length
29 getPotentialPawnMoves([x
, y
]) {
30 let moves
= super.getPotentialPawnMoves([x
, y
]);
31 // Add potential promotions into king
32 const color
= this.turn
;
33 const shift
= color
== "w" ? -1 : 1;
34 const lastRank
= color
== "w" ? 0 : V
.size
.x
- 1;
36 if (x
+ shift
== lastRank
) {
38 if (this.board
[x
+ shift
][y
] == V
.EMPTY
)
40 this.getBasicMove([x
, y
], [x
+ shift
, y
], { c: color
, p: V
.KING
})
45 this.board
[x
+ shift
][y
- 1] != V
.EMPTY
&&
46 this.canTake([x
, y
], [x
+ shift
, y
- 1])
49 this.getBasicMove([x
, y
], [x
+ shift
, y
- 1], { c: color
, p: V
.KING
})
54 this.board
[x
+ shift
][y
+ 1] != V
.EMPTY
&&
55 this.canTake([x
, y
], [x
+ shift
, y
+ 1])
58 this.getBasicMove([x
, y
], [x
+ shift
, y
+ 1], { c: color
, p: V
.KING
})
66 // TODO: verify this assertion
68 return true; //always at least one possible move
72 return false; //there is no check
79 updateVariables(move) {
80 super.updateVariables(move);
81 // Treat the promotion case: (not the capture part)
82 if (move.appear
[0].p
!= move.vanish
[0].p
) {
83 this.material
[move.appear
[0].c
][move.appear
[0].p
]++;
84 this.material
[move.appear
[0].c
][V
.PAWN
]--;
86 if (move.vanish
.length
== 2 && move.appear
.length
== 1)
88 this.material
[move.vanish
[1].c
][move.vanish
[1].p
]--;
91 unupdateVariables(move) {
92 super.unupdateVariables(move);
93 if (move.appear
[0].p
!= move.vanish
[0].p
) {
94 this.material
[move.appear
[0].c
][move.appear
[0].p
]--;
95 this.material
[move.appear
[0].c
][V
.PAWN
]++;
97 if (move.vanish
.length
== 2 && move.appear
.length
== 1)
98 this.material
[move.vanish
[1].c
][move.vanish
[1].p
]++;
102 if (this.atLeastOneMove()) {
104 const color
= this.turn
;
106 Object
.keys(this.material
[color
]).some(p
=> {
107 return this.material
[color
][p
] == 0;
110 return this.turn
== "w" ? "0-1" : "1-0";
115 return this.turn
== "w" ? "0-1" : "1-0"; //NOTE: currently unreachable...
119 const color
= this.turn
;
121 Object
.keys(this.material
[color
]).some(p
=> {
122 return this.material
[color
][p
] == 0;
125 // Very negative (resp. positive) if white (reps. black) pieces set is incomplete
126 return (color
== "w" ? -1 : 1) * V
.INFINITY
;
128 return super.evalPosition();