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.

Moderators: Forum Moderators, Developers

Post Reply
User avatar
FAAB
Inactive Developer
Posts: 52
Joined: November 15th, 2008, 12:15 pm

Re: Exercises in Formula and Lua AI

Post by FAAB »

mattsc wrote:I have some comments and questions back:
FAAB wrote: - move the village protection lower than the attack (to avoid situation 2.)
- however, keep the enemy village stealing higher than attack (*)
Maybe I misunderstand you, but I thought one of the main points of what Rigor suggested was to have grunts sit on villages so that the enemy wastes a lot of hitpoints trying to get rid of them.
You have two problems in your hands.
The first one is to implement a grunt rush. This supposes:
- recruiting lot of grunts
- attacking everywhere
- taking and holding villages abusively
The first item was done by your initial code. The second is achieved by my proposal.
The third item means to put grunts on exposed village where it is likely to get bad hits because they might give a lot retaliation, they have a lot of HP and they are cheap anyway. That (I guess) is what rigor meant by "grunt on village".
NB: Grunt rush, while being the most difficult to counter, is not always good. It depends on the map. Grunt rush never work against Undead though.

Your might have misunderstood him, and implement a fix to another problem: village protection.
This is a weakness in the standard AI to care too little about village (usually falling behind in village count after ~10 turns) and to underestimate the power of peaceful village steal. So you may have thought that was what rigor was describing.
The village protection can be done by any unit and usually the best one is the one with enough HP to hold one turn and is able the give more retaliation. For example that would be a assassin against 2 mages (but you would take a grunt if one of the mage could be killed in one hit). As you see this is a complex algorithm: it depends on surrounding units, their HP, yours, their HP, the time of day. Units XP are also in the equation.

Implementing solution to problem 1 does not give you a better AI. It is just an AI that can do Grunt rush.
Implementing solution to problem 2 would be a general improvement and could be used in any AI.

[edit]
If I only make villages stealing higher priority than attacks, we're (almost) back to the default behavior (after reachable villages have been taken). I have tried this and I think it makes the custom AI play worse, so I took it out again, but left the code for it in the file. If you want to try it, comment out the line 'return 290000' and uncomment the one following it.
I am pretty sure standard AI is attacking before collecting enemy's village (as any World Conquest player could confirm [the attack phase is pretty long]).
[/edit]
FAAB wrote:(*) actually a potential unit kill is usually better than a village steal
Agreed. So the way I have done that: if any of the units with moves left has a >50% chance of making a kill, then the village grabbing/holding action for all units has lower priority than attack, otherwise it's the other way around. Does that sound right?
Seems worth trying.
FAAB wrote:(**) with a change the logic on 60% grunt recruit to insure getting one more grunt when we have 3 out of 5 units (60%)
I have nothing against the new version at all, but wasn't that already done by using '>' rather than '>='. But then, that 60% was pretty much a random choice anyway, so if you have another preference, just let me know.
The logic behind the +1 is:
"If the ratio of grunt is kept above 60% even after I recruit something else (hence using 'number of unit +1'), I can skip the grunt recruitment". So that it makes semantically more sense than using 61% or >= to me.
One other thing I have noticed: most often when the custom AI loses, it has more units (and villages) than the enemy, but some enemy units managed to sneak around the defenses and take out the leader while some grunts sit on close villages and watch. I could add something that does priority targeting of those enemies. E.g. 2 AI units for any enemy that is closer to the AI's leader than any AI unit; or for any enemy unit within attack range of the leader. Or something. Suggestions?
I think the standard AI is doing OK at defending his leader. So the reason for what you describe might be that you take over the hand with your CA while you should leave it to the standard AI (attack or goto CA).
The standard AI is good and you just need to change one move every 3 or 4 to improve the AI. Overriding the standard AI too much will most certainly give poorer results. That is why I would leave turn 1 recruitment to standard AI for example rather than just getting 2 scouts.

[edit 2]
mattsc wrote:The new orcs_engine.lua is attached.
It does not work for me.
console error:
[/edit 2]
Last edited by FAAB on June 26th, 2012, 7:19 am, edited 2 times in total.
mattsc
Developer
Posts: 1166
Joined: October 13th, 2010, 6:14 pm
Location: Hidden on the hex behind Fred

