Currently Online

Latest Posts

Topic: Artificial artificial intelligence. ;)

ixprefect

Joined: 2009-02-27, 14:28
Posts: 367
Ranking
Tribe Member
Posted at: 2010-05-07, 14:50

For the replay format, the code is the documentation (and I would argue that it would be somewhat pointless to formalize the format).

Basically, replays are a savegame (this is the state where the replay starts) and then simply a stream of saved PlayerCommands including all commands ever sent by any play. In addition to that, there are sync check packets. It's really quite straightforward to follow, starting at the Replay class which does the actual storing and loading of the format.


Top Quote
hulagutten

Topic Opener
Joined: 2009-07-19, 21:34
Posts: 56
Ranking
Likes to be here
Posted at: 2010-05-09, 01:16

I located the replay.cc and attempted to use my Java brain to understand it. My Java brain could spend a month and still not understand this. Is there anyone who is up for the task of converting replays to Lua script?


Top Quote
hulagutten

Topic Opener
Joined: 2009-07-19, 21:34
Posts: 56
Ranking
Likes to be here
Posted at: 2010-05-13, 13:51

I would like to make an example AAI (artificial artificial intelligence) using Lua. The idea was to take the Impact map and add some lua to it. My first attempt was to add a "scripting" subdirectory to the map and add "init.lua". It seems, though, that this script is never started.


Top Quote
SirVer

Joined: 2009-02-19, 15:18
Posts: 1445
Ranking
One Elder of Players
Location: Germany - Munich
Posted at: 2010-05-13, 15:01

lua was only added after build 15. If you use a build later than that, it should quite definitively run. There is documentation here:

http://wl.widelands.org/docs/lua/.


Top Quote
hulagutten

Topic Opener
Joined: 2009-07-19, 21:34
Posts: 56
Ranking
Likes to be here
Posted at: 2010-05-13, 16:02

I have the newest nightly build and I created the init.lua according to the instructions. The only content of the init.lua was: print "###############################" print "Hello World" print "###############################"

I then opened the map as a scenario and the map came out completely black and without writing the "Hello World" to stdout.txt or commandline. If I loaded the map as a map, it was fine. Also if I replaced the init.lua with the two lua files from the tutorial, init.lua and texts.lua, I got my Impact map to start with the same texts as the tuturial. I therefore, believe that the wiki pages need to be updated and that the most basic script needs something more than just print in order to function.

I have what I need now, and I will hack on.


Top Quote
SirVer

Joined: 2009-02-19, 15:18
Posts: 1445
Ranking
One Elder of Players
Location: Germany - Munich
Posted at: 2010-05-13, 16:21

no, the wiki page is up to date. I cannot say what went wrong in your case though.

That the map is completely black is expected, but the text should have been printed on the console also someplace. At least some debug messages should have been appeared someplace (not necessarily as the very last message though).


Top Quote
hulagutten

Topic Opener
Joined: 2009-07-19, 21:34
Posts: 56
Ranking
Likes to be here
Posted at: 2010-05-13, 22:59

I am still unable to get any output to stdout.txt or command line. So far I have managed to create a backery automatically and connecting it by road using Lua. My map can be found at https://eksempel.s3.amazonaws.com/ImpactEGG.wmf.zip

The problem that I have been struggling with for the last hour is how to set that the human player is player number 2. The point is that I want to build the buldings on behalf of the AI and set that the human is player number 2.

How can I set which player the human will control?


Top Quote
SirVer

Joined: 2009-02-19, 15:18
Posts: 1445
Ranking
One Elder of Players
Location: Germany - Munich
Posted at: 2010-05-13, 23:57

In a scenario, the human player is always plr 1. Sorry, you cannot change this at this moment. You could switch the positions of player 1 and player 2 though.


Top Quote
hulagutten

Topic Opener
Joined: 2009-07-19, 21:34
Posts: 56
Ranking
Likes to be here
Posted at: 2010-05-14, 09:09

I will try switching positions, then.

Does Widelands have to be compiled with debugging enabled to get error messages from Lua?


Top Quote
hulagutten

Topic Opener
Joined: 2009-07-19, 21:34
Posts: 56
Ranking
Likes to be here
Posted at: 2010-05-14, 21:30

How can I create construction sites in Lua, not just finished buildings? I want the AAI to have the same conditions as a human.


Top Quote