Latest Posts

Topic: Automated network game testing

Tibor

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

Hi

I would like to set up some automated tests - to test AI. The setup would be - starting from command line, so the comand would start a map, all slots as AI, and also load a script - that would set up a gamespeed and terminate the game after f.e. 5 hours of gametime. And over and over.

The game help does not indicate that loading a map this way is possible. Also, when I use "--scenario=" I am not able to make it use my script.

I run:

/var/widelands/BZR/ai-post-b19-installed/widelands --scenario=/home/tibor/.widelands/maps/Crabsome\ Island.wmf --script=/var/widelands/BZR/TESTING/SLOT1/scripting/init.lua

it loads, but script is not run, see error I got:

Trying to run: /var/widelands/BZR/TESTING/SLOT1/scripting/init.lua: not found.

I did more experiments, but I am not able to figure it out.

The minimum that would do is to start the game with given speed. But this option is not available either...

Any ideas?


Top Quote
SirVer

Joined: 2009-02-19, 14:18
Posts: 1445
Ranking
One Elder of Players
Location: Germany - Munich
Posted at: 2016-08-29, 20:53

this should work: mkdir ~/.widelands/scripting/; mv <your init.lua> ~/.widelands/scripting/.

Now try:

/var/widelands/BZR/ai-post-b19-installed/widelands --scenario=Crabsome\ Island.wmf --script=scripting/init.lua

The layered file system will only allow searching in directories registered with it, not arbitrary paths.


Top Quote
Tibor

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

Great, it works! Partially at least face-sad.png

... now I am getting:

Trying to run: /home/tibor/.widelands/scripting/init.lua:
Scenario not started: Game data error: lua: [/var/widelands/BZR/ai-post-b19/src/scripting/lua_errors.cc:22] attempt to yield from outside a coroutine

The script is (shortened):

 include "scripting/lunit.lua"
 include "scripting/coroutine.lua"
 include "scripting/infrastructure.lua"
 include "scripting/ui.lua"

 game = wl.Game()
 map = game.map

 game = wl.Game()
 game.desired_speed = 10
 sleep(15 * 60 * 1000)
 wl.ui.MapView():close()

Top Quote
SirVer

Joined: 2009-02-19, 14:18
Posts: 1445
Ranking
One Elder of Players
Location: Germany - Munich
Posted at: 2016-08-30, 06:25

The problem is the sleep call here. You can only sleep a coroutine (think of it as a separate thread of execution), not the main entry point. But that should be simple to work around, try changing your last two lines to:

run(function()
    sleep(15 * 60 * 1000)
    wl.ui.MapView():close()
end)

this spawns a new coroutine which will keep running for the rest of the game and eventually close the game.


Top Quote
Tibor

Topic Opener
Joined: 2009-03-23, 22:24
Posts: 1377
Ranking
One Elder of Players
Location: Slovakia
Posted at: 2016-08-30, 11:01

SirVer wrote:

The problem is the sleep call here. You can only sleep a coroutine (think of it as a separate thread of execution), not the main entry point. But that should be simple to work around, try changing your last two lines to:

run(function()
    sleep(15 * 60 * 1000)
    wl.ui.MapView():close()
end)

this spawns a new coroutine which will keep running for the rest of the game and eventually close the game.

Thanks, it works!


Top Quote
Tibor

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

Well, but I just noticed the game is standing, time is going, but AI is doing nothing and the screen is black - though I dont need to see anything, so this is not a problem...


Top Quote
SirVer

Joined: 2009-02-19, 14:18
Posts: 1445
Ranking
One Elder of Players
Location: Germany - Munich
Posted at: 2016-08-31, 06:28

I think if you start a map using --scenario the settings from the player_names file in the map will be used (example). So you can set the desired AI strengths there.

As for seeing something, if you leave the first player as a human, you will be controlling it. You can add a game.players[1].see_all = true in your script which will reveal the full map for you. I do not think there is another way to reveal the full map for an observer via scripting.


Top Quote
Tibor

Topic Opener
Joined: 2009-03-23, 22:24
Posts: 1377
Ranking
One Elder of Players
Location: Slovakia
Posted at: 2016-09-04, 21:32

Well, I modified player_names, now I see that AI starts (custom printfs in terminal), but there are no other logs on the terminal - as expected by normal run of game. The screen is dark of course.

So how can I verify that "--scenario=" option is working as supposed?


Top Quote
GunChleoc
Avatar
Joined: 2013-10-07, 14:56
Posts: 3324
Ranking
One Elder of Players
Location: RenderedRect
Posted at: 2016-09-05, 08:05

You could add some Lua code to the scenario with a print statement to the console.


Busy indexing nil values

Top Quote
Tibor

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

I have a print in scenario file, it is printed.

Another issue - when I save network game and load it with --loadgame - it is loaded as single player game - so first player is "lost" for my testing.

Frustrating....


Top Quote