Exercises in Formula and Lua AI and AI-demos add-on feedback

Discussion of all aspects of the game engine, including development of new and existing features.

Moderator: Forum Moderators

Post Reply
User avatar
Rigor
Posts: 941
Joined: September 27th, 2007, 1:40 am

Re: Exercises in Formula and Lua AI

Post by Rigor »

interesting you say that nelson. i found myself playing a bit mroe unconventional this time, attacking the grunt rush ai on my own, with the result that i could build on prior knowledge about the ais behaviour and capitalize on it. not having seen your games i wonder if you have done something extravagant that lead to the assumption that its a worse behaviour, or we just understand how its ticking way better.

anyways, i played elves and found many improvements backfiring, simply because the conditions e.g. kill a half dead unit didnt offer really great chances and the ai took it anyways, exactly as we taught it ;) - just the rng didnt work out well.

but i think with this upgrade the grunt rush ai might not play better than in the last version but is certainly more likely to win the game than in the previous one - why? because it plays more reasonably, and when the parameters are meticulously rehauled, it will show.
Attachments
2p_—_The_Freelands_treelands.gz
Treelands
(21.97 KiB) Downloaded 145 times
nelson
Posts: 91
Joined: March 19th, 2008, 11:15 pm
Contact:

Re: Exercises in Formula and Lua AI

Post by nelson »

Rigor, I love your hilariously bold attack right into the teeth of the AI's nighttime grunt rush! If you tried that against me I would send you home in pieces ;-) I think we need to train the AI to trap units, especially in conjunction with poisoning them. Sometimes it misses the opportunity to trap. If he had units in position to trap your hilarious attackers, he should have been able to hold them near his base at a bad time of day and pump out units to massacre them.

I also think we need to train the AI to hold its villages on the left better. It needs to make sure the forward village and the far left village do not get stolen! It's ok if the two inner villages get stolen, because the leader can easily come to help clean it out, and reinforcements can help clean those villages in 1 turn.

UPDATE: Also, it is crucial that we teach the AI to put healthy units in villages that are under attack that it is trying to hold, and send injured units to heal at home or in protected occupied villages. In a game that I just watched against an inexperienced human, the AI was in a great position as dawn came, but it put mortally wounded grunts in its occupied villages and as the human killed the injured units and reclaimed his villages the AI lost its nighttime gains. If it had put healthy units in those villages it could have held on indefinitely, and probably would have won.
AI
Developer
Posts: 2396
Joined: January 31st, 2008, 8:38 pm

Re: Exercises in Formula and Lua AI

Post by AI »

I haven't actually managed to try this out before now, so I'll post everything I find here.

Patrols:
Jabb only attacks if he happens to end up next to Jacques, which, due to ZoC, doesn't happen unless Jacques hangs around on or right next to one of the waypoints.

Prune cart (stationary/vs AI):
I'm impressed with the healer positioning until turn 11, it moves both healers into corner of the lines together, severely limiting the amount of healing that can be done.

Messenger escort:
They certainly try, but it's easy to peel off escorts and herd the messenger into the forest.

Pass defense:
On turn 4, a bowman melee-attacks a grunt, this causes him to be killed later that turn.
Another bowman melee-attacks a grunt on turn 5, first watch... he dies too.
On turn 6, another unit dies due to unwarranted melee-attacks. A spearman this time.
Turn 9. The lieutenant attacks an orcish archer with his crossbow...

I think there's a problem with the evaluation of potential attacks here. Thanks to the positioning of units, they still manage to hold out to turn 21 or so though.

The protect-the-wizard and HttT01 AI seems to work well.

I haven't gotten around to the grunt-rush AI yet.
Attachments
AI-demos-Defend_the_Pass_herspeel.gz
(19 KiB) Downloaded 148 times
AI-demos-Prune_Cart_herspeel.gz
(27.03 KiB) Downloaded 148 times
mattsc
Inactive Developer
Posts: 1217
Joined: October 13th, 2010, 6:14 pm

Re: Exercises in Formula and Lua AI

