Free and Open Source real time strategy game with a new take on micro-management

Difference between revisions of "AINicowar"

From Globulation2

Jump to: navigation, search
m (Upgrade and Repair Manegement System)
m (Reverted edits by Michaelrandolph (talk) to last revision by Nmw)
 
(20 intermediate revisions by 11 users not shown)
Line 1: Line 1:
Nicowar is the new powerhouse AI. AI's for Globulation 2 generally perform poorly compared to the skilled player, but Nicowar is an attempt to close that gap. Nicowar is based upon the Echo AI system, which provides easy functionality that saves Nicowar from doing a lot of the work. Nicowar has a bunch of groups of functions, each of which are called in sequence from tick.
{{AI|name=Nicowar}}
Nicowar is going to be the most difficult AI in the game. It uses complicated statistics manegement along with full action records in order to achieve the best balance. It is designed as a set of independantly working modules, of which there only interaction with eachother is by applying factors to eachother. However, a module should still be able to run even if all of the modules it interacts with where not loaded. This, each module is self sufficient, but relies on other modules to help it run efficently and with the most difficulty.


==Upgrade and Repair Management System==
== The Phase System ==
This was the first system to be created. It bassically manages upgrades and repairs. It will cycle through buildings (in a random order), starting upgrades(or repairs) as long as it has enough spare workers with the right skill levels. It will also retask buildings that are already being upgraded or repaired depending on how many units are available at that time. So, it can adjust to changes throughout the construction of a building. If something has happens and it discovers that it does not have enough units to keep constructing a building, it cancels construction.


Nicowar's layout, code wise, is straightforward. First, there are a variety of phases. Nicowar phases are "fuzzy" in that they don't transition from one phase to the next. Instead, any number of phases can be active at any one time, and the effects of the phases are meant to stack. There are a large number of phases that activate any number of different behaviours. For example, the skilled work phase activates building schools, racetracks and swimming pools, where as the war preparation phase causes swarms to build warriors, and workers to build barracks.
==Air Search and Assault System==
This system deals with exploration and air attacks. Air attacks are a devilish strategy involving the fact the explorers can attack ground units after they go through a level 3 school. This makes them extremely powerfull, as they can not be defended against by anything but other explorers. However, it takes allot of explorers to harvest an attack, which can take swarm ytime away from other areas. Exploration is much simpler, the AI will try to uncover as much of the map as possible that is covered with hidden squares using exploration flags. It dramatically decreases the amount of time before it can see everything on the map.


== Building Queues and Orders ==
==Swarm Controller==
The swarm controller takes in factors from all of the other modules in order to control the spawns on what to build. Other modules send in amount of units that they want and priorites along with them. The Spawn Controller will do its best to try and maintain these numbers of units, so that every module gets what they want. It creates ratios by adding up the number of units wanted by every module, giving 1 point for desired units, 2 poitns for required units, and 3 points for emergency units. It will then compare the ratios of the three types of units and their respective scores in order to give the ratios for the swarm.


