- if (this.getPiece(x, y) == V.PHOENIX)
- return this.getPotentialPhoenixMoves([x, y]);
- return super.getPotentialMovesFrom([x, y]);
- }
-
- // "Sliders": at most 3 steps
- getSlideNJumpMoves([x, y], steps, oneStep) {
- let moves = [];
- outerLoop: for (let step of steps) {
- let i = x + step[0];
- let j = y + step[1];
- let stepCount = 1;
- while (V.OnBoard(i, j) && this.board[i][j] == V.EMPTY) {
- moves.push(this.getBasicMove([x, y], [i, j]));
- if (oneStep || stepCount == 3) continue outerLoop;
- i += step[0];
- j += step[1];
- stepCount++;
+ let moves = undefined;
+ const piece = this.getPiece(x, y);
+ if (piece == V.PHOENIX)
+ moves = this.getPotentialPhoenixMoves([x, y]);
+ else moves = super.getPotentialMovesFrom([x, y]);
+ // Add "taking ball in place" move (at most one in list)
+ for (let m of moves) {
+ if (
+ m.vanish.length == 2 &&
+ m.vanish[1].p != 'a' &&
+ m.vanish[0].c != m.vanish[1].c &&
+ Object.keys(V.HAS_BALL_DECODE).includes(m.appear[0].p)
+ ) {
+ const color = this.turn;
+ const oppCol = V.GetOppCol(color);
+ moves.push(
+ new Move({
+ appear: [
+ new PiPo({
+ x: x,
+ y: y,
+ c: color,
+ p: m.appear[0].p
+ }),
+ new PiPo({
+ x: m.vanish[1].x,
+ y: m.vanish[1].y,
+ c: oppCol,
+ p: V.HAS_BALL_DECODE[m.vanish[1].p]
+ })
+ ],
+ vanish: [
+ new PiPo({
+ x: x,
+ y: y,
+ c: color,
+ p: piece
+ }),
+ new PiPo({
+ x: m.vanish[1].x,
+ y: m.vanish[1].y,
+ c: oppCol,
+ p: m.vanish[1].p
+ })
+ ],
+ end: { x: m.end.x, y: m.end.y }
+ })
+ );
+ break;