Latest Posts

Topic: AI patch suggestion

Tibor
Joined: 2009-03-23, 23:24
Posts: 1374
Ranking
One Elder of Players
Location: Slovakia
Posted at: 2014-04-24, 21:16
Hi,

today I spent some time digging in src/ai/defaultai.cc. It was for first time :)

And I have a patch related to building lumberjacs huts. It fixes the problem when AI does not builds cutters huts even when all territory is full of trees and there is no free room to expand. The patch is here:

   if (bf->trees_nearby>15) prio +=(bf->trees_nearby-15)*5;


Well, that is all, and exact location should be in src/ai/defaultai.cc:

   // Priority of woodcutters depend on the number of near trees
   prio += bf->trees_nearby * 3;
   prio /= 3 * (1 + bf->producers_nearby.at(bo.outputs.at(0)));
   					
   if (bf->trees_nearby>15) prio +=(bf->trees_nearby-15)*5;   //<--- this is the patch


As a proof I did some tests, here is one of them:



Usually AI is able to expand for 2-3 hours of playing time. Here AI was able to grow for about 4 hours and more. Red player even managed to overtake teritory of yellow player and grow for 8 hours. And AI players now keeps their territories trees-free.

I know about launchpad, I am just setting onw branch there, but still - could somebody merge this directly to trunk or so. I believe this is pretty minimal change...
Top Quote
Tibor
Joined: 2009-03-23, 23:24
Posts: 1374
Ranking
One Elder of Players
Location: Slovakia
Posted at: 2014-04-25, 23:20
Hi,

after further investigation I found a problem with "onlymissing" - variable and feature. When it is set "true" it blocks building of new production buildings (including iron / tools producers and food "industry") but allow military buildings and some other buildings. Result is big territory with a lot of empty military buildings, shortage of all goods and products and no further growth.

I disabled this feature and here is the result:



Surprisingly no tragedy happened, though now the algorithm is not consistent according to developers intend, but I believe this is the way to go. Or at least to be considered.

I have few questions about calculate_need_for_ps function:

http://pastebin.com/CKcJLgsJ

Here they are:

"economy" is an area belonging to one warehouse/headquarter and each warehouse/headquarter has own economy?

.producers and .consumers is count of buildings in the economy?

wo.preciousness - is some hardcoded amount or somehow reflects amount of available material?

bo.current_stats - is average % of current producion of the same building within the same economy?

bo.total_count - count of the same buildings in the same economy?

So many questions are about 'single economy vs all buildings of player'...


The code of the game is too extensive and it is hard to navigate in... so I need some help :)
Top Quote
einstein13
Avatar
Joined: 2013-07-29, 00:01
Posts: 1118
Ranking
One Elder of Players
Location: Poland
Posted at: 2014-04-26, 00:31

Hi!

I really don't know the answers for many of your questions, but I would like to suggest you something:

Some months ago I've made a map "The maze" (https://wl.widelands.org/maps/the-maze-v11/)

I can remember, that there was a major problem with wood for any AI player. So you can test your idea on this map.

And probably you know that you can test the game without playing it: just open a new multiplayer game with only AI players. On my map there are 8 slots, so you will see lots of cases on testing face-smile.png

Also I can test it too, but probably it has to be merged with trunk version first.

Have a good weekend!

einstein

Ps.: you did GREAT job here!

Edited: 2014-04-26, 00:31

einstein13
calculations & maps packages: http://wuatek.no-ip.org/~rak/widelands/
backup website files: http://kartezjusz.ddns.net/upload/widelands/

Top Quote
SirVer
Joined: 2009-02-19, 15:18
Posts: 1441
Ranking
One Elder of Players
Location: Germany - Munich
Posted at: 2014-04-26, 11:51

I have few questions about calculate_need_for_ps function:

http://pastebin.com/CKcJLgsJ

Why do you not link to launchpad? No need to copy and paste.

I cannot answer all of your questions as I am not familiar with the AI code. But some.

"economy" is an area belonging to one warehouse/headquarter and each warehouse/headquarter has own economy?

an economy is a connected network of flags (and ship routes) and buildings. Each building, flag and road belongs to exactly one economy.

wo.preciousness - is some hardcoded amount or somehow reflects amount of available material?

not sure about this, but there is a ware property in the conf files with the same name. Likely this is this value. I have no idea how to interpret it though.

The code of the game is too extensive and it is hard to navigate in... so I need some help face-smile.png

Not harder to navigate than other projects of similar size. face-smile.png


