1 import { ChessRules
} from "@/base_rules";
3 export const VariantRules
= class ExtinctionRules
extends ChessRules
7 super.setOtherVariables(fen
);
8 const pos
= V
.ParseFen(fen
).position
;
9 // NOTE: no need for safety "|| []", because each piece type must be present
10 // (otherwise game is already over!)
15 [V
.KING
]: pos
.match(/K
/g
).length
,
16 [V
.QUEEN
]: pos
.match(/Q
/g
).length
,
17 [V
.ROOK
]: pos
.match(/R
/g
).length
,
18 [V
.KNIGHT
]: pos
.match(/N
/g
).length
,
19 [V
.BISHOP
]: pos
.match(/B
/g
).length
,
20 [V
.PAWN
]: pos
.match(/P
/g
).length
24 [V
.KING
]: pos
.match(/k
/g
).length
,
25 [V
.QUEEN
]: pos
.match(/q
/g
).length
,
26 [V
.ROOK
]: pos
.match(/r
/g
).length
,
27 [V
.KNIGHT
]: pos
.match(/n
/g
).length
,
28 [V
.BISHOP
]: pos
.match(/b
/g
).length
,
29 [V
.PAWN
]: pos
.match(/p
/g
).length
34 getPotentialPawnMoves([x
,y
])
36 let moves
= super.getPotentialPawnMoves([x
,y
]);
37 // Add potential promotions into king
38 const color
= this.turn
;
39 const shift
= (color
== "w" ? -1 : 1);
40 const lastRank
= (color
== "w" ? 0 : V
.size
.x
-1);
42 if (x
+shift
== lastRank
)
45 if (this.board
[x
+shift
][y
] == V
.EMPTY
)
46 moves
.push(this.getBasicMove([x
,y
], [x
+shift
,y
], {c:color
,p:V
.KING
}));
48 if (y
>0 && this.board
[x
+shift
][y
-1] != V
.EMPTY
49 && this.canTake([x
,y
], [x
+shift
,y
-1]))
51 moves
.push(this.getBasicMove([x
,y
], [x
+shift
,y
-1], {c:color
,p:V
.KING
}));
53 if (y
<V
.size
.y
-1 && this.board
[x
+shift
][y
+1] != V
.EMPTY
54 && this.canTake([x
,y
], [x
+shift
,y
+1]))
56 moves
.push(this.getBasicMove([x
,y
], [x
+shift
,y
+1], {c:color
,p:V
.KING
}));
63 // TODO: verify this assertion
66 return true; //always at least one possible move
71 return false; //there is no check
74 getCheckSquares(color
)
81 super.updateVariables(move);
82 // Treat the promotion case: (not the capture part)
83 if (move.appear
[0].p
!= move.vanish
[0].p
)
85 this.material
[move.appear
[0].c
][move.appear
[0].p
]++;
86 this.material
[move.appear
[0].c
][V
.PAWN
]--;
88 if (move.vanish
.length
==2 && move.appear
.length
==1) //capture
89 this.material
[move.vanish
[1].c
][move.vanish
[1].p
]--;
92 unupdateVariables(move)
94 super.unupdateVariables(move);
95 if (move.appear
[0].p
!= move.vanish
[0].p
)
97 this.material
[move.appear
[0].c
][move.appear
[0].p
]--;
98 this.material
[move.appear
[0].c
][V
.PAWN
]++;
100 if (move.vanish
.length
==2 && move.appear
.length
==1)
101 this.material
[move.vanish
[1].c
][move.vanish
[1].p
]++;
106 if (this.atLeastOneMove()) // game not over?
108 const color
= this.turn
;
109 if (Object
.keys(this.material
[color
]).some(
110 p
=> { return this.material
[color
][p
] == 0; }))
112 return (this.turn
== "w" ? "0-1" : "1-0");
117 return (this.turn
== "w" ? "0-1" : "1-0"); //NOTE: currently unreachable...
122 const color
= this.turn
;
123 if (Object
.keys(this.material
[color
]).some(
124 p
=> { return this.material
[color
][p
] == 0; }))
126 // Very negative (resp. positive) if white (reps. black) pieces set is incomplete
127 return (color
=="w"?-1:1) * V
.INFINITY
;
129 return super.evalPosition();