1 import { ChessRules
} from "@/base_rules";
3 export class IsardamRules
extends ChessRules
{
6 const oppCol
= V
.GetOppCol(this.getColor(sq
[0], sq
[1]));
7 const piece
= this.getPiece(sq
[0], sq
[1]);
10 // NOTE: cannot use super.isAttackedByXXX
11 // because it would call the redefined isAttackedBySlideNJump
12 // => Infinite recursive calls.
14 const forward
= (oppCol
== 'w' ? 1 : -1);
15 steps
= [[forward
, 1], [forward
, -1]];
21 steps
= V
.steps
[piece
];
25 steps
= V
.steps
[V
.ROOK
].concat(V
.steps
[V
.BISHOP
]);
28 return super.isAttackedBySlideNJump(
29 sq
, oppCol
, piece
, steps
, [V
.KING
, V
.PAWN
, V
.KNIGHT
].includes(piece
))
32 getPotentialMovesFrom([x
, y
]) {
34 super.getPotentialMovesFrom([x
, y
]).filter(m
=> {
37 if (this.isImmobilized([m
.end
.x
, m
.end
.y
])) res
= false;
39 // Check discovered attacks
40 for (let step
of V
.steps
[V
.BISHOP
].concat(V
.steps
[V
.ROOK
])) {
41 let allowedPieces
= [V
.QUEEN
];
42 if (step
[0] == 0 || step
[1] == 0) allowedPieces
.push(V
.ROOK
);
43 else allowedPieces
.push(V
.BISHOP
);
44 let [i
, j
] = [m
.start
.x
+ step
[0], m
.start
.y
+ step
[1]];
45 while (V
.OnBoard(i
, j
) && this.board
[i
][j
] == V
.EMPTY
) {
49 if (V
.OnBoard(i
, j
)) {
50 const meet
= { c: this.getColor(i
, j
), p: this.getPiece(i
, j
) };
51 if (allowedPieces
.includes(meet
.p
)) {
52 // Search in the other direction
53 [i
, j
] = [m
.start
.x
- step
[0], m
.start
.y
- step
[1]];
54 while (V
.OnBoard(i
, j
) && this.board
[i
][j
] == V
.EMPTY
) {
60 this.getPiece(i
, j
) == meet
.p
&&
61 this.getColor(i
, j
) != meet
.c