Latest Posts

Topic: Improving the AI

hessenfarmer
Avatar
Joined: 2014-12-11, 23:16
Posts: 2646
Ranking
One Elder of Players
Location: Bavaria
Posted at: 2020-02-16, 14:07

the-x wrote:

Indeed, why we need it i think is because we have so many small and medium maps. So even if i play a medium map, the first contact with AI is always the same. A barrack with 2 soldiers, untrained of course and they attack. So if you play this some times, it really gets all the time the same. So, if the AI has 2 soldiers with evade training, the next 1 with attack and evade it gets so much more exciting and i have the feeling that i could really lose against the AI.

As said it would work the other way round as well just choose village for yourself and trading outpot for AI. this should give you a challenge.


Top Quote
king_of_nowhere
Avatar
Joined: 2014-09-15, 18:35
Posts: 1668
Ranking
One Elder of Players
Posted at: 2020-02-16, 14:26

I think we should have different AI for different tribes, and at least a couple different setting for each tribe for small and big maps (ideally, every map should be tagged for the AI; those who are not, the AI uses the generic algorithm).

the reason is that optimal strategies change completely. In a large map you want to build 10+ woodcutters and foresters to expand quickly. in a small map you build 5-6 of them because you'd run out of space otherwise. in a large map you postpone the production of military buildings for when you have a strong economy. in a small map you build them first to have a few soldiers with some promotion, otherwise you will be smashed by early game attacks. also economy target change; in a large map you want a large stock to absorb fluctuations in the demand while wares need a long time traveling through the economy; in a small map you want a minimal stock to avoid wasting resources.

differences between tribes are even greater. with barbarians you must make early mines and weapon smith to give your soldiers some attack promotions; you cannot give evade promotions early, because the brewer needs training time. with empire and atlanteans you want instead to train in evade first. with amazons you need to prioritize attack again. with atlanteans you're not going to make any mine in the first 40 minutes (at least) because they are very expensive. and you may skip stone mines entirely. with empire making a stone mine is a top priority. with atlanteans you have few logs and many planks, so you want to build many woodcutters first and wait to make a sawmill, do it too early and it will suck precious logs to give planks that you already have aplenty; with barbarians it is the opposite, fail to make one early and you'll run out of hardwood.

and the genetic algorithm is tested with different tribes on different maps; it can never improve this way, because there is no way to make one single algorithm for all situations. it would be like trying to "optimize" the fit of a piece of clothing while trying to fit it alternatively to people of different sizes and genders.

a generic ai should stay there for things like modding new tribes and maps, but nothing more. many players report that AI has gotten worse in the latest iteration; i think it should be acknowledged that the current attempt at optimizing the ai is not working.


Top Quote
hessenfarmer
Avatar
Joined: 2014-12-11, 23:16
Posts: 2646
Ranking
One Elder of Players
Location: Bavaria
Posted at: 2020-02-16, 14:53

king_of_nowhere wrote:

I think we should have different AI for different tribes, and at least a couple different setting for each tribe for small and big maps (ideally, every map should be tagged for the AI; those who are not, the AI uses the generic algorithm).

that would be possible if we would get to the point that we could train the AI per map per tribe. Problem is if we discover a real issue in the code like in recrent changes we need to retrain every permutation we already did. It is not undoable but we would need acces to a big cluster of computers, which is expensive if nobody has any connections in that area.

the reason is that optimal strategies change completely. In a large map you want to build 10+ woodcutters and foresters to expand quickly. in a small map you build 5-6 of them because you'd run out of space otherwise. in a large map you postpone the production of military buildings for when you have a strong economy. in a small map you build them first to have a few soldiers with some promotion, otherwise you will be smashed by early game attacks. also economy target change; in a large map you want a large stock to absorb fluctuations in the demand while wares need a long time traveling through the economy; in a small map you want a minimal stock to avoid wasting resources.

