public abstract class BasePlayerTradeStrategy extends Object implements ch.sahits.game.openpatrician.model.player.IAITradeStrategy
| Modifier and Type | Class and Description |
|---|---|
private static class |
BasePlayerTradeStrategy.WareNeedComparator |
| Modifier and Type | Field and Description |
|---|---|
private org.springframework.context.ApplicationContext |
context |
private PathInterpolatorMap |
interpolators |
private org.apache.logging.log4j.Logger |
logger |
private MapProxy |
mapProxy |
private MapService |
mapService |
protected ch.sahits.game.openpatrician.model.player.IAITradeStrategyType |
tradeStrategyType |
| Constructor and Description |
|---|
BasePlayerTradeStrategy() |
| Modifier and Type | Method and Description |
|---|---|
protected void |
addDefaultTradeSteps(ch.sahits.game.openpatrician.model.ship.INavigableVessel vessel,
ch.sahits.game.openpatrician.model.IAIPlayer player,
ch.sahits.game.openpatrician.model.city.ICity city,
ch.sahits.game.openpatrician.model.city.ICity nextStop,
Set<ch.sahits.game.openpatrician.model.product.IWare> nonSellableWares,
Set<ch.sahits.game.openpatrician.model.product.IWare> buyWares,
boolean skipRepair)
Add default trading steps:
AggregatesSellTradeStep
PayBackLoanTradeStep
PayBackLoanTradeStep
AggregatedCheckedBuyTradeStep
CheckForRepairTradeStep
HireSailorsStep
TravelToTradeStep
|
void |
append(ch.sahits.game.openpatrician.model.IAIPlayer player,
ch.sahits.game.openpatrician.model.ship.INavigableVessel vessel,
ch.sahits.game.openpatrician.model.product.ITradeStep step)
Add a new trade step for a player.
|
protected AggregatedBuyTradeStep |
createAggregatedBuyTradeStep(ch.sahits.game.openpatrician.model.ship.INavigableVessel vessel,
ch.sahits.game.openpatrician.model.city.ICity city,
List<ch.sahits.game.openpatrician.model.product.IWare> waresToBuy) |
protected AggregatedCheckedBuyTradeStep |
createAggregatedCheckedBuyTradeStep(ch.sahits.game.openpatrician.model.ship.INavigableVessel vessel,
ch.sahits.game.openpatrician.model.city.ICity city,
List<ch.sahits.game.openpatrician.model.product.IWare> waresToBuy) |
protected AggregatesDumpTradeStep |
createAggregatedDumpStep(ch.sahits.game.openpatrician.model.ship.INavigableVessel vessel,
ch.sahits.game.openpatrician.model.city.ICity city,
List<ch.sahits.game.openpatrician.model.product.IWare> waresToSell) |
protected AggregatesSellTradeStep |
createAggregatedSellStep(ch.sahits.game.openpatrician.model.ship.INavigableVessel vessel,
ch.sahits.game.openpatrician.model.city.ICity city,
List<ch.sahits.game.openpatrician.model.product.IWare> waresToSell) |
protected TakeLoanTradeStep |
createCheckAndTakeLoanStep(ch.sahits.game.openpatrician.model.IAIPlayer player,
ch.sahits.game.openpatrician.model.city.ICity city)
Create a new instance of the TakeLoan trade step.
|
protected CheckForRepairTradeStep |
createCheckRepairStep(ch.sahits.game.openpatrician.model.ship.INavigableVessel vessel,
ch.sahits.game.openpatrician.model.city.ICity city)
Create the trade step to check for repairs.
|
protected AmountBasedAggregatedDumpTradeStep |
createConditionalAggregatedDumpStep(ch.sahits.game.openpatrician.model.ship.INavigableVessel vessel,
ch.sahits.game.openpatrician.model.city.ICity city,
List<ch.sahits.game.openpatrician.model.product.IWare> waresToSell,
int maxAmount)
Create a conditional dump trade step.
|
protected CheckHireCaptainTradeStep |
createHireCaptain(ch.sahits.game.openpatrician.model.ship.INavigableVessel vessel,
ch.sahits.game.openpatrician.model.city.ICity city,
ch.sahits.game.openpatrician.model.IAIPlayer player)
Create the trade step to check and hire a captain.
|
protected HireSailorsStep |
createHireSailorStep(ch.sahits.game.openpatrician.model.ship.INavigableVessel vessel,
ch.sahits.game.openpatrician.model.city.ICity city)
Create a new instance forthe hire sailor step.
|
protected GuildJoinTradeStep |
createJoinGuildTradeStep(ch.sahits.game.openpatrician.model.ship.INavigableVessel vessel,
ch.sahits.game.openpatrician.model.city.ICity city,
ch.sahits.game.openpatrician.model.IAIPlayer player) |
protected PayBackLoanTradeStep |
createPaybackLoanStep(ch.sahits.game.openpatrician.model.IAIPlayer player,
ch.sahits.game.openpatrician.model.city.ICity city)
Create a new instance of the TakeLoan trade step.
|
protected TravelToTradeStep |
createTravelToStep(ch.sahits.game.openpatrician.model.ship.INavigableVessel vessel,
ch.sahits.game.openpatrician.model.city.ICity travelToCity)
Create the travel step to a different city.
|
boolean |
executeTradeSteps(ch.sahits.game.openpatrician.model.IAIPlayer player,
ch.sahits.game.openpatrician.model.ship.INavigableVessel vessel)
The implementation of the execute trade steps makes the following assumptions:
When called there is at least one trade step defined
Typically the trade steps are defined up to the travel step.
|
(package private) ch.sahits.game.openpatrician.model.city.ICity |
findCitySupplyingWare(ch.sahits.game.openpatrician.model.IAIPlayer player,
ch.sahits.game.openpatrician.model.product.IWare ware,
ch.sahits.game.openpatrician.model.ship.INavigableVessel vessel,
Optional<ch.sahits.game.openpatrician.model.city.ICity> excludeCity)
Finding a destination that can supply a ware.
|
(package private) Optional<ch.sahits.game.openpatrician.model.city.ICity> |
findCityWithAllRequiredWares(List<ch.sahits.game.openpatrician.model.product.IWare> requiredWares,
ch.sahits.game.openpatrician.model.IAIPlayer player,
ch.sahits.game.openpatrician.model.ship.INavigableVessel vessel,
Optional<ch.sahits.game.openpatrician.model.city.ICity> excludeCity)
Find a destination city that requires all the wares.
|
protected ch.sahits.game.openpatrician.model.city.ICity |
findDestinationToBuyRequiredProductionWares(ch.sahits.game.openpatrician.model.IAIPlayer player,
List<ch.sahits.game.openpatrician.model.product.IWare> requiredWares,
ch.sahits.game.openpatrician.model.ship.INavigableVessel vessel,
Optional<ch.sahits.game.openpatrician.model.city.ICity> excludeCity)
Determine the city to travel to based on the required wares.
|
protected ch.sahits.game.openpatrician.model.city.ICity |
findNextStop(ch.sahits.game.openpatrician.model.city.ICity baseTown,
ch.sahits.game.openpatrician.model.player.IProductionConsumptionKnowledge knowledge,
List<ch.sahits.game.openpatrician.model.product.IWare> waresOfInterest,
ch.sahits.game.openpatrician.model.ship.INavigableVessel vessel,
ch.sahits.game.openpatrician.model.city.ICity exclude)
Figure out what the next stop should be to supply the ware in the list
waresOfInterest. |
protected ArrayList<ch.sahits.game.openpatrician.model.product.IWare> |
findWaresOfInterest(List<javafx.util.Pair<ch.sahits.game.openpatrician.model.product.IWare,Number>> sortedNeeds) |
protected List<ch.sahits.game.openpatrician.model.product.IWare> |
getLoadedWares(ch.sahits.game.openpatrician.model.ship.INavigableVessel vessel)
Find all wares that are loaded on the ship.
|
List<javafx.util.Pair<ch.sahits.game.openpatrician.model.product.IWare,Number>> |
getMostNeededWares(ch.sahits.game.openpatrician.model.player.ICityProductionConsumptionKnowledge knowledge)
Figure out the ware that are most needed in the city.
|
List<javafx.util.Pair<ch.sahits.game.openpatrician.model.product.IWare,Number>> |
getMostNeededWares(ch.sahits.game.openpatrician.model.player.ICityProductionConsumptionKnowledge knowledge,
ch.sahits.game.openpatrician.model.ship.INavigableVessel vessel)
Figure out the ware that are most needed in the city.
|
ch.sahits.game.openpatrician.model.product.ITradeStep |
getNextStep(ch.sahits.game.openpatrician.model.IAIPlayer player,
ch.sahits.game.openpatrician.model.ship.INavigableVessel vessel)
Retrieve the next trade step that should be executed and remove it from the list of an AI player.
|
protected List<ch.sahits.game.openpatrician.model.product.IWare> |
getWaresNeedIn(ch.sahits.game.openpatrician.model.player.IProductionConsumptionKnowledge knowledge,
ch.sahits.game.openpatrician.model.player.ICityProductionConsumptionKnowledge knowledgeCurrentTown,
ch.sahits.game.openpatrician.model.city.ICity nextStop)
Figure out what wares are needed in
nextStop, that can be provided in the current town. |
void |
handleHireSailors(HireSailorEvent event)
Andling the hiring of sailors.
|
void |
handleRepairFinished(RepairFinishedEvent event)
Handle the event of the ship coming back from repair and the trade steps have to
be picked up again.
|
boolean |
hasMoreTradeSteps(ch.sahits.game.openpatrician.model.IAIPlayer player,
ch.sahits.game.openpatrician.model.ship.INavigableVessel vessel)
Check whether the AI player has more trade steps
|
void |
inject(ch.sahits.game.openpatrician.model.IAIPlayer player,
ch.sahits.game.openpatrician.model.ship.INavigableVessel vessel,
ch.sahits.game.openpatrician.model.product.ITradeStep step)
Add a new trade step to the begining of the list.
|
protected boolean |
isMatchingTradeStrategy(ch.sahits.game.openpatrician.model.IAIPlayer player,
ch.sahits.game.openpatrician.model.ship.INavigableVessel vessel) |
boolean |
isNeeded(ch.sahits.game.openpatrician.model.player.ICityProductionConsumptionKnowledge knowledge,
ch.sahits.game.openpatrician.model.product.IWare ware)
Check if the
ware is needed in a city. |
private final org.apache.logging.log4j.Logger logger
@Autowired private MapProxy mapProxy
@Autowired private org.springframework.context.ApplicationContext context
@Autowired private MapService mapService
@Autowired private PathInterpolatorMap interpolators
protected ch.sahits.game.openpatrician.model.player.IAITradeStrategyType tradeStrategyType
protected boolean isMatchingTradeStrategy(ch.sahits.game.openpatrician.model.IAIPlayer player,
ch.sahits.game.openpatrician.model.ship.INavigableVessel vessel)
public ch.sahits.game.openpatrician.model.product.ITradeStep getNextStep(ch.sahits.game.openpatrician.model.IAIPlayer player,
ch.sahits.game.openpatrician.model.ship.INavigableVessel vessel)
player - on witch to retrieve the next taskpublic boolean hasMoreTradeSteps(ch.sahits.game.openpatrician.model.IAIPlayer player,
ch.sahits.game.openpatrician.model.ship.INavigableVessel vessel)
player - on which to checkpublic void append(ch.sahits.game.openpatrician.model.IAIPlayer player,
ch.sahits.game.openpatrician.model.ship.INavigableVessel vessel,
ch.sahits.game.openpatrician.model.product.ITradeStep step)
player - for which to add the trade stepstep - to be added.public void inject(ch.sahits.game.openpatrician.model.IAIPlayer player,
ch.sahits.game.openpatrician.model.ship.INavigableVessel vessel,
ch.sahits.game.openpatrician.model.product.ITradeStep step)
player - for which to add the trade stepstep - to be added.vessel - public List<javafx.util.Pair<ch.sahits.game.openpatrician.model.product.IWare,Number>> getMostNeededWares(ch.sahits.game.openpatrician.model.player.ICityProductionConsumptionKnowledge knowledge)
knowledge - base knowledgepublic boolean isNeeded(ch.sahits.game.openpatrician.model.player.ICityProductionConsumptionKnowledge knowledge,
ch.sahits.game.openpatrician.model.product.IWare ware)
ware is needed in a city.knowledge - of the city that should be checked.ware - for which should be checked.public List<javafx.util.Pair<ch.sahits.game.openpatrician.model.product.IWare,Number>> getMostNeededWares(ch.sahits.game.openpatrician.model.player.ICityProductionConsumptionKnowledge knowledge, ch.sahits.game.openpatrician.model.ship.INavigableVessel vessel)
vessel. That ware is treated the same way as if it stored in the city, with the
effect that on the first call the most needed ware might be BEER, but once an amount is bought the most needed ware might
change.knowledge - base knowledgevessel - on which the wares are loaded.protected List<ch.sahits.game.openpatrician.model.product.IWare> getWaresNeedIn(ch.sahits.game.openpatrician.model.player.IProductionConsumptionKnowledge knowledge, ch.sahits.game.openpatrician.model.player.ICityProductionConsumptionKnowledge knowledgeCurrentTown, ch.sahits.game.openpatrician.model.city.ICity nextStop)
nextStop, that can be provided in the current town.knowledge - base knowledgeknowledgeCurrentTown - knowledge of the current townnextStop - stop of the next city.nextStopprotected ch.sahits.game.openpatrician.model.city.ICity findNextStop(ch.sahits.game.openpatrician.model.city.ICity baseTown,
ch.sahits.game.openpatrician.model.player.IProductionConsumptionKnowledge knowledge,
List<ch.sahits.game.openpatrician.model.product.IWare> waresOfInterest,
ch.sahits.game.openpatrician.model.ship.INavigableVessel vessel,
ch.sahits.game.openpatrician.model.city.ICity exclude)
waresOfInterest.
This list is ordered so that wares in the front are more important.baseTown - city from which the travel startsknowledge - datawaresOfInterest - ordered list of needed waresexclude - city to which should not be traveled.protected TravelToTradeStep createTravelToStep(ch.sahits.game.openpatrician.model.ship.INavigableVessel vessel, ch.sahits.game.openpatrician.model.city.ICity travelToCity)
vessel - that is travellingtravelToCity - destination cityprotected CheckForRepairTradeStep createCheckRepairStep(ch.sahits.game.openpatrician.model.ship.INavigableVessel vessel, ch.sahits.game.openpatrician.model.city.ICity city)
vessel - that should be checked.city - in which should be checked.protected HireSailorsStep createHireSailorStep(ch.sahits.game.openpatrician.model.ship.INavigableVessel vessel, ch.sahits.game.openpatrician.model.city.ICity city)
vessel - city - protected TakeLoanTradeStep createCheckAndTakeLoanStep(ch.sahits.game.openpatrician.model.IAIPlayer player, ch.sahits.game.openpatrician.model.city.ICity city)
player - that takes a loancity - in which the loan is takenprotected PayBackLoanTradeStep createPaybackLoanStep(ch.sahits.game.openpatrician.model.IAIPlayer player, ch.sahits.game.openpatrician.model.city.ICity city)
player - that takes a loancity - in which the loan is takenprotected AggregatedBuyTradeStep createAggregatedBuyTradeStep(ch.sahits.game.openpatrician.model.ship.INavigableVessel vessel, ch.sahits.game.openpatrician.model.city.ICity city, List<ch.sahits.game.openpatrician.model.product.IWare> waresToBuy)
protected AggregatedCheckedBuyTradeStep createAggregatedCheckedBuyTradeStep(ch.sahits.game.openpatrician.model.ship.INavigableVessel vessel, ch.sahits.game.openpatrician.model.city.ICity city, List<ch.sahits.game.openpatrician.model.product.IWare> waresToBuy)
protected AggregatesSellTradeStep createAggregatedSellStep(ch.sahits.game.openpatrician.model.ship.INavigableVessel vessel, ch.sahits.game.openpatrician.model.city.ICity city, List<ch.sahits.game.openpatrician.model.product.IWare> waresToSell)
protected AggregatesDumpTradeStep createAggregatedDumpStep(ch.sahits.game.openpatrician.model.ship.INavigableVessel vessel, ch.sahits.game.openpatrician.model.city.ICity city, List<ch.sahits.game.openpatrician.model.product.IWare> waresToSell)
protected AmountBasedAggregatedDumpTradeStep createConditionalAggregatedDumpStep(ch.sahits.game.openpatrician.model.ship.INavigableVessel vessel, ch.sahits.game.openpatrician.model.city.ICity city, List<ch.sahits.game.openpatrician.model.product.IWare> waresToSell, int maxAmount)
maxAmount.vessel - in the trade stepcity - where the trade step happenswaresToSell - list of wares that should be soldmaxAmount - max amount of wares that should be on the shipprotected CheckHireCaptainTradeStep createHireCaptain(ch.sahits.game.openpatrician.model.ship.INavigableVessel vessel, ch.sahits.game.openpatrician.model.city.ICity city, ch.sahits.game.openpatrician.model.IAIPlayer player)
vessel - city - player - protected GuildJoinTradeStep createJoinGuildTradeStep(ch.sahits.game.openpatrician.model.ship.INavigableVessel vessel, ch.sahits.game.openpatrician.model.city.ICity city, ch.sahits.game.openpatrician.model.IAIPlayer player)
public boolean executeTradeSteps(ch.sahits.game.openpatrician.model.IAIPlayer player,
ch.sahits.game.openpatrician.model.ship.INavigableVessel vessel)
executeTradeSteps in interface ch.sahits.game.openpatrician.model.player.IAITradeStrategyplayer - vessel - public void handleRepairFinished(RepairFinishedEvent event)
event - public void handleHireSailors(HireSailorEvent event)
event - protected List<ch.sahits.game.openpatrician.model.product.IWare> getLoadedWares(ch.sahits.game.openpatrician.model.ship.INavigableVessel vessel)
vessel - protected ArrayList<ch.sahits.game.openpatrician.model.product.IWare> findWaresOfInterest(List<javafx.util.Pair<ch.sahits.game.openpatrician.model.product.IWare,Number>> sortedNeeds)
protected ch.sahits.game.openpatrician.model.city.ICity findDestinationToBuyRequiredProductionWares(ch.sahits.game.openpatrician.model.IAIPlayer player,
List<ch.sahits.game.openpatrician.model.product.IWare> requiredWares,
ch.sahits.game.openpatrician.model.ship.INavigableVessel vessel,
Optional<ch.sahits.game.openpatrician.model.city.ICity> excludeCity)
player - requiredWares - list of required waresexcludeCity - origin city to which should not be traveled.Optional<ch.sahits.game.openpatrician.model.city.ICity> findCityWithAllRequiredWares(List<ch.sahits.game.openpatrician.model.product.IWare> requiredWares, ch.sahits.game.openpatrician.model.IAIPlayer player, ch.sahits.game.openpatrician.model.ship.INavigableVessel vessel, Optional<ch.sahits.game.openpatrician.model.city.ICity> excludeCity)
requiredWares - player - excludeCity - ch.sahits.game.openpatrician.model.city.ICity findCitySupplyingWare(ch.sahits.game.openpatrician.model.IAIPlayer player,
ch.sahits.game.openpatrician.model.product.IWare ware,
ch.sahits.game.openpatrician.model.ship.INavigableVessel vessel,
Optional<ch.sahits.game.openpatrician.model.city.ICity> excludeCity)
player - ware - excludeCity - protected void addDefaultTradeSteps(ch.sahits.game.openpatrician.model.ship.INavigableVessel vessel,
ch.sahits.game.openpatrician.model.IAIPlayer player,
ch.sahits.game.openpatrician.model.city.ICity city,
ch.sahits.game.openpatrician.model.city.ICity nextStop,
Set<ch.sahits.game.openpatrician.model.product.IWare> nonSellableWares,
Set<ch.sahits.game.openpatrician.model.product.IWare> buyWares,
boolean skipRepair)
vessel - doing the tradeplayer - owner of the vesselcity - current citynextStop - next stopnonSellableWares - wares that cannot be soldbuyWares - wares that need to be boughtskipRepair - skip the task for repairing ships.Copyright © 2011-2017 Sahits GmbH. All Rights Reserved.