Search in sources :

Example 1 with CutoffExceededException

use of soc.util.CutoffExceededException in project JSettlers2 by jdmonin.

the class SOCRobotClient method handleROBOTDISMISS.

/**
 * handle the "dismiss robot" message
 * @param mes  the message
 */
protected void handleROBOTDISMISS(SOCRobotDismiss mes) {
    SOCGame ga = games.get(mes.getGame());
    CappedQueue<SOCMessage> brainQ = brainQs.get(mes.getGame());
    if ((ga != null) && (brainQ != null)) {
        try {
            brainQ.put(mes);
        } catch (CutoffExceededException exc) {
            D.ebugPrintln("CutoffExceededException" + exc);
        }
        /**
         * if the brain isn't alive, then we need to leave
         * the game here, instead of having the brain leave it
         */
        SOCRobotBrain brain = robotBrains.get(mes.getGame());
        if ((brain == null) || (!brain.isAlive())) {
            leaveGame(games.get(mes.getGame()), "brain not alive in handleROBOTDISMISS", true, false);
        }
    }
}
Also used : CutoffExceededException(soc.util.CutoffExceededException) SOCGame(soc.game.SOCGame)

Example 2 with CutoffExceededException

use of soc.util.CutoffExceededException in project JSettlers2 by jdmonin.

the class SOCRobotDM method getWinGameETABonusForRoad.

/**
 * For {@link #SMART_STRATEGY}, add a bonus to the road or ship score
 * based on the change in win game ETA for this one road or ship
 * (possible settlements are 1 road closer, longest road bonus, etc).
 *<UL>
 * <LI> Calls {@link SOCPlayerTracker#tryPutPiece(SOCPlayingPiece, SOCGame, HashMap)}
 *      which makes a copy of the player trackers and puts the piece there.
 *      This also updates our player's VP total, including any special VP from placement.
 * <LI> Calls {@link SOCPlayerTracker#updateWinGameETAs(HashMap)} on that copy
 * <LI> Calls {@link #calcWGETABonus(HashMap, HashMap)} to compare WGETA before and after placement
 * <LI> Calls {@link #getETABonus(int, int, float)} to weigh that bonus
 * <LI> Adds that to {@code posRoad}'s {@link SOCPossiblePiece#getScore()}
 * <LI> Cleans up with {@link SOCPlayerTracker#undoTryPutPiece(SOCPlayingPiece, SOCGame)}
 *</UL>
 *
 * @param posRoad  the possible piece that we're scoring
 * @param roadETA  the ETA for a road or ship, from building speed estimates
 * @param leadersCurrentWGETA  the leaders current WGETA
 * @param playerTrackers  the player trackers (for figuring out road building plan and bonus/ETA)
 */
protected float getWinGameETABonusForRoad(final SOCPossibleRoad posRoad, final int roadETA, final int leadersCurrentWGETA, HashMap<Integer, SOCPlayerTracker> playerTrackers) {
    D.ebugPrintln("--- addWinGameETABonusForRoad");
    int ourCurrentWGETA = ourPlayerTracker.getWinGameETA();
    D.ebugPrintln("ourCurrentWGETA = " + ourCurrentWGETA);
    HashMap<Integer, SOCPlayerTracker> trackersCopy = null;
    SOCRoad tmpRoad1 = null;
    // Building road or ship?  TODO Better ETA calc for coastal road/ship
    final boolean isShip = (posRoad instanceof SOCPossibleShip) && !((SOCPossibleShip) posRoad).isCoastalRoadAndShip;
    final SOCResourceSet rsrcs = (isShip ? SOCShip.COST : SOCRoad.COST);
    D.ebugPrintln("--- before [start] ---");
    SOCResourceSet originalResources = ourPlayerData.getResources().copy();
    SOCBuildingSpeedEstimate estimate = new SOCBuildingSpeedEstimate(ourPlayerData.getNumbers());
    // SOCPlayerTracker.playerTrackersDebug(playerTrackers);
    D.ebugPrintln("--- before [end] ---");
    try {
        SOCResSetBuildTimePair btp = estimate.calculateRollsAndRsrcFast(ourPlayerData.getResources(), rsrcs, 50, ourPlayerData.getPortFlags());
        btp.getResources().subtract(rsrcs);
        ourPlayerData.getResources().setAmounts(btp.getResources());
    } catch (CutoffExceededException e) {
        D.ebugPrintln("crap in getWinGameETABonusForRoad - " + e);
    }
    tmpRoad1 = (isShip) ? new SOCShip(ourPlayerData, posRoad.getCoordinates(), null) : new SOCRoad(ourPlayerData, posRoad.getCoordinates(), null);
    trackersCopy = SOCPlayerTracker.tryPutPiece(tmpRoad1, game, playerTrackers);
    SOCPlayerTracker.updateWinGameETAs(trackersCopy);
    float score = calcWGETABonus(playerTrackers, trackersCopy);
    if (!posRoad.getThreats().isEmpty()) {
        score *= threatMultiplier;
        D.ebugPrintln("***  (THREAT MULTIPLIER) score * " + threatMultiplier + " = " + score);
    }
    D.ebugPrintln("*** ETA for road = " + roadETA);
    float etaBonus = getETABonus(roadETA, leadersCurrentWGETA, score);
    D.ebugPrintln("$$$ score = " + score);
    D.ebugPrintln("etaBonus = " + etaBonus);
    posRoad.addToScore(etaBonus);
    if ((brain != null) && (brain.getDRecorder().isOn())) {
        brain.getDRecorder().record("ETA = " + roadETA);
        brain.getDRecorder().record("WGETA Score = " + df1.format(score));
        brain.getDRecorder().record("Total road score = " + df1.format(etaBonus));
    }
    D.ebugPrintln("--- after [end] ---");
    SOCPlayerTracker.undoTryPutPiece(tmpRoad1, game);
    ourPlayerData.getResources().clear();
    ourPlayerData.getResources().add(originalResources);
    D.ebugPrintln("--- cleanup done ---");
    return etaBonus;
}
Also used : SOCShip(soc.game.SOCShip) SOCRoad(soc.game.SOCRoad) CutoffExceededException(soc.util.CutoffExceededException) SOCResourceSet(soc.game.SOCResourceSet)

Aggregations

CutoffExceededException (soc.util.CutoffExceededException)2 SOCGame (soc.game.SOCGame)1 SOCResourceSet (soc.game.SOCResourceSet)1 SOCRoad (soc.game.SOCRoad)1 SOCShip (soc.game.SOCShip)1