1 import ChessRules
from "/base_rules.js";
3 export default class ChecklessRules
extends ChessRules
{
5 // Cannot use super.atLeastOneMove: lead to infinite recursion
6 atLeastOneMove_aux(kingPos
, oppKingPos
, color
, oppCol
) {
7 for (let i
= 0; i
< this.size
.x
; i
++) {
8 for (let j
= 0; j
< this.size
.y
; j
++) {
9 if (this.getColor(i
, j
) == color
) {
10 const moves
= this.getPotentialMovesFrom([i
, j
]);
11 for (let m
of moves
) {
13 const res
= this.trackKingWrap(m
, kingPos
, (kp
) => {
14 return !this.underCheck(kp
, [oppCol
]);
27 const fmoves
= super.filterValid(moves
);
28 // Filter out moves giving check but not checkmate
29 const color
= this.turn
;
30 const oppCol
= C
.GetOppTurn(color
);
31 let kingPos
= this.searchKingPos(color
),
32 oppKingPos
= this.searchKingPos(oppCol
);
33 return fmoves
.filter(m
=> {
35 const res
= this.trackKingWrap(m
, oppKingPos
, (oppKp
) => {
37 !this.underCheck(oppKp
, [color
]) ||
38 !this.atLeastOneMove_aux(oppKp
, kingPos
, oppCol
, color
)