Latest Posts

Topic: News about AI

GunChleoc
Avatar
Joined: 2013-10-07, 15:56
Posts: 3324
Ranking
One Elder of Players
Location: RenderedRect
Posted at: 2017-05-30, 20:56

No, there isn't - we can only do that with scenario code in Lua - something like this:

run(function()
   sleep(1000)
   game.desired_speed = 5000
end)

Busy indexing nil values

Top Quote
Tibor

Topic Opener
Joined: 2009-03-23, 23:24
Posts: 1377
Ranking
One Elder of Players
Location: Slovakia
Posted at: 2017-05-30, 21:00

I am using exactly the same setup, savegame made/started in few starting seconds. To be 100% sure, look at the command line output and look for lines like that:

 1: basic economy not established, 1 buildings still missing, f.e. barbarians_wood_hardener

Probably your starting place is too small and then AI is not smart enough to build these buildings. I dont see any no-logs-deadlocks during my tests.

I am using script that regulates speed of game, it uses command line switch "--script=/......../bla_bla_bla.lua" that allows commands like:

game.desired_speed = 9 * 1000

When "Winner" windows pups up, I see in console something like that:

GameHost::report_result(1, 1, win_condition=Teritorial time;win_condition_version=1;tribe=barbarians;score=2167)

maybe this can be modified to contain more info...


Top Quote
PkK

Joined: 2012-01-06, 12:19
Posts: 236
Ranking
Widelands-Forum-Junkie
Posted at: 2017-05-30, 21:51

First testing result (on Lesser ring 1.1 using 4 x HQ, 4 x trading outpost): The AI seems to build a shipyard early, which IMO is typically not that useful early in the game. Also, it seems to build a colosseum / arena rather late, even though that is a relatively cheap way to boost military capabilities.

Philipp


Top Quote
Tibor

Topic Opener
Joined: 2009-03-23, 23:24
Posts: 1377
Ranking
One Elder of Players
Location: Slovakia
Posted at: 2017-05-30, 22:05

Well, these big buildings are problem for genetic algorithm. The overall effect on AI performance is low so AI does not know cope well with them.

F.e. the difference between 1 ranger and 5 ranger is huge and for AI it is easier to figure out that 5 is usually better than 1.

I think some manual tweaking will be needed there... And then we still have that forced_after and prohibited_till flags...


Top Quote
Tibor

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

I added the text into log clearly saying that basic economy mode is to be started:

1 Starting the basic economy mode, required buildings:
74 / barbarians_ironmine ,  target 1
65 / barbarians_farm     ,  target 1
58 / barbarians_smelting_works,  target 1
56 / barbarians_tavern   ,  target 1
53 / barbarians_micro_brewery,  target 1

I will add support for save/load in few days


Top Quote
soulless
Avatar
Joined: 2017-04-09, 13:20
Posts: 22
Ranking
Pry about Widelands
Posted at: 2017-05-31, 14:01

I read the forum often and this basic economy sounds very interesting and like the logic I had in mind after finding the lua-files with not-before and forced_after. So I will try to explain the full logic I had in mind. As I am no real programmer (but can read code a little bit) this is just the logic how I think it could be possible to do:

In the lua-file:

basic_count=X 
basic_shipyard_count=y

in DefaultAI::construct_building:

