1 class ExtinctionRules
extends ChessRules
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!)
13 [V
.KING
]: pos
.match(/K
/g
).length
,
14 [V
.QUEEN
]: pos
.match(/Q
/g
).length
,
15 [V
.ROOK
]: pos
.match(/R
/g
).length
,
16 [V
.KNIGHT
]: pos
.match(/N
/g
).length
,
17 [V
.BISHOP
]: pos
.match(/B
/g
).length
,
18 [V
.PAWN
]: pos
.match(/P
/g
).length
22 [V
.KING
]: pos
.match(/k
/g
).length
,
23 [V
.QUEEN
]: pos
.match(/q
/g
).length
,
24 [V
.ROOK
]: pos
.match(/r
/g
).length
,
25 [V
.KNIGHT
]: pos
.match(/n
/g
).length
,
26 [V
.BISHOP
]: pos
.match(/b
/g
).length
,
27 [V
.PAWN
]: pos
.match(/p
/g
).length
32 getPotentialPawnMoves([x
,y
])
34 let moves
= super.getPotentialPawnMoves([x
,y
]);
35 // Add potential promotions into king
36 const color
= this.turn
;
37 const shift
= (color
== "w" ? -1 : 1);
38 const lastRank
= (color
== "w" ? 0 : V
.size
.x
-1);
40 if (x
+shift
== lastRank
)
43 if (this.board
[x
+shift
][y
] == V
.EMPTY
)
44 moves
.push(this.getBasicMove([x
,y
], [x
+shift
,y
], {c:color
,p:V
.KING
}));
46 if (y
>0 && this.board
[x
+shift
][y
-1] != V
.EMPTY
47 && this.canTake([x
,y
], [x
+shift
,y
-1]))
49 moves
.push(this.getBasicMove([x
,y
], [x
+shift
,y
-1], {c:color
,p:V
.KING
}));
51 if (y
<V
.size
.y
-1 && this.board
[x
+shift
][y
+1] != V
.EMPTY
52 && this.canTake([x
,y
], [x
+shift
,y
+1]))
54 moves
.push(this.getBasicMove([x
,y
], [x
+shift
,y
+1], {c:color
,p:V
.KING
}));
61 // TODO: verify this assertion
64 return true; //always at least one possible move
69 return false; //there is no check
72 getCheckSquares(color
)
79 super.updateVariables(move);
80 // Treat the promotion case: (not the capture part)
81 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) //capture
87 this.material
[move.vanish
[1].c
][move.vanish
[1].p
]--;
90 unupdateVariables(move)
92 super.unupdateVariables(move);
93 if (move.appear
[0].p
!= move.vanish
[0].p
)
95 this.material
[move.appear
[0].c
][move.appear
[0].p
]--;
96 this.material
[move.appear
[0].c
][V
.PAWN
]++;
98 if (move.vanish
.length
==2 && move.appear
.length
==1)
99 this.material
[move.vanish
[1].c
][move.vanish
[1].p
]++;
104 if (this.checkRepetition())
107 if (this.atLeastOneMove()) // game not over?
109 const color
= this.turn
;
110 if (Object
.keys(this.material
[color
]).some(
111 p
=> { return this.material
[color
][p
] == 0; }))
113 return this.checkGameEnd();
118 return this.checkGameEnd(); //NOTE: currently unreachable...
123 return (this.turn
== "w" ? "0-1" : "1-0");
128 const color
= this.turn
;
129 if (Object
.keys(this.material
[color
]).some(
130 p
=> { return this.material
[color
][p
] == 0; }))
132 // Very negative (resp. positive) if white (reps. black) pieces set is incomplete
133 return (color
=="w"?-1:1) * V
.INFINITY
;
135 return super.evalPosition();