Re: Exercises in Formula and Lua AI

Post by mattsc »

Thanks a lot, FAAB. I am not going to reply in detail right now because you and Rigor have given me a lot to think about that I need to digest first. I think I understand what you're saying in general and need to consider what that means for adjusting the AI code. I'll let you know when I have more.

Thanks again! I am really enjoying this (and am learning a lot).
User avatar
Rigor
Posts: 941
Joined: September 27th, 2007, 1:40 am

Re: Exercises in Formula and Lua AI

Post by Rigor »

i really like to talk about this too! :lol2: about potential misunderstandings: ill do a short verb list what i actually meant ok ? implement a grunt rush: recruite a lot of grunts, ok. attacking everywhere ? no. just at the most exposed village in the first night, after success go back and repeat in the next night, repeat one more time and THEN attack everywhere) because until now you have enough grunts to really be dangerous just everywhere). holding village, or village protection, as faab put it, happens somewhere between the repeats, when your loss of a grunt is more of a disadvantage to your opponent as already pointed out (retaliation, economy disaster, loss of initiative in their time of day). if you need me to explain more just let me know.

grunt rush à la rigoroise:

an attack using at least 3 if not 4 grunts and a supporter unit (wolf archer assassin but never ever nagini gobos or trolls) in order to get the most exposed village on p2s side. works best on freelands, eclusively when p1 and if the opponent doesnt reveal himself to be UD (still works sometimes, but u need an opponent who positioned himself really, really badly).

after the obvious village threat at turn 3-4 you are able to either 1) take it!!!! or if not, 2) KILL THE STUFF INSIDE!!!! ur CTK on the unit inside if usually between 3 grunt slashes with a minimum of (resists not counted now - but usually not such a big deal) 11 dmgx6 if not 12x6 that means even if only half of the grunts can deliver you still do your 33 dmg. plus, your one supporter unit taking the 4th hex to attack might just make the difference (assassin archer wolf) with 3 strikes which makes the whole affair less of a gamble for the orcs.

ok lets suppose you somehow got that village. you want to threaten one more position, namely, the one on the south east. his troop there would be quite lonely, being cut off from fast reinforcements like that. your grunts are already there, so are your supporters. if you have an assassin his defender will die of hunger there even if he doesnt die in one turn. he will still die, and you just kiled at least 28 gold in vivo while potentially grabbing two villages. and now the really interesting part begins:

:eng: it is sufficient if you just grab this one village that is yours anyways and then hold it. if you repeat this procedure many times, you are able to stay there forever without being forced to go back during an unfavorable time of day. in order to being able to stand a chance during day, you should recruit trolls at some point too. they make sure that the enemy doesnt focus too much on grunts whom you will need for the next night. eventually ill come up with a concept what to recruit when, but now i gotta go and work so i hope that helped. ah one last thing: i just had this idea to tell the ai when fresh grunts are needed, i think this might be better than making a "50%+" rule: take all grunts hp together and look how far from maximum HP it is: e.g. 3 grunts have 30,20,10 HP and max would be around 40: so that means, 3 grunts with average HP 20 are around, which is a bad thing. Make the AI recruit grunts until an average of at least 25 HP (a guesstimate - or somewhere close to that) in order to be a healthy and well-adjusted orcish horde. :twisted:
mattsc
Developer
Posts: 1166
Joined: October 13th, 2010, 6:14 pm
Location: Hidden on the hex behind Fred

Re: Exercises in Formula and Lua AI

Post by mattsc »

FAAB wrote:[edit]
I am pretty sure standard AI is attacking before collecting enemy's village (as any World Conquest player could confirm [the attack phase is pretty long]).
Yes, that's correct. I didn't express myself very well there. I meant: once the village grabbing is done, the rest of the behavior is pretty close to default (as opposed to then sitting on villages and waiting). Which might, in fact, be what you want, so I left the option in. My perception of the AI playing 'better' or 'worse' is solely based on watching it play against the default AI, which is probably not the best metric.
FAAB wrote:[edit 2]
mattsc wrote:The new orcs_engine.lua is attached.
It does not work for me.
Ugh! That's because I'm an idiot. This is caused by the bug with the identical id's for the two leaders. To take care of that I had to change other files also. So, please download v0.9.5 instead, that way I am sure not to forget something again. Sorry for that!
Edit: Here's what I use to launch things from command line at the moment:

