Add unambiguous section in the PGN + some fixes + code formatting and fix typos
[vchess.git] / client / src / variants / Dynamo.js
CommitLineData
0d5335de
BA
1import { ChessRules } from "@/base_rules";
2
3export class DynamoRules extends ChessRules {
c7550017
BA
4 canIplay(side, [x, y]) {
5 // Sometimes opponent's pieces can be moved directly
6 return true;
7 }
8
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;
13 let moves = [];
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).
19 // TODO
20 } else {
21 // Look in every direction for a friendly pusher/puller.
22 // This means that the action is done without moving.
23 // TODO
24 }
25 } else {
26 // My piece: fill first with normal moves (if any),
27 // and add pushes/pulls (if any).
28 // TODO
29 }
30 }
31
32 getPPpath(m) {
33 let imgName = "";
34 if (m.vanish.length == 1) imgName = "empty";
35 else {
36 // Something is pushed or pull: count by how many squares
37 if (m.appear.length == 1)
38 // It just exit the board
39 imgName = "raus";
40 else {
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;
45 else
46 // Special knight push/pull: just print "P"
47 imgName = "pstep";
48 }
49 }
50 return "Dynamo/" + imgName;
51 }
52
53 isAttackedBySlideNJump([x, y], color, piece, steps, oneStep) {
54 for (let step of steps) {
55 let rx = x + step[0],
56 ry = y + step[1];
57 while (V.OnBoard(rx, ry) && this.board[rx][ry] == V.EMPTY && !oneStep) {
58 rx += step[0];
59 ry += step[1];
60 }
61 if (
62 V.OnBoard(rx, ry) &&
63 this.getPiece(rx, ry) == piece &&
64 this.getColor(rx, ry) == color
65 ) {
66 // Now step in the other direction: if end of the world, then attacked
67 rx = x - step[0];
68 ry = y - step[1];
2c5d7b20
BA
69 while (
70 V.OnBoard(rx, ry) &&
71 this.board[rx][ry] == V.EMPTY &&
72 !oneStep
73 ) {
c7550017
BA
74 rx -= step[0];
75 ry -= step[1];
76 }
77 if (!V.OnBoard(rx, ry)) return true;
78 }
79 }
80 return false;
81 }
82
83 isAttackedByPawn([x, y], color) {
84 const lastRank = (color == 'w' ? 0 : 7);
85 if (y != lastRank)
86 // The king can be pushed out by a pawn only on last rank
87 return false;
88 const pawnShift = (color == "w" ? 1 : -1);
89 for (let i of [-1, 1]) {
90 if (
91 y + i >= 0 &&
92 y + i < V.size.y &&
93 this.getPiece(x + pawnShift, y + i) == V.PAWN &&
94 this.getColor(x + pawnShift, y + i) == color
95 ) {
96 return true;
97 }
98 }
99 return false;
100 }
0d5335de 101};