AI
From Wiki
Back to Imperium.
Contents |
Overview
Writing a good AI player for a game as complex as Imperium is a big task. Not impossible, but one that requires a fair deal of knowledge about AI algorithms, a lot of time and dedication. I have none of those, so the AI follows some guidelines and, well, cheats...
The idea of the AI player is to play a fairly good game and give the player some opposition. A human player should be able to win against the AI, but it should not be a walk over.
Does it cheat?
Yes. It's too hard right now to make an AI that can also explore the map in a meaningful way, so the AI player will basically know the entire map and eveything on it. This would be a huge benefit for a human player, but for the AI is merely makes some basic algorithms possible. Thus the AI can analyze whole islands at one time as well as react to oncoming threats.
The AI could be given some production bonuses too?
General algorithm
The AI does a few things for each player it controls:
- analyzes all islands where it has cities and categorizes them according to what else is on that island
- analyzes the threat level to each own city
- assigns production to cities based on island status and city threat level
- analyzes external threats to its cities (invading transports)
- assigns units to deal with threats
- assigns units to conquer cities
- assigns units to conquer other islands
Hopefully this will lead to an AI that can at least somehow react to what happens around it. :)
Island analyzis
Each island where the AI has one or more cities is analyzed and assigned a category. This category defines further actions for cities and units on that island and is one of:
- conquered island
- expansion island
- contested island
The types are discussed below. Analysis in this case is just a simple "check all hexes that make up the island and see what we can find".
Safe islands
This is the state where the AI has conquered all cities on the island as well as eliminated all enemy units. It owns the island and it can be said to be safe. These islands can now be turned into factories that produce the troops for further expansion to new islands. A safe island is also where the AI mainly produces expensive units such as transports and other ships. It's a waste of resources to produce expensive ships in cities that may be conquered by the enemy or where armies and air units are needed. Safe islands will however produce armies and fighters too for the transports and if enemy transports are seen nearby.
Expansion islands
This are islands where the AI has not yet conquered all cities, but where the only cities are neutral ones and where there are no enemy units. These islands have nothing that is of any danger to the AI, so it can focus on producing armies to conquer the rest of the cities and perhaps produce fighters and transports as well for future expansion. What a city produces depends on how near the enemy city it is. Cities closest to neutral cities produce armies and remote cities something else.
Contested islands
A contested island is one where at least one other player has armies and/or units. On such islands the AI will produce mostly armies and try to conquer all cities and fight off units that threaten its own cities.
Invaded islands
These are islands where the AI has no cities yet but only troops that are invading it.
Handling production
Each city can produce something each turn and what should be produced depends on what is needed and the island threat. Some ideas for each island type.
Safe islands
Safe islands produce units depending their size and whether the cities have harbors or not.
- 1 city islands produce warships if they have a harbor or air units if not.
- 2-3 city islands produce transports and armies if they have a harbor, otherwise land and air units.
- 4+ city islands produce mixes of the above.
Expansion islands
Contested islands
Invaded islands
The AI has no cities on these islands and thus no production to manage.
First island
If the AI has only one island and that island is a one city island that special measures need to be taken. That island must produce a transport and then some armies and start conquering the world. So until it has got at least one other island or city it should alternate between those.
City threat analysis
The AI will perform a threat analysis for cities on contested islands. The threat level is calculated from enemy units and distance to enemy cities. Enemies that are closer are of a higher threat than those further away. Land units are also of a higher threat than, say, a submarine, as the land unit can actually conquer a city. A higher threat level will have the AI produce armies in the city and a very low one will cause more expensive units such as fighters, armor, transports etc to be built.
The analysis also finds the enemy unit that is most dangerous to the city.
Handling threats
Once threats to cities have been identified they need to be dealt with.
External threats
Threats to a city or an island are not only internal to the island itself, the enemy will also try to invade over water. This phase tries to determine if any enemy transports or other ships are nearby and threaten to invade an island. If the external threat is high then the city could do:
- build armies to fight off the invaders once they arrive (the risk being that the city will produce huge amounts of armies if the enemy doesn't invade...)
- build or direct fighters to attack the enemy transports
- call in sea units to fight the invading force
Assign units to deal with threats
On contested islands the Ai will have armies or will at least be producing armies. These should have a defensive role where they are assigned to attack the nearest high threat unit or an offensive role where they are assigned to attack nearby enemy cities. The priority should be to attack enemy units and especially units that can conquer a city, i.e. land units. A cruiser sailing along the coast is of course a threat, but it can not actually conquer any cities, just attack units.
Assign units to conquer cities
On expansion islands the cities closest to the neutral cities produce armies and these will be assigned to attack the neutral cities.
Assign units to conquer other islands
On conquered islands the Ai should produce means to attack other islands, such as transports, armies etc. This can also take place on peaceful ends of contested or expansion islands where the cities have a very low threat level.
Managing transports
Transports are the backbone of the expansions and the transport manager tries to manage transports so that full transports are used to invade enemy cities and empty ones moved to safe islands to refill.
Full transports
Full transports are the ones that have more than a certain number of armies aboard. These will be navigated to the closest enemy or neutral city on another island with the aim of conquering. Once the transport has reached the city the armies will invade and try to conquer the city. If successful and the transport stil has armies it will try to find another nearby city and repeat the process until it runs out of armies. When that happens it's an empty transport.
Empty transports
Empty transports will head for safe or singular islands which produce armies and try to pick up armies. Once they reach a place near a city on such an island they will wait for armies to be produced and embarked onto the transport. When the number of armies reaches a certain limit then the transport is considered full.
Managing warships
Warships are more or less independent entities that patrol the seas and try to sink enemy ships and attack enemy land units within range. These are moved to where enemies are present and given random patrolling routes.
Other things to consider
Some other good rules that may need to be considered in order to avoid having the AI do obviously stupid decisions.
- what about own transports that get near enemy warships? Should they flee or just steam on hoping that the enemy doesn't spot them?
- reinforcement lines for air units? These can be produced behind the lines and need to be relayed towards the front by hopping between cities (or carriers).