Nicowar basically queues buildings to be constructed in the queue_* functions. Each of these are responsible for deciding how many of which buildings will be constructed. Buildings can also have different kinds of placements, in the BuildingPlacement enum they are listed. For now, Nicowar really has only one method of placement for most buildings, and a couple of special methods for the starvation recovery inns. One obvious flaw in this system is that buildings are queued based on the circumstances at point t, but between t and when the building is actually constructed circumstances might have changed, leaving one to conclude that Nicowar should have built a different building. I have tried the other method, where the type of building to be constructed is done on the fly. While theoretically it should be better, in reality this method produced very poor performance, because most of the time Nicowar thinks it should be constructing Inns, leaving little room for other construction. Every once in a while, Nicowar has to sacrifice building an Inn to build more important buildings for the greater good of the colony.
==Inn Manager==
The inn manager is probably the most complex module algorithmically. About every 100 ticks, the inn manager records the number of units in a specific inn, and the amount of food in it. This recording is done round robin, meaning that everytime it hits the end of the vector its recording to, it starts back at the beggining. Then, every so often, the inn will compile a list of all the inns, the total number of units that where in the inn, and the total amount of food that was in the inn (some units and bits of food may be counted twice, or even more, this is ok). It then copies this list into to other lists, sorting them by the total units and the total food. In the total units one, the less units, the closer to the beggining you are. With the food one, the more food, the closer to the beggining you are. So, an inn that has few units and allot of food will be near the beggining of both lists. Then it makes a fourth, final list by taking each building, and compiling it with its respective score on each of the two other lists. For example, an inn that was near the top of both lists will have the highest score. Then it sorts this list based on the two scores added together. The top ones in this final list are the ones with allot of units eating at them but with very little food to supply them with. The inn manager increases the number of units assigned to each of these tied top ones. It then goes to the bottom of the list. Those inns are the ones who get very few units eating at them, and are constantly full of food. They will have one unit taken away from them. This algorithm allows for inns that are very commonly used but hard to keep full get the most units assigned to them. The algorithm also keeps track of the number of units it needs to fill the inns, and gives the swarm manager these numbers plus a few extra (backup).


Queued buildings are picked up and constructed in the order_* methods. Only a certain number of buildings can be constructed at once. Every building has different parameters to its placement.
==Ground Attack System==
A simple, building based, priority based ground attack system. However, this is one of the most important modules, without this, it would be impossible for the AI to actually win the game. First, when its ready to attack, it chooses who to attack by picking the weakest opponent. Some would say this is mean, however I think its effective. It then picks the buildings to attack, based on the priority. Meaning it will destroy all of one type of building before it works on the next. Since some buildings may be deep in the enemies area, there may very well be a large path of destruction from where the AI's warriors went to get to the targett building. The priorites where devised by first destroying anything that can directly benifit the enemies warriors, especially in combat. The priorites are: Barracks -> Hospital -> Racetrack -> Inn -> Swimming Pool -> School -> Swarm -> Tower -> Market. Some people may argue why hospital is so high up. Well I say, because warriors allways run to heal themselves. If units can't heal themselves, then the enemy has to entirely rely on warriors coming out of its spawn, while the rest of its army devours away at the food and without any health, don't do anything else. So the enemy becomes an easy target. Also notice that a school is a very low priority building, mainly because the school is of no use in an attack. You *wouldn't* want to be upgrading things during an attack. And without inns (which are a fiarly high priority), no workers will ever go to train.


== Building Management ==
==Defense Engine==
The defense engine is my simple, zone defending defense system. Every so often, it checks to see if a building is being attacked. If it is being attacked, it finds what zone that building is in. If that zone is already being defended, it quits. However, if it is not already being defended, it checks to see how many available warriors it has to defend with. It also counts up how many warriors are in that zone. It always tried to defend with as many warriors are attacking *1.5. If does not have enough warriors it tells the swarms to produce more with an emergency status. Then it creates the flag, and hopes for the best. It will delete the flag when there are no longer enemy units in the zone.


Nicowar really only does post-construction management on two types of buildings: Swarms and Inns. The manage_buildings function goes through all buildings, and calls the respective manage_* functions for those buildings.
==Tower Controller==

Probably the simplest module, all it does is tell the spawn manager how many units it needs for the towers, and assigns these numbers to the towers. TODO: Implement statistics information to find out what towers are attacked most, and give them more units.
Managing Inns is fairly simple. If the Inn has less than a certain amount of wheat for its level, then it will be given more workers, if it has more than enough wheat, it will be given less. These variables are hard coded in Beta1-rc and previous, however they are in the nicowar.txt and nicowar.default.txt files in later releases (and the repository).

