Program: 39328
Project: 39328
Buggy source:
/** 
 * Takes in the current Tetris state and finds each of the possible after states, as well as the actions to get to that state. The after states will be states for each possible orientation of the falling piece as they hit the bottom from each placement across the width.
 * @param ts
 * @return arraylist of pairs (evaluated after-states and arraylist of actions)
 */
public static ArrayList<Pair<TetrisState,ArrayList<Integer>>> evaluateAfterStates(TetrisState ts){
  int possibleOrientations=4;
  ArrayList<Pair<TetrisState,ArrayList<Integer>>> evaluated=new ArrayList<Pair<TetrisState,ArrayList<Integer>>>(possibleOrientations * TetrisState.worldWidth);
  for (int i=0; i < possibleOrientations; i++) {
    for (int j=-5; j < TetrisState.worldWidth; j++) {
      TetrisState copy=new TetrisState(ts);
      ArrayList<Integer> actionList=new ArrayList<Integer>();
      while (copy.currentRotation != i) {
        copy.take_action(TetrisState.CW);
        copy.update();
        actionList.add(TetrisState.CW);
      }
      int lastX=-100;
      while (copy.currentX != j && copy.currentX != lastX) {
        lastX=copy.currentX;
        if (copy.currentX > j) {
          copy.take_action(TetrisState.LEFT);
          copy.update();
          actionList.add(TetrisState.LEFT);
        }
 else {
          copy.take_action(TetrisState.RIGHT);
          copy.update();
          actionList.add(TetrisState.RIGHT);
        }
      }
      while (copy.blockMobile) {
        copy.take_action(TetrisState.FALL);
        copy.update();
        actionList.add(TetrisState.FALL);
      }
      copy.update();
      evaluated.add(new Pair<TetrisState,ArrayList<Integer>>(copy,actionList));
    }
  }
  return evaluated;
}

Fixed version (ground truth):
/** 
 * Takes in the current Tetris state and finds each of the possible after states, as well as the actions to get to that state. The after states will be states for each possible orientation of the falling piece as they hit the bottom from each placement across the width.
 * @param ts
 * @return arraylist of pairs (evaluated after-states and arraylist of actions)
 */
public static ArrayList<Pair<TetrisState,ArrayList<Integer>>> evaluateAfterStates(TetrisState ts){
  int possibleOrientations=4;
  ArrayList<Pair<TetrisState,ArrayList<Integer>>> evaluated=new ArrayList<Pair<TetrisState,ArrayList<Integer>>>(possibleOrientations * TetrisState.worldWidth);
  for (int i=0; i < possibleOrientations; i++) {
    for (int j=-5; j < TetrisState.worldWidth; j++) {
      TetrisState copy=new TetrisState(ts);
      ArrayList<Integer> actionList=new ArrayList<Integer>();
      while (copy.currentRotation != i) {
        copy.take_action(TetrisState.CW);
        copy.update();
        actionList.add(TetrisState.CW);
      }
      int lastX=-100;
      while (copy.currentX != j && copy.currentX != lastX) {
        lastX=copy.currentX;
        if (copy.currentX > j) {
          copy.take_action(TetrisState.LEFT);
          copy.update();
          actionList.add(TetrisState.LEFT);
        }
 else {
          copy.take_action(TetrisState.RIGHT);
          copy.update();
          actionList.add(TetrisState.RIGHT);
        }
      }
      while (copy.blockMobile) {
        copy.update();
        actionList.add(TetrisState.FALL);
      }
      copy.spawn_block();
      copy.update();
      evaluated.add(new Pair<TetrisState,ArrayList<Integer>>(copy,actionList));
    }
  }
  return evaluated;
}