e16d78f564ebf9e7c76d772a796f0972fd9ad523
1 import { ChessRules
} from "@/base_rules";
3 export class MadrasiRules
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 const nbSteps
= [V
.KING
, V
.PAWN
, V
.KNIGHT
].includes(piece
) ? 1 : null;
29 return super.isAttackedBySlideNJump(sq
, oppCol
, piece
, steps
, nbSteps
);
32 getPotentialMovesFrom([x
, y
]) {
34 !this.isImmobilized([x
, y
])
35 ? super.getPotentialMovesFrom([x
, y
])
40 isAttackedBySlideNJump([x
, y
], color
, piece
, steps
, oneStep
) {
41 for (let step
of steps
) {
44 while (V
.OnBoard(rx
, ry
) && this.board
[rx
][ry
] == V
.EMPTY
&& !oneStep
) {
50 this.getPiece(rx
, ry
) == piece
&&
51 this.getColor(rx
, ry
) == color
&&
52 // If enemy is immobilized, it doesn't attack:
53 !this.isImmobilized([rx
, ry
])
62 // Connected kings paralyze each other