Managing Swarms is more complex. The variety of different phases activate different behaviours for the swarm. It also uses statistics to decide whether to assign more or less workers to the swarm, and, like the Inn, adjusts depending on the amount of wheat in the swarm. Phases also change a swarm's various ratios; for example, war_preperation turns on warrior production, and no_workers turns off worker production.

== Building Upgrades ==

Buildings upgrades are mostly random. Basically, Nicowar manages a maximum number of upgrades at one moment for each building level (and a special override for schools, which should not be upgraded in parallel). When it decides it needs to upgrade its buildings, it looks at the options. Nicowar chooses a building type to upgrade randomly (although certain building types are weighted over others), then it chooses among the existing buildings of that type. This means the number of buildings on the map is irrelevant, except when there are no buildings of a type. Barracks are weighted very highly, for example, as part of Nicowar's strategy.


== Anti-Nicowar strategy ==
Here is a list of good practices to follow to beat Nicowar. Most of
these points represent flaws in Nicowar (that is, you can consider this a
weird kind of bug report), although some of them can be considered
general good advice also useful against humans.

1. Do extensive barrier farming around your perimeter. Try to grow a resource wall around the entire perimeter of your base.

2. Make sure there is a hole in your resource perimeter that Nicowar's globules can reach. As long as there is a hole, Nicowar will not try to clear a hole. You are in horrible danger if Nicowar starts to try to clear a hole, so avoid that at all costs.

3. Watch out for resources disappearing along a path between Nicowar's
base and you. This means that Nicowar has started to clear a path and
you must instantly prepare your defense. You can instantly see the
path being cleared (provided you look at the right portion of the map)
even if you can't see the workers doing the clearing. Be suspicious
any time resources disappear in a strange location.

4. Put a defense tower surrounded by walls on three sides in any very
large gaps that won't overgrow in time. Use two defense towers if the
gap is ridiculously large. This is not necessary for small fertile gaps
(less than three or four cells wide) because they can still overgrow after
Nicowar attacks. Make sure there is space (at least two cells) around
the walls so your warriors can reach the other side. The walls
prevent enemy warriors from killing your defense tower, and your
warriors prevent enemy warriors from killing the walls and also make
the enemy warriors stand still long enough to be hit by the defense
tower.

5. Until you are sure you can easily beat off an attack, keep the hole
in your perimeter narrow. Unless you are launching an attack
yourself, you probably want to keep the hole only 2 cells wide. It
helps if the hole is narrower at a point, but you must make sure the
hole never closes due to growth of wheat or wood. A good option is to
find a small gap between stone, because then you can clear away the
resources on your side so that the hole doesn't accidentally become
closed.

6. When you are under attack, you can allow resource growth to
temporarily make the hole smaller to slow down the flow of enemy
warriors (but don't let the hole close!).

7. Try to make all perimeter holes into long “tunnels”. This will
allow you to easily guard a hole with only three or four warriors. If you
have a defense tower nearby it can damage them severely while they are
stuck in the tunnel.

8. Position any perimeter hole near stone, so that a defense tower
built on one side or the other can easily be resupplied.

9. Try to choose a location for your hole that is as far from
Nicowar's base as possible while still guaranteed to remain reachable.
This way Nicowar's warriors will arrive hungry and won't stay long.
Plus, if you damage them, they are more likely to starve to death on
the way back.

10. Try to choose a location for your hole so that Nicowar's warriors
must march past suitable spots for defense towers. Build these towers
as needed. Nicowar's warriors will get hit both on the way to the
attack and when they retreat for food and healing, and you are likely
to kill many of them this way.

11. Be extremely careful any time you open a hole in your perimeter,
because Nicowar's warriors will find any hole almost instantly! Try
to keep the number of holes to a minimum (only one until the middle of the
game, maybe two later). Put one guard area cell near any hole.
Don't use war flags to guard a hole unless you can do that with level
2 or better warriors, because war flags prevent training.

12. Make sure your resource barriers are thicker if Nicowar has
buildings anywhere nearby. If Nicowar has inns or a swarm nearby, you
need a much thicker wheat barrier. Wood barriers should be thicker
near anywhere Nicowar might make a new building or upgrade an existing
one. Watch carefully to see if Nicowar might be about to make a hole
in your resource barrier and react quickly if a hole forms, because
Nicowar's warriors will find the gap almost instantly.

13. Once you have surveyed Nicowar's base with explorers, you have to
choose whether to attack immediately with warriors or wait until you
have ground-attack explorers. You may want to attack immediately if
you are close enough to Nicowar's base and/or Nicowar is undeveloped.
If Nicowar doesn't have any barracks yet and you do (so Nicowar's
level 1 warriors will be defenseless against your level 2 warriors),
this is a good time to attack. Another good motivation for a quick
attack is if you have (or can make) a clear path of attack that can
directly strike Nicowar's barracks (and also inns and hospitals)
without getting bogged down in farmed wheat fields and hives, which
are Nicowar's strongest defenses.

