1 import { ChessRules
, PiPo
, Move
} from "@/base_rules";
3 export const VariantRules
= class RifleRules
extends ChessRules
{
4 getBasicMove([sx
, sy
], [ex
, ey
], tr
) {
11 if (this.board
[ex
][ey
] != V
.EMPTY
) {
12 // No movement: just vanishing enemy piece
17 c: this.getColor(ex
, ey
),
18 p: this.getPiece(ex
, ey
)
28 c: tr
? tr
.c : this.getColor(sx
, sy
),
29 p: tr
? tr
.p : this.getPiece(sx
, sy
)
36 c: this.getColor(sx
, sy
),
37 p: this.getPiece(sx
, sy
)
45 getPotentialPawnMoves([x
, y
]) {
46 const color
= this.turn
;
48 const [sizeX
, sizeY
] = [V
.size
.x
, V
.size
.y
];
49 const shiftX
= color
== "w" ? -1 : 1;
50 const startRank
= color
== "w" ? sizeX
- 2 : 1;
51 const lastRank
= color
== "w" ? 0 : sizeX
- 1;
54 x
+ shiftX
== lastRank
55 ? [V
.ROOK
, V
.KNIGHT
, V
.BISHOP
, V
.QUEEN
]
57 if (this.board
[x
+ shiftX
][y
] == V
.EMPTY
) {
58 for (let piece
of finalPieces
) {
60 this.getBasicMove([x
, y
], [x
+ shiftX
, y
], {
68 this.board
[x
+ 2 * shiftX
][y
] == V
.EMPTY
70 moves
.push(this.getBasicMove([x
, y
], [x
+ 2 * shiftX
, y
]));
74 for (let shiftY
of [-1, 1]) {
78 this.board
[x
+ shiftX
][y
+ shiftY
] != V
.EMPTY
&&
79 this.canTake([x
, y
], [x
+ shiftX
, y
+ shiftY
])
81 for (let piece
of finalPieces
) {
83 this.getBasicMove([x
, y
], [x
+ shiftX
, y
+ shiftY
], {
93 const Lep
= this.epSquares
.length
;
94 const epSquare
= this.epSquares
[Lep
- 1]; //always at least one element
97 epSquare
.x
== x
+ shiftX
&&
98 Math
.abs(epSquare
.y
- y
) == 1
100 let enpassantMove
= new Move({
104 end: {x:x
+shiftX
, y:epSquare
.y
}
106 enpassantMove
.vanish
.push({
110 c: this.getColor(x
, epSquare
.y
)
112 moves
.push(enpassantMove
);