Post by mattsc »

Hey AI, thanks for testing and the comments! Quick question: are you checking this out with BfW 1.10 or trunk? There's an incompatibility in the choice of weapon between the two versions. I have it check for version in Prune Cart, but not yet in other scenarios, so that might explain the problem with Pass Defense (and it probably affects other scenarios as well). Thanks for the reminder that I need to do that!!

I'll reply to your other comments (and nelson and Rigor) later...

Edit: :doh: I can just check the version in your replays, of course. So yes, the Pass Defense issues you are seeing are because you are playing this with 1.11.0-svn. You could either try again with 1.10, or wait until the next release, I'll fix it in that.

Edit 2: Some more comments:
AI wrote:I haven't actually managed to try this out before now, so I'll post everything I find here.
Cool, thanks.
AI wrote:Patrols:
Jabb only attacks if he happens to end up next to Jacques, which, due to ZoC, doesn't happen unless Jacques hangs around on or right next to one of the waypoints.
That's how it is done in 'A Rough Life', where this AI code comes from. I assume that it was done intentionally, so you'll have to take this up with Elvish_Hunter. ;) It could be changed, of course, and I'll be happy to do that if somebody would like something different for another campaign, but I went with the original code from ARL here.
AI wrote:Prune cart (stationary/vs AI):
I'm impressed with the healer positioning until turn 11, it moves both healers into corner of the lines together, severely limiting the amount of healing that can be done.
Prune Cart is very much incomplete still. I've observed that too, the AI does pretty well for a while, but then things sometimes start to fall apart (healer positioning being one of the issues, but by far not the only one). I think I have learned a lot of things while working on the grunt rush, so I'll go back to this sometime and (hopefully) improve things.
AI wrote:Messenger escort:
They certainly try, but it's easy to peel off escorts and herd the messenger into the forest.
Hmm, I'll have to look into that again sometime. Thanks.


nelson & Rigor: thanks much (yet again) for all the good suggestions. A lot of the things you mention are known (to me). I was hoping that they would be minor problems and that the overall behavior would be better. Well, not against human players apparently... But after watching your replays, I see some light at the horizon anyway. ;) Knowing what the AI is doing, I can see that a lot of it is not fundamentally wrong, but mostly caused by still incomplete and/or non-ideally tuned code.

