Step 1: Calculate needs of empire
The basic question of production management is: what do I need to run my empire? So the AI emperor needs to determine what demands his empire has. Demands as:
- for resources: look if specific resources are required
- for exploration: look if enough scouts are available
- for expansion: look at empire size in relation to other empires/galaxy
- for military, defense: peace-war state, current fleet strength of own empire/other empires
- for shipyards: min 1, depending on empire size; no shipyard => great need to build one
- depend also on personality of AI leader: expansionist, militarist, scientist, economist etc.
Step 2: Create a list that holds all buildable items, figure out which demand(s) they satisfy and how much they satisfy it
The AI will need to know what ships and buildings are available to build. For that reason I'd compose a list that holds all ships and buildings which are available. ShipDesign and BuildingType will be mapped to a productionItem type and written into a list (availableProductionItems). (This has the advantage that the AI won't have to think in categories, it'll be able to just ask itself which item will satisfy its demands and not from which category an item is.)
Code: Select all
type productionItem:
name = "" # string
type = (none, ship, building)
ID = original ID of sb (shipDesignID, buildingType)
demandsSatisfied = [...] # (none, exploration, expansion, minerals, production, money, science, military, shipyards)
demandsValue = [...] # list of integer
So now we have all buildable items at hand, but the AI will also need to determine what kind of demand(s) an item satisfies. For this, it will need to know:
- about the purpose of a ship (colonisation, exploration, war, etc); will store in a dictionary what ship purpose a design name belongs to
- as well as the purpose of buildings (do they promote resources, which type?, defense, etc); should be able to [read the buildings effects or] derive this from a list
- recognize shipyards
- As well as how well a productionItem satisfies a demand. (For now, this can just be the cost of a ship/building per turn. Will need to be considered in more detail.)
Step 3: Determine how much the current production queue satisfies the demands.
If the current production queue satisfies the current demands, it shouldn't be changed at all. To determine if it does it will be mapped to a productionQueue type:
Code: Select all
type productionQueue:
items = [] # list of integers, uses IDs of availableProductionItems: 1, 5, 23...
numItems = 0 # integer
demandsSatisfied = [] # list of demandEnum
demandsValue = [] # list of integers
Step 4: Create all different kinds of production queues and look which one meets the current demands best.
The AI could much like a human player intelligently choose different items and put them on the prod queue. However, for now I would recommend a more CPU-consuming, but complete algorithm; I'd use a brute-force algorithm to create all conceivable combinations of productionItems. (Stop point for adding items would be that all PP have been used up.) As a result we'd have a couple of prodQueues with all possible combinations of prodItems.
Suggestion for a non-brute force algorithm by m_k see below.
Then the AI would have to determine if and which of these queues satisfies the empires demands best. So the satisfaction profiles of the queues would be compared to the demand profile.
At this point I'd assign build locations to the winning combination. (This could be done earlier to allow higher flexibility. Will need thought.)
Step 5: Change production queue
Even if a major change needs to be done to the production queue, old projects should be kept so as not to waste production. Projects should only be removed if a design becomes obsolete. Projects that are already being produced do not need to be added again.
1) Move down items of production queue that are not on the new queue (only postpone)
2) Remove items from the new prod queue that are part of the old queue (don't build them twice)
3) Add items that remain on the new queue at the top of the production queue (important projects)
4) Remove items from the production queue that have become obsolete (cleanup)
Suggestions?
[Edit: orbitals removed; components up for review marked blue]