1 class LoserRules
extends ChessRules
5 // No castling, hence no flags; but flags defined for compatibility
7 const epSq
= this.moves
.length
> 0 ? this.getEpSquare(this.lastMove
) : undefined;
8 this.epSquares
= [ epSq
];
13 getPotentialPawnMoves([x
,y
])
15 let moves
= super.getPotentialPawnMoves([x
,y
]);
17 // Complete with promotion(s) into king, if possible
18 const color
= this.turn
;
19 const V
= VariantRules
;
20 const [sizeX
,sizeY
] = VariantRules
.size
;
21 const shift
= (color
== "w" ? -1 : 1);
22 const lastRank
= (color
== "w" ? 0 : sizeX
-1);
23 if (x
+shift
== lastRank
)
27 if (this.board
[x
+shift
][y
] == V
.EMPTY
)
28 moves
.push(this.getBasicMove([x
,y
], [x
+shift
,y
], {c:color
,p:p
}));
30 if (y
>0 && this.canTake([x
,y
], [x
+shift
,y
-1]) && this.board
[x
+shift
][y
-1] != V
.EMPTY
)
31 moves
.push(this.getBasicMove([x
,y
], [x
+shift
,y
-1], {c:color
,p:p
}));
32 if (y
<sizeY
-1 && this.canTake([x
,y
], [x
+shift
,y
+1]) && this.board
[x
+shift
][y
+1] != V
.EMPTY
)
33 moves
.push(this.getBasicMove([x
,y
], [x
+shift
,y
+1], {c:color
,p:p
}));
39 getPotentialKingMoves(sq
)
41 const V
= VariantRules
;
42 return this.getSlideNJumpMoves(sq
,
43 V
.steps
[V
.ROOK
].concat(V
.steps
[V
.BISHOP
]), "oneStep");
46 // Stop at the first capture found (if any)
49 const color
= this.turn
;
50 const oppCol
= this.getOppCol(color
);
51 const [sizeX
,sizeY
] = VariantRules
.size
;
52 for (let i
=0; i
<sizeX
; i
++)
54 for (let j
=0; j
<sizeY
; j
++)
56 if (this.board
[i
][j
] != VariantRules
.EMPTY
&& this.getColor(i
,j
) != oppCol
)
58 const moves
= this.getPotentialMovesFrom([i
,j
]);
61 for (let k
=0; k
<moves
.length
; k
++)
63 if (moves
[k
].vanish
.length
==2 && this.filterValid([moves
[k
]]).length
> 0)
73 // Trim all non-capturing moves
74 static KeepCaptures(moves
)
76 return moves
.filter(m
=> { return m
.vanish
.length
== 2; });
79 getPossibleMovesFrom(sq
)
81 let moves
= this.filterValid( this.getPotentialMovesFrom(sq
) );
82 // This is called from interface: we need to know if a capture is possible
83 if (this.atLeastOneCapture())
84 moves
= VariantRules
.KeepCaptures(moves
);
90 let moves
= super.getAllValidMoves();
91 if (moves
.some(m
=> { return m
.vanish
.length
== 2; }))
92 moves
= VariantRules
.KeepCaptures(moves
);
98 return false; //No notion of check
101 getCheckSquares(move)
107 updateVariables(move) { }
108 unupdateVariables(move) { }
109 parseFlags(flags
) { }
113 // No valid move: you win!
114 return this.turn
== "w" ? "1-0" : "0-1";
117 static get VALUES() { //experimental...
128 static get SEARCH_DEPTH() { return 4; }
132 return - super.evalPosition(); //better with less material