Adjust Chakart rules
[vchess.git] / client / src / variants / Selfabsorb.js
CommitLineData
e023d747
BA
1import { ChessRules } from "@/base_rules";
2import { AbsorptionRules } from "@/variants/Absorption";
3
1943de6b 4export class SelfabsorbRules extends AbsorptionRules {
e023d747
BA
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 &&
d2af3400
BA
12 [V.QUEEN, V.RN, V.BN, V.ROOK, V.KNIGHT, V.BISHOP].includes(p1) &&
13 [V.QUEEN, V.RN, V.BN, V.ROOK, V.KNIGHT, V.BISHOP].includes(p2) &&
34b79fe4 14 (p1 != V.QUEEN || p2 == V.KNIGHT) &&
d2af3400
BA
15 (p2 != V.QUEEN || p1 == V.KNIGHT) &&
16 (p1 != V.RN || p2 == V.BISHOP) &&
17 (p2 != V.RN || p1 == V.BISHOP) &&
18 (p1 != V.BN || p2 == V.ROOK) &&
19 (p2 != V.BN || p1 == V.ROOK)
e023d747
BA
20 );
21 }
22
23 getPotentialMovesFrom(sq) {
24 let moves = [];
25 const piece = this.getPiece(sq[0], sq[1]);
26 switch (piece) {
27 case V.RN:
28 moves =
29 super.getPotentialRookMoves(sq).concat(
30 super.getPotentialKnightMoves(sq));
31 break;
32 case V.BN:
33 moves =
34 super.getPotentialBishopMoves(sq).concat(
35 super.getPotentialKnightMoves(sq));
36 break;
37 case V.QN:
38 moves =
39 super.getPotentialQueenMoves(sq).concat(
40 super.getPotentialKnightMoves(sq));
41 break;
42 case V.PAWN:
43 moves = super.getPotentialPawnMoves(sq);
44 break;
45 case V.ROOK:
46 moves = super.getPotentialRookMoves(sq);
47 break;
48 case V.KNIGHT:
49 moves = super.getPotentialKnightMoves(sq);
50 break;
51 case V.BISHOP:
52 moves = super.getPotentialBishopMoves(sq);
53 break;
54 case V.QUEEN:
55 moves = super.getPotentialQueenMoves(sq);
56 break;
57 case V.KING:
58 moves = super.getPotentialKingMoves(sq);
59 break;
60 }
61 moves.forEach(m => {
62 if (
63 m.vanish.length == 2 && m.appear.length == 1 &&
64 piece != m.vanish[1].p && m.vanish[0].c == m.vanish[1].c
65 ) {
66 // Augment pieces abilities in case of self-captures
67 m.appear[0].p = V.Fusion(piece, m.vanish[1].p);
68 }
69 });
70 return moves;
71 }
72
ded43c88
BA
73 static get SEARCH_DEPTH() {
74 return 2;
75 }
76
e023d747 77};