1 import { Teleport1Rules
} from "@/variants/Teleport1";
3 export class Teleport2Rules
extends Teleport1Rules
{
5 canTake([x1
, y1
], [x2
, y2
]) {
6 // Cannot teleport king:
7 return (this.subTurn
== 1 && this.getPiece(x2
, y2
) != V
.KING
);
12 return this.isAttacked(this.kingPos
[color
], V
.GetOppCol(color
));
16 if (move.vanish
.length
> 0) {
18 if (move.appear
[0].p
== V
.KING
)
19 this.kingPos
[move.appear
[0].c
] = [move.appear
[0].x
, move.appear
[0].y
];
20 this.updateCastleFlags(move);
24 updateCastleFlags(move) {
25 // Standard method: TODO = find a better way... (not rewriting)
26 const c
= move.vanish
[0].c
;
27 const firstRank
= (c
== "w" ? V
.size
.x
- 1 : 0);
28 const oppCol
= this.turn
;
29 const oppFirstRank
= V
.size
.x
- 1 - firstRank
;
30 if (move.vanish
[0].p
== V
.KING
&& move.appear
.length
> 0)
31 this.castleFlags
[c
] = [V
.size
.y
, V
.size
.y
];
33 move.start
.x
== firstRank
&&
34 this.castleFlags
[c
].includes(move.start
.y
)
36 const flagIdx
= (move.start
.y
== this.castleFlags
[c
][0] ? 0 : 1);
37 this.castleFlags
[c
][flagIdx
] = V
.size
.y
;
40 move.end
.x
== oppFirstRank
&&
41 this.castleFlags
[oppCol
].includes(move.end
.y
)
43 const flagIdx
= (move.end
.y
== this.castleFlags
[oppCol
][0] ? 0 : 1);
44 this.castleFlags
[oppCol
][flagIdx
] = V
.size
.y
;
49 if (move.vanish
.length
> 0) {
51 const c
= this.getColor(move.start
.x
, move.start
.y
);
52 if (this.getPiece(move.start
.x
, move.start
.y
) == V
.KING
)
53 this.kingPos
[c
] = [move.start
.x
, move.start
.y
];