Code: Select all

/Applications/Wesnoth-1.10.app/Contents/MacOS/Wesnoth -d -m --controller 1:ai --controller 2:ai --side 1:Northerners --side 2:Northerners --parm 1:fog:no --parm 2:fog:no --ai-config 1:~add-ons/AI-demos/ais/ai_orcs.cfg
It uses the Freelands map (default) and 100 gold per side (default), but turns fog off for both sides, so it's easier to see what is going on. It also activates debug mode from the beginning, to make it easier to "mess with things".
Rigor wrote:i really like to talk about this too! :lol2:
Great. :)
Rigor wrote: so i hope that helped.
Yes, a lot. I think I understand the overall strategy, now I need to figure out how to teach the AI that. Some of it is easy, some not quite. Obviously I don't want to hard-code all the moves. I mean, telling it that the village at x,y is crucial and needs to be taken is fine. Telling it the exact sequence of opening moves not so much and way too inflexible. I'll report back.
Rigor wrote:ah one last thing: i just had this idea to tell the ai when fresh grunts are needed, i think this might be better than making a "50%+" rule: take all grunts hp together and look how far from maximum HP it is: e.g. 3 grunts have 30,20,10 HP and max would be around 40: so that means, 3 grunts with average HP 20 are around, which is a bad thing. Make the AI recruit grunts until an average of at least 25 HP (a guesstimate - or somewhere close to that) in order to be a healthy and well-adjusted orcish horde. :twisted:
That's easy enough to do. As for the numerical value, I can put all those things into variables and collect them in one place in the file for easy adjusting. Or I could pop up a menu at the beginning of the scenario in which you can change them. I'm already doing that in another scenario, so let me know if you'd like to see that.
mattsc
Developer
Posts: 1166
Joined: October 13th, 2010, 6:14 pm
Location: Hidden on the hex behind Fred

Re: Exercises in Formula and Lua AI

Post by mattsc »

Rigor, FAAB, all:

So, after some struggles, I have put together a first attempt of a Grunt Rush a la Rigor AI (on Freelands for Side 1 only). It's still incomplete and rough around the edges, with some gaping holes (see below), so don't expect it to play great yet, but if you could tell me if the things that it does are about right, and what the most obvious paths for improvement are at this stage, that would be great.

Once you download v0.9.6 of 'AI Demos', you can start it into local MP mode with

Code: Select all

wesnoth -d -m --controller 1:ai --controller 2:human --side 1:Northerners --side 2:Loyalists --parm 1:fog:no --parm 2:fog:no --ai-config 1:~add-ons/AI-demos/ais/ai_grunt-rush-Freelands-S1.cfg
This will put you in charge of Loyalist Side 2 with fog turned off for better viewing.

Rigor: if you want to use this on the server, copy file ~add-ons/AI-demos/ais/ai_grunt-rush-Freelands-S1.cfg into directory ai/dev/ in your data directory. You can then select it in MP game setup options.
Edit: Ah, I just noticed that that only works in debug mode. So you need to launch Wesnoth from the command line with the '-d' option for this.

So here's what the AI does so far:
- Recruitment
- Sent 2 units to the left, but currently let them do what they want there (except village grabbing)
- All other units go right
- Grab enemy and unowned villages, but don't keep units on them
- If the exposed village on the right is available, move unit onto it and keep it there
- If it's night-time and there's an enemy on that village -> attack
- During other times of the day, just position units on strong terrain around that village (but not directly adjacent)
- This last step is skipped starting from the beginning of the third night (Turn 17), when we let the standard AI combat phase take over and attack at will

It doesn't work too well against the default AI yet which just storms up the middle (although it does win more often than not) and obviously it won't work against somebody coming up the left side, but those are provisions that can be built in later. I also have not had time yet to implement everything Rigor suggested (such as also going for the village in the SE), this is how far I got.

So, for now I am mostly interested in hearing how to improve what's there, and what the most urgent things to add next are.

Thanks much!
User avatar
FAAB
Inactive Developer
Posts: 52
Joined: November 15th, 2008, 12:15 pm

Re: Exercises in Formula and Lua AI

Post by FAAB »

