Exercises in Formula and Lua AI and AI-demos add-on feedback
Moderator: Forum Moderators
Re: Exercises in Formula and Lua AI
Thanks, Anonymissimus. This is due to a change from 1.10 to 1.11 in how the weapon number is specified in 'ai.attack()'. Before 1.11 weapon numbers started at 0, which is inconsistent with any other numbering in Lua.
I will add a version checker to this part of the code to ensure that it works in both 1.10 and 1.11. I'll add an 'edit' to this post when it is done, until then this scenario will only work correctly in 1.10.
EDIT: Hmm, looks like there's a bug in trunk at the moment that doesn't let me fix this. I'll file a bug report, but until that is taken care of, I'm afraid that you'll have to use 1.10.
I will add a version checker to this part of the code to ensure that it works in both 1.10 and 1.11. I'll add an 'edit' to this post when it is done, until then this scenario will only work correctly in 1.10.
EDIT: Hmm, looks like there's a bug in trunk at the moment that doesn't let me fix this. I'll file a bug report, but until that is taken care of, I'm afraid that you'll have to use 1.10.
SP campaigns: Galuldur's First Journey (1.12 & 1.14) & Grnk the Mighty (1.10 & 1.12)
AI experiments: Micro AIs (wiki, forum thread, known/fixed bugs), Fred, AI-demos add-on
AI experiments: Micro AIs (wiki, forum thread, known/fixed bugs), Fred, AI-demos add-on
Re: Exercises in Formula and Lua AI
I just stumbled onto this thread and it led me to downloading the AI demo. This is some very impressive work! I have had my dabble in the wesnoth AI in the past, in particular before python AI became obsolete due to security issues. But Wesnoth might just a bit too complicated to have an elegant solution for an AI. Plus the fact that I found it difficult to analyse possible moves / look ahead without a facility to generate a mirror map on which to perform analysis. If someone builds this into the core engine, I would be very happy indeed...
Looking around your Lua code for Prune cart, there are some very nice ideas in there. I like how you consider several units at the same time and figure out if there is a suitable formation, something which is not really done by the old default AI. In the old default AR, every unit essentially fights for themselves and no real cooperation between units. Not sure how that has changed in the RCA AI though.
There seems to be quite a few bits of code in here which are fairly reusable. I wouldn't call the bit on formation easy-to-reuse (or understand ), but the other bits I am quite interested in having a play around to see what I can come up with.
Looking around your Lua code for Prune cart, there are some very nice ideas in there. I like how you consider several units at the same time and figure out if there is a suitable formation, something which is not really done by the old default AI. In the old default AR, every unit essentially fights for themselves and no real cooperation between units. Not sure how that has changed in the RCA AI though.
There seems to be quite a few bits of code in here which are fairly reusable. I wouldn't call the bit on formation easy-to-reuse (or understand ), but the other bits I am quite interested in having a play around to see what I can come up with.
Re: Exercises in Formula and Lua AI
Thanks, Derekkk! It would be great if you started using some of this and see what you can do with it. Since you have looked at the code, I probably don't have to point out that this is all still work in progress and not optimized at all (and that some of the code is still quite a mess). There are certainly things that need improvement or generalization (one simple example is that the code currently assumes that all units of a side have the same terrain defense stats). There also must be a few bugs that I haven't found yet, because sometimes the AI does moves that I cannot explain based on what I have coded.
I haven't done anything on this since my last post because I needed to do something else for a while (and I also was a bit frustrated with it). I will get back to it soon-ish. If you work on it, please let me know what you find, especially if there's something that could be improved. I have a long list of that myself, but it would be good to hear others' opinions.
EDIT: Also, the code is not at all optimized for speed at this time. There's lots of duplication and things that can be done much faster in the end, but for now I am (mostly) only concerned with getting the behavior right.
I haven't done anything on this since my last post because I needed to do something else for a while (and I also was a bit frustrated with it). I will get back to it soon-ish. If you work on it, please let me know what you find, especially if there's something that could be improved. I have a long list of that myself, but it would be good to hear others' opinions.
Well, yeah, and I don't even know if it is a good way of doing this. But it seemed like a good starting point.Derekkk wrote:I wouldn't call the bit on formation easy-to-reuse (or understand )
EDIT: Also, the code is not at all optimized for speed at this time. There's lots of duplication and things that can be done much faster in the end, but for now I am (mostly) only concerned with getting the behavior right.
SP campaigns: Galuldur's First Journey (1.12 & 1.14) & Grnk the Mighty (1.10 & 1.12)
AI experiments: Micro AIs (wiki, forum thread, known/fixed bugs), Fred, AI-demos add-on
AI experiments: Micro AIs (wiki, forum thread, known/fixed bugs), Fred, AI-demos add-on
Re: Exercises in Formula and Lua AI
The bug's been fixed, so the 'Prune Cart' scenario can now be played with trunk. You need at least r54340 of Wesnoth and v0.6.7b of 'AI Demos'.mattsc wrote:Hmm, looks like there's a bug in trunk at the moment that doesn't let me fix this. I'll file a bug report, but until that is taken care of, I'm afraid that you'll have to use 1.10.
SP campaigns: Galuldur's First Journey (1.12 & 1.14) & Grnk the Mighty (1.10 & 1.12)
AI experiments: Micro AIs (wiki, forum thread, known/fixed bugs), Fred, AI-demos add-on
AI experiments: Micro AIs (wiki, forum thread, known/fixed bugs), Fred, AI-demos add-on
Re: Exercises in Formula and Lua AI
Hi,
awesome work, really impressive
Sadly ive encountered a bug in the "Prune Cart" scenario with Wesnoth 1.10 and AI Demos v0.6.7b . Directly after the "This is WIP" notification the game crashes to desktop without any errors. Tested it on 3 different computers, Windows and Linux. Am I the only one with this problem?^^
awesome work, really impressive
Sadly ive encountered a bug in the "Prune Cart" scenario with Wesnoth 1.10 and AI Demos v0.6.7b . Directly after the "This is WIP" notification the game crashes to desktop without any errors. Tested it on 3 different computers, Windows and Linux. Am I the only one with this problem?^^
Re: Exercises in Formula and Lua AI
Hi, Saytiras. Thanks!Saytiras wrote:awesome work, really impressive
Hmm, strange. The next thing that happens after that message is a check for the Wesnoth version, but I thought that I have it set up so that it should work whether 'wesnoth.compare_versions()' exists or not. I've tried it in both 1.10.2 and 1.11.0-svn and don't get an error or crash (this is on a Mac).Saytiras wrote:Sadly ive encountered a bug in the "Prune Cart" scenario with Wesnoth 1.10 and AI Demos v0.6.7b . Directly after the "This is WIP" notification the game crashes to desktop without any errors. Tested it on 3 different computers, Windows and Linux. Am I the only one with this problem?^^
Could you try to start the scenario from a terminal window with
/usr/local/share/wesnoth -l AI-demos-Prune\ Cart.gz
(note that the path to the Wesnoth executable might be different)
and tell me what error message you get then? (When the scenario crashes like that, it is almost certainly a Lua error, which should be displayed in the terminal window.)
Thanks much for the feedback!
EDIT: Just downloaded BfW 1.10.3 and tested AI Demos v0.6.7b. No problems with that either for me.
SP campaigns: Galuldur's First Journey (1.12 & 1.14) & Grnk the Mighty (1.10 & 1.12)
AI experiments: Micro AIs (wiki, forum thread, known/fixed bugs), Fred, AI-demos add-on
AI experiments: Micro AIs (wiki, forum thread, known/fixed bugs), Fred, AI-demos add-on
Re: Exercises in Formula and Lua AI
Yeah, Prune Cart doesn't work for me either. I'm on Linux with Wesnoth 1.10.2. Here's the error message:
By the way, it's about time you updated your signature
Code: Select all
20120604 13:46:19 error scripting/lua: ...1.10/data/add-ons/AI-demos/lua/prune-cart_engine.lua:8: bad argument #1 to 'require' (file not found)
stack traceback:
[C]: in function 'require'
...1.10/data/add-ons/AI-demos/lua/prune-cart_engine.lua:8: in main chunk
[C]: in function 'require'
[string "..."]:3: in main chunk
PANIC: unprotected error in call to Lua API (attempt to index a nil value)
Re: Exercises in Formula and Lua AI
Thanks. That was not at all what I had expected. It should be fixed in 0.6.7c.lipk wrote:Yeah, Prune Cart doesn't work for me either. I'm on Linux with Wesnoth 1.10.2. Here's the error message:
[I am using Wesnoth Lua Pack for bebugging and had forgotten to comment out the line which loads the debug_utils library. Sorry for that! I should really make the loading dependent on whether WLP exists...]
Done.lipk wrote:By the way, it's about time you updated your signature
SP campaigns: Galuldur's First Journey (1.12 & 1.14) & Grnk the Mighty (1.10 & 1.12)
AI experiments: Micro AIs (wiki, forum thread, known/fixed bugs), Fred, AI-demos add-on
AI experiments: Micro AIs (wiki, forum thread, known/fixed bugs), Fred, AI-demos add-on
-
- Inactive Developer
- Posts: 2461
- Joined: August 15th, 2008, 8:46 pm
- Location: Germany
Re: Exercises in Formula and Lua AI
This line looks very frightening to me; the scenario failing or even being force-quitted to the titlescreen is expected behavior, but if the engine crashes to the desktop that's a bug. Please report.lipk wrote: PANIC: unprotected error in call to Lua API (attempt to index a nil value)
I didn't get this, perhaps since I have the WLP locally ?
projects (BfW 1.12):
A Simple Campaign: campaign draft for wml starters • Plan Your Advancements: mp mod
The Earth's Gut: sp campaign • Settlers of Wesnoth: mp scenario • Wesnoth Lua Pack: lua tags and utils
updated to 1.8 and handed over: A Gryphon's Tale: sp campaign
A Simple Campaign: campaign draft for wml starters • Plan Your Advancements: mp mod
The Earth's Gut: sp campaign • Settlers of Wesnoth: mp scenario • Wesnoth Lua Pack: lua tags and utils
updated to 1.8 and handed over: A Gryphon's Tale: sp campaign
Re: Exercises in Formula and Lua AI
Will do. Wesnoth crashes on errors in Lua AI code happen reasonably frequently (although I do not remember off hand if I'm just making the same type of mistake over and over again). I thought that was known behavior (I thought I've read about it somewhere) and did therefore not report this. I'll do so from now on as I come across them.Anonymissimus wrote:This line looks very frightening to me; the scenario failing or even being force-quitted to the titlescreen is expected behavior, but if the engine crashes to the desktop that's a bug. Please report.
Yes, that's also the reason why I did not notice it.Anonymissimus wrote:I didn't get this, perhaps since I have the WLP locally ?
Edit: bug reported here.
SP campaigns: Galuldur's First Journey (1.12 & 1.14) & Grnk the Mighty (1.10 & 1.12)
AI experiments: Micro AIs (wiki, forum thread, known/fixed bugs), Fred, AI-demos add-on
AI experiments: Micro AIs (wiki, forum thread, known/fixed bugs), Fred, AI-demos add-on
Re: Exercises in Formula and Lua AI
AI-Demos v0.7.0 is out with a new scenario, demonstrating a whole bunch of different animal behaviors. This now brings the count to 10 scenarios and 25 different AIs -- although I am cheating a bit here, since I am counting the RCA AI in that (and a few custom routines by others), so there are really only about 20 of my own. To quote from the scenario dialog:
This is just a fun little scenario with a bunch of different animal AIs, mostly for watching only. The animal AIs behave as follows:
General: These AI's are set up to simulate (to some extent) how these animals would act in real life. This includes that they are animals, meaning that they are not super smart. As an example, the wolves generally hunt in a pack, but are easily distracted by prey coming into range. They are also decent, but not great at cornering deer. For the most part, this is intentional. I'd be happy to help if you'd like somewhat modified behavior for your own scenarios - and, of course, if you see something that should be improved, please let me know.
Bears, Spiders and Yetis mostly just wander in their respective parts of the map. They stay out of each other's way (and out of the way of the dogs), but do attack each other if cornered. They will attack the other, weaker animals (deer etc.) if those are within range.
Wolves hunt in a pack of up to three. They actively go after the closest deer (as long as it stays in the forest) and try to corner it (not always super successfully), but are easily distracted by other prey coming into range. The wolves try to avoid getting into the range of bears, spiders, dogs and the yeti, except when they are going in for an attack. If you let them move for long enough, they will also learn that it is not healthy to attack the tusklets. When no deer is left, they wander randomly. Note that the wolf AI only works with 3 or fewer wolves.
Each deer wanders randomly on forest tiles, except when enemies get in its (the deer's) range, in which case it flees to the farthest point it can reach.
Tuskers exhibit the same behavior as deer, except when an enemy is next to one of the tusklets. This enemy will then experience the full wrath of an irate boar.
Tusklets blindly follow the closest adult tusker, except when there is no tusker left, in which case they behave the same as deer.
Rabbits also wander randomly, but in addition disappear into their holes (if any are within reach) when enemies are close. They reappear out of their holes at the beginning of the turn, if it is safe.
Sheep dogs try to keep their sheep safe. This involves keeping them inside the area outlined by the path the dogs have worn into the meadow, positioning themselves in between the sheep and approaching enemies, and attacking the enemies if those get too close. You might have to let the scenario play for quite some time before you get to see an interesting dog/wolf interaction. If no active herding or protecting move is needed, the dogs go to a random location on the path.
Sheep wander aimlessly except when a sheep dog is next to them, in which case they run away from the dog. The dogs exploit this by positioning themselves on the outside of the sheep, if possible. The sheep, dogs and forest creatures (deer, tuskers, rabbits) have learned that they are no threat to each other and leave each other alone, demonstrating the enormous self control of a well trained sheep dog.
This is just a fun little scenario with a bunch of different animal AIs, mostly for watching only. The animal AIs behave as follows:
General: These AI's are set up to simulate (to some extent) how these animals would act in real life. This includes that they are animals, meaning that they are not super smart. As an example, the wolves generally hunt in a pack, but are easily distracted by prey coming into range. They are also decent, but not great at cornering deer. For the most part, this is intentional. I'd be happy to help if you'd like somewhat modified behavior for your own scenarios - and, of course, if you see something that should be improved, please let me know.
Bears, Spiders and Yetis mostly just wander in their respective parts of the map. They stay out of each other's way (and out of the way of the dogs), but do attack each other if cornered. They will attack the other, weaker animals (deer etc.) if those are within range.
Wolves hunt in a pack of up to three. They actively go after the closest deer (as long as it stays in the forest) and try to corner it (not always super successfully), but are easily distracted by other prey coming into range. The wolves try to avoid getting into the range of bears, spiders, dogs and the yeti, except when they are going in for an attack. If you let them move for long enough, they will also learn that it is not healthy to attack the tusklets. When no deer is left, they wander randomly. Note that the wolf AI only works with 3 or fewer wolves.
Each deer wanders randomly on forest tiles, except when enemies get in its (the deer's) range, in which case it flees to the farthest point it can reach.
Tuskers exhibit the same behavior as deer, except when an enemy is next to one of the tusklets. This enemy will then experience the full wrath of an irate boar.
Tusklets blindly follow the closest adult tusker, except when there is no tusker left, in which case they behave the same as deer.
Rabbits also wander randomly, but in addition disappear into their holes (if any are within reach) when enemies are close. They reappear out of their holes at the beginning of the turn, if it is safe.
Sheep dogs try to keep their sheep safe. This involves keeping them inside the area outlined by the path the dogs have worn into the meadow, positioning themselves in between the sheep and approaching enemies, and attacking the enemies if those get too close. You might have to let the scenario play for quite some time before you get to see an interesting dog/wolf interaction. If no active herding or protecting move is needed, the dogs go to a random location on the path.
Sheep wander aimlessly except when a sheep dog is next to them, in which case they run away from the dog. The dogs exploit this by positioning themselves on the outside of the sheep, if possible. The sheep, dogs and forest creatures (deer, tuskers, rabbits) have learned that they are no threat to each other and leave each other alone, demonstrating the enormous self control of a well trained sheep dog.
SP campaigns: Galuldur's First Journey (1.12 & 1.14) & Grnk the Mighty (1.10 & 1.12)
AI experiments: Micro AIs (wiki, forum thread, known/fixed bugs), Fred, AI-demos add-on
AI experiments: Micro AIs (wiki, forum thread, known/fixed bugs), Fred, AI-demos add-on
Re: Exercises in Formula and Lua AI
On request by a fellow Wesnothian, I have added another scenario, 'Wolves', with a different wolf pack behavior from 'Animals'. Because of how I want the packs to behave (e.g. all wolves in a pack move together, before we go on to another pack, even if not all of them do the same thing; or wolves being assigned to packs automatically), this turned out to be a bit more complex than I had expected, almost 500 lines of code for a "reasonably simple" AI. Point being, while I believe that I have done thorough bug testing, it's quite possible that I missed something and any comments concerning unwanted behavior would be much appreciated. Because of the complexity, I'll need a replay in order to track things down though.
Anyways, this is available in v0.8.0,
Anyways, this is available in v0.8.0,
with the wolves behaving as follows (taken from the scenario dialog):
SP campaigns: Galuldur's First Journey (1.12 & 1.14) & Grnk the Mighty (1.10 & 1.12)
AI experiments: Micro AIs (wiki, forum thread, known/fixed bugs), Fred, AI-demos add-on
AI experiments: Micro AIs (wiki, forum thread, known/fixed bugs), Fred, AI-demos add-on
Re: Exercises in Formula and Lua AI
And there's another new scenario, following the suggestion by yet another fellow BfW-er: 'Swarm'. Thanks for all the ideas, everybody!
Bats moving around in a swarm (or a flock, or colony, or whatever):
SP campaigns: Galuldur's First Journey (1.12 & 1.14) & Grnk the Mighty (1.10 & 1.12)
AI experiments: Micro AIs (wiki, forum thread, known/fixed bugs), Fred, AI-demos add-on
AI experiments: Micro AIs (wiki, forum thread, known/fixed bugs), Fred, AI-demos add-on
- Simons Mith
- Posts: 821
- Joined: January 27th, 2005, 10:46 pm
- Location: Twickenham
- Contact:
Re: Exercises in Formula and Lua AI
Hey mattsc, I found a description of a wolves' hunting algorithm in New Scientist 22/10/2011, pg11. In brief:
'Co-operation not vital to hunting in packs'
A virtual wolf pack may be possible with just two rules.
Each wolf 'moves towards prey until it reached a certain safe distance. It then moves away from any other wolves that had reached that distance.'
Simulated wolves (in a five-strong wolf pack) following these rules closed on prey and encircled it, and if the prey veered right or left, one of the wolves sometimes pulled away to maintain its distance from its fellows. That wolf ended up waiting in the prey's path, seemingly in ambush.
Further on in the same article, 'packs do not hunt more eficiently above a certain pack size, suggesting that larger packs enjoy little advantage in obtaining food.'
Thought you might find that interesting.
'Co-operation not vital to hunting in packs'
A virtual wolf pack may be possible with just two rules.
Each wolf 'moves towards prey until it reached a certain safe distance. It then moves away from any other wolves that had reached that distance.'
Simulated wolves (in a five-strong wolf pack) following these rules closed on prey and encircled it, and if the prey veered right or left, one of the wolves sometimes pulled away to maintain its distance from its fellows. That wolf ended up waiting in the prey's path, seemingly in ambush.
Further on in the same article, 'packs do not hunt more eficiently above a certain pack size, suggesting that larger packs enjoy little advantage in obtaining food.'
Thought you might find that interesting.