Currently Online

Latest Posts

Topic: News about AI

Tibor

Topic Opener
Joined: 2009-03-23, 22:24
Posts: 1377
Ranking
One Elder of Players
Location: Slovakia
Posted at: 2017-07-18, 08:09

I finally started the training again, I did a change in fitness function, obviously it was too much focused to expansion, so now military strength has much bigger weight. I will see how it will evolve...


Top Quote
soulless
Avatar
Joined: 2017-04-09, 12:20
Posts: 22
Ranking
Pry about Widelands
Posted at: 2017-07-18, 11:06

Tibor wrote:

Also I dont think we have anything like building_economy and I dont think that hardcoding is a good way. The problem are corner cases. And there are always corner cases.

At the moment the ai only had a building economy. Basic_amount is only for buildings needed to get a building economy. Except barbarians where smelting works and metal workshop had a basic_amount. That's why the ai is able to expand fast and also, at least in my case, builds a lot of military building near the border. But ai also needs a military economy to build new soldiers and a food economy to make thoses soldiers stronger and get the mines working. Because in all those military buildings there is only one or two soldiers and a lot of them were empty. And that are no corner cases like "on map x on position y the ai had problems with terrain or lack of resources". tinker describes the same on the map far north and far north and islands at war are easy maps with a lot of building spots and all needed resources available.

But ok, if you think there is only training needed please post a explanation how one can help if you finished writing and reading the mentioned files. I am willing to help because I like to play widelands from time to time ... and the stronger the ai the more fun face-wink.png


Top Quote
Tibor

Topic Opener
Joined: 2009-03-23, 22:24
Posts: 1377
Ranking
One Elder of Players
Location: Slovakia
Posted at: 2017-07-18, 11:59

To list buildings that are involved in "military economy" is not of big use. Even if we hardcoded it, still 95% of work would be algorithm about placing, time, order and so. Basically what AI is doing now (poorly of course). So I still believe that we should let AI to figure it out. At least right now I am not willing to spend many hours coding before I am sure that it cannot be fixed with training. And this I will know only if training will not bring expected results.

Current AI was teached to expand at all costs, and it worked well as it played against similarly weak players. Now I want to focus more on training of soldiers and strength of player.

I was thinking how can one help with training, but I am skeptic here. First, in current (poor) state it would be waste of human power. But even later, one should need to play like 200-500 games per week, and after every like 10-20 games, he would do some review and AI DNA files shuffling. And at the same time, nobody other would be able to train the AI.

Or if few peoples train the ai concurently, they would need to exchange AI files real-time (few times per day) - that is hard to imagine.

Biggest bottleneck is a machine where training would run 24/7. If we had one... with four cores so 4 games could run concurrently, as they run here on my PC...

Training takes time, I will do it in ai_dna_dump branch so after few days volunters could test it to say if they see a difference...


Top Quote
soulless
Avatar
Joined: 2017-04-09, 12:20
Posts: 22
Ranking
Pry about Widelands
Posted at: 2017-07-18, 12:50

Tibor wrote:

To list buildings that are involved in "military economy" is not of big use. Even if we hardcoded it, still 95% of work would be algorithm about placing, time, order and so. Basically what AI is doing now (poorly of course). So I still believe that we should let AI to figure it out. At least right now I am not willing to spend many hours coding before I am sure that it cannot be fixed with training. And this I will know only if training will not bring expected results.

Ok, that is understandable.

Current AI was teached to expand at all costs, and it worked well as it played against similarly weak players. Now I want to focus more on training of soldiers and strength of player.

I was thinking how can one help with training, but I am skeptic here. First, in current (poor) state it would be waste of human power. But even later, one should need to play like 200-500 games per week, and after every like 10-20 games, he would do some review and AI DNA files shuffling. And at the same time, nobody other would be able to train the AI.

But if I understand https://wl.widelands.org/forum/topic/2646/?page=24#post-20844 correctly there are 4 base-dna-files? So at least 4 players can test and give new and hopefully better dna-files, or am I wrong?

Or if few peoples train the ai concurently, they would need to exchange AI files real-time (few times per day) - that is hard to imagine.

