isAttackedByPawn([x, y], color) {
    // Square (x,y) must be surroundable by two enemy pieces,
    // and one of them at least should be a pawn (moving).
    const dirs = [
      [1, 0],
      [0, 1]
    ];
    const steps = V.steps[V.ROOK];
    for (let dir of dirs) {
      const [i1, j1] = [x - dir[0], y - dir[1]]; //"before"
      const [i2, j2] = [x + dir[0], y + dir[1]]; //"after"
      if (V.OnBoard(i1, j1) && V.OnBoard(i2, j2)) {
        if (
          (
            this.board[i1][j1] != V.EMPTY &&
            this.getColor(i1, j1) == color &&
            this.board[i2][j2] == V.EMPTY
          )
          ||
          (
            this.board[i2][j2] != V.EMPTY &&
            this.getColor(i2, j2) == color &&
            this.board[i1][j1] == V.EMPTY
          )
        ) {
          // Search a movable enemy pawn landing on the empty square
          for (let step of steps) {
            let [ii, jj] = this.board[i1][j1] == V.EMPTY ? [i1, j1] : [i2, j2];
            let [i3, j3] = [ii + step[0], jj + step[1]];
            while (V.OnBoard(i3, j3) && this.board[i3][j3] == V.EMPTY) {
              i3 += step[0];
              j3 += step[1];
            }
            if (
              V.OnBoard(i3, j3) &&
              this.getColor(i3, j3) == color &&
              this.getPiece(i3, j3) == V.PAWN &&
              !this.isImmobilized([i3, j3])
            ) {
              return true;
            }
          }
        }
      }
    }
    return false;
  }
// isAttacked() is OK because the immobilizer doesn't take
isAttacked() is OK because the immobilizer doesn't take
isAttacked () is OK because the immobilizer doesn ' t take
isAttackedByPawn([x, y], color) {
    const dirs = [
      [1, 0],
      [0, 1]
    ];
    const steps = V.steps[V.ROOK];
    for (let dir of dirs) {
      const [i1, j1] = [x - dir[0], y - dir[1]]; 
      const [i2, j2] = [x + dir[0], y + dir[1]]; 
      if (V.OnBoard(i1, j1) && V.OnBoard(i2, j2)) {
        if (
          (
            this.board[i1][j1] != V.EMPTY &&
            this.getColor(i1, j1) == color &&
            this.board[i2][j2] == V.EMPTY
          )
          ||
          (
            this.board[i2][j2] != V.EMPTY &&
            this.getColor(i2, j2) == color &&
            this.board[i1][j1] == V.EMPTY
          )
        ) {
          for (let step of steps) {
            let [ii, jj] = this.board[i1][j1] == V.EMPTY ? [i1, j1] : [i2, j2];
            let [i3, j3] = [ii + step[0], jj + step[1]];
            while (V.OnBoard(i3, j3) && this.board[i3][j3] == V.EMPTY) {
              i3 += step[0];
              j3 += step[1];
            }
            if (
              V.OnBoard(i3, j3) &&
              this.getColor(i3, j3) == color &&
              this.getPiece(i3, j3) == V.PAWN &&
              !this.isImmobilized([i3, j3])
            ) {
              return true;
            }
          }
        }
      }
    }
    return false;
  }
isAttackedByPawn ( [ x , y ] , color ) { const dirs = [ [ 1 , 0 ] , [ 0 , 1 ] ] ; const steps = V . steps [ V . ROOK ] ; for ( let dir of dirs ) { const [ i1 , j1 ] = [ x - dir [ 0 ] , y - dir [ 1 ] ] ; const [ i2 , j2 ] = [ x + dir [ 0 ] , y + dir [ 1 ] ] ; if ( V . OnBoard ( i1 , j1 ) && V . OnBoard ( i2 , j2 ) ) { if ( ( this . board [ i1 ] [ j1 ] != V . EMPTY && this . getColor ( i1 , j1 ) == color && this . board [ i2 ] [ j2 ] == V . EMPTY ) || ( this . board [ i2 ] [ j2 ] != V . EMPTY && this . getColor ( i2 , j2 ) == color && this . board [ i1 ] [ j1 ] == V . EMPTY ) ) { for ( let step of steps ) { let [ ii , jj ] = this . board [ i1 ] [ j1 ] == V . EMPTY ? [ i1 , j1 ] : [ i2 , j2 ] ; let [ i3 , j3 ] = [ ii + step [ 0 ] , jj + step [ 1 ] ] ; while ( V . OnBoard ( i3 , j3 ) && this . board [ i3 ] [ j3 ] == V . EMPTY ) { i3 += step [ 0 ] ; j3 += step [ 1 ] ; } if ( V . OnBoard ( i3 , j3 ) && this . getColor ( i3 , j3 ) == color && this . getPiece ( i3 , j3 ) == V . PAWN && ! this . isImmobilized ( [ i3 , j3 ] ) ) { return true ; } } } } } return false ; }
isAttacked() is OK because the immobilizer doesn't take
isAttacked () is OK because the immobilizer doesn ' t take
// Square (x,y) must be surroundable by two enemy pieces, // and one of them at least should be a pawn (moving). //"before" //"after" // Search a movable enemy pawn landing on the empty square