Latest Posts

Topic: Improving the AI

hessenfarmer
Avatar
Joined: 2014-12-11, 23:16
Posts: 1330
Ranking
One Elder of Players
Location: Bavaria
Posted at: 2020-04-25, 19:39

I fully agree to both teppo and Tibor. The map specific trained AI might give us the last 10% when our basic AI environment is stable and reasonably bug free. However it might need tribe specific training as well. And as long as we don't have sufficient fitness function to chose the next gen auto training isn't possible.
@ JanO
AI has knowledge about defnding soldiers in visible enemysites. Basically it does evaluation of about 30 to 40 of the defined decision inputs (this will change after training I believe). So we need to define another bunch of question (inputs in the code) to make buoldings with wounded soldier getting a higher score.
currently only the threshhold for my powr to enemy power is subject to difficutly settings. But if we really get to a point where we need them it can be applied to various parameters.
For our discussion it would make things easier to know whether you can read c++ (it is not that hard to read if you know some basic structures that are similar in each coding language) and if you have read our ai code. If this is the case we could point to relevant lines in the code. If not it is no problem I just might need to explain a bit more what is going on currently.
Some of the hidden magic is within the numbers in the .wai files. Basically the first 200 numbers are used to weigh certain parameters in a decision making process. I wanted to compile an excel what their use is. However the real thing is in the FNeurons. They are large integers represented by 100011110101011001 sequences binary. For some decisions we define a bunch (most times around 96) questions related to the decision to make. The result of each question is a small positive or negative score. which question is really evaluated is decided by the Fneuron. if the bit at the position with the number of the question is 1 it is evaluated else it is not.


Top Quote
JanO
Avatar
Joined: 2015-08-02, 11:56
Posts: 139
Ranking
At home in WL-forums
Posted at: 2020-04-25, 21:47

C++, in theory I should be able to read some basics. That's about 10 years ago without any repetition face-wink.png
I will have a look into it, hopefully I find the time tomorrow.

Actually, my suggestions were not meant to be anything like map-specific. Those military considerations seem very basic to me. Map-specific is more applicable to economic decisions, I guess.


Top Quote
hessenfarmer
Avatar
Joined: 2014-12-11, 23:16
Posts: 1330
Ranking
One Elder of Players
Location: Bavaria
Posted at: 2020-04-25, 23:21

when I started reading the Ai code I downloaded a c++ guide face-wink.png but all you really need and which is not standard ist the short of if then
it reads like this
(logical statement) ? returniftrue value : returniffalse value

the rest should be clearly understandable and if you have problems just ask (here or by PM) Would be good to have another person around looking over this code.

BTW here is the link to the related Pullrequest where you can see the latest status. Code seems to work. Needs some training rounds though.
https://github.com/widelands/widelands/pull/3873

Edited: 2020-04-25, 23:21

Top Quote
teppo
Joined: 2012-01-30, 09:42
Posts: 392
Ranking
Tribe Member
Posted at: 2020-04-26, 11:06

Tibor wrote:

teppo wrote:

Therefore, would it be a good idea, if it was possible to include AI DNA into a map.

The problem here can be that interpretation of wai files by C++ can change (also in this branch) so after long time you could have very differing C++ and wai files

Of course, there should be fingerprint (DNA packet version) so that the C++ could ignore too-old DNAs.

If it was possible to run the training loop by itself then training such DNA for selected maps would be within reach.

Do you mean like let your computer to train for 24 hours or so? The process of handling the wai files is still too fragile for this.

Long term goal.. ..tell more, please! I am not familiar with the details, but it is easy to imagine that the goal also includes improvements to AI scoring code etc.


Top Quote
Tibor
Joined: 2009-03-23, 23:24
Posts: 1332
Ranking
One Elder of Players
Location: Slovakia
Posted at: 2020-04-26, 11:39

teppo wrote:

Long term goal.. ..tell more, please! I am not familiar with the details, but it is easy to imagine that the goal also includes improvements to AI scoring code etc.

Maybe not that long term - but somebody would sit down and spend some time on this. But the score is quite an challenge here. You can set up a score an any way - whatever you prefer, but currently you have to edit C++ code to change the score, so it is also a complication here.


Top Quote
teppo
Joined: 2012-01-30, 09:42
Posts: 392
Ranking
Tribe Member
Posted at: 2020-04-26, 13:29

but somebody would sit down and spend some time on this

There might be a lot of time for nerdy things during the summer holiday period this year. It is not that far away.

but currently you have to edit C++ code to change the score, so it is also a complication here.

How much work would it to make a lua callback for this?

I think that the more interesting is the question of opposition: Should the opponent algorithm(s) be constant during evaluation, and what algorithm to use to refine the DNA. It is kind-of minimizing problem, with many dimensions and expensive step size (=running games is slow).


Top Quote
Tibor
Joined: 2009-03-23, 23:24
Posts: 1332
Ranking
One Elder of Players
Location: Slovakia
Posted at: 2020-04-26, 13:34

teppo wrote:

but currently you have to edit C++ code to change the score, so it is also a complication here.

How much work would it to make a lua callback for this?

LUA is very good idea. However currently there are not LUA hooks in AI code. So this would be brand new chapter.


Top Quote
hessenfarmer
Avatar
Joined: 2014-12-11, 23:16
Posts: 1330
Ranking
One Elder of Players
Location: Bavaria
Posted at: 2020-04-26, 14:58

teppo wrote:

but somebody would sit down and spend some time on this

There might be a lot of time for nerdy things during the summer holiday period this year. It is not that far away.

but currently you have to edit C++ code to change the score, so it is also a complication here.

How much work would it to make a lua callback for this?

I think that the more interesting is the question of opposition: Should the opponent algorithm(s) be constant during evaluation, and what algorithm to use to refine the DNA. It is kind-of minimizing problem, with many dimensions and expensive step size (=running games is slow).

lua might be good to change some parts of the fitness function, but we should be careful as lua is dead slow.

From my perspective it doesn't matter much whether the opponent is stable or not, as we currently search for the DNA which does best in certain circumstances. And then we test it again in different challenges. by repeating and changing tribe as well as map we get the AI that does best in most circumstances.


Top Quote
hessenfarmer
Avatar
Joined: 2014-12-11, 23:16
Posts: 1330
Ranking
One Elder of Players
Location: Bavaria
Posted at: 2020-04-26, 15:06

BTW

https://github.com/widelands/widelands/pull/3873

Branch / Pull request is ready for review. Would be fine if somebody else then Tibor and me could test this.


Top Quote
teppo
Joined: 2012-01-30, 09:42
Posts: 392
Ranking
Tribe Member
Posted at: 2020-04-26, 15:49

hessenfarmer wrote:

lua might be good to change some parts of the fitness function, but we should be careful as lua is dead slow.

How often does the lua file need to be called? I guess it is best to let the lua function decide how often it wants to be run, and whether it still wants the game to continue after this evaluation round or not.

If the evaluation is run infrequently, efficiency does not matter that much. If some scoring algorithm needs to be run constantly, it would still be possible with open approach.


Top Quote