a4aafd3a0d49587f6765daf52a3be76e59c377cc
1 import { ChessRules
} from "@/base_rules";
3 export class Squatter1Rules
extends ChessRules
{
12 // Find possible captures by opponent on [x, y]
13 findCaptures([x
, y
]) {
14 const color
= this.getColor(x
, y
);
15 const forward
= (color
== 'w' ? -1 : 1);
18 // Rook and bishop: included in queen case
19 p: { s: [[forward
, -1], [forward
, 1]], one: true },
20 n: { s: V
.steps
[V
.KNIGHT
], one: true },
21 q: { s: V
.steps
[V
.ROOK
].concat(V
.steps
[V
.BISHOP
]) },
22 k: { s: V
.steps
[V
.ROOK
].concat(V
.steps
[V
.BISHOP
]), one: true }
24 const oppCol
= V
.GetOppCol(color
);
25 Object
.keys(steps
).forEach(piece
=> {
26 outerLoop: for (let loop
= 0; loop
< steps
[piece
].s
.length
; loop
++) {
27 const step
= steps
[piece
].s
[loop
];
30 while (V
.OnBoard(i
, j
) && this.board
[i
][j
] == V
.EMPTY
) {
31 if (steps
[piece
].one
) continue outerLoop
;
37 this.board
[i
][j
] != V
.EMPTY
&&
38 this.getColor(i
, j
) == oppCol
40 const oppPiece
= this.getPiece(i
, j
);
46 (oppPiece
== V
.ROOK
&& step
.some(e
=> e
== 0)) ||
47 (oppPiece
== V
.BISHOP
&& step
.every(e
=> e
!= 0))
51 // Possible capture (do not care about promotions):
52 moves
.push(this.getBasicMove([i
, j
], [x
, y
]));
59 someValid(moves
, color
) {
60 // Stop at first valid move found:
61 for (let m
of moves
) {
63 const res
= !this.underCheck(color
);
71 // Try both colors (to detect potential suicides)
72 for (let c
of ['w', 'b']) {
73 const oppCol
= V
.GetOppCol(c
);
74 const goal
= (c
== 'w' ? 0 : 7);
76 this.board
[goal
].some(
81 !this.isAttacked([goal
, j
], oppCol
) ||
82 !this.someValid(this.findCaptures([goal
, j
]), oppCol
)
88 return c
== 'w' ? "1-0" : "0-1";
91 return super.getCurrentScore();
94 static get SEARCH_DEPTH() {