if (!check_basic_economy_build()) {
  ExpansionMode=expand_cheap_and_fast
elseif (!check_shipyard_economy_build()) {
  ExpansionMode=stop_shipyard
else
 //now we must decide if we go after spots or economy boost

in check_basic_economy_build check for all buildings with basic_count if their number >= basic_count (and perhaps also if stock for wares produced by basic_economy >= basic_count in wares.lua)

in check_shipyard_economy_build check for all buildings with basic_shipyard_count if their number >= basic_shipyard_count

perhaps the return-value for this functions can be cached for some time whith:

uint32_t basic_economy_last_checked
bool basic_economy_result

and

if (gametime >= basic_economy_last_check + cache_time) {
   check the building count and set basic_economoy_result

return basic_economy_result

that should solve the save and load-game problem and also puts the ai back in basic_economy if it lost some basic buildings.

And than in mode expand_cheap_and_fast only build military buildings which are cheap and help to expand fast like sentry or blockhouse or perhaps barrier and buildings needed for basic_economy. And in mode stop_shipyard set all wares in shipyard to 0 and stop the shipyard so resources are not spent for building ships before having the buildings needed to found a new colony and get soldiers there.

For empire I would suggest the following settings for basic_economy:

tavern = 1
winery = 1
vineyard = 2
stonemason = 1
sawmill = 1
farm = 1
mill = 1
bakery = 1
marblemine = 1

and wares if possible:

log = 15
planks = 5
marble = 10
marble_column = 2
bread = 5
wine = 10

and for shipyard_economy

sawmill = 2
farm = 3
sheepfarm = 1
weaving_mill = 1
brewery = 1
ironmine = 1
colemine = 1
armorsmithy = 1
weaponsmithy = 1
smelting_works = 1

as I did not play the other tribes that often no suggestions for them from me.

I would also like to note that I like some of the new functions very much, specially that the building windows are not closed after pressing stop / start / dismantle buttons. I also will try to test the new post-ai the next few days because that basic_economy sounds like a good solution for some weakness of the ai.


Top Quote
WorldSavior
Avatar
Joined: 2016-10-15, 04:10
Posts: 2091
OS: Linux
Version: Recent tournament version
Ranking
One Elder of Players
Location: Germany
Posted at: 2017-05-31, 17:02

Nordfriese wrote:

I´m happy to help face-wink.png

I just remembered I didn´t even present my own list yet! Here it is:

  • N-BAR: wood hardener, fernery, lime kiln, smelting works, 2×metal workshop, well, tavern, hunter, gamekeeper, barracks

  • N-ATL: sawmill, smokery, mill, farm, blackroot farm, bakery, spiderfarm, weaving mill, well, fisher, fishbreeder, hunter, barracks

  • N-EMP: sawmill, stonemason, tavern, smelting works, vineyard, winery, hunter, fisher, well, farm, brewery, barracks

EDIT: Sorry, typo. I removed the bakery from the list for empire. They don´t get a mill or bakery.

Interesting. It's good that they don't get mills or bakeries face-smile.png

As you can see, I did not add mines.

Yes, that's clever. It makes the AI more flexible.

But I added barracks. Why? I watched some first test games to get an idea about the new AI and I noticed that one of them never built barracks and was after some first victories defeated by the other player. That is why I think barracks are important.

Ouh... I didn't anything which improves military strength because my lists should be good for all cases.

If barbarians are close to their enemies, a barrack is a good option for early fights. But I think that empire and especially atlanteans are stronger in this situation, if they don't build a barrack, but an arena, or a trainings camp, or an arena and a trainings camp, or even a colosseum, or respectively a labyrinth, or a labyrinth and a dungeon...

Tibor wrote:

AI was never using geologists. It would be more complex to code than just query the content of ground. So yes, it is cheating here.

No, that's not cheating, it looked at the map editor once and didn't forget anything face-tongue.png

7 hardeners - this is really weird especially if it is during basic economy stage - must be a bug... (please confirm if this was during basic economy face-smile-big.png

Well... For trading outpost, it could make sense face-tongue.png

Nordfriese wrote:

I will add 1 ranger/forester and 1 lumberjack/woodcutter to every tribe´s basic economy for every list. Perhaps this will solve this problem.

I thought about that to avoid deadlocks. But if it's on the lists it means that the AI will not build more of those before everything else is build, so it is a little catastrophy... And anyway, the wood economy can also be build without being on the list...

And I think that the wood economy is just too map-dependent for being on the list...

soulless wrote:

For empire I would suggest the following settings for basic_economy:

tavern = 1
winery = 1
vineyard = 2
stonemason = 1
sawmill = 1
farm = 1
mill = 1
bakery = 1
marblemine = 1

Yay, someone who likes the second vineyard... face-smile.png

and wares if possible:

log = 15
planks = 5
marble = 10
marble_column = 2
bread = 5
wine = 10

and for shipyard_economy

sawmill = 2
farm = 3
sheepfarm = 1
weaving_mill = 1
brewery = 1
ironmine = 1
colemine = 1
armorsmithy = 1
weaponsmithy = 1
smelting_works = 1

armorsmithy and weaponsmithy?

Edited: 2017-05-31, 17:04

Wanted to save the world, then I got widetracked

Top Quote
Tibor

Topic Opener
Joined: 2009-03-23, 23:24
Posts: 1377
Ranking
One Elder of Players
Location: Slovakia
Posted at: 2017-05-31, 19:58

Well, I want to clarify some details about implementation of BE. The core data container is remaining_basic_buildings that is unordered_map of <building id:count>, that is generated on the begining based on flags in lua files, and once a particular building is build, it is removed from the "list". Once the list is empty, the basic economy is achieved. This list will be preserved in the savegame.

I opted for this design also for upgrading of buidings - even though such building is upgraded, it is not added to the list. Intentionally. We can ofcourse discuss whether upgrading during BE stage would be allowed.

Basic economy is really intended as a starter, ideally for first 30 minutes. If it takes more than hour - this is not good. If you add ranger (or similar) to the list it will not make big difference, unless you add something like <ranger:20>.

As for shipyard economy - this complicates things. I am not against a dependency BE->shipyard/port, f.e. 'do not build/stock shipyard untill BE is completed' though. This can be nicely hardcoded. Shipyard currently ignores BE altogether.

I repeat - forced_after and prohibited_till controlled about first 30 minutes of game. BE should not last much longer, if at all.

Of course many approaches are possible, but experiments take a lot of time and work...


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: 2017-05-31, 20:31

Hello, I´m back with a large number of test results! I tested a lot of games, but I did not store the number or even the individual statistics – only average values for each list and map.

First some comments on AI in general (I do not mean to offend, even if the AI may seem stupid now):

  • It builds lots of trainingsites and always sets their capacity to 0. Exception: Is the Trainer position is vacant, capacity is set to 1.

  • As long as the basic economy is not established, AI builds only buildings belonging the the basic economy (but lots of them). Someone was worried that a target of 1 ranger would lead to having just 1: No need to worry. AI will soon have 10.

  • After the basic economy is finished, all metal workshops are upgraded and no new ones are built. Tool production isn´t perfect.

  • If the AI doesn´t know what to do, it builds a lumberjack. Preferably where there are no trees.

  • Autocrat games rarely finish. AI simply isn´t interested in defeating a player that has already accepted his defeat (yes, AI does that very obviously!).

On the positive side, AI generally is better than in current trunk.

I did not test Autocrat games, as they take so long. I only used Collectors.

The test results surprised me. I used my program to draw diagrams of each player´s land,productivity,NbWorkers,NbWares,NbBuildings. Also, I noted the Points diagram from the Game Statistics Window. I used a simple, flat, rich map for 3 players (1-BAR, 2-EMP, 3-ATL). The map was divided into 3 equal compartments so AIs were completely unable to interact. Results for the Collector Points:

  • Presets (P): ATL increased almost constantly but slowly. EMP started by falling to 0, stayed down, then, in late game, rose steeply and won. BAR started by falling to a low value and rose only slowly. Final score EMP>ATL>BAR.

  • WorldSaviour´s List (W): EMP quickly fell to 0, then increased quickly, stayed constant in late game and won. ATL stayed almost constant all the time with a slight plus. BAR started by falling slightly, the increased some more, than remained constant. Final score EMP>BAR>ATL.

  • My list (N): ATL started by rising slightly, then fell slightly, then constant. EMP fell slightly, then rose slightly, then constant. BAR fell slightly, then kept rising and won. Final score BAR>EMP>ATL

The statistics for the other values:

The graphs are a bit confusing. The colours are: Blue for BAR, Red for EMP, Green for ATL. The shadings code for the categories (land, ware number etc). Quick summary:

  • P: Land: EMP>=ATL>BAR; Buildings: BAR>ATL>EMP; Workers: BAR>ATL>EMP; Productivity: BAR=ATL>EMP; Wares: EMP>ATL>BAR

  • W: Land: EMP>ATL>BAR; Buildings: ATL>BAR>EMP; Workers: ATL>BAR>EMP; Productivity: ATL>EMP>BAR; Wares: BAR>EMP>ATL

  • N: Land: EMP=ATL>BAR; Buildings: BAR>EMP=ATL; Workers: BAR>EMP=ATL; Productivity: BAR>EMP>ATL; Wares: EMP>ATL>BAR

All in all, I am under the impression that Barbarians play best with N>P>W, Empire with P>N>W Atlanteans with P>W>N.

In other words: Tibor´s presets are the best suggestion for Empire and Atlanteans. My lists are best for Barbarians. WorldSaviour´s lists are also good, but not the best for any tribe.

Would you like me to do more testing (more maps, more win conditions, …)?


Top Quote
Tibor

Topic Opener
Joined: 2009-03-23, 23:24
Posts: 1377
Ranking
One Elder of Players
Location: Slovakia
Posted at: 2017-05-31, 20:51

@Nordfriese

Thanks for your effort and feedback!

So I will update the presents for barbarians, can you post them here once more?

You mentioned some points, so few words about them:

  • Yes, AI builds too many trainingsites, this has to be manually finetuned.
  • A traininsite waits till it is stocked and then sets its capacity to 1. Untill then ... 0.
  • AI always build something. If other buildings are prohibited, rangers and lumberjacks wins. As long as there is a shortage of logs. That is almost always the case.
  • I know that AI sometimes fails to "finish" an enemy. Though the problem can be reachability of enemy's militarysites. Must be debugged with outputs to the console.

From my standpoint no further testing is needed. As I said I will adopt your list for barbarians and let AI train with that. If you can, preserve your testing setup, in the future you can use it again I think.


Top Quote