- // Handle explosions
- moves.forEach(m => {
- if (m.vanish.length > 1 && m.appear.length <= 1) //avoid castles
- {
- // Explosion! TODO(?): drop moves which explode our king here
- let steps = [ [-1,-1],[-1,0],[-1,1],[0,-1],[0,1],[1,-1],[1,0],[1,1] ];
- for (let step of steps)
- {
- let x = m.end.x + step[0];
- let y = m.end.y + step[1];
- if (V.OnBoard(x,y) && this.board[x][y] != V.EMPTY
- && this.getPiece(x,y) != V.PAWN)
- {
- m.vanish.push(
- new PiPo({p:this.getPiece(x,y),c:this.getColor(x,y),x:x,y:y}));
- }
- }
- m.end = {x:m.appear[0].x, y:m.appear[0].y};
- m.appear.pop(); //Nothin appears in this case
- }
- });
+ // Handle explosions
+ moves.forEach(m => {
+ // NOTE: if vanish.length==2 and appear.length==2, this is castle
+ if (m.vanish.length > 1 && m.appear.length <= 1) {
+ // Explosion! (TODO?: drop moves which explode our king here)
+ let steps = [
+ [-1, -1],
+ [-1, 0],
+ [-1, 1],
+ [0, -1],
+ [0, 1],
+ [1, -1],
+ [1, 0],
+ [1, 1]
+ ];
+ for (let step of steps) {
+ let x = m.end.x + step[0];
+ let y = m.end.y + step[1];
+ if (
+ V.OnBoard(x, y) &&
+ this.board[x][y] != V.EMPTY &&
+ this.getPiece(x, y) != V.PAWN
+ ) {
+ m.vanish.push(
+ new PiPo({
+ p: this.getPiece(x, y),
+ c: this.getColor(x, y),
+ x: x,
+ y: y
+ })
+ );
+ }
+ }
+ m.end = { x: m.appear[0].x, y: m.appear[0].y };
+ m.appear.pop(); //Nothin appears in this case
+ }
+ });