1 import { ChessRules
} from "@/base_rules";
3 export class ExtinctionRules
extends ChessRules
{
4 static get PawnSpecs() {
8 { promotions: ChessRules
.PawnSpecs
.promotions
.concat([V
.KING
]) }
12 static IsGoodPosition(position
) {
13 if (!ChessRules
.IsGoodPosition(position
)) return false;
14 // Also check that each piece type is present
15 const rows
= position
.split("/");
17 for (let row
of rows
) {
18 for (let i
= 0; i
< row
.length
; i
++) {
19 if (isNaN(parseInt(row
[i
])) && !pieces
[row
[i
]])
20 pieces
[row
[i
]] = true;
23 if (Object
.keys(pieces
).length
!= 12) return false;
27 setOtherVariables(fen
) {
28 super.setOtherVariables(fen
);
29 const pos
= V
.ParseFen(fen
).position
;
30 // NOTE: no need for safety "|| []", because each piece type is present
31 // (otherwise game is already over!)
34 [V
.KING
]: pos
.match(/K
/g
).length
,
35 [V
.QUEEN
]: pos
.match(/Q
/g
).length
,
36 [V
.ROOK
]: pos
.match(/R
/g
).length
,
37 [V
.KNIGHT
]: pos
.match(/N
/g
).length
,
38 [V
.BISHOP
]: pos
.match(/B
/g
).length
,
39 [V
.PAWN
]: pos
.match(/P
/g
).length
42 [V
.KING
]: pos
.match(/k
/g
).length
,
43 [V
.QUEEN
]: pos
.match(/q
/g
).length
,
44 [V
.ROOK
]: pos
.match(/r
/g
).length
,
45 [V
.KNIGHT
]: pos
.match(/n
/g
).length
,
46 [V
.BISHOP
]: pos
.match(/b
/g
).length
,
47 [V
.PAWN
]: pos
.match(/p
/g
).length
52 // TODO: verify this assertion
54 return true; //always at least one possible move
58 return moves
; //there is no check
67 // Treat the promotion case: (not the capture part)
68 if (move.appear
[0].p
!= move.vanish
[0].p
) {
69 this.material
[move.appear
[0].c
][move.appear
[0].p
]++;
70 this.material
[move.appear
[0].c
][V
.PAWN
]--;
72 if (move.vanish
.length
== 2 && move.appear
.length
== 1)
74 this.material
[move.vanish
[1].c
][move.vanish
[1].p
]--;
79 if (move.appear
[0].p
!= move.vanish
[0].p
) {
80 this.material
[move.appear
[0].c
][move.appear
[0].p
]--;
81 this.material
[move.appear
[0].c
][V
.PAWN
]++;
83 if (move.vanish
.length
== 2 && move.appear
.length
== 1)
84 this.material
[move.vanish
[1].c
][move.vanish
[1].p
]++;
88 if (this.atLeastOneMove()) {
90 const color
= this.turn
;
92 Object
.keys(this.material
[color
]).some(p
=> {
93 return this.material
[color
][p
] == 0;
96 return this.turn
== "w" ? "0-1" : "1-0";
100 return this.turn
== "w" ? "0-1" : "1-0"; //NOTE: currently unreachable...
104 const color
= this.turn
;
106 Object
.keys(this.material
[color
]).some(p
=> {
107 return this.material
[color
][p
] == 0;
110 // Very negative (resp. positive)
111 // if white (reps. black) pieces set is incomplete
112 return (color
== "w" ? -1 : 1) * V
.INFINITY
;
114 return super.evalPosition();