Commit | Line | Data |
---|---|---|
6b7b2cf7 BA |
1 | import { ChessRules } from "@/base_rules"; |
2 | import { ArrayFun } from "@/utils/array"; | |
3 | import { randInt } from "@/utils/alea"; | |
4 | ||
5 | export const VariantRules = class LosersRules extends ChessRules { | |
6 | // Trim all non-capturing moves | |
7 | static KeepCaptures(moves) { | |
8 | return moves.filter(m => m.vanish.length == 2); | |
9 | } | |
10 | ||
11 | // Stop at the first capture found (if any) | |
12 | atLeastOneCapture() { | |
13 | const color = this.turn; | |
14 | const oppCol = V.GetOppCol(color); | |
15 | for (let i = 0; i < V.size.x; i++) { | |
16 | for (let j = 0; j < V.size.y; j++) { | |
17 | if ( | |
18 | this.board[i][j] != V.EMPTY && | |
19 | this.getColor(i, j) != oppCol && | |
20 | this.getPotentialMovesFrom([i, j]).some(m => | |
21 | // Warning: duscard castle moves | |
22 | m.vanish.length == 2 && m.appear.length == 1) | |
23 | ) { | |
24 | return true; | |
25 | } | |
26 | } | |
27 | } | |
28 | return false; | |
29 | } | |
30 | ||
31 | getPossibleMovesFrom(sq) { | |
32 | let moves = this.filterValid(this.getPotentialMovesFrom(sq)); | |
33 | const captureMoves = V.KeepCaptures(moves); | |
34 | if (captureMoves.length > 0) return captureMoves; | |
35 | if (this.atLeastOneCapture()) return []; | |
36 | return moves; | |
37 | } | |
38 | ||
39 | getAllValidMoves() { | |
40 | const moves = super.getAllValidMoves(); | |
41 | if (moves.some(m => m.vanish.length == 2)) return V.KeepCaptures(moves); | |
42 | return moves; | |
43 | } | |
44 | ||
45 | static get SEARCH_DEPTH() { | |
46 | return 4; | |
47 | } | |
48 | }; |