-export const VariantRules = class ExtinctionRules extends ChessRules
-{
- setOtherVariables(fen)
- {
- super.setOtherVariables(fen);
- const pos = V.ParseFen(fen).position;
- // NOTE: no need for safety "|| []", because each piece type must be present
- // (otherwise game is already over!)
- this.material =
- {
- "w":
- {
- [V.KING]: pos.match(/K/g).length,
- [V.QUEEN]: pos.match(/Q/g).length,
- [V.ROOK]: pos.match(/R/g).length,
- [V.KNIGHT]: pos.match(/N/g).length,
- [V.BISHOP]: pos.match(/B/g).length,
- [V.PAWN]: pos.match(/P/g).length
- },
- "b":
- {
- [V.KING]: pos.match(/k/g).length,
- [V.QUEEN]: pos.match(/q/g).length,
- [V.ROOK]: pos.match(/r/g).length,
- [V.KNIGHT]: pos.match(/n/g).length,
- [V.BISHOP]: pos.match(/b/g).length,
- [V.PAWN]: pos.match(/p/g).length
- }
- };
- }
+export const VariantRules = class ExtinctionRules extends ChessRules {
+ static IsGoodPosition(position) {
+ if (!ChessRules.IsGoodPosition(position))
+ return false;
+ // Also check that each piece type is present
+ const rows = position.split("/");
+ let pieces = {};
+ for (let row of rows) {
+ for (let i = 0; i < row.length; i++) {
+ if (isNaN(parseInt(row[i])) && !pieces[row[i]])
+ pieces[row[i]] = true;
+ }
+ }
+ if (Object.keys(pieces).length != 12)
+ return false;
+ return true;
+ }