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