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;
29 setOtherVariables(fen
) {
30 super.setOtherVariables(fen
);
31 const pos
= V
.ParseFen(fen
).position
;
32 // NOTE: no need for safety "|| []", because each piece type must be present
33 // (otherwise game is already over!)
36 [V
.KING
]: pos
.match(/K
/g
).length
,
37 [V
.QUEEN
]: pos
.match(/Q
/g
).length
,
38 [V
.ROOK
]: pos
.match(/R
/g
).length
,
39 [V
.KNIGHT
]: pos
.match(/N
/g
).length
,
40 [V
.BISHOP
]: pos
.match(/B
/g
).length
,
41 [V
.PAWN
]: pos
.match(/P
/g
).length
44 [V
.KING
]: pos
.match(/k
/g
).length
,
45 [V
.QUEEN
]: pos
.match(/q
/g
).length
,
46 [V
.ROOK
]: pos
.match(/r
/g
).length
,
47 [V
.KNIGHT
]: pos
.match(/n
/g
).length
,
48 [V
.BISHOP
]: pos
.match(/b
/g
).length
,
49 [V
.PAWN
]: pos
.match(/p
/g
).length
54 // TODO: verify this assertion
56 return true; //always at least one possible move
60 return moves
; //there is no check
69 // Treat the promotion case: (not the capture part)
70 if (move.appear
[0].p
!= move.vanish
[0].p
) {
71 this.material
[move.appear
[0].c
][move.appear
[0].p
]++;
72 this.material
[move.appear
[0].c
][V
.PAWN
]--;
74 if (move.vanish
.length
== 2 && move.appear
.length
== 1)
76 this.material
[move.vanish
[1].c
][move.vanish
[1].p
]--;
81 if (move.appear
[0].p
!= move.vanish
[0].p
) {
82 this.material
[move.appear
[0].c
][move.appear
[0].p
]--;
83 this.material
[move.appear
[0].c
][V
.PAWN
]++;
85 if (move.vanish
.length
== 2 && move.appear
.length
== 1)
86 this.material
[move.vanish
[1].c
][move.vanish
[1].p
]++;
90 if (this.atLeastOneMove()) {
92 const color
= this.turn
;
94 Object
.keys(this.material
[color
]).some(p
=> {
95 return this.material
[color
][p
] == 0;
98 return this.turn
== "w" ? "0-1" : "1-0";
102 return this.turn
== "w" ? "0-1" : "1-0"; //NOTE: currently unreachable...
106 const color
= this.turn
;
108 Object
.keys(this.material
[color
]).some(p
=> {
109 return this.material
[color
][p
] == 0;
112 // Very negative (resp. positive) if white (reps. black) pieces set is incomplete
113 return (color
== "w" ? -1 : 1) * V
.INFINITY
;
115 return super.evalPosition();