Artificial Inteligence specification
< Specifications
The artificial inteligence is triggered by the AIPlayerEngine. The behavour of the AI is defined by a set of strategies that are defined per vessel:
- Repair strategy:This strategy defines when a ship should be repaired. The repair strategy is invoked by the repair step of the trade strategy.
- Trade strategy: This strategy defines how the trading is done.
- TakeLoanStrategy: This strategy decides if and what loan should be taken. The take loan strategy is invoked by the take loan step in the trade strategy.
- ConstructionSelectionStrategy: Strategy to decide on ship building
- JoinGuildStrategy: Strategy to decide if a guild should be joined.
The Trading strategy is composed of a sequence of trade steps. The trade stradegy basically follows this pattern:
- Execute the next step. This execution indicates if further steps can be executed or if the execution of that step blocks further exectution. This is typically the case when the step execution initiated something that will take time to execute (e.g. traveling to another city). The handling of the next step is then picked up by the engine/strategy again when an appropriate event is issued to indicate the finishing of that task.
- If the next step can also be executed (the execution of the previous step indicated this), execute the next step if one is defined, otherwise define next steps and execute.
When adding the trade steps several steps up to the traveling are defined. Upon the event ShipEntersPort new steps can be defined.
Handled task
The following events are handled to pick up the execution of trade steps:
- ShipEntersPort: This event is handled by the engine, which then delegates to the strategy. This is important, as the engine requires to perfom some action before the event is delegated to the strategy.
- RepairFinished: This event is handled by the strategy.
Trade steps
The following trade steps are defined and can be used to create the strategy:
- BuyTradeStep: Buy a ware up to a maximum price.
- SellTradeStep: Sell a ware till a minimal sell price.
- AggregateBuyTradeStep: Aggregation of BuyTradeSteps. Wares that are not available are skiped.
- AggregateSellTradeStep: Aggregation of SellTradeSteps. Wares that are not available are skiped.
- TravelToTradeStep: Send the ship on the journey to a different city. This step is blocking and the trade is picked up again with a ShipEntersPort event.
- CheckRepairTradeStep: Check based on the repair strategy if a repair is necessary and if yes initiate it. In the latter case this step is blocking and the trade is picked up again with a RepairFinished event.
- HireSailorsStep: Hire sailors for the ship
- TakeLoanTradeStep: Check if a loan needs to be taken.
- CheckHireCaptainTradeStep: Check if a captain should be hired
- GuildJoinTradeStep: Check if the guild should be joined.
Supply Hometown strategy

Cheap production strategy
This is probably the most simple strategy. Basically it is a repetition of these steps:
- Sell wares on the ship
- Find the ware that is produced cheap and available in the city
- Buy that ware
- Find nearest city that needs this ware
- Travel to that city
Intermixed in these steps is stuff to hire sailors, repair ship, take loan ...