use of soc.game.SOCRoad in project JSettlers2 by jdmonin.
the class SOCPlayerTracker method updateLRValues.
/**
* update the longest road values for all possible roads/ships.
*<P>
* longest road value is how much this
* road/ship would increase our longest road
* if it were built.
*<P>
* the longest road potential is how much
* this road/ship would increase our LR value
* if other roads supported by this one were
* built.
*/
public void updateLRValues() {
SOCPlayer dummy = new SOCPlayer(player);
int lrLength = player.getLongestRoadLength();
//
// for each possible road with no necessary roads
//
Iterator<SOCPossibleRoad> posRoadsIter = possibleRoads.values().iterator();
while (posRoadsIter.hasNext()) {
SOCPossibleRoad posRoad = posRoadsIter.next();
if (posRoad.getNecessaryRoads().isEmpty()) {
//
// calc longest road value
//
SOCRoad dummyRoad;
if (posRoad.isRoadNotShip() || ((posRoad instanceof SOCPossibleShip) && ((SOCPossibleShip) posRoad).isCoastalRoadAndShip))
// TODO better coastal handling
dummyRoad = new SOCRoad(dummy, posRoad.getCoordinates(), null);
else
dummyRoad = new SOCShip(dummy, posRoad.getCoordinates(), null);
dummy.putPiece(dummyRoad, true);
int newLRLength = dummy.calcLongestRoad2();
if (newLRLength <= lrLength) {
posRoad.setLRValue(0);
} else {
posRoad.setLRValue(newLRLength - lrLength);
}
// D.ebugPrintln("$$ updateLRValue for "+Integer.toHexString(posRoad.getCoordinates())+" is "+posRoad.getLRValue());
//
// update potential LR value
//
posRoad.setLRPotential(0);
updateLRPotential(posRoad, dummy, dummyRoad, lrLength, LR_CALC_LEVEL);
dummy.removePiece(dummyRoad, null);
} else {
posRoad.setLRValue(0);
posRoad.setLRPotential(0);
}
}
dummy.destroyPlayer();
}
Aggregations