1 import { ChessRules
, PiPo
, Move
} from "@/base_rules";
3 export const VariantRules
= class RifleRules
extends ChessRules
{
4 getEpSquare(moveOrSquare
) {
5 if (typeof moveOrSquare
!== "object" || move.appear
.length
> 0)
6 return super.getEpSquare(moveOrSquare
);
7 // Capturing move: no en-passant
11 getBasicMove([sx
, sy
], [ex
, ey
], tr
) {
18 if (this.board
[ex
][ey
] != V
.EMPTY
) {
19 // No movement: just vanishing enemy piece
24 c: this.getColor(ex
, ey
),
25 p: this.getPiece(ex
, ey
)
35 c: tr
? tr
.c : this.getColor(sx
, sy
),
36 p: tr
? tr
.p : this.getPiece(sx
, sy
)
43 c: this.getColor(sx
, sy
),
44 p: this.getPiece(sx
, sy
)
52 getPotentialPawnMoves([x
, y
]) {
53 const color
= this.turn
;
55 const [sizeX
, sizeY
] = [V
.size
.x
, V
.size
.y
];
56 const shiftX
= color
== "w" ? -1 : 1;
57 const startRank
= color
== "w" ? sizeX
- 2 : 1;
58 const lastRank
= color
== "w" ? 0 : sizeX
- 1;
61 x
+ shiftX
== lastRank
62 ? [V
.ROOK
, V
.KNIGHT
, V
.BISHOP
, V
.QUEEN
]
64 if (this.board
[x
+ shiftX
][y
] == V
.EMPTY
) {
65 for (let piece
of finalPieces
) {
67 this.getBasicMove([x
, y
], [x
+ shiftX
, y
], {
75 this.board
[x
+ 2 * shiftX
][y
] == V
.EMPTY
77 moves
.push(this.getBasicMove([x
, y
], [x
+ 2 * shiftX
, y
]));
81 for (let shiftY
of [-1, 1]) {
85 this.board
[x
+ shiftX
][y
+ shiftY
] != V
.EMPTY
&&
86 this.canTake([x
, y
], [x
+ shiftX
, y
+ shiftY
])
88 for (let piece
of finalPieces
) {
90 this.getBasicMove([x
, y
], [x
+ shiftX
, y
+ shiftY
], {
100 const Lep
= this.epSquares
.length
;
101 const epSquare
= this.epSquares
[Lep
- 1]; //always at least one element
104 epSquare
.x
== x
+ shiftX
&&
105 Math
.abs(epSquare
.y
- y
) == 1
107 let enpassantMove
= new Move({
111 end: {x:x
+shiftX
, y:epSquare
.y
}
113 enpassantMove
.vanish
.push({
117 c: this.getColor(x
, epSquare
.y
)
119 moves
.push(enpassantMove
);