Fix typo
[vchess.git] / client / src / variants / Selfabsorption.js
CommitLineData
e023d747
BA
1import { ChessRules } from "@/base_rules";
2import { AbsorptionRules } from "@/variants/Absorption";
3
4export class SelfabsorptionRules extends AbsorptionRules {
5
6 canTake([x1, y1], [x2, y2]) {
7 if (this.getColor(x1, y1) !== this.getColor(x2, y2)) return true;
8 const p1 = this.getPiece(x1, y1);
9 const p2 = this.getPiece(x2, y2);
10 return (
11 p1 != p2 &&
12 [V.QUEEN, V.ROOK, V.KNIGHT, V.BISHOP].includes(p1) &&
13 [V.QUEEN, V.ROOK, V.KNIGHT, V.BISHOP].includes(p2)
14 );
15 }
16
17 getPotentialMovesFrom(sq) {
18 let moves = [];
19 const piece = this.getPiece(sq[0], sq[1]);
20 switch (piece) {
21 case V.RN:
22 moves =
23 super.getPotentialRookMoves(sq).concat(
24 super.getPotentialKnightMoves(sq));
25 break;
26 case V.BN:
27 moves =
28 super.getPotentialBishopMoves(sq).concat(
29 super.getPotentialKnightMoves(sq));
30 break;
31 case V.QN:
32 moves =
33 super.getPotentialQueenMoves(sq).concat(
34 super.getPotentialKnightMoves(sq));
35 break;
36 case V.PAWN:
37 moves = super.getPotentialPawnMoves(sq);
38 break;
39 case V.ROOK:
40 moves = super.getPotentialRookMoves(sq);
41 break;
42 case V.KNIGHT:
43 moves = super.getPotentialKnightMoves(sq);
44 break;
45 case V.BISHOP:
46 moves = super.getPotentialBishopMoves(sq);
47 break;
48 case V.QUEEN:
49 moves = super.getPotentialQueenMoves(sq);
50 break;
51 case V.KING:
52 moves = super.getPotentialKingMoves(sq);
53 break;
54 }
55 moves.forEach(m => {
56 if (
57 m.vanish.length == 2 && m.appear.length == 1 &&
58 piece != m.vanish[1].p && m.vanish[0].c == m.vanish[1].c
59 ) {
60 // Augment pieces abilities in case of self-captures
61 m.appear[0].p = V.Fusion(piece, m.vanish[1].p);
62 }
63 });
64 return moves;
65 }
66
67};