1 import { ChessRules
} from "@/base_rules";
3 export class DynamoRules
extends ChessRules
{
4 canIplay(side
, [x
, y
]) {
5 // Sometimes opponent's pieces can be moved directly
9 // NOTE: to push a piece out of the board, make it slide until our piece
10 // (doing the action, moving or not)
11 getPotentialMovesFrom([x
, y
]) {
12 const color
= this.turn
;
14 if (this.getColor(x
, y
) != color
) {
15 // Push or pull something: freely only if subTurn == 1
16 if (this.subTurn
== 2) {
17 // I know that someone is pushing/pulling: find out who,
18 // and deduce my possible squares (or exit).
21 // Look in every direction for a friendly pusher/puller.
22 // This means that the action is done without moving.
26 // My piece: fill first with normal moves (if any),
27 // and add pushes/pulls (if any).
34 if (m
.vanish
.length
== 1) imgName
= "empty";
36 // Something is pushed or pull: count by how many squares
37 if (m
.appear
.length
== 1)
38 // It just exit the board
41 const deltaX
= Math
.abs(m
.appear
[1].x
- m
.vanish
[1].x
);
42 const deltaY
= Math
.abs(m
.appear
[1].y
- m
.vanish
[1].y
);
43 if (deltaX
== 0) imgName
= "shift" + deltaY
;
44 else if (deltaY
== 0) imgName
= "shift" + deltaX
;
46 // Special knight push/pull: just print "P"
50 return "Dynamo/" + imgName
;
53 isAttackedBySlideNJump([x
, y
], color
, piece
, steps
, oneStep
) {
54 for (let step
of steps
) {
57 while (V
.OnBoard(rx
, ry
) && this.board
[rx
][ry
] == V
.EMPTY
&& !oneStep
) {
63 this.getPiece(rx
, ry
) == piece
&&
64 this.getColor(rx
, ry
) == color
66 // Now step in the other direction: if end of the world, then attacked
69 while (V
.OnBoard(rx
, ry
) && this.board
[rx
][ry
] == V
.EMPTY
&& !oneStep
) {
73 if (!V
.OnBoard(rx
, ry
)) return true;
79 isAttackedByPawn([x
, y
], color
) {
80 const lastRank
= (color
== 'w' ? 0 : 7);
82 // The king can be pushed out by a pawn only on last rank
84 const pawnShift
= (color
== "w" ? 1 : -1);
85 for (let i
of [-1, 1]) {
89 this.getPiece(x
+ pawnShift
, y
+ i
) == V
.PAWN
&&
90 this.getColor(x
+ pawnShift
, y
+ i
) == color