14. If you do attack early with warriors, you may want to build extra
barracks (three or even four total) to ensure a good supply of level 2
warriors. Monitor your number of level 1 warriors and consider
building another barracks if the number of level 1 warriors is going
up. (Level 1 warriors are pretty much useless on the attack if the
enemy has any level 2 warriors. They are mainly useful on the defense
to slow down enemy warriors long enough for them to be hit by defense
towers or for your level 2 warriors to arrive.)

15. If you do attack early with warriors, quickly make lots and lots
of inns and hospitals off to the side, somewhere close to Nicowar's
base but not on a path that any of Nicowar's warriors might take in
attacking your bigger buildings. Your inns and hospitals will be safe
as long as they are off to the side far enough because Nicowar will
choose to put war flags on your more significant buildings. The speed
with which you can feed and heal your warriors will govern how strong
your attack is.

16. Only attack with level 2 warriors or greater. You need to leave
your level 1 warriors at home so that they will train. They won't
train if they are called to a war flag.

17. If you don't think a direct strike with warriors can beat Nicowar,
then you have to get ground-attack explorers by making level 4
schools. For this, your main priority will be to defend your
perimeter while also ensuring there is a clear, uncongested path
between your schools and algae (also stone is sometimes difficult to
get). You may need to open an extra hole in your perimeter for this.
Once you have ground-attack explorers you can easily win as long as
you can hold your perimeter against any active attack by Nicowar's
warriors. Support your warrior attacks with 15-20 ground-attack explorers
with narrow (8-10) working range, especially if you are trying to
get through farmed fields of wheat.

18. NicoWar sends its explorers to your inns. So if they have ground-attack
ability you will start losing your workers very fast. But this is also a
good point - build level 2 Defence Towers near the inns and you will kill
most of explorers very fast.

[[Category:en]]
[[Category:AI]]
[[Category:User_Manual]]

Latest revision as of 14:59, 3 February 2014

Nicowar is the new powerhouse AI. AI's for Globulation 2 generally perform poorly compared to the skilled player, but Nicowar is an attempt to close that gap. Nicowar is based upon the Echo AI system, which provides easy functionality that saves Nicowar from doing a lot of the work. Nicowar has a bunch of groups of functions, each of which are called in sequence from tick.

The Phase System

Nicowar's layout, code wise, is straightforward. First, there are a variety of phases. Nicowar phases are "fuzzy" in that they don't transition from one phase to the next. Instead, any number of phases can be active at any one time, and the effects of the phases are meant to stack. There are a large number of phases that activate any number of different behaviours. For example, the skilled work phase activates building schools, racetracks and swimming pools, where as the war preparation phase causes swarms to build warriors, and workers to build barracks.

Building Queues and Orders

