Program: 50008
Project: 50008
Buggy source:
/** 
 * Generate the ArrayList of legal destinations for this Piece
 * @param board The Board on which to look for legal destinations
 * @return The number of legal destinations for this Piece
 */
public int genLegalDests(Board board){
  getLegalDests().clear();
  getGuardSquares().clear();
  setPinnedBy(null);
  boolean done=false;
  Square dest;
  boolean wraparound=board.isWraparound();
  if (movements.containsKey('E')) {
    int northMax=movements.get('E') + curSquare.getCol();
    if (northMax > board.getMaxCol() || movements.get('E') == -1)     if (!wraparound) {
      northMax=board.getMaxCol();
    }
    for (int c=curSquare.getCol() + 1; ((movements.get('E') == -1 && wraparound) ? true : c <= northMax) && !done; c++) {
      int j=c;
      if (wraparound)       if (j > board.getMaxCol()) {
        j=j % board.getMaxCol();
      }
      if (j == 0) {
        break;
      }
      dest=board.getSquare(curSquare.getRow(),j);
      done=!addLegalDest(dest);
      done=(done || (dest.isOccupied() && !(board.isBlackTurn() != isBlack() && dest.getPiece().equals(board.getGame().getOtherObjectivePiece(isBlack())))));
    }
  }
  done=false;
  if (movements.containsKey('W')) {
    int southMax=curSquare.getCol() - movements.get('W');
    if (southMax < 1 || movements.get('W') == -1)     if (!wraparound) {
      southMax=1;
    }
    for (int c=curSquare.getCol() - 1; ((movements.get('W') == -1 && wraparound) ? true : c >= southMax) && !done; c--) {
      int j=c;
      if (wraparound)       if (j < 1) {
        j=board.getMaxCol() + j;
      }
      dest=board.getSquare(curSquare.getRow(),j);
      done=!addLegalDest(dest);
      done=(done || leaper ? false : (dest.isOccupied() && !(board.isBlackTurn() != isBlack() && dest.getPiece().equals(board.getGame().getOtherObjectivePiece(isBlack())))));
    }
  }
  done=false;
  if (movements.containsKey('N')) {
    int eastMax=movements.get('N') + curSquare.getRow();
    if (eastMax >= board.getMaxRow() || movements.get('N') == -1) {
      eastMax=board.getMaxRow();
    }
    for (int r=curSquare.getRow() + 1; (r <= eastMax) && !done; r++) {
      int j=r;
      dest=board.getSquare(j,curSquare.getCol());
      done=!addLegalDest(dest);
      done=(done || leaper ? false : (dest.isOccupied() && !(board.isBlackTurn() != isBlack() && dest.getPiece().equals(board.getGame().getOtherObjectivePiece(isBlack())))));
    }
  }
  done=false;
  if (movements.containsKey('S')) {
    int westMax=curSquare.getRow() - movements.get('S');
    if (westMax < 1 || movements.get('S') == -1) {
      westMax=1;
    }
    for (int r=curSquare.getRow() - 1; (r >= westMax) && !done; r--) {
      int j=r;
      dest=board.getSquare(j,curSquare.getCol());
      done=!addLegalDest(dest);
      done=(done || leaper ? false : (dest.isOccupied() && !(board.isBlackTurn() != isBlack() && dest.getPiece().equals(board.getGame().getOtherObjectivePiece(isBlack())))));
    }
  }
  done=false;
  if (movements.containsKey('R')) {
    int neMax=((curSquare.getRow() >= curSquare.getCol()) ? curSquare.getRow() : curSquare.getCol()) + movements.get('R');
    if (neMax >= board.getMaxCol() || movements.get('R') == -1) {
      neMax=board.getMaxCol();
    }
    if (neMax >= board.getMaxRow() || movements.get('R') == -1) {
      neMax=board.getMaxRow();
    }
    for (int r=curSquare.getRow() + 1, c=curSquare.getCol() + 1; r <= neMax && c <= neMax && !done; r++, c++) {
      dest=board.getSquare(r,c);
      done=!addLegalDest(dest);
      done=(done || leaper ? false : (dest.isOccupied() && !(board.isBlackTurn() != isBlack() && dest.getPiece().equals(board.getGame().getOtherObjectivePiece(isBlack())))));
    }
  }
  done=false;
  if (movements.containsKey('r')) {
    int eastMax=curSquare.getCol() + movements.get('r');
    if (eastMax >= board.getMaxCol() || movements.get('r') == -1) {
      eastMax=board.getMaxCol();
    }
    int southMin=curSquare.getRow() - movements.get('r');
    if (southMin <= 1 || movements.get('R') == -1) {
      southMin=1;
    }
    for (int r=curSquare.getRow() - 1, c=curSquare.getCol() + 1; r >= southMin && c <= eastMax && !done; r--, c++) {
      dest=board.getSquare(r,c);
      done=!addLegalDest(dest);
      done=(done || leaper ? false : (dest.isOccupied() && !(board.isBlackTurn() != isBlack() && dest.getPiece().equals(board.getGame().getOtherObjectivePiece(isBlack())))));
    }
  }
  done=false;
  if (movements.containsKey('L')) {
    int westMin=curSquare.getCol() - movements.get('L');
    if (westMin <= 1 || movements.get('L') == -1) {
      westMin=1;
    }
    int NorthMax=curSquare.getRow() + movements.get('L');
    if (NorthMax >= board.getMaxRow() || movements.get('L') == -1) {
      NorthMax=board.getMaxRow();
    }
    for (int r=curSquare.getRow() + 1, c=curSquare.getCol() - 1; r <= NorthMax && c >= westMin && !done; r++, c--) {
      dest=board.getSquare(r,c);
      done=!addLegalDest(dest);
      done=(done || leaper ? false : (dest.isOccupied() && !(board.isBlackTurn() != isBlack() && dest.getPiece().equals(board.getGame().getOtherObjectivePiece(isBlack())))));
    }
  }
  done=false;
  if (movements.containsKey('l')) {
    int westMin=curSquare.getCol() - movements.get('l');
    if (westMin <= 1 || movements.get('l') == -1) {
      westMin=1;
    }
    int southMin=curSquare.getRow() - movements.get('l');
    if (southMin <= 1 || movements.get('l') == -1) {
      southMin=1;
    }
    for (int r=curSquare.getRow() - 1, c=curSquare.getCol() - 1; r >= southMin && c >= westMin && !done; r--, c--) {
      dest=board.getSquare(r,c);
      done=!addLegalDest(dest);
      done=(done || leaper ? false : (dest.isOccupied() && !(board.isBlackTurn() != isBlack() && dest.getPiece().equals(board.getGame().getOtherObjectivePiece(isBlack())))));
    }
  }
  int f, r;
  int Rank=3;
  int File=2;
  f=(curSquare.getRow() + File);
  r=(curSquare.getCol() + Rank);
  if (wraparound) {
    if (r > board.getMaxCol() + 1) {
      r=r % board.getMaxCol();
    }
  }
  if (board.isRowValid(f) && board.isColValid(r)) {
    addLegalDest(board.getSquare(f,r));
  }
  f=(curSquare.getRow() + Rank);
  r=(curSquare.getCol() + File);
  if (wraparound) {
    if (r > board.getMaxCol() + 1) {
      r=r % board.getMaxCol();
    }
  }
  if (board.isRowValid(f) && board.isColValid(r)) {
    addLegalDest(board.getSquare(f,r));
  }
  f=(curSquare.getRow() + File);
  r=(curSquare.getCol() - Rank);
  if (wraparound) {
    if (r < 1) {
      r=board.getMaxCol() + r;
    }
  }
  if (board.isRowValid(f) && board.isColValid(r)) {
    addLegalDest(board.getSquare(f,r));
  }
  f=(curSquare.getRow() + Rank);
  r=(curSquare.getCol() - File);
  if (wraparound) {
    if (r < 1) {
      r=board.getMaxCol() + r;
    }
  }
  if (board.isRowValid(f) && board.isColValid(r)) {
    addLegalDest(board.getSquare(f,r));
  }
  f=(curSquare.getRow() - File);
  r=(curSquare.getCol() - Rank);
  if (wraparound) {
    if (r < 1) {
      r=board.getMaxCol() + r;
    }
  }
  if (board.isRowValid(f) && board.isColValid(r)) {
    addLegalDest(board.getSquare(f,r));
  }
  f=(curSquare.getRow() - Rank);
  r=(curSquare.getCol() - File);
  if (wraparound) {
    if (r < 1) {
      r=board.getMaxCol() + r;
    }
  }
  if (board.isRowValid(f) && board.isColValid(r)) {
    addLegalDest(board.getSquare(f,r));
  }
  f=(curSquare.getRow() - File);
  r=(curSquare.getCol() + Rank);
  if (wraparound) {
    if (r > board.getMaxCol() + 1) {
      r=r % board.getMaxCol();
    }
  }
  if (board.isRowValid(f) && board.isColValid(r)) {
    addLegalDest(board.getSquare(f,r));
  }
  f=(curSquare.getRow() - Rank);
  r=(curSquare.getCol() + File);
  if (wraparound) {
    if (r > board.getMaxCol() + 1) {
      r=r % board.getMaxCol();
    }
  }
  if (board.isRowValid(f) && board.isColValid(r)) {
    addLegalDest(board.getSquare(f,r));
  }
  return getLegalDests().size();
}

