1 import { ChessRules
} from "@/base_rules";
3 export class ExtinctionRules
extends ChessRules
{
5 static get PawnSpecs() {
9 { promotions: ChessRules
.PawnSpecs
.promotions
.concat([V
.KING
]) }
13 static IsGoodPosition(position
) {
14 if (!ChessRules
.IsGoodPosition(position
)) return false;
15 // Also check that each piece type is present
16 const rows
= position
.split("/");
18 for (let row
of rows
) {
19 for (let i
= 0; i
< row
.length
; i
++) {
20 if (isNaN(parseInt(row
[i
], 10)) && !pieces
[row
[i
]])
21 pieces
[row
[i
]] = true;
24 if (Object
.keys(pieces
).length
!= 12) return false;
28 setOtherVariables(fen
) {
29 super.setOtherVariables(fen
);
30 const pos
= V
.ParseFen(fen
).position
;
31 // NOTE: no need for safety "|| []", because each piece type is present
32 // (otherwise game is already over!)
35 [V
.KING
]: pos
.match(/K
/g
).length
,
36 [V
.QUEEN
]: pos
.match(/Q
/g
).length
,
37 [V
.ROOK
]: pos
.match(/R
/g
).length
,
38 [V
.KNIGHT
]: pos
.match(/N
/g
).length
,
39 [V
.BISHOP
]: pos
.match(/B
/g
).length
,
40 [V
.PAWN
]: pos
.match(/P
/g
).length
43 [V
.KING
]: pos
.match(/k
/g
).length
,
44 [V
.QUEEN
]: pos
.match(/q
/g
).length
,
45 [V
.ROOK
]: pos
.match(/r
/g
).length
,
46 [V
.KNIGHT
]: pos
.match(/n
/g
).length
,
47 [V
.BISHOP
]: pos
.match(/b
/g
).length
,
48 [V
.PAWN
]: pos
.match(/p
/g
).length
53 // TODO: verify this assertion
55 return true; //always at least one possible move
59 return moves
; //there is no check
68 // Treat the promotion case: (not the capture part)
69 if (move.appear
[0].p
!= move.vanish
[0].p
) {
70 this.material
[move.appear
[0].c
][move.appear
[0].p
]++;
71 this.material
[move.appear
[0].c
][V
.PAWN
]--;
73 if (move.vanish
.length
== 2 && move.appear
.length
== 1)
75 this.material
[move.vanish
[1].c
][move.vanish
[1].p
]--;
80 if (move.appear
[0].p
!= move.vanish
[0].p
) {
81 this.material
[move.appear
[0].c
][move.appear
[0].p
]--;
82 this.material
[move.appear
[0].c
][V
.PAWN
]++;
84 if (move.vanish
.length
== 2 && move.appear
.length
== 1)
85 this.material
[move.vanish
[1].c
][move.vanish
[1].p
]++;
89 if (this.atLeastOneMove()) {
91 const color
= this.turn
;
93 Object
.keys(this.material
[color
]).some(p
=> {
94 return this.material
[color
][p
] == 0;
97 return this.turn
== "w" ? "0-1" : "1-0";
101 return this.turn
== "w" ? "0-1" : "1-0"; //NOTE: currently unreachable...
105 const color
= this.turn
;
107 Object
.keys(this.material
[color
]).some(p
=> {
108 return this.material
[color
][p
] == 0;
111 // Very negative (resp. positive)
112 // if white (reps. black) pieces set is incomplete
113 return (color
== "w" ? -1 : 1) * V
.INFINITY
;
115 return super.evalPosition();