Biggest bottleneck is a machine where training would run 24/7. If we had one... with four cores so 4 games could run concurrently, as they run here on my PC...

Ok, I have a server which runs 24/7 for mail and nextcloud, with a Core i7-4770 and 4 cores and 8 threads and 32 GB RAM but of course with no graphic. There is not much load. At the moment there is running boinc with 2 threads. I will try to get widelands running there in headless mode inside a lxc-container. The container can than have 16GB RAM and 4 threads without problems for the other stuff running there. If this succeeds you can either explain to me how to run the games and what output / saved files you need or perhaps it is also possible to add a widelands-user and give you ssh-access. I will try the next time and give feedback.

Training takes time, I will do it in ai_dna_dump branch so after few days volunters could test it to say if they see a difference...


Top Quote
Tibor

Topic Opener
Joined: 2009-03-23, 22:24
Posts: 1377
Ranking
One Elder of Players
Location: Slovakia
Posted at: 2017-07-18, 13:21

Well 4 players can concurrently train AI the way that after 10-20 games (if 1:1 games), each of them pick (generated) ai file of best performer, and all exchange these files and put them into corresponding "slots". This might mean daily exchange of files. Or more... Quite complicated....

But the other possibility looks much better. I was trying to run widelands in headless mode, but failed due to missing 3D acceleration or whatever. Of course I would help you set up the environment there. I have one python script that "orchestrates" the games and takes care of AI files promotion...


Top Quote
hessenfarmer
Avatar
Joined: 2014-12-11, 22:16
Posts: 2651
Ranking
One Elder of Players
Location: Bavaria
Posted at: 2017-07-18, 19:53

I'm not quite sure if training would help to care all of the problems. As I said my obeservatins were made with the trunk branch at 8402 (which incorporates ai after b 19 branch) As far as I understand the code a ware that is missing over longtime (beer) and keeps mines from working should have gotten a high preciousness regardless the initial weighing factors. This should result in getting the first brewery at some time in the game. the problem might have been that ai saw the enemy almost he the same time than it could build mines to use up the remaining beer. If I understood some of the comments in the code correctly (as I'm not a coder and C++ is not that much readable to me ) this eventually switched the ai into another mode where it remains without evaluating the beer shartage anymore.
I'm also concerned that the weighing is not working well for buildings which produce more than one ware. I couldn't see if only the first ware is evaluated which could lead to the behaviour to not build a toolsmithy due to picks were still available. Perhaps I'll try a short game with starting condition of 0 picks to get some evidence about it.
Unfortunately can't help train the ai as I can't compile the dna branch for my windows machine.


Top Quote
Tibor

Topic Opener
Joined: 2009-03-23, 22:24
Posts: 1377
Ranking
One Elder of Players
Location: Slovakia
Posted at: 2017-07-18, 20:37

hessenfarmer wrote:

I'm not quite sure if training would help to care all of the problems. As I said my obeservatins were made with the trunk branch at 8402 (which incorporates ai after b 19 branch) As far as I understand the code a ware that is missing over longtime (beer) and keeps mines from working should have gotten a high preciousness regardless the initial weighing factors. This should result in getting the first brewery at some time in the game. the problem might have been that ai saw the enemy almost he the same time than it could build mines to use up the remaining beer. If I understood some of the comments in the code correctly (as I'm not a coder and C++ is not that much readable to me ) this eventually switched the ai into another mode where it remains without evaluating the beer shartage anymore.

I dont think that AI stops considering normal productionsites when enemy is seen, but this fact is of course considered. But we can talk about specific place in code if you wish. But this all is very complicated and hidden beyond genetic algorithm stuff

I'm also concerned that the weighing is not working well for buildings which produce more than one ware. I couldn't see if only the first ware is evaluated which could lead to the behaviour to not build a toolsmithy due to picks were still available. Perhaps I'll try a short game with starting condition of 0 picks to get some evidence about it.

No, all outputs are checked and "max_needed_preciousness" is calculated from preciousness of products that are needed. If this "max_needed_preciousness" is positive, the building is considered for further evaluation and scoring.