Fixed version (ground truth):
/** 
 * Generate the ArrayList of legal destinations for this Piece
 * @param board The Board on which to look for legal destinations
 * @return The number of legal destinations for this Piece
 */
public int genLegalDests(Board board){
  getLegalDests().clear();
  getGuardSquares().clear();
  setPinnedBy(null);
  boolean done=false;
  Square dest;
  boolean wraparound=board.isWraparound();
  if (movements.containsKey('E')) {
    int northMax=movements.get('E') + curSquare.getCol();
    if (northMax > board.getMaxCol() || movements.get('E') == -1)     if (!wraparound) {
      northMax=board.getMaxCol();
    }
    for (int c=curSquare.getCol() + 1; ((movements.get('E') == -1 && wraparound) ? true : c <= northMax) && !done; c++) {
      int j=c;
      if (wraparound)       if (j > board.getMaxCol()) {
        j=j % board.getMaxCol();
      }
      if (j == 0) {
        break;
      }
      dest=board.getSquare(curSquare.getRow(),j);
      done=!addLegalDest(dest);
      done=(done || (dest.isOccupied() && !(board.isBlackTurn() != isBlack() && dest.getPiece().equals(board.getGame().getOtherObjectivePiece(isBlack())))));
    }
  }
  done=false;
  if (movements.containsKey('W')) {
    int southMax=curSquare.getCol() - movements.get('W');
    if (southMax < 1 || movements.get('W') == -1)     if (!wraparound) {
      southMax=1;
    }
    for (int c=curSquare.getCol() - 1; ((movements.get('W') == -1 && wraparound) ? true : c >= southMax) && !done; c--) {
      int j=c;
      if (wraparound)       if (j < 1) {
        j=board.getMaxCol() + j;
      }
      dest=board.getSquare(curSquare.getRow(),j);
      done=!addLegalDest(dest);
      done=(done || leaper ? false : (dest.isOccupied() && !(board.isBlackTurn() != isBlack() && dest.getPiece().equals(board.getGame().getOtherObjectivePiece(isBlack())))));
    }
  }
  done=false;
  if (movements.containsKey('N')) {
    int eastMax=movements.get('N') + curSquare.getRow();
    if (eastMax >= board.getMaxRow() || movements.get('N') == -1) {
      eastMax=board.getMaxRow();
    }
    for (int r=curSquare.getRow() + 1; (r <= eastMax) && !done; r++) {
      int j=r;
      dest=board.getSquare(j,curSquare.getCol());
      done=!addLegalDest(dest);
      done=(done || leaper ? false : (dest.isOccupied() && !(board.isBlackTurn() != isBlack() && dest.getPiece().equals(board.getGame().getOtherObjectivePiece(isBlack())))));
    }
  }
  done=false;
  if (movements.containsKey('S')) {
    int westMax=curSquare.getRow() - movements.get('S');
    if (westMax < 1 || movements.get('S') == -1) {
      westMax=1;
    }
    for (int r=curSquare.getRow() - 1; (r >= westMax) && !done; r--) {
      int j=r;
      dest=board.getSquare(j,curSquare.getCol());
      done=!addLegalDest(dest);
      done=(done || leaper ? false : (dest.isOccupied() && !(board.isBlackTurn() != isBlack() && dest.getPiece().equals(board.getGame().getOtherObjectivePiece(isBlack())))));
    }
  }
  done=false;
  if (movements.containsKey('R')) {
    int neMax=((curSquare.getRow() >= curSquare.getCol()) ? curSquare.getRow() : curSquare.getCol()) + movements.get('R');
    if (neMax >= board.getMaxCol() || movements.get('R') == -1) {
      neMax=board.getMaxCol();
    }
    if (neMax >= board.getMaxRow() || movements.get('R') == -1) {
      neMax=board.getMaxRow();
    }
    for (int r=curSquare.getRow() + 1, c=curSquare.getCol() + 1; r <= neMax && c <= neMax && !done; r++, c++) {
      dest=board.getSquare(r,c);
      done=!addLegalDest(dest);
      done=(done || leaper ? false : (dest.isOccupied() && !(board.isBlackTurn() != isBlack() && dest.getPiece().equals(board.getGame().getOtherObjectivePiece(isBlack())))));
    }
  }
  done=false;
  if (movements.containsKey('r')) {
    int eastMax=curSquare.getCol() + movements.get('r');
    if (eastMax >= board.getMaxCol() || movements.get('r') == -1) {
      eastMax=board.getMaxCol();
    }
    int southMin=curSquare.getRow() - movements.get('r');
    if (southMin <= 1 || movements.get('R') == -1) {
      southMin=1;
    }
    for (int r=curSquare.getRow() - 1, c=curSquare.getCol() + 1; r >= southMin && c <= eastMax && !done; r--, c++) {
      dest=board.getSquare(r,c);
      done=!addLegalDest(dest);
      done=(done || leaper ? false : (dest.isOccupied() && !(board.isBlackTurn() != isBlack() && dest.getPiece().equals(board.getGame().getOtherObjectivePiece(isBlack())))));
    }
  }
  done=false;
  if (movements.containsKey('L')) {
    int westMin=curSquare.getCol() - movements.get('L');
    if (westMin <= 1 || movements.get('L') == -1) {
      westMin=1;
    }
    int NorthMax=curSquare.getRow() + movements.get('L');
    if (NorthMax >= board.getMaxRow() || movements.get('L') == -1) {
      NorthMax=board.getMaxRow();
    }
    for (int r=curSquare.getRow() + 1, c=curSquare.getCol() - 1; r <= NorthMax && c >= westMin && !done; r++, c--) {
      dest=board.getSquare(r,c);
      done=!addLegalDest(dest);
      done=(done || leaper ? false : (dest.isOccupied() && !(board.isBlackTurn() != isBlack() && dest.getPiece().equals(board.getGame().getOtherObjectivePiece(isBlack())))));
    }
  }
  done=false;
  if (movements.containsKey('l')) {
    int westMin=curSquare.getCol() - movements.get('l');
    if (westMin <= 1 || movements.get('l') == -1) {
      westMin=1;
    }
    int southMin=curSquare.getRow() - movements.get('l');
    if (southMin <= 1 || movements.get('l') == -1) {
      southMin=1;
    }
    for (int r=curSquare.getRow() - 1, c=curSquare.getCol() - 1; r >= southMin && c >= westMin && !done; r--, c--) {
      dest=board.getSquare(r,c);
      done=!addLegalDest(dest);
      done=(done || leaper ? false : (dest.isOccupied() && !(board.isBlackTurn() != isBlack() && dest.getPiece().equals(board.getGame().getOtherObjectivePiece(isBlack())))));
    }
  }
  if (movements.containsKey('x')) {
    int f, r;
    int Rank=movements.get('x');
    int File=movements.get('y');
    f=(curSquare.getRow() + File);
    r=(curSquare.getCol() + Rank);
    if (wraparound) {
      if (r > board.getMaxCol() + 1) {
        r=r % board.getMaxCol();
      }
    }
    if (board.isRowValid(f) && board.isColValid(r)) {
      addLegalDest(board.getSquare(f,r));
    }
    f=(curSquare.getRow() + Rank);
    r=(curSquare.getCol() + File);
    if (wraparound) {
      if (r > board.getMaxCol() + 1) {
        r=r % board.getMaxCol();
      }
    }
    if (board.isRowValid(f) && board.isColValid(r)) {
      addLegalDest(board.getSquare(f,r));
    }
    f=(curSquare.getRow() + File);
    r=(curSquare.getCol() - Rank);
    if (wraparound) {
      if (r < 1) {
        r=board.getMaxCol() + r;
      }
    }
    if (board.isRowValid(f) && board.isColValid(r)) {
      addLegalDest(board.getSquare(f,r));
    }
    f=(curSquare.getRow() + Rank);
    r=(curSquare.getCol() - File);
    if (wraparound) {
      if (r < 1) {
        r=board.getMaxCol() + r;
      }
    }
    if (board.isRowValid(f) && board.isColValid(r)) {
      addLegalDest(board.getSquare(f,r));
    }
    f=(curSquare.getRow() - File);
    r=(curSquare.getCol() - Rank);
    if (wraparound) {
      if (r < 1) {
        r=board.getMaxCol() + r;
      }
    }
    if (board.isRowValid(f) && board.isColValid(r)) {
      addLegalDest(board.getSquare(f,r));
    }
    f=(curSquare.getRow() - Rank);
    r=(curSquare.getCol() - File);
    if (wraparound) {
      if (r < 1) {
        r=board.getMaxCol() + r;
      }
    }
    if (board.isRowValid(f) && board.isColValid(r)) {
      addLegalDest(board.getSquare(f,r));
    }
    f=(curSquare.getRow() - File);
    r=(curSquare.getCol() + Rank);
    if (wraparound) {
      if (r > board.getMaxCol() + 1) {
        r=r % board.getMaxCol();
      }
    }
    if (board.isRowValid(f) && board.isColValid(r)) {
      addLegalDest(board.getSquare(f,r));
    }
    f=(curSquare.getRow() - Rank);
    r=(curSquare.getCol() + File);
    if (wraparound) {
      if (r > board.getMaxCol() + 1) {
        r=r % board.getMaxCol();
      }
    }
    if (board.isRowValid(f) && board.isColValid(r)) {
      addLegalDest(board.getSquare(f,r));
    }
  }
  return getLegalDests().size();
}