Program: 173795
Project: 173795
Buggy source:
/** 
 * Modify possibleActions to follow the Pullmann train trading rules.
 */
@Override public void setBuyableTrains(){
  if (operatingCompany == null)   return;
  TrainManager trainMgr=gameManager.getTrainManager();
  int cash=operatingCompany.getCash();
  int cost;
  List<TrainI> trains;
  boolean hasTrains=operatingCompany.getPortfolio().getNumberOfTrains() > 0;
  boolean atTrainLimit=operatingCompany.getNumberOfTrains() >= operatingCompany.getCurrentTrainLimit();
  boolean canBuyTrainNow=canBuyTrain();
  boolean presidentMayHelp=operatingCompany.mustOwnATrain();
  TrainI cheapestTrain=null;
  int costOfCheapestTrain=0;
  TrainI ownedPTrain=null;
  if (hasTrains) {
    ownedPTrain=operatingCompany.getPortfolio().getTrainOfType(pullmannType);
  }
  trains=trainMgr.getAvailableNewTrains();
  for (  TrainI train : trains) {
    cost=train.getCost();
    if (cost <= cash) {
      if (canBuyTrainNow)       possibleActions.add(new BuyTrain(train,ipo,cost));
    }
 else     if (costOfCheapestTrain == 0 || cost < costOfCheapestTrain) {
      cheapestTrain=train;
      costOfCheapestTrain=cost;
    }
    if (atTrainLimit && ownedPTrain != null) {
      BuyTrain action=new BuyTrain(train,ipo,cost);
      List<TrainI> pTrains=new ArrayList<TrainI>();
      pTrains.add(ownedPTrain);
      action.setTrainsForExchange(pTrains);
      action.setForcedExchange(true);
      possibleActions.add(action);
    }
    if (!canBuyTrainNow)     return;
  }
  if (!canBuyTrainNow)   return;
  trains=pool.getUniqueTrains();
  for (  TrainI train : trains) {
    if ((ownedPTrain != null || !hasTrains) && train.getType().getName().equals("String_Node_Str")) {
      continue;
    }
    cost=train.getCost();
    if (cost <= cash) {
      possibleActions.add(new BuyTrain(train,pool,cost));
    }
 else     if (costOfCheapestTrain == 0 || cost < costOfCheapestTrain) {
      cheapestTrain=train;
      costOfCheapestTrain=cost;
    }
  }
  if (!hasTrains && presidentMayHelp && possibleActions.getType(BuyTrain.class).isEmpty()&& cheapestTrain != null) {
    possibleActions.add(new BuyTrain(cheapestTrain,cheapestTrain.getHolder(),costOfCheapestTrain).setPresidentMustAddCash(costOfCheapestTrain - cash));
  }
  if (!canBuyTrainNow)   return;
  if (currentPhase.isTrainTradingAllowed()) {
    PublicCompanyI c;
    BuyTrain bt;
    Player p;
    Portfolio pf;
    int index;
    List<List<PublicCompanyI>> companiesPerPlayer=new ArrayList<List<PublicCompanyI>>(numberOfPlayers);
    for (int i=0; i < numberOfPlayers; i++)     companiesPerPlayer.add(new ArrayList<PublicCompanyI>(4));
    List<PublicCompanyI> companies;
    for (int j=0; j < operatingCompanyArray.length; j++) {
      c=operatingCompanyArray[j];
      if (c == operatingCompany)       continue;
      p=c.getPresident();
      index=p.getIndex();
      companiesPerPlayer.get(index).add(c);
    }
    int currentPlayerIndex=operatingCompany.getPresident().getIndex();
    for (int i=currentPlayerIndex; i < currentPlayerIndex + numberOfPlayers; i++) {
      companies=companiesPerPlayer.get(i % numberOfPlayers);
      for (      PublicCompanyI company : companies) {
        pf=company.getPortfolio();
        trains=pf.getUniqueTrains();
        for (        TrainI train : trains) {
          if (train.getType().getName().equals("String_Node_Str"))           continue;
          bt=new BuyTrain(train,pf,0);
          possibleActions.add(bt);
        }
      }
    }
  }
}