there is already a definition problem: what is a large map? this can't be determined from size. cause if you have only some small islands it is different again and it doesn't need to be water there are other unbuildable terrains as well. So really there can't be any general rule for anything like this. So we would again end with a per map per tribe AI. this could only be achieved if ever with a genetic algorithm trained for this but having the same code base. As developing code for every permutation would be more then overkill (btw defaultai.cc already has m ore then 7000 lines of code)

differences between tribes are even greater. with barbarians you must make early mines and weapon smith to give your soldiers some attack promotions; you cannot give evade promotions early, because the brewer needs training time. with empire and atlanteans you want instead to train in evade first. with amazons you need to prioritize attack again. with atlanteans you're not going to make any mine in the first 40 minutes (at least) because they are very expensive. and you may skip stone mines entirely. with empire making a stone mine is a top priority. with atlanteans you have few logs and many planks, so you want to build many woodcutters first and wait to make a sawmill, do it too early and it will suck precious logs to give planks that you already have aplenty; with barbarians it is the opposite, fail to make one early and you'll run out of hardwood.

and the genetic algorithm is tested with different tribes on different maps; it can never improve this way, because there is no way to make one single algorithm for all situations. it would be like trying to "optimize" the fit of a piece of clothing while trying to fit it alternatively to people of different sizes and genders.

see above as long as I am not confident that the code base is mature enough (no fundamental shortfalls in the decisions to be made) I just would feel that any attempt to make these specific AI instances would be a waste of time.
So I still like to follow the policy of small steps. I recognized an issue with the Ai building not enough mines recently and fixed that. Next could be analysing why it does stupid dismantling of military buildings, and so on. So please keep reporting issues identified but don't expect quick and overwhelming changes.

a generic ai should stay there for things like modding new tribes and maps, but nothing more. many players report that AI has gotten worse in the latest iteration; i think it should be acknowledged that the current attempt at optimizing the ai is not working.

Which iteration?

Edited: 2020-02-16, 14:53

Top Quote
king_of_nowhere
Avatar
Joined: 2014-09-15, 18:35
Posts: 1668
Ranking
One Elder of Players
Posted at: 2020-02-16, 17:53

hessenfarmer wrote:

there is already a definition problem: what is a large map? this can't be determined from size. cause if you have only some small islands it is different again and it doesn't need to be water there are other unbuildable terrains as well. So really there can't be any general rule for anything like this.

that's why i suggested that any map has a tag for it. humans themselves can't figure out the big/small map distinction if they don't know the map in advance. and the generic, unmodified algorithm running if there is no tag on the map.

now, to truly optimize one would have to prepare for each map specifically, as is done sometimes in tournaments by some players. but i'm not so crazy as to suggest running a different ai on any different map.

see above as long as I am not confident that the code base is mature enough (no fundamental shortfalls in the decisions to be made) I just would feel that any attempt to make these specific AI instances would be a waste of time.

i see. it makes sense, and you certainly know the issue of ai development better than i do

a generic ai should stay there for things like modding new tribes and maps, but nothing more. many players report that AI has gotten worse in the latest iteration; i think it should be acknowledged that the current attempt at optimizing the ai is not working.

Which iteration? haven't played much against AI lately (as in, in years) but i refer to comments like this one: https://www.widelands.org/forum/topic/4768/?page=3#post-31518


Top Quote
Nordfriese
Avatar
Joined: 2017-01-17, 18:07
Posts: 1929
OS: Debian Testing
Version: Latest master
Ranking
One Elder of Players
Location: 0x55555d3a34c0
Posted at: 2020-02-16, 18:02

there is already a definition problem: what is a large map? this can't be determined from size. cause if you have only some small islands it is different again and it doesn't need to be water there are other unbuildable terrains as well. So really there can't be any general rule for anything like this.

that's why i suggested that any map has a tag for it. humans themselves can't figure out the big/small map distinction if they don't know the map in advance. and the generic, unmodified algorithm running if there is no tag on the map.

I haven't been following the discussion closely, but the AI has full access to the entire game state, including full knowledge of all terrains, heights, resources etc. So there is no need to use tags – it could be possible to define some "Map Types" (small, big, many_small_islands, …) which can be determined by the AI when the game starts using all the information there is (possibly weighted with genetic neurons to define whether a medium-sized map is considered big or small), and take the Map Type into account when making decisions.