Top Quote
Tibor
Joined: 2009-03-23, 23:24
Posts: 1374
Ranking
One Elder of Players
Location: Slovakia
Posted at: 2014-04-26, 23:07
Einstein,

Of course I know how to test a game without playing it. :) So here is your maze map test:



I am curious how the game would look with current widelands.

I created new branch (- is it correct term?) of widelands:

https://code.launchpad.net/~tiborb95/widelands/tiborb-ai

But this contain only my first "against-trees" patch. I hope that in about one week I will be able to polish my changes and upload them there and you will be able to test it by yourselves.
Top Quote
Tibor
Joined: 2009-03-23, 23:24
Posts: 1374
Ranking
One Elder of Players
Location: Slovakia
Posted at: 2014-04-26, 23:19

SirVer wrote:

Why do you not link to launchpad? No need to copy and paste.

I did not know about this possibility. And can I point to specific line or just portion of a file?

I cannot answer all of your questions as I am not familiar with the AI code.

I believed you are the author. BTW the author is no longer active with widelands?

an economy is a connected network of flags (and ship routes) and buildings. Each building, flag and road belongs to exactly one economy.

All right, so usually a player have just one economy. This simplifies things...

wo.preciousness - is some hardcoded amount or somehow reflects amount of available material?

not sure about this, but there is a ware property in the conf files with the same name. Likely this is this value. I have no idea how to interpret it though.

Well, I have to say I grep-ped src directory for 'preciousness' but to no avail. You are right, it is defined some other directory and values are hardcoded. Interpretation is clear: f.e. log has preciosness 10, gold 1 - this tells that AI should build buildings producing logs and then gold.

The code of the game is too extensive and it is hard to navigate in... so I need some help face-smile.png

Not harder to navigate than other projects of similar size. :)

I agree, so the fault is mine and not of the game code, but this still makes little difference to me face-smile.png


Top Quote
hjd
Joined: 2011-06-12, 20:24
Posts: 164
Ranking
At home in WL-forums
Location: bugs.launchpad.net/widelands
Posted at: 2014-04-27, 11:04

Why do you not link to launchpad? No need to copy and paste.

I did not know about this possibility. And can I point to specific line or just portion of a file?

Yes, you can link to a specific line.

On the branch page, click on Browse the code to navigate the files in the repo like in a file explorer. If you click on a file, you will see the line numbers on the left side, and these are links to that particular line. For instance, I'm able to link to the change you did in defaultai.cc : http://bazaar.launchpad.net/~tiborb95/widelands/tiborb-ai/view/head:/src/ai/defaultai.cc#L878. face-smile.png

(Btw, I tried to place the link in the nice markdown brackets/parenthesis format, but it didn't like the second colon face-sad.png )


Ships!

Top Quote
SirVer
Joined: 2009-02-19, 15:18
Posts: 1441
Ranking
One Elder of Players
Location: Germany - Munich
Posted at: 2014-04-27, 21:34

I believed you are the author. BTW the author is no longer active with widelands?

Oh no, I did nothing on the AI, except the occasional bug fixes and code cleanups. Main authors are sigra (no longer active), nasenbaer (still around) and ixprefect (still around) and a bunch of drive by contributors - all gone again.

an economy is a connected network of flags (and ship routes) and buildings. Each building, flag and road belongs to exactly one economy.

All right, so usually a player have just one economy. This simplifies things...

You cannot rely on this assumption - if you split your road network into two (even temporarily) you have more than one economy.


Top Quote
einstein13
Avatar
Joined: 2013-07-29, 00:01
Posts: 1118
Ranking
One Elder of Players
Location: Poland
Posted at: 2014-04-28, 12:24
Tibor
I am curious how the game would look with current widelands.




Sorry for late response.
Here is a picture of bzr6890 version and I have also tested 6958 version, but It just stucked. Maybe later I will add something ;)

I can remember, that in build17 some players didn't expand at all, like the violet player here.

I'm not sure if in 6958 are the woodcutter changes, but in the beggining the players make another things in both tests (6890 and 6958).
Edited: 2014-04-28, 12:26

einstein13
calculations & maps packages: http://wuatek.no-ip.org/~rak/widelands/
backup website files: http://kartezjusz.ddns.net/upload/widelands/

Top Quote
Tibor
Joined: 2009-03-23, 23:24
Posts: 1374
Ranking
One Elder of Players
Location: Slovakia
Posted at: 2014-04-28, 21:29


This is based on changes I did today, I must say AI is as by now bit unbalanced, non-military buildings gets higher score and teriroty expansion is slower. I will keep working on it and make it avaiable once it works reasonable well. In few days I believe.




Top Quote