Nicowar basically queues buildings to be constructed in the queue_* functions. Each of these are responsible for deciding how many of which buildings will be constructed. Buildings can also have different kinds of placements, in the BuildingPlacement enum they are listed. For now, Nicowar really has only one method of placement for most buildings, and a couple of special methods for the starvation recovery inns. One obvious flaw in this system is that buildings are queued based on the circumstances at point t, but between t and when the building is actually constructed circumstances might have changed, leaving one to conclude that Nicowar should have built a different building. I have tried the other method, where the type of building to be constructed is done on the fly. While theoretically it should be better, in reality this method produced very poor performance, because most of the time Nicowar thinks it should be constructing Inns, leaving little room for other construction. Every once in a while, Nicowar has to sacrifice building an Inn to build more important buildings for the greater good of the colony.

Queued buildings are picked up and constructed in the order_* methods. Only a certain number of buildings can be constructed at once. Every building has different parameters to its placement.

Building Management

Nicowar really only does post-construction management on two types of buildings: Swarms and Inns. The manage_buildings function goes through all buildings, and calls the respective manage_* functions for those buildings.

Managing Inns is fairly simple. If the Inn has less than a certain amount of wheat for its level, then it will be given more workers, if it has more than enough wheat, it will be given less. These variables are hard coded in Beta1-rc and previous, however they are in the nicowar.txt and nicowar.default.txt files in later releases (and the repository).

Managing Swarms is more complex. The variety of different phases activate different behaviours for the swarm. It also uses statistics to decide whether to assign more or less workers to the swarm, and, like the Inn, adjusts depending on the amount of wheat in the swarm. Phases also change a swarm's various ratios; for example, war_preperation turns on warrior production, and no_workers turns off worker production.

Building Upgrades

Buildings upgrades are mostly random. Basically, Nicowar manages a maximum number of upgrades at one moment for each building level (and a special override for schools, which should not be upgraded in parallel). When it decides it needs to upgrade its buildings, it looks at the options. Nicowar chooses a building type to upgrade randomly (although certain building types are weighted over others), then it chooses among the existing buildings of that type. This means the number of buildings on the map is irrelevant, except when there are no buildings of a type. Barracks are weighted very highly, for example, as part of Nicowar's strategy.


Anti-Nicowar strategy

Here is a list of good practices to follow to beat Nicowar. Most of these points represent flaws in Nicowar (that is, you can consider this a weird kind of bug report), although some of them can be considered general good advice also useful against humans.

1. Do extensive barrier farming around your perimeter. Try to grow a resource wall around the entire perimeter of your base.

2. Make sure there is a hole in your resource perimeter that Nicowar's globules can reach. As long as there is a hole, Nicowar will not try to clear a hole. You are in horrible danger if Nicowar starts to try to clear a hole, so avoid that at all costs.

3. Watch out for resources disappearing along a path between Nicowar's base and you. This means that Nicowar has started to clear a path and you must instantly prepare your defense. You can instantly see the path being cleared (provided you look at the right portion of the map) even if you can't see the workers doing the clearing. Be suspicious any time resources disappear in a strange location.

4. Put a defense tower surrounded by walls on three sides in any very large gaps that won't overgrow in time. Use two defense towers if the gap is ridiculously large. This is not necessary for small fertile gaps (less than three or four cells wide) because they can still overgrow after Nicowar attacks. Make sure there is space (at least two cells) around the walls so your warriors can reach the other side. The walls prevent enemy warriors from killing your defense tower, and your warriors prevent enemy warriors from killing the walls and also make the enemy warriors stand still long enough to be hit by the defense tower.

5. Until you are sure you can easily beat off an attack, keep the hole in your perimeter narrow. Unless you are launching an attack yourself, you probably want to keep the hole only 2 cells wide. It helps if the hole is narrower at a point, but you must make sure the hole never closes due to growth of wheat or wood. A good option is to find a small gap between stone, because then you can clear away the resources on your side so that the hole doesn't accidentally become closed.

