- // TODO: If subTurn == 2:
- // if square is empty && firstMove is compatible,
- // complete the move (banana or bomb or piece exchange).
- // if square not empty, just complete with empty move
- const Lf = this.firstMove.length;
- if (this.subTurn == 2) {
- if (
- this.board[square[0]][square[1]] == V.EMPTY &&
- (La == 0 || !this.oppositeMoves(this.amoves[La-1], this.firstMove[Lf-1]))
- ) {
- return {
- start: { x: -1, y: -1 },
- end: { x: -1, y: -1 },
- appear: [],
- vanish: []
- };
- }
+ if (this.subTurn == 1) return null;
+ const L = this.firstMove.length;
+ const fm = this.firstMove[L-1];
+ if (fm.end.effect != 0) return null;
+ const [x, y] = [square[0], square[1]];
+ const deltaX = Math.abs(fm.end.x - x);
+ const deltaY = Math.abs(fm.end.y - y);
+ if (deltaX == 0 && deltaY == 0) {
+ // Empty move:
+ return {
+ start: { x: -1, y: -1 },
+ end: { x: -1, y: -1 },
+ appear: [],
+ vanish: []
+ };
+ }
+ if (
+ this.board[x][y] == V.EMPTY &&
+ (
+ (fm.vanish[0].p == V.ROOK && deltaX == 1 && deltaY == 1) ||
+ (fm.vanish[0].p == V.BISHOP && deltaX + deltaY == 1)
+ )
+ ) {
+ return new Move({
+ start: { x: -1, y: -1 },
+ end: { x: x, y: y },
+ appear: [
+ new PiPo({
+ x: x,
+ y: y,
+ c: 'a',
+ p: (fm.vanish[0].p == V.ROOK ? V.BANANA : V.BOMB)
+ })
+ ],
+ vanish: []
+ });