Search in sources :

Example 21 with SOCRoad

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();
}
Also used : SOCShip(soc.game.SOCShip) SOCPlayer(soc.game.SOCPlayer) SOCRoad(soc.game.SOCRoad)

Aggregations

SOCRoad (soc.game.SOCRoad)21 SOCShip (soc.game.SOCShip)17 SOCCity (soc.game.SOCCity)10 SOCSettlement (soc.game.SOCSettlement)10 SOCPlayer (soc.game.SOCPlayer)9 SOCBoard (soc.game.SOCBoard)5 SOCBoardLarge (soc.game.SOCBoardLarge)4 SOCFortress (soc.game.SOCFortress)4 SOCPlayingPiece (soc.game.SOCPlayingPiece)3 ArrayList (java.util.ArrayList)2 SOCResourceSet (soc.game.SOCResourceSet)2 SOCVillage (soc.game.SOCVillage)2 Graphics2D (java.awt.Graphics2D)1 Image (java.awt.Image)1 BufferedImage (java.awt.image.BufferedImage)1 Stack (java.util.Stack)1 CutoffExceededException (soc.util.CutoffExceededException)1