So, after some struggles, I have put together a first attempt of a Grunt Rush a la Rigor AI (on Freelands for Side 1 only).
mattsc, reading this line make me wish I had [edit 2]more[/edit 2] free time. Spending time on an AI that plays northerners as side 1 on freelands with grunt rush 'a la rigoraise' is something I am not doing. I can spend some time on some generic AI improvements only. Using some grunt rush as a simple strategy template is OK for me as long as it helps creating general AI rules.

Running the test in --nogui mode is certainly nice but I would like to be able to ask for a replay in case the console output hints some interesting mechanics I can open the replay (like default AI winning in 6 turns). Not having this feature makes any AI testing a pain when your time is limited.
Improving the console output by listing the 'recruited (gold) and 'killed (gold)' (as displayed in the statistics dialog) would be nice too.
These two changes would require some C++ coding from developer interested in helping AI Demos.
mattsc wrote:So, for now I am mostly interested in hearing how to improve what's there, and what the most urgent things to add next are.
First I think the AI is still protecting some village that are out of reach. I am wondering if the following change is not required (based on AI demos 0.9.5)?
Spoiler:
Second is that you could improve the usability of your AI a bit.
In team game, the following line is a problem. You have to replace it with some code using is_enemy() function. Otherwise it will keep stealing its partner's villages.

Code: Select all

if (owner ~= wesnoth.current.side) then rating = rating + 2000 end
Next it would be good if you could refactor your code so that 'Orcish Grunt' is a parameter given to the functions. This way we could run the same code with different kinds of rush ('Spearman', 'Elvish Fighter', ...) to see how general the code is.

A new area of improvement you could work on could be the management of units with poison (assassins in northerners case).
The rules to apply to them could be:
  • - do poison units on highest defense
  • - do poison units with high HP (as the effect of poison will stop when the HP=1, you want to have them feel the effect as long as possible)
  • - do not poison already poisoned units
  • - poisoning units on village (or with regeneration) is less useful as it only cancel next turn's healing (but only useless if the unit is full HP)
  • - do not poison units you are likely to kill anyway (better poison a unit that survives so that poison will have effect next turn)
  • - do not use unit with poison to kill (same reason). Exception if the unit with poison can level.
All these rules have some exceptions obviously but I think they are a pretty decent set for a first iteration.
All the rules should apply to any unit with poison.

[edit]
Here is some code to support AI selection in MP. When selecting the new era, the orc AI is available in the AI selection list.
Spoiler:
[/edit]
Last edited by FAAB on June 29th, 2012, 4:08 am, edited 3 times in total.
mattsc
Developer
Posts: 1166
Joined: October 13th, 2010, 6:14 pm
Location: Hidden on the hex behind Fred

Re: Exercises in Formula and Lua AI

Post by mattsc »

FAAB: Thank you very much for all the comments, suggestions, going through the code, etc. That's very much appreciated and helps me a lot.
FAAB wrote:mattsc, reading this line make me wish I had as much free time as you have.
So do I. Seriously, I've been overstretching the time I can spend on Wesnoth a lot over the last week or so and won't be able to keep that up. As for general vs. specialized code, the general version still exists in v0.9.6, I just renamed it from 'ai_orcs.cfg' to 'ai_grunt-rush.cfg', I don't think I touched its content at all while working on the specialized version.
FAAB wrote:These two changes would require some C++ coding from developer interested in helping AI Demos.
Actually, the latter (additional console output) I can do in Lua, I think. I'll ask around how hard that option to save replays might be to implement. I definitely like that idea as I've also had the "I wish I knew what happened there" thought.
FAAB wrote:First I think the AI is still protecting some village that are out of reach.
Thanks, that's quite possible. In fact, I have found at least one other bug with the code. I'll go over the whole thing again and will also try to generalize things some more. I'm aware of the enemy_of bit, for example - that's something I did quickly to see if it worked and then never got back to fixing it. I wish I had more time for ... Oh, wait, we said that already. ;)
FAAB wrote:Next it would be good if you could refactor your code so that 'Orcish Grunt' is a parameter given to the functions. This way we could run the same code with different kinds of rush ('Spearman', 'Elvish Fighter', ...) to see how general the code is.
I like that - among other reasons because it's easy to do. And I like the using poison suggestion as well. The rules you suggest are all quite simple to implement, except for the least two. I mean, it's easy if these refer to kills by a single attack. But taking attack combinations into account is not as simple - at least not in 1.10. Once 1.11 is out that will be simplified quite a bit, with some of the modifications that have recently been made to trunk.
FAAB wrote:Here is some code to support AI selection in MP. When selecting the new era, the orc AI is available in the AI selection list.
Wow, that's really cool! I should have known about that... Thanks!

