1 import { ChessRules
, Move
, PiPo
} from "@/base_rules";
3 // TODO: need FEN lastmove pour interdire défaire dernière poussée
4 // --> check appear et vanish totally reversed.
6 // TODO: pawn promotions by push (en + des promotions standard)
7 // --> similar to Zen promotions.
9 export class DynamoRules
extends ChessRules
{
10 canIplay(side
, [x
, y
]) {
11 // Sometimes opponent's pieces can be moved directly
17 if (m
.vanish
.length
== 1) imgName
= "empty";
19 // Something is pushed or pull: count by how many squares
20 if (m
.appear
.length
== 1)
21 // It just exit the board
24 const deltaX
= Math
.abs(m
.appear
[1].x
- m
.vanish
[1].x
);
25 const deltaY
= Math
.abs(m
.appear
[1].y
- m
.vanish
[1].y
);
26 if (deltaX
== 0) imgName
= "shift_" + deltaY
;
27 else if (deltaY
== 0) imgName
= "shift_" + deltaX
;
29 // Special knight push/pull: just print "P"
33 return "Dynamo/" + imgName
;
36 getPactions(sq
, by
, color
) {
40 // const lineAdd = (allowedPieces) = {
41 // // attacking piece must be of the allowed types
44 // Look in all directions for a "color" piece
45 for (let step
of V
.steps
[V
.KNIGHT
]) {
46 const xx
= x
+ step
[0],
50 this.getPiece(xx
, yy
) == V
.KNIGHT
&&
51 this.getColor(xx
, yy
) == color
53 const px
= x
- step
[0],
55 if (V
.OnBoard(px
, py
) && this.board
[px
][py
] == V
.EMPTY
) {
56 const hash
= "s" + px
+ py
;
59 moves
.push(this.getBasicMove([x
, y
], [px
, py
]));
62 const hash
= "s" + xx
+ yy
;
67 start: { x: x
, y: y
},
68 end: { x: xx
, y: yy
},
74 p: this.getPiece(x
, y
),
84 for (let step
in V
.steps
[V
.ROOK
]) {
85 // color is enemy, so no pawn pushes: king, rook and queen
87 for (let step
in V
.steps
[V
.BISHOP
]) {
88 // King, bishop, queen, and possibly pawns attacks
92 // // TODO: probably in a different function for now.
97 // NOTE: to push a piece out of the board, make it slide until our piece
98 // (doing the action, moving or not)
99 getPotentialMovesFrom([x
, y
]) {
100 const color
= this.turn
;
101 const oppCol
= V
.GetOppCol(color
);
102 if (this.getColor(x
, y
) != color
) {
103 // Look in every direction for a friendly pusher/puller.
104 // This means that the action is done without moving.
105 return this.getPactions([x
, y
], null, color
);
107 // Playing my pieces: do they attack an enemy?
109 //this.getPattacks(sq, [x, y]);
111 return super.getPotentialMovesFrom([x
, y
]);
113 return []; //never reached
116 isAttackedBySlideNJump([x
, y
], color
, piece
, steps
, oneStep
) {
117 for (let step
of steps
) {
118 let rx
= x
+ step
[0],
120 while (V
.OnBoard(rx
, ry
) && this.board
[rx
][ry
] == V
.EMPTY
&& !oneStep
) {
126 this.getPiece(rx
, ry
) == piece
&&
127 this.getColor(rx
, ry
) == color
129 // Now step in the other direction: if end of the world, then attacked
134 this.board
[rx
][ry
] == V
.EMPTY
&&
140 if (!V
.OnBoard(rx
, ry
)) return true;
146 isAttackedByPawn([x
, y
], color
) {
147 const lastRank
= (color
== 'w' ? 0 : 7);
149 // The king can be pushed out by a pawn only on last rank
151 const pawnShift
= (color
== "w" ? 1 : -1);
152 for (let i
of [-1, 1]) {
156 this.getPiece(x
+ pawnShift
, y
+ i
) == V
.PAWN
&&
157 this.getColor(x
+ pawnShift
, y
+ i
) == color