I'll keep working on it. Unfortunately, I'll have very little time for the next couple weeks. I might be able to do some of the easier stuff (e.g. retreating injured units out of harm's way, rather than into the middle of a battle) over the next few days, but other things will have to wait until after I am back from traveling at the end of next week.

I was also wondering whether I should set up yet another version of the grunt rush which lets you choose some of the AI parameters at the beginning of the game. It would be more work for you, testing things with different settings, but I think it would help me a lot.

Thanks to all of you again!
User avatar
taptap
Posts: 980
Joined: October 6th, 2011, 5:42 pm

Re: Exercises in Formula and Lua AI

Post by taptap »

I was positively impressed with the escort - yes you can stop them easily - but the same might happen to a human player when he doesn't manage to break through the first unit that blocks the way, he won't break through during dusk and won't survive the night when the archers arrive doing 9-3 damage. If you play a little sloppy they pass by. (E.g. I would have lost in a certain UtbS scenario if the messenger would have been controlled by this AI.)

The wolf packs and especially the sheep dogs are nice additions too. (The wolves in the first scenario of Galuldur's journey might be a good application.) I wonder whether the sheep dogs (maybe some more) would manage to control a larger herd of sheep (without increasing their movement), because sometimes they scare away a sheep from the herd and take some time to catch it. They often use adjacent hexes (reduced ZoC range) to block approaching predators which sometimes allows a wolf or a spider to go around. (Btw. The first wolf attacking a sheep was killed by the sheep, when I watched :))

The patrols don't seem to work very well and are easily lured to do crazy stuff (going straight through a gallery of enemies 1 hex at a time to your destination, going back and forth if you open the destination and block it alternating).

The mage protection works, but the mage party did win the battle hands down (killing all enemies) anyway. The question is how good the protection will be when they are a little more hard pressed, it would be interesting to watch.
I am a Saurian Skirmisher: I'm a real pest, especially at night.
mattsc
Inactive Developer
Posts: 1217
Joined: October 13th, 2010, 6:14 pm

Re: Exercises in Formula and Lua AI

Post by mattsc »

Hi taptap, thanks for playing and commenting.
taptap wrote:I was positively impressed with the escort - yes you can stop them easily - but the same might happen to a human player when he doesn't manage to break through the first unit that blocks the way, he won't break through during dusk and won't survive the night when the archers arrive doing 9-3 damage. If you play a little sloppy they pass by. (E.g. I would have lost in a certain UtbS scenario if the messenger would have been controlled by this AI.)
You should replay UtBS once 1.11 comes out then. :twisted: Btw, if you want it to be slightly more of a challenge (since I know that you play things on the hardest level), try doing this scenario without the wolf rider. That's how I had it originally, but after discussing it with others, we decided that that would be too hard for a demo scenario. Of course, it's still much easier than some of the stuff you play...
taptap wrote:The wolf packs and especially the sheep dogs are nice additions too. (The wolves in the first scenario of Galuldur's journey might be a good application.) I wonder whether the sheep dogs (maybe some more) would manage to control a larger herd of sheep (without increasing their movement), because sometimes they scare away a sheep from the herd and take some time to catch it. They often use adjacent hexes (reduced ZoC range) to block approaching predators which sometimes allows a wolf or a spider to go around.
Interesting suggestion. I could add a right-click option for the player to add more sheep and dogs, to see what happens. As for the dogs' behavior, I am aware of those limitations and did that intentional. They're "only dogs" after all. :) (And the real reason is that for the application I have in mind, in Grnk Part 2, I need the animals' behaviors to be sub-optimal.)
taptap wrote: (Btw. The first wolf attacking a sheep was killed by the sheep, when I watched :))
I guess the sheep landed a lucky kick to the head or something. :lol2:
taptap wrote:The patrols don't seem to work very well and are easily lured to do crazy stuff (going straight through a gallery of enemies 1 hex at a time to your destination, going back and forth if you open the destination and block it alternating).
'Patrols' was one of the first scenarios I did and the Konrad Impostor AI is really not very good. It's on the list of things to be redone, sometime...
taptap wrote:The mage protection works, but the mage party did win the battle hands down (killing all enemies) anyway. The question is how good the protection will be when they are a little more hard pressed, it would be interesting to watch.
Good question. I guess I could add options and/or difficulty levels here too. Actually, how about I add gold for both sides to the AI parameters one can choose at the beginning of this scenario?

Thanks!
mattsc
Inactive Developer
Posts: 1217
Joined: October 13th, 2010, 6:14 pm

Re: Exercises in Formula and Lua AI

Post by mattsc »

nelson, Rigor, all: I just released a new version, v0.9.18, which includes some re-prioritizing and minor changes:

Code: Select all

0.9.18, 26 July 2012
- Freelands Side 1 Grunt Rush:
  - Recruit more assassins (and slightly fewer orcs) and do poison attack with higher priority
  - Retreat injured units to village only if that village is (comparatively) safe
  - Rush on right is a little more conservative
  - Higher priority to occupying villages already owned by AI
- Defend Pass, Messenger Attack, Grunt Rushes:
  - Made sure weapon choice works in both 1.10 and 1.11
These changes have some side effects, e.g. there are fewer orcs available for the rush on the right, injured units might not retreat at all if there's no safe village available (also, they might still retreat to an unsafe village after all; it's not perfect), it is possible to keep several AI units sitting idly on villages with a single enemy, etc. But as I said, I don't have time to do these things "correctly" right now.

If you want, have a look and see if this makes things better or worse. On average, I mean - there are situations when it makes things better, and others for which it's worse. I can revert any or all of these changes if you want. More significant changes will have to wait for now...

AI: The 1.10/1.11 incompatibility issue that caused the weapon problem in 'Pass Defense' (and several other scenarios, but in a more subtle way) is fixed also.

Edit: Oh, also, I am really not happy with how the attacks on the right are executed, but that's not at all trivial to fix. So it will have to do for now.
nelson
Posts: 91
Joined: March 19th, 2008, 11:15 pm
Contact:

Re: Exercises in Formula and Lua AI

Post by nelson »

First of all, while initial double assassins is great against some factions like Loyalists, since it would be so disastrous against (competent) Undead I don't recommend that. I would get one assassin and one archer for the initial attacking force, and grunts for the rest. Besides, an archer would be better for killing cavalry, which is my main Loyalist defense against a grunt rush.

Also, the AI has a disconcerting habit of continuing to attack into my main army as day is approaching, instead of running away at second watch or dawn. It needs to flee at daybreak, unless it can maintain a strong defensive line on my villages with healthy grunts holding each village. A strong defensive line means one that I cannot easily break (i.e. I can't attack units from too many hexes, especially injured units) and where I cannot trap any units without breaking the line.

Here are two replays:
2p_—_The_Freelands_replay_AI_loss.gz
(27.08 KiB) Downloaded 153 times
4. The AI lets me grab its outer left village at 8,5 while my fencer sets up to grab the rear village at 12,2. Very bad! Still needs to prioritize holding the outer villages against village stealers.

5. Given that I have stolen a village, the AI should trap my cavalry to make sure it cannot escape, but it misses the opportunity. Also, I personally would avoid attacking units that are already poisoned (unless they are on a village), I would put damage into unpoisoned units since I will have to retreat and heal poisoned units anyway (unless they are about to level). But maybe I am wrong, focus fire makes those poisoned units useless for the foreseeable future, they will be healing for a long time, and my whole front has to retreat to protect those units now anyway, letting him take 2 villages.

6. Misses another opportunity to trap my cav on the left, which would insure its death and prevent it from stealing another village. If I hadn't stolen all of his villages on the left, the AI would be in a good position on the right, up two villages.

7. On the right the AI foolishly continues to attack at day, instead of trying to hold the line at the villages or simply retreating completely. This costs him his eastern army.

9. If the AI ran away it could have made it dangerous for me to follow him, but no, it hangs around.

10. Instead I am able kill the two units he leaves behind.

11. At this point I have a 7-2 kill advantage and I think the game is basically over. The injured wolf, injured grunt and assassin all committing suicide by village stealing on the left doesn't help. However, I get too bold on the right at night and the AI punishes me (good job!).

14. Did my eyes deceive me, or did I just watch a grunt melee a Swordsman standing on a castle tile at daytime? I think I can quit my commentary at this point.

23. The AI is bad at fighting at the end when it is almost hopeless. What it should try to do is gather its few remaining units together with its leader and try to rack up kills while maintaining its remaining units. Its last hope is to level its remaining units into a killing force that can clear territory and eventually get its income back. Instead, as you see this turn it sends two grunts off alone to separate battles while leaving the leader sitting alone in its keep at night. Those three units should have been fighting together at night in a desperate last-ditch attempt to get kills and level units. (Obviously by this turn it is too late, but that should be the AI's strategy in the losing endgame.)
2p_—_The_Freelands_replay_AI_loss_2.gz
(19.08 KiB) Downloaded 173 times
4. Good, the AI held on to the two outer villages, allowing my pillaging cavalry to take an inner village where it can easily be trapped and killed!

5. Too bad it still doesn't know how to trap, but RNG will let it kill the pillaging cavalryman anyway. In the east, putting the fragile assassin in the front line on flat where it can be hit from 3 hexes is a mistake. Sure enough, I kill it in my counterattack. Protect the squishy, expensive assassins better!

6. Here is an opportunity to hit the village from 4 hexes! I prioritized killing the assassin over protecting my village, so the AI should try to kill my village-holding spearman with the 3 grunts, and either take the village with the assassin if that succeeds or attack the spearman (maybe consider poisoning something else if the assassin has no CTK on the village spearman). Instead the AI has another assassin commit suicide from the flat ground where it can be hit from 3 hexes, and doesn't attack at all with two injured grunts. Focus fire! Keep the assassin shielded and on good terrain! If you're not going to go all out with your attack, retreat! (2nd watch is a good time to retreat if it looks like you won't get more kills or take a village.)

7. Dear god don't attack now! Was there even a ctk on the spearman? Don't attack units you can't kill unless you can trap them. Don't hang around at day. And especially don't hang around at day if there is a mage nearby, your dodginess on villages doesn't help you, it's a bad gamble. Putting a grunt on a hex that can be maged at dawn is a bad deal.

8. This game is over, I now have a 6-1 kill advantage and it is morning.

9. A foolish village-stealing grunt gets trapped. Don't attempt to village steal if you can be trapped outside a village!

10. 9-1 kill advantage plus an income advantage, I'm done commenting.

16. At the very least the doomed AI leader could poison cavalry that can't retaliate. Maybe if it dodges for long enough it could level and recharge its health bar! Get some XP!
Anonymissimus
Inactive Developer
Posts: 2461
Joined: August 15th, 2008, 8:46 pm
Location: Germany

Re: Exercises in Formula and Lua AI

Post by Anonymissimus »

Okay, so I've played this as well.
mainline 1.11.0-svn@r54874, ai demos 0.9.18
Got OOS when watching as replay, clicked ingnore all, noticed no obvious errors in comparison to the play.
Attachments
2p_—_The_Freelands_Turn_18.gz
(32.83 KiB) Downloaded 156 times
projects (BfW 1.12):
A Simple Campaign: campaign draft for wml startersPlan Your Advancements: mp mod
The Earth's Gut: sp campaignSettlers of Wesnoth: mp scenarioWesnoth Lua Pack: lua tags and utils
updated to 1.8 and handed over: A Gryphon's Tale: sp campaign
mattsc
Inactive Developer
Posts: 1217
Joined: October 13th, 2010, 6:14 pm

Re: Exercises in Formula and Lua AI

Post by mattsc »

Thanks again, everybody, for all the comments and replays. Sorry for repeating myself, but I have essentially no time for Wesnoth until the end of next week. And then, none of the changes that are needed now are quick and easy any more. So it'll probably be a while until the next update. But that's not for lack of interest or good comments to be working with ...

Interesting, Anonymissimus, that you got OOS errors. In all the replays I have watched, this is the first time that has happened. Actually, playing the replay from a terminal, there are tons of errors of this kind:

Code: Select all

20120728 18:37:34 error replay: SYNC: In attack Orcish Archer (19,4) vs Troll (18,4): the data source says the hit did 12 damage, while in-game calculations show the hit doing 9 damage (over-riding game calculations with data source results)
20120728 18:37:35 error replay: SYNC: In attack Orcish Grunt (17,5) vs Troll (18,4): the data source says the hit did 10 damage, while in-game calculations show the hit doing 9 damage (over-riding game calculations with data source results)
20120728 18:37:38 error replay: SYNC: In attack Troll Whelp (18,4) vs Orcish Grunt (17,5): the data source says the hit did 10 damage, while in-game calculations show the hit doing 9 damage (over-riding game calculations with data source results)
20120728 18:37:40 error replay: SYNC: In attack Orcish Grunt (12,4) vs Wolf Rider (11,5): the data source says the hit did 6 damage, while in-game calculations show the hit doing 7 damage (over-riding game calculations with data source results)
I have no idea how my AI could cause something like that. Given that you're playing trunk, maybe this has something to do with one of the recent commits?
Anonymissimus
Inactive Developer
Posts: 2461
Joined: August 15th, 2008, 8:46 pm
Location: Germany

Re: Exercises in Formula and Lua AI

Post by Anonymissimus »

The first OOS error I get says a recruited unit has different checksum than it got during the play; the later errors about different battle results seem just consecutive ones. This could be caused by the recruited unit(s) having different traits for instance. In any case, looks like a bug in trunk yes.
projects (BfW 1.12):
A Simple Campaign: campaign draft for wml startersPlan Your Advancements: mp mod
The Earth's Gut: sp campaignSettlers of Wesnoth: mp scenarioWesnoth Lua Pack: lua tags and utils
updated to 1.8 and handed over: A Gryphon's Tale: sp campaign
mattsc
Inactive Developer
Posts: 1217
Joined: October 13th, 2010, 6:14 pm

Re: Exercises in Formula and Lua AI

Post by mattsc »

There's a new scenario, 'Dragon', (and therefore an update in the minor version number) in v0.10.0. This is a variation on the big animals AI from 'Animals' on request by another scenario designer. It's probably only of interest to those of you who might consider including something like this in your own campaigns, it's not a particularly exciting scenario.

The dragon explains his behavior himself at the beginning of the scenario. A few additional technical details:
- A side can contain several hunt_and_rest units with different parameters, as well as other units that are controlled by the normal AI.
- The dragon is healed 12 HP when in his lava pool. If something like that is desired, it needs to be done from WML, not from within the AI, otherwise there would be OOS errors.
- Setting the area of random wander for the dragon with hunt_x,hunt_y does not mean that he will not leave that area. It just means that the end point of his wander (which can be more than one move away) is inside it.

That's all, I think.

PS: I was considering naming Rowck 'Pooph, the Mighty Dragon', but I figured that that would be just asking for trouble. :)
User avatar
Rigor
Posts: 941
Joined: September 27th, 2007, 1:40 am

Re: Exercises in Formula and Lua AI

Post by Rigor »

can the dragon spit grunts too :twisted: ? btw heres a replay-before-you-posted-updates featuring natasiel, the creator of world conquest versus the horde. i thought maybe you would exchange your experiences with the AI, hes quite the reference. i also played an actual version, and just one thing i noticed: at the very end of the game, the AI didnt retreat the crossbow leader out of range of my ulf. i mean, ok the ulf died, but the leader had so little hp left...and then the thief came backstabbing too. it was pretty clear he would die, is the potential damage form backstabbing taken into account when retreating leaders? in a game with a lot of thieves, this could lead to the funny situation that the leader charges into a minefile dof thieves :)
Attachments
2p_—_The_Freelands_replay.gz
rig
(17.41 KiB) Downloaded 150 times
2p_—_The_Freelands_natasiel_1.gz
nat
(28.23 KiB) Downloaded 151 times
mattsc
Inactive Developer
Posts: 1217
Joined: October 13th, 2010, 6:14 pm

Re: Exercises in Formula and Lua AI

Post by mattsc »

Rigor wrote:can the dragon spit grunts too :twisted: ?
I'm sure he could; also you'd have to be careful how that is done or it would cause OOS errors. ;)
Rigor wrote:i also played an actual version, and just one thing i noticed: at the very end of the game, the AI didnt retreat the crossbow leader out of range of my ulf. i mean, ok the ulf died, but the leader had so little hp left...and then the thief came backstabbing too. it was pretty clear he would die, is the potential damage form backstabbing taken into account when retreating leaders? in a game with a lot of thieves, this could lead to the funny situation that the leader charges into a minefile dof thieves :)
Retreating of the leader (other than to the keep or to a village when very injured) is not done at all at the moment. And no, backstabbing isn't taken into account either. IMO, those are "refinements" that I can worry about once I have the main part of the grunt rush working - which, at the moment, is pretty badly broken. I'll get back to this soon, but as I've said, it's going to take a little. We're not talking about minor tweaks for the next steps...
User avatar
negusnyul
Posts: 12
Joined: April 18th, 2010, 7:52 am

Re: Exercises in Formula and Lua AI

Post by negusnyul »

Undead (P2) vs. Grunt rush AI (P1) on Freelands
A bit of luck + ghouls = ai defeat
good game
Attachments
2p_—_The_Freelands_replay_AI.gz
(25.69 KiB) Downloaded 160 times
Post Reply