Here is where "basic_buildings" come - it forces their building even if the outputs are not needed.


Top Quote
hessenfarmer
Avatar
Joined: 2014-12-11, 22:16
Posts: 2651
Ranking
One Elder of Players
Location: Bavaria
Posted at: 2017-07-19, 06:57

ok I did another game on comet islands with me (frisians) on blue and red and yelllow beeing empire (still on trunk version 8402 where the dna was not in files but rather somewhere else). Here are my observations from watching the replay:

  • both ai empire build nearly the same buildings in almost the same order although being in totally different starting environments so they didn't take their economy much into acount if at all.
  • I reduced picks and axes to zero in starting conditions. but they refused to build a toolsmithy and a smelting works over the whole game (5 hours) although they had unoccupied lumberjacks and were short on log all the time.
  • What I saw was, they only build buildings with some kind of exception in the code. This means they build all buildings with basic_amount > 0; fisher, hunter, lumberjack and forrester (the latter were turned off and dismantled after too many trees were around so wood policy seems to work) and the whole training infrastructure with a weapon smithy.
  • After seeing each other (around 2 hours of gametime) they started attacking each other very heavily and very dumb ( attacking with less than 20 % health meant they were sometimes commiting suicide.)
  • After running out of soldiers they rested in their "drawn" state with no further activity to build any other type of building.

My conclusion so far is that the code works fine for every building that is forced somehow by the code. but it refuses to build any other building that should be chosen based on preciousness. I just can't imagine that this should be due to wrong dna which I consider a weighing factor delaying or speeding up some types of buildings but not to prevent all buildings with no exception. What I am not sure is if it could work in my revision or if important parts are missing that are still in the dna branch. For now I need to consider the state of the ai in trunk not ready for release.
Will test again this evening with another map.


Top Quote
Tibor

Topic Opener
Joined: 2009-03-23, 22:24
Posts: 1377
Ranking
One Elder of Players
Location: Slovakia
Posted at: 2017-07-19, 08:00

hessenfarmer wrote:

My conclusion so far is that the code works fine for every building that is forced somehow by the code. but it refuses to build any other building that should be chosen based on preciousness. I just can't imagine that this should be due to wrong dna which I consider a weighing factor delaying or speeding up some types of buildings but not to prevent all buildings with no exception. What I am not sure is if it could work in my revision or if important parts are missing that are still in the dna branch. For now I need to consider the state of the ai in trunk not ready for release.
Will test again this evening with another map.

You are right, this what we have been discussing last few days here. Genetic algorithm is open-ended on both sides. If not properly trained, it can build zero or many production sites of the non-basic type. There was not enough review while in branch (and if they were they were quite positive), so it was merged to get attention and this is what happens now.

I am heavily working on the issue now. But it takes time.

You can test another map, but I dont see a reason why it should work differently...


Top Quote
Ex-Member
Avatar
Joined: 2014-09-12, 09:53
Posts: 184
Ranking
Widelands-Forum-Junkie
Posted at: 2017-07-19, 10:27

hessenfarmer wrote:

  • After seeing each other (around 2 hours of gametime) they started attacking each other very heavily and very dumb ( attacking with less than 20 % health meant they were sometimes commiting suicide.)
  • After running out of soldiers they rested in their "drawn" state with no further activity to build any other type of building.

I have also noticed this action in several games over the weekend, As soon as an enemy is seen they thow everything at them without a care. At some point they pause when they run out of soldiers/ If they have got as far as creating a barracks and are making axes they send new recruits to the front as they are created. I watched one do this for 8 hours, send one new recruit to the front where they attack 2 towers (fully manned), about 300 soldiers wasted.

The problem of 20% health attackers is I think more of a general code problem than an AI one. Having killed an opponent an injured soldiers returns to his base to heal, as soon as any healing has occured he returns to the front line instead of the 100% fit soldiers in his building going out. It is similar when under attack, the wounded defender goes back in, a new attacked arrives at the door and the most injured soldier goes out to fight while a 100% fit one does nothing.

Edited: 2017-07-19, 10:29

Top Quote