Ok, so here's my suggestion. I'll try to get 0.9.7 out by the end of the weekend, for which I will:
  • Go through the existing code to find bugs and things that might not work on different maps, or with more than 2 players
  • Generalize things so that they work with other units/factions
  • Add the poisoner control
  • Make sure the leader is protected well enough (probably just need to make sure that the default behavior is not overridden for this)
  • Add the MP selection option code
  • Add some additional console output
  • Talk to people about the replay option
Actually, looking at that I don't know if I can get this done by Sunday. But I'll see what I can do.

Thanks again! I'm repeating myself, but this is great! And a lot of fun.
User avatar
Rigor
Posts: 941
Joined: September 27th, 2007, 1:40 am

Re: Exercises in Formula and Lua AI

Post by Rigor »

today i wanted to test it out but i couldnt start the grunt rush game - im using windows 7 while Mint had no such issues, typing in the whole code and it worked for him. he said that the gold you get per village is just 1, instead of regularly 2, which is significantly different. ideas about the center and the left: how hard is it to code the following: if >= 2 units with e.g. 7 movement points can reach my left exposed village, 6 mp away and sit down in it, recruit troops in the lefternmost castle hex. the ai should still have its 2 defender units only on that side so far and this would be the only thing that stops it form continuing the pressure on the right, like in real life ;) he sent me the rp but i got a crash no: line 1295, file src\game_display.cpp assertion failed
mattsc
Developer
Posts: 1166
Joined: October 13th, 2010, 6:14 pm
Location: Hidden on the hex behind Fred

Re: Exercises in Formula and Lua AI

Post by mattsc »

Rigor: Could you try something? Download v0.9.6-a (new as of a few minutes ago). I added the MP era code FABB provided. Then go to MP, select era 'Default+Experimental AI'. If you then start a Freelands game, for the computer player you should now be able to select between 'Experimental Grunt Rush AI' and 'Experimental Grunt Rush AI - for Freelands, Side 1'. Select the latter, set up the sides and see if that works.

The gold thing is interesting. Apparently, if you start the game from the command line, it defaults to 1 gold, rather than 2. I hadn't even noticed. You can change that by adding yet another parameter for each side '--parm 1:village_gold:2 --parm 2:village_gold:2', but I should probably report that as a bug also.
Does anybody know if I can set up a file with all the command-line options, and just give the file as a parameter rather than this whole long rat's tail of options?

Setting up the left-side condition as you suggest is easy, and pretty much what I had been planning to do. I just hadn't gotten around to it yet. As on the right, the hard part is coding the AI behavior once there, so I was waiting for comments on the right-side behavior before doing anything with the rest if the map (because I can probably use either the same or very similar code - in fact, the goal should be to have code that works on both sides). I also need some 'intercept units going straight for the leader through the middle' code, to be able to deal with a suicidal enemy rush of that sort.
User avatar
Rigor
Posts: 941
Joined: September 27th, 2007, 1:40 am

Re: Exercises in Formula and Lua AI

Post by Rigor »

absolutely fantastic and very impressive, matt!

i tried several things to provoke some yes or no behaviour from the AI. look here: the east is very solid, i like the constant reinforcements a lot. the left side was as expected not coded to do smart things, but watch this: passing enemy lines has no effect at all on its movement, which can be good or bad. i think its good in a grunt rush because you need to supply your troops and shouldnt be interrupted. bad thing is that your west can collapse prematurely if there are two pillaging units - otherwise a fast wolf could reclaim the villages very quickly) and the grunt rush cant be supported any longer. the leader does walk out of his keep which is ok when he can kill enemies in sight.

in the case that the left side should be threatened, the orc should in no case stay in the occupied region with all his troops, being cut off from reinforcements during a most unfavorable tod! a complete retreat is smart but not always due to the reasons that a grunt in an enemy village is a good grunt. maybe a gambling factor "stay or go" would be fun to work with in the future, for now try to retreat all units.