Fixed version (ground truth):
/** 
 * Modify possibleActions to follow the Pullmann train trading rules.
 */
@Override public void setBuyableTrains(){
  if (operatingCompany == null)   return;
  TrainManager trainMgr=gameManager.getTrainManager();
  int cash=operatingCompany.getCash();
  int cost;
  List<TrainI> trains;
  boolean hasTrains=operatingCompany.getPortfolio().getNumberOfTrains() > 0;
  boolean atTrainLimit=operatingCompany.getNumberOfTrains() >= operatingCompany.getCurrentTrainLimit();
  boolean canBuyTrainNow=isBelowTrainLimit();
  boolean presidentMayHelp=operatingCompany.mustOwnATrain();
  TrainI cheapestTrain=null;
  int costOfCheapestTrain=0;
  TrainI ownedPTrain=null;
  if (hasTrains) {
    ownedPTrain=operatingCompany.getPortfolio().getTrainOfType(pullmannType);
  }
  trains=trainMgr.getAvailableNewTrains();
  for (  TrainI train : trains) {
    cost=train.getCost();
    if (cost <= cash) {
      if (canBuyTrainNow)       possibleActions.add(new BuyTrain(train,ipo,cost));
    }
 else     if (costOfCheapestTrain == 0 || cost < costOfCheapestTrain) {
      cheapestTrain=train;
      costOfCheapestTrain=cost;
    }
    if (atTrainLimit && ownedPTrain != null) {
      BuyTrain action=new BuyTrain(train,ipo,cost);
      List<TrainI> pTrains=new ArrayList<TrainI>();
      pTrains.add(ownedPTrain);
      action.setTrainsForExchange(pTrains);
      action.setForcedExchange(true);
      possibleActions.add(action);
    }
    if (!canBuyTrainNow)     return;
  }
  if (!canBuyTrainNow)   return;
  trains=pool.getUniqueTrains();
  for (  TrainI train : trains) {
    if ((ownedPTrain != null || !hasTrains) && train.getType().getName().equals("String_Node_Str")) {
      continue;
    }
    cost=train.getCost();
    if (cost <= cash) {
      possibleActions.add(new BuyTrain(train,pool,cost));
    }
 else     if (costOfCheapestTrain == 0 || cost < costOfCheapestTrain) {
      cheapestTrain=train;
      costOfCheapestTrain=cost;
    }
  }
  if (!hasTrains && presidentMayHelp && possibleActions.getType(BuyTrain.class).isEmpty()&& cheapestTrain != null) {
    possibleActions.add(new BuyTrain(cheapestTrain,cheapestTrain.getHolder(),costOfCheapestTrain).setPresidentMustAddCash(costOfCheapestTrain - cash));
  }
  if (!canBuyTrainNow)   return;
  if (currentPhase.isTrainTradingAllowed()) {
    PublicCompanyI c;
    BuyTrain bt;
    Player p;
    Portfolio pf;
    int index;
    List<List<PublicCompanyI>> companiesPerPlayer=new ArrayList<List<PublicCompanyI>>(numberOfPlayers);
    for (int i=0; i < numberOfPlayers; i++)     companiesPerPlayer.add(new ArrayList<PublicCompanyI>(4));
    List<PublicCompanyI> companies;
    for (int j=0; j < operatingCompanyArray.length; j++) {
      c=operatingCompanyArray[j];
      if (c == operatingCompany)       continue;
      p=c.getPresident();
      index=p.getIndex();
      companiesPerPlayer.get(index).add(c);
    }
    int currentPlayerIndex=operatingCompany.getPresident().getIndex();
    for (int i=currentPlayerIndex; i < currentPlayerIndex + numberOfPlayers; i++) {
      companies=companiesPerPlayer.get(i % numberOfPlayers);
      for (      PublicCompanyI company : companies) {
        pf=company.getPortfolio();
        trains=pf.getUniqueTrains();
        for (        TrainI train : trains) {
          if (train.getType().getName().equals("String_Node_Str"))           continue;
          bt=new BuyTrain(train,pf,0);
          possibleActions.add(bt);
        }
      }
    }
  }
}