6. When you are under attack, you can allow resource growth to temporarily make the hole smaller to slow down the flow of enemy warriors (but don't let the hole close!).

7. Try to make all perimeter holes into long “tunnels”. This will allow you to easily guard a hole with only three or four warriors. If you have a defense tower nearby it can damage them severely while they are stuck in the tunnel.

8. Position any perimeter hole near stone, so that a defense tower built on one side or the other can easily be resupplied.

9. Try to choose a location for your hole that is as far from Nicowar's base as possible while still guaranteed to remain reachable. This way Nicowar's warriors will arrive hungry and won't stay long. Plus, if you damage them, they are more likely to starve to death on the way back.

10. Try to choose a location for your hole so that Nicowar's warriors must march past suitable spots for defense towers. Build these towers as needed. Nicowar's warriors will get hit both on the way to the attack and when they retreat for food and healing, and you are likely to kill many of them this way.

11. Be extremely careful any time you open a hole in your perimeter, because Nicowar's warriors will find any hole almost instantly! Try to keep the number of holes to a minimum (only one until the middle of the game, maybe two later). Put one guard area cell near any hole. Don't use war flags to guard a hole unless you can do that with level 2 or better warriors, because war flags prevent training.

12. Make sure your resource barriers are thicker if Nicowar has buildings anywhere nearby. If Nicowar has inns or a swarm nearby, you need a much thicker wheat barrier. Wood barriers should be thicker near anywhere Nicowar might make a new building or upgrade an existing one. Watch carefully to see if Nicowar might be about to make a hole in your resource barrier and react quickly if a hole forms, because Nicowar's warriors will find the gap almost instantly.

13. Once you have surveyed Nicowar's base with explorers, you have to choose whether to attack immediately with warriors or wait until you have ground-attack explorers. You may want to attack immediately if you are close enough to Nicowar's base and/or Nicowar is undeveloped. If Nicowar doesn't have any barracks yet and you do (so Nicowar's level 1 warriors will be defenseless against your level 2 warriors), this is a good time to attack. Another good motivation for a quick attack is if you have (or can make) a clear path of attack that can directly strike Nicowar's barracks (and also inns and hospitals) without getting bogged down in farmed wheat fields and hives, which are Nicowar's strongest defenses.

14. If you do attack early with warriors, you may want to build extra barracks (three or even four total) to ensure a good supply of level 2 warriors. Monitor your number of level 1 warriors and consider building another barracks if the number of level 1 warriors is going up. (Level 1 warriors are pretty much useless on the attack if the enemy has any level 2 warriors. They are mainly useful on the defense to slow down enemy warriors long enough for them to be hit by defense towers or for your level 2 warriors to arrive.)

15. If you do attack early with warriors, quickly make lots and lots of inns and hospitals off to the side, somewhere close to Nicowar's base but not on a path that any of Nicowar's warriors might take in attacking your bigger buildings. Your inns and hospitals will be safe as long as they are off to the side far enough because Nicowar will choose to put war flags on your more significant buildings. The speed with which you can feed and heal your warriors will govern how strong your attack is.

16. Only attack with level 2 warriors or greater. You need to leave your level 1 warriors at home so that they will train. They won't train if they are called to a war flag.

17. If you don't think a direct strike with warriors can beat Nicowar, then you have to get ground-attack explorers by making level 4 schools. For this, your main priority will be to defend your perimeter while also ensuring there is a clear, uncongested path between your schools and algae (also stone is sometimes difficult to get). You may need to open an extra hole in your perimeter for this. Once you have ground-attack explorers you can easily win as long as you can hold your perimeter against any active attack by Nicowar's warriors. Support your warrior attacks with 15-20 ground-attack explorers with narrow (8-10) working range, especially if you are trying to get through farmed fields of wheat.

18. NicoWar sends its explorers to your inns. So if they have ground-attack ability you will start losing your workers very fast. But this is also a good point - build level 2 Defence Towers near the inns and you will kill most of explorers very fast.

Misc