something funny i noticed: the urge to execute the grunt rush is so strong that orcish grunts leave own villages on their side when they could attack an enemy whom they could kill with 2 strikes!! maybe tune this wish down a tad bit ;D

the leader should never run around grabbing back villages that a diversive enemy unit might take. being 2 turns away from the keep is always a super bad idea so those vills should get the flag "dont take with leader when the leader is not injured"!!

one more thing: if not everything is finished yet i would implement a time limit for the grunt rush: make it 10 turns: this is the next dusk, that means, a whole attack-defense cycle is completed and the ai should have some kind of advantage that it would not have if it was playing randomly.

something else: this is not generic alright, but its exactly this kidn of tests we need for the ai to find the puzzle pieces how to use units, we are on the right way by testing a specific example. thx for the easy implementation in the wes mp lobby btw, thats really nice!
Attachments
2p_—_The_Freelands ai_replay.gz
aiai
(18.37 KiB) Downloaded 112 times
2p_—_The_Freelands_ai.gz
ai
(15.18 KiB) Downloaded 96 times
mattsc
Developer
Posts: 1166
Joined: October 13th, 2010, 6:14 pm
Location: Hidden on the hex behind Fred

Re: Exercises in Formula and Lua AI

Post by mattsc »

Rigor: Thank you!! I'll work through your comments and suggestions later, and study the replays as well (Btw, the one marked 'aiai' comes up as invalid for me, does it work for you if you re-download it? The other one works just fine. This is a separate issue from the other error message; see below).
Just a few quick comments right now:
Rigor wrote:one more thing: if not everything is finished yet i would implement a time limit for the grunt rush: make it 10 turns: this is the next dusk, that means, a whole attack-defense cycle is completed and the ai should have some kind of advantage that it would not have if it was playing randomly.
It actually already has a time limit, but it is currently 17 turns, which is probably too long? So I'll need to change a single character in the code to do that. ;)
Rigor wrote:thx for the easy implementation in the wes mp lobby btw, thats really nice!
I agree - but I can't take the credit for that. It's entirely FAAB's code. :)

As for this:
Rigor wrote:he sent me the rp but i got a crash no: line 1295, file src\game_display.cpp assertion failed
That seems to be another issue with command-line mode. When I start Wesnoth from command line, the replay crashes with that error. If I start the MP game manually, the replay is just fine. I've reported this on IRC and will file a bug report. Since we can start the AI from the MP lobby now, it's not really an issue for that, however:

FAAB: Unfortunately that means that getting a replay at the end of a --nogui run will be pointless, because it won't work. I have actually been able to "trick" the game into producing a replay save even in all-AI nogui mode, but the replay then crashes with the above error.

Producing additional command-line output on the other hand is easy, anything I output with the print function in Lua will show up there. So, FAAB, if you tell me what you want to see, I'll make it appear. I could even set it up so that that only happens in debug mode, so you'd be able to turn it on and off.

EDIT: Ah, :evil: :augh: :doh:!! I've been trying to troubleshoot the more generic grunt rush code and been getting really frustrated by it just getting slaughtered by the RCA all the time. I guess if I set the command-line options so that the sides get the default 2-gold village income, I should do that for my side also, not just the enemy. :oops:
Sorry, just had to vent for a moment...
mattsc
Developer
Posts: 1166
Joined: October 13th, 2010, 6:14 pm
Location: Hidden on the hex behind Fred

Re: Exercises in Formula and Lua AI

Post by mattsc »

FAAB: I've uploaded a new version of the general Grunt Rush code in v0.9.7. Changes from the previous version are:
  • Added targeted poisoning of enemies
  • Switched the orc recruiting function to that used in the specific Freelands-Side-1 AI, but with some mods so that it isn't dependent on that specific map.
  • Added support for doing the grunt rush with a different unit type (arbitrary faction), if desired. Obviously, this does not work with the orc recruiting candidate action (CA) if the faction is not Northerners, so I added an alternative recruiting routine based on the previous general grunt rush recruiting (with some modifications). Currently these are separate CA's, but they could be combined, of course, with a condition that checks for whether grunts can be recruited. The unit type used for the rush can be passed as a parameter to the CA (and to the village grabbing CA). If it is not provided, it defaults to grunt.
  • One of the mods I made to the old recruiting routine is that it does not take over at Turn 2 any more, but after 3 other units have been recruited by the default CA. This is because on a map with a large keep and 100 starting gold, the gold is long spent before we get to Turn 2.
  • Made a few bug fixes and added all your suggestions; also a couple changes that should ensure that this works on arbitrary maps and with arbitrary number of players.
  • Not yet done is adding more console output. Unfortunately, the game statistics don't seem to be available from in-game, so I cannot do that easily. On the other hand, if you want something like current number of own and enemy units at the beginning of the turn (or even exactly what units those are), that's easy.