Top Quote
the-x
Avatar
Topic Opener
Joined: 2019-01-19, 13:23
Posts: 967
Ranking
One Elder of Players
Posted at: 2020-02-16, 18:35

I dont know if it can be useful, but maybe we could make 2 different types of AI, economic and rush - they wont solve all the seafearing problems, but the problem with the size of the map. So every player can chose the tribe for the AI and the type of AI?

And another question: the generic algorithm works if i have different versions of widelands, so i can spot the difference if i watch AI playing against themselves for many times?

Edited: 2020-02-16, 18:37

Top Quote
hessenfarmer
Avatar
Joined: 2014-12-11, 23:16
Posts: 2646
Ranking
One Elder of Players
Location: Bavaria
Posted at: 2020-02-16, 18:55

Nordfriese wrote:

there is already a definition problem: what is a large map? this can't be determined from size. cause if you have only some small islands it is different again and it doesn't need to be water there are other unbuildable terrains as well. So really there can't be any general rule for anything like this.

that's why i suggested that any map has a tag for it. humans themselves can't figure out the big/small map distinction if they don't know the map in advance. and the generic, unmodified algorithm running if there is no tag on the map.

I haven't been following the discussion closely, but the AI has full access to the entire game state, including full knowledge of all terrains, heights, resources etc. So there is no need to use tags – it could be possible to define some "Map Types" (small, big, many_small_islands, …) which can be determined by the AI when the game starts using all the information there is (possibly weighted with genetic neurons to define whether a medium-sized map is considered big or small), and take the Map Type into account when making decisions.

my point is that we either have a map specific AI for a map or we have the algorithm we are trying to improve currently. There are so many different things to take into account for a good strategy that you can't implement them in the code. Basically we have a lot of if statements that are only vlaid in certain circumstances and these circumstances are mutually dependent on each other. So if we are happy with the content we could speak top train a per map per tribe AI. However until then and even then I don't see this happen due to the amount of computing power needed.


Top Quote
hessenfarmer
Avatar
Joined: 2014-12-11, 23:16
Posts: 2646
Ranking
One Elder of Players
Location: Bavaria
Posted at: 2020-02-16, 18:58

the-x wrote:

I dont know if it can be useful, but maybe we could make 2 different types of AI, economic and rush - they wont solve all the seafearing problems, but the problem with the size of the map. So every player can chose the tribe for the AI and the type of AI?

you can already choose. however the choice is not very useful as normal Ai is still much to weak for an experienced player. Train 2 different types would be possible however someone with a lot of computing power has to do this.

And another question: the generic algorithm works if i have different versions of widelands, so i can spot the difference if i watch AI playing against themselves for many times?

you can always watch the AI. just setup a local Ip multiplayer with only AI slots you will be an observer then and watch.


Top Quote
Tibor

Joined: 2009-03-23, 23:24
Posts: 1377
Ranking
One Elder of Players
Location: Slovakia
Posted at: 2020-02-16, 19:05

As for small vs big maps - it is true that AI sees all map, but to interpret what it sees is close to impossible. AI does not have such capabilities. And it is not matter of training at all. It would be job for neural network, but we are far from this now.

To train own branch of AI is possible (needs some work to set up), just remember that results are not mergeable back into AI in the main branch.


Top Quote
the-x
Avatar
Topic Opener
Joined: 2019-01-19, 13:23
Posts: 967
Ranking
One Elder of Players
Posted at: 2020-02-16, 19:08

hessenfarmer wrote:

the-x wrote:

I dont know if it can be useful, but maybe we could make 2 different types of AI, economic and rush - they wont solve all the seafearing problems, but the problem with the size of the map. So every player can chose the tribe for the AI and the type of AI?

you can already choose. however the choice is not very useful as normal Ai is still much to weak for an experienced player.

+1

exactly that is it, maybe we need sth like a "hard ai"


Top Quote