Some other fixes
[vchess.git] / client / src / variants / Rifle.js
1 import { ChessRules, PiPo, Move } from "@/base_rules";
2
3 export class RifleRules extends ChessRules {
4 getEpSquare(moveOrSquare) {
5 if (typeof moveOrSquare !== "object" || moveOrSquare.appear.length > 0)
6 return super.getEpSquare(moveOrSquare);
7 // Capturing move: no en-passant
8 return undefined;
9 }
10
11 getBasicMove([sx, sy], [ex, ey], tr) {
12 let mv = new Move({
13 appear: [],
14 vanish: [],
15 start: {x:sx, y:sy},
16 end: {x:ex, y:ey}
17 });
18 if (this.board[ex][ey] != V.EMPTY) {
19 // No movement: just vanishing enemy piece
20 mv.vanish = [
21 new PiPo({
22 x: ex,
23 y: ey,
24 c: this.getColor(ex, ey),
25 p: this.getPiece(ex, ey)
26 })
27 ];
28 }
29 else {
30 // Normal move
31 mv.appear = [
32 new PiPo({
33 x: ex,
34 y: ey,
35 c: tr ? tr.c : this.getColor(sx, sy),
36 p: tr ? tr.p : this.getPiece(sx, sy)
37 })
38 ];
39 mv.vanish = [
40 new PiPo({
41 x: sx,
42 y: sy,
43 c: this.getColor(sx, sy),
44 p: this.getPiece(sx, sy)
45 })
46 ];
47 }
48
49 return mv;
50 }
51
52 getEnpassantCaptures([x, y], shiftX) {
53 let moves = [];
54 const Lep = this.epSquares.length;
55 const epSquare = this.epSquares[Lep - 1]; //always at least one element
56 if (
57 !!epSquare &&
58 epSquare.x == x + shiftX &&
59 Math.abs(epSquare.y - y) == 1
60 ) {
61 let enpassantMove = new Move({
62 appear: [],
63 vanish: [],
64 start: {x:x, y:y},
65 end: {x:x+shiftX, y:epSquare.y}
66 });
67 enpassantMove.vanish.push({
68 x: x,
69 y: epSquare.y,
70 p: "p",
71 c: this.getColor(x, epSquare.y)
72 });
73 moves.push(enpassantMove);
74 }
75 return moves;
76 }
77
78 static get SEARCH_DEPTH() {
79 return 2;
80 }
81 };