1 import { ChessRules
} from "@/base_rules";
3 export class MadrasiRules
extends ChessRules
{
5 const oppCol
= V
.GetOppCol(this.getColor(sq
[0], sq
[1]));
6 const piece
= this.getPiece(sq
[0], sq
[1]);
9 // NOTE: cannot use super.isAttackedByXXX
10 // because it would call the redefined isAttackedBySlideNJump
11 // => Infinite recursive calls.
13 const forward
= (oppCol
== 'w' ? 1 : -1);
14 steps
= [[forward
, 1], [forward
, -1]];
20 steps
= V
.steps
[piece
];
24 steps
= V
.steps
[V
.ROOK
].concat(V
.steps
[V
.BISHOP
]);
27 return super.isAttackedBySlideNJump(
28 sq
, oppCol
, piece
, steps
, [V
.KING
, V
.PAWN
, V
.KNIGHT
].includes(piece
))
31 getPotentialMovesFrom([x
, y
]) {
33 !this.isImmobilized([x
, y
])
34 ? super.getPotentialMovesFrom([x
, y
])
39 isAttackedBySlideNJump([x
, y
], color
, piece
, steps
, oneStep
) {
40 for (let step
of steps
) {
43 while (V
.OnBoard(rx
, ry
) && this.board
[rx
][ry
] == V
.EMPTY
&& !oneStep
) {
49 this.getPiece(rx
, ry
) == piece
&&
50 this.getColor(rx
, ry
) == color
&&
51 // If enemy is immobilized, it doesn't attack:
52 !this.isImmobilized([rx
, ry
])
61 // Connected kings paralyze each other