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 org.apache.logging.log4j.Logger |
logger |
private ch.sahits.game.openpatrician.model.map.IMap |
map |
private MapService |
mapService |
protected ch.sahits.game.openpatrician.model.player.IAITradeStrategyType |
tradeStrategyType |
| Constructor and Description |
|---|
BasePlayerTradeStrategy() |
| Modifier and Type | Method and Description |
|---|---|
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 void |
clearRemainingTradeSteps(ch.sahits.game.openpatrician.model.ship.INavigableVessel vessel,
ch.sahits.game.openpatrician.model.IAIPlayer player)
Remove any remaining trade steps.
|
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 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 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 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.
|
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.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) |
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 org.springframework.context.ApplicationContext context
@Autowired private ch.sahits.game.openpatrician.model.map.IMap map
@Autowired private MapService mapService
protected ch.sahits.game.openpatrician.model.player.IAITradeStrategyType tradeStrategyType
protected boolean isMatchingTradeStrategy(ch.sahits.game.openpatrician.model.IAIPlayer player)
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.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 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 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)
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 - protected void clearRemainingTradeSteps(ch.sahits.game.openpatrician.model.ship.INavigableVessel vessel,
ch.sahits.game.openpatrician.model.IAIPlayer player)
vessel - for which the trade steps should be checkedplayer - for which the trade steps should be checked.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 - Copyright © 2011-2016 Sahits GmbH. All Rights Reserved.