use of soc.game.SOCResourceSet 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;
}
use of soc.game.SOCResourceSet in project JSettlers2 by jdmonin.
the class SOCDiscardOrGainResDialog method setVisible.
/**
* Show or hide this dialog.
* If showing (<tt>vis == true</tt>), also sets the initial values
* of our current resources, based on {@link SOCPlayer#getResources()},
* and requests focus on the Discard/Pick button.
*
* @param vis True to make visible, false to hide
*/
@Override
public void setVisible(final boolean vis) {
if (vis) {
/**
* set initial values
*/
SOCPlayer player = playerInterface.getGame().getPlayer(playerInterface.getClient().getNickname());
SOCResourceSet resources = player.getResources();
keep[0].setIntValue(resources.getAmount(SOCResourceConstants.CLAY));
keep[1].setIntValue(resources.getAmount(SOCResourceConstants.ORE));
keep[2].setIntValue(resources.getAmount(SOCResourceConstants.SHEEP));
keep[3].setIntValue(resources.getAmount(SOCResourceConstants.WHEAT));
keep[4].setIntValue(resources.getAmount(SOCResourceConstants.WOOD));
okBut.requestFocus();
playerInterface.playSound((isDiscard) ? SOCPlayerInterface.SOUND_RSRC_LOST : SOCPlayerInterface.SOUND_RSRC_GAINED_FREE);
}
super.setVisible(vis);
}
use of soc.game.SOCResourceSet in project JSettlers2 by jdmonin.
the class TestResourceSet method onePerType_typesAreKnown.
@Test
public void onePerType_typesAreKnown() {
SOCResourceSet rs = onePerType();
assertEquals(5, rs.getResourceTypeCount());
}
use of soc.game.SOCResourceSet in project JSettlers2 by jdmonin.
the class TestResourceSet method almostClone_isNotContained.
@Test
public void almostClone_isNotContained() {
SOCResourceSet rs1 = onePerType();
SOCResourceSet rs2 = onePerType();
rs2.subtract(1, SOCResourceConstants.CLAY);
assertTrue(rs1.contains(rs2));
assertFalse(rs2.contains(rs1));
}
use of soc.game.SOCResourceSet in project JSettlers2 by jdmonin.
the class TestResourceSet method onePerType_hasOnePerType2.
@Test
public void onePerType_hasOnePerType2() {
SOCResourceSet rs = onePerType();
assertEquals(1, rs.getAmount(SOCResourceConstants.CLAY));
assertEquals(1, rs.getAmount(SOCResourceConstants.ORE));
assertEquals(1, rs.getAmount(SOCResourceConstants.SHEEP));
assertEquals(1, rs.getAmount(SOCResourceConstants.WOOD));
assertEquals(1, rs.getAmount(SOCResourceConstants.WHEAT));
}
Aggregations