After making these changes, I have not seen the grunt rush AI lose any more against the RCA AI for either Side 1 or Side 2 (as long as it doesn't play against the undead; although I have seen it win even against those). In fact, it usually wins by an overwhelming margin and often barely even breaks a sweat. A reasonably typical (details vary by quite a bit) replay save is attached.

However, one of the crucial factors is obviously being able to hire of a lot of cheap units. Thus, the bug not giving 2 village_gold when launched from the command line is a problem and you need to make sure to set village_gold manually if you launch the game from the command line. (If launched from the MP lobby, this is not an issue.) Here's the command line syntax for a game of the Grunt Rush AI vs. Loyalists:

Code: Select all

wesnoth -d -m --controller 1:ai --controller 2:ai --side 1:Northerners --side 2:Loyalists --parm 1:fog:no --parm 2:fog:no --parm 1:village_gold:2 --parm 2:village_gold:2 --ai-config 1:~add-ons/AI-demos/ais/ai_grunt-rush.cfg
If you want to see how the "grunt" rush works with Elvish Fighters, there's a separate AI file provided (it's almost the same, I'm only providing it separately to emphasize how to do it), which can be started with the following command line call (or by choosing the respective AI from the MP lobby):

Code: Select all

wesnoth -d -m --controller 1:ai --controller 2:ai --side 1:Rebels --side 2:Loyalists --parm 1:fog:no --parm 2:fog:no --parm 1:village_gold:2 --parm 2:village_gold:2 --ai-config 1:~add-ons/AI-demos/ais/ai_grunt-rush-Elvish-Fighter.cfg
EDIT: Oops, that was the wrong replay (it had the previously mention crash problem). The one attached now should work. I hope. :oops:
Attachments
2p_—_The_Freelands_replay_-_GR.gz
(14.64 KiB) Downloaded 98 times
Last edited by mattsc on July 1st, 2012, 4:48 pm, edited 1 time in total.
User avatar
Rigor
Posts: 941
Joined: September 27th, 2007, 1:40 am

Re: Exercises in Formula and Lua AI

Post by Rigor »

getting two errors, one for playing the rp, the other for setting up a game with the ai in multiplayer.

it says: "assertion failed, program wesnoth exe and file, strangely, D:\boost_1_46_1/boost/smart_ptr/shared_ptr.hpp

line 412 (u have an idea what THAT could be?)

expression px!=0"

wtffffff ?!?! :mrgreen:
mattsc
Developer
Posts: 1166
Joined: October 13th, 2010, 6:14 pm
Location: Hidden on the hex behind Fred

Re: Exercises in Formula and Lua AI

Post by mattsc »

Rigor: Sorry, I uploaded the wrong replay save. I edited the post. It should work now.

As for the other error, I have no idea right now what that might be -- and I'm on my way out the door. So unfortunately that will have to wait until I am back tonight. Sorry...
mattsc
Developer
Posts: 1166
Joined: October 13th, 2010, 6:14 pm
Location: Hidden on the hex behind Fred

Re: Exercises in Formula and Lua AI

Post by mattsc »

Rigor: thanks much for pointing me to the problem and for the live demonstration of the weaknesses and faults of the current version.

All: The problem causing the crash was a simple typo (and the reason why I had not found it before was because it was in the specialized Freelands AI, rather than the new generic grunt rush). :doh: It's fixed now - and the poisoning code has been added to the Freelands-Side-1 AI also. See v0.9.8.

Rigor: I'll get going on the improvements next. Some of them are easy, so there'll probably be another release quite soon, while some take a bit more work. I'll post incremental updates here. Thanks again, that was very educational. :)
Post Reply