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
nelson
Posts: 91
Joined: March 19th, 2008, 11:15 pm
Contact:

Re: Exercises in Formula and Lua AI

Post by nelson » September 6th, 2012, 7:26 pm

Just so you don't get discouraged, here's one where Fred defeats RCA drakes with 150 +2 gold. Mostly it is because Fred succeeds in stealing all of the eastern villages, negating all of his other mistakes, as well as some nice luck.
2p_—_The_Freelands_replay_Fred_crushes_RCA_drakes.gz
Fred kills RCA drakes with 150 +2 gold.
(22.16 KiB) Downloaded 137 times
8. Center: Trapping the burner is good, but leaving the village next to him empty is a TERRIBLE MISTAKE! Putting even an injured unit in that village would be better.

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

Re: Exercises in Formula and Lua AI

Post by Rigor » September 6th, 2012, 8:13 pm

oh my! well, nelson, seems you are a good story teller, thats good :geek: . but you know whats better - if you could cut yourself short and transform the fred does this and fred does that (which are observations) into fred "code" which could look like this or like that in order to deal with ....the things you just described!!! i try to think like the machine which receives these bits of information to form a powerful engine that can deal with smartass players like you and me :lol2: but be aware that some of your suggestions are on a level far above the ais orders such as:

:eng: "if the fencer wants to move...then you should block the good terrain" how should the ai know what you want to do? ^_^
:eng: "Fred should..." why should he, whats the trigger, whats the reason, how to tell?
:eng: "either attack or heal..." when to attack, when to heal, try to find a generally good approach todo this or that, use examples and think of the general usability.
:eng: "focus fire" that might be a good idea in one situation and a very bad one in another. example: good use during night, bad use during day: you could deliver unspecific damage with assassins and archers to a lot of units, while focus fire would make all the assassins and archers go for just one unit. see what i mean? perhaps make it tod dependent, in which case you again need additional parameters to work rather good.
:eng: "should have taken the risk" oh yeah? :mrgreen: and why should he have done that? is fred losing, how to tell? is there some mathematical equation you can think of that would help making the all or nothing decision to risk attacking a leader in a bad game?
:eng: "terribe mistakes" hopefully only one or not more than 2 terrible mistakes that decide the game happen in one, those might be good points to start from to reshape the AI.

so, once again, battle reports will have the value they deserve when the testing players have an extremely interesting kind of behaviour that can possibly be changed with just a few lines of code.

focus on those rare (?) events - post screens if you can, and describe how you propose to change this weird behaviour into good behaviour. ok?

machine tactics follow a reasoning. units dont just attack hopelessly because they are silly, they probably have the ulterior motive to kill a threat to the king. however, if you dont know you just see the lousy result. a more helpful approach would be to give the ai directions in which mostly a certain pattern (heal units even though your king is in grave danger) is a good idea. probably in certain cases this will be exactly the opposite of a good idea and then again we all will think "what a truly dumb move."

User avatar
Alarantalara
Art Contributor
Posts: 782
Joined: April 23rd, 2010, 8:17 pm
Location: Canada

Re: Exercises in Formula and Lua AI

Post by Alarantalara » September 7th, 2012, 12:02 am

Adding a replay of a game where nelson demonstrates how a grunt rush should be done so we have a positive example to work from.
Attachments
2p_—_nelson_rush_replay.gz
(23.63 KiB) Downloaded 126 times

nelson
Posts: 91
Joined: March 19th, 2008, 11:15 pm
Contact:

Re: Exercises in Formula and Lua AI

Post by nelson » September 7th, 2012, 12:59 am

Hey Rigor, I'm aware of the need for more "rigorous" testing/analysis :) Right now I'm more trying to get an overview of the classes of problems that the AI has, and a feel for what its highest-priority mistakes are. I just had a long discussion in IRC (#wesnoth-umc-dev) with mattsc about specific test cases and how Fred should deal with a few precise situations, and we will have more of those as we move forward. I welcome more posts like your last one, that was very helpful!

User avatar
Alarantalara
Art Contributor
Posts: 782
Joined: April 23rd, 2010, 8:17 pm
Location: Canada

Re: Exercises in Formula and Lua AI

Post by Alarantalara » September 7th, 2012, 2:42 am

Rigor (or anyone else who cares to answer), if you didn't need scouts, what are the reasons you might buy Wolf Riders early in the game?

Edit: Added two games vs drakes which prompted the question.
Attachments
2p_—_drakes_2_replay.gz
(20.53 KiB) Downloaded 140 times
2p_—_drakes_1_replay.gz
(30.57 KiB) Downloaded 127 times

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

Re: Exercises in Formula and Lua AI

Post by Rigor » September 7th, 2012, 6:03 am

u woke my ambition...

the game is far from lost what is this for a give up mentality :lol2:

as to the exemplatory grunt rush where i took the replay from, well of course human players dont really need to do the gobo recruit so early in game because they mostly can control the other human player by placing units in front of his left vills in such a way that his opponent will for a longer time not get the opportunity to steal anything - but code that for the ai, it could take longer than anything else. it is a prevention of getting owned too early at the cost of half a lacking reinforcement on the right or elsewhere and worth the money.

about scouts: they not only scout, they deal three strikes, and when its night not too bad kind of dmg. whats more, they force the opponent to be careful about the stealing opportunities they could get away with too! the ai can steal villages, therefore its good to have scouts in the first recruits. i imagine the following unit composition on the left to be ok when actually focusing on the right: 2 grunts, 1 assassin 1 wolf. together with the gobo who joins the crowd, you have a batallion that can effectively threaten to attack anything on the left from multiple hexes with a good chance to kill while all troops are needed on the other. that means there wont be more than 2 at most 3 units to defend.

getting those recruits might require fred to play so good that he will survive not only his own grunt rush but the following counter.

in the replay we saw nelson doing what i suggested about grunts: deal unspecific damage with archers, assassin, and place a grunt/troll that does not attack right next to those specialists so they dont get hurt. when you attack, you could do the same by placing units next to a village and not attack with the meatshields while the specialists deal their safe damage. its a good strategy.
Attachments
2p_—_The_Freelands_Turn_16R.gz
alantara..tsk tsk tsk
(38.2 KiB) Downloaded 144 times

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

Re: Exercises in Formula and Lua AI

Post by Rigor » September 7th, 2012, 6:17 am

by the way seems there is an AI arena out there since version 1.11 is out:

http://svn.gna.org/viewcvs/*checkout*/w ... /changelog

AI
Developer
Posts: 2394
Joined: January 31st, 2008, 8:38 pm

Re: Exercises in Formula and Lua AI

Post by AI » September 7th, 2012, 1:26 pm

I'm not sure what this replay means, but I think fred might be able to learn something from it. (github fred on a week-old wesnoth trunk)
Attachments
Freelands_Overrun_Fred.gz
(15.44 KiB) Downloaded 134 times

nelson
Posts: 91
Joined: March 19th, 2008, 11:15 pm
Contact:

Re: Exercises in Formula and Lua AI

Post by nelson » September 9th, 2012, 1:40 am

Hey folks, I've been playing some games as P1 Orcs on Freelands just so I could give you some sample replays to show you how orcs should be played (and how orcs should NOT be played). Here are some games I lost:
2p_—_The_Freelands_Turn_18_replay_My_freelands_orcs_lose_to_YAMADA.gz
My orcs lose to YAMADA's Loys with Red Mage
(27.55 KiB) Downloaded 127 times
- YAMADA's picked Loyalists with picked Red Mage leader beat me. I believe I lost because I rushed a Red Mage. He just killed everything and leveled his units, eventually offsetting my income advantage. Against a scary leader like that, you have to wait until you have enough units to attack multiple sides at once, so that he has to choose what front to use his Red Mage on. We have to teach Fred to be cautious when facing deadly leaders.
2p_—_The_Freelands_replay_my_orcs_lose_to_drakes.gz
My orcs lose to Alarantalara's drakes (with some misdirection in the opening)
(28.96 KiB) Downloaded 136 times
- Alarantalara's Drakes beat me. This is partly because he said he would attack like an overly aggressive AI, and I believed him and went defensive, which threw off my initial rush. We have to teach Fred to not commit units to defending the center if there is not a serious threat, it's better to send units on to the rush on the right and use reinforcements to shore up the center if a real enemy attack develops there. Also, retreat as day approaches :P

UPDATE: Oh, Alarantalara already posted our drake games, oh well.
Last edited by nelson on September 9th, 2012, 2:07 am, edited 3 times in total.

nelson
Posts: 91
Joined: March 19th, 2008, 11:15 pm
Contact:

Re: Exercises in Formula and Lua AI

Post by nelson » September 9th, 2012, 1:45 am

And here are some games I won as P1 orcs on Freelands:
2p_—_The_Freelands_replay_my_orcs_kill_drakes.gz
My orcs kill Alarantalara's drakes
(20.89 KiB) Downloaded 134 times
- I defeat Alarantalara's Drakes. Partly it is because I got a bit lucky in my initial attack and took out his village-holding clasher quickly, but I had 3 hexes at night so it wasn't shocking. I also took the center village from an augur that first night, and from then on my income advantage was punishing. Also I poisoned his leader and trapped him outside of a village, and he couldn't afford an augur to keep him alive :)
2p_—_The_Freelands_replay_nelson_beats_darkiller.gz
My orcs kill darkiller's elves.
(17.29 KiB) Downloaded 144 times
- I defeat darkiller's Rebels. I killed his village-holding elf archer while it was still dusk, and then at first watch took two villages on the right and stole a village on the left. Then I trapped his leader outside his keep, and went and recruited on his keep just to rub it in :)
2p_—_The_Freelands_replay_nelson_v_Edicka.gz
My orcs beat Edicka's Knalgans.
(17.18 KiB) Downloaded 138 times
- I defeat Edicka's Knalgans. His biggest mistake was surrendering villages to me when it was not absolutely necessary to do so. I got him to do that by threatening to kill a mortally injured unit that was about to level, which caused him to shield it, and by generally threatening to grab as many villages as possible so that when he moved off of a village to fight, I was able to steal it. I gained a deadly income advantage and poisoned his leader (and many other units), which ultimately led to his assassination when he ran out of shields.
2p_—_The_Freelands_replay_nelson_beats_Schlamarcel.gz
My orcs beat Schlamarcel's Undead.
(16.59 KiB) Downloaded 128 times
- I defeat Schlamarcel's picked Undead. Schlamarcel spammed low-damage units like ghosts and zombies, but these were decent shields for his DAs I must admit. I was able to take villages, however, and once I stole 3-4 villages he was pretty doomed. Luck was on his side initially, but when it swung back to my side he surrendered. Note that I initially put my forces on the left instead of rushing the right, because I expected him to rush me the first night.

mattsc
Posts: 1068
Joined: October 13th, 2010, 6:14 pm
Location: Wandering, mostly aimlessly

Re: Exercises in Formula and Lua AI

Post by mattsc » September 30th, 2012, 2:14 pm

AI-Demos v0.11.0 is on the add-ons server, featuring the introduction of [wiki]Micro AIs[/wiki]. From the wiki page:

"Mirco AIs add specific functionalities to a side's AI that can be added to a scenario easily using only a few lines of WML code. Adding (or deleting) a Micro AI is done via the [micro_ai] tag, which also lets the campaign designer configure the AI behavior to the specific need of the scenario."

Currently, there are 2 Micro AIs:
  1. The 'Pass Defense' scenario (now called 'Bottleneck Defense') has been generalized to work on any map (well, any map with a bottleneck). Configuring it to the map requires only the WML [micro_ai] tag, no changes whatsoever to the AI code are necessary.
  2. A new scenario called 'Healer Support', which demonstrates the use of healers to back up injured or threatened units rather than having them attack unconditionally (some of them might still attack, depending on the settings chosen). The aggressiveness (or lack thereof) of the healers can be set via the [micro_ai] tag. Note that an AI with healer support will not necessarily beat one without in an even game, as the AI takes healers away from attacks. It's up to the scenario designer to choose what works best in a given situation.
The goal of the new Micro AI formalism is to let scenario designers set up specialized AI behaviors customized to the need of a scenario with no need for any AI coding knowledge. Only the WML [micro_ai] tag is needed. If you have comments on improvements of the mechanism itself, the existing Micro AIs or suggestions for additional Micro AIs (see also the list at the bottom of the wiki page), please let us know.

For those of you mostly interested in the MP grunt rush AIs, I'll have to ask you for a little more patience. Ron is almost unchanged and while Fred has seen a lot of changes, most of them (except the changes to recruitment; see the changelog below) have been internal refacturing in order to enable real improvements to the AI that were not possible with the previous code structure. So Fred's in a bit of disarray at the moment, with some parts of his tactics improved and some slightly worse than before. Be warned, taking him for a real test run right now is probably not too useful and might lead to frustration. ;) I have another busy week coming up, but after that I will get back to helping poor little Fred stand up to those nasty MP players.
Complete changelog

Code: Select all

0.11.0, 30 Sep 2012
- Introduction of Micro AIs and the [micro_ai] tag
  - This includes a new scenario: Healer Support, which is the first to use the MAI functionality
  - Bottleneck Defense (formerly Pass Defense)
    - Changed code to work as a Micro AI
    - Generalized code to work on any map with a bottleneck
  - See http://wiki.wesnoth.org/Micro_AIs for details
- Generic Rush
  - Do not try to spread poison to undead units
- Freelands Side 1 Grunt Rush:
  - New easy-to-use single-CA testing mechanism
  - Lots of changes to recruit CA, including:
    - Added counter recruiting of troll whelps
    - Reduced number of assassins recruited against undead
    - Do not spread poison to undead units
    - Prefer to avoid poisoning units with magical ranged attacks
    - Improved turn 1 recruit vs undead
  - Increase aggressiveness if there's an enemy around the NW villages
  - Retreat seriously injured units toward villages, even if they are more than one move away
    - As part of that: retreat trolls toward mountains, not villages
  - Complete restructuring of the rush and hold/retreat CAs
    - This will allow for dynamic adaptation to the situation on the map (to be implemented later)
  - Do not poison enemy if enemy could level up on its turn after being attacked
  - Lots of refactoring and tuning of priorities and ratings
- ai_helper:
  - Added functions ai_helper.get_closest_location(), ai_helper.skip_CA(), ai_helper.has_ability()
  - ai_helper.movefull_stopunit(), ai_helper.move_unit_out_of_way(): now works also if unit cannot get there in one move
  - ai_helper.movefull_outofway_stopunit(): only move unit out of way if the approaching unit can actually get there
- Scale background image in campaign menu to avoid horizontal scroll bar
- Added GPL v2+ file (so that it is clear for the github site, mostly)

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

Re: Exercises in Formula and Lua AI

Post by Rigor » October 3rd, 2012, 12:14 pm

very nice!

i immediately tried it with undead of course, here some points to be considered:

orcs do well during day, during night too, but its better if they try to do somethign during day i guess, especially if there are trolls involved. those are often fearless and do most damage during the downtime of the ud. one peculiarity of ud v orcs is that ghosts can be quite the pest. try to attack those wiht two archers if possible, and mostly not melee unless u r on some very high defence ground ;).

i noticed that the ai emphasizes on healing before calculating a ctk on a unit respectively when it calculates how to attack. i mean, this is somethign that no mp player does: retreat an injured unit just because its injured with poison before deciding to attack a villaged ghoul. first should be: can i kill this unit, and if so, use the injured unit if it doesnt die first. if it could die, use another and try to get the vilalge with the injured vilalge which is free after success.

i also saw a ctk on my leader at some point, does the ai know about the leaders value or nto coded yet? if higher than.../or if about to lose the game...attack!

something that is very important in AI improvement: sometimes players like to lure others into attacking a unit which is placed in a manner that its not only disadvantageous to do it but completely displaces the ensnared unit. its is a common multiplayer tactics to do that, and therefore the ai must know about it! so when i put a skeleton on 20% water and there s a troll around, im pretty sure not only the ai but also any noob would take the bait. the ai should follow its own direction and try to have units in the location it wants to be strong in. not on 30% after attacking me and eating all the retaliation while my skel can withdraw and recover in a village. i dont know yet how i would translate this in machine-lingo,could someone plz help?

below the savegame.
Attachments
AI11.0.gz
11.0
(19.97 KiB) Downloaded 128 times

mattsc
Posts: 1068
Joined: October 13th, 2010, 6:14 pm
Location: Wandering, mostly aimlessly

Re: Exercises in Formula and Lua AI

Post by mattsc » October 4th, 2012, 3:36 am

Hey Rigor,

Thanks much for the comments. I'm still pretty busy throughout this week, but hopefully I'll be able to spend a little more time on poor old neglected Fred after that...

I did notice in your replay that the AI spent a huge amount of resources on that ghost in the NW and never got rid of it. But then, you can't just let it roam or it will grab all the villages. So Fred should send archers its way, that's what you're saying, right?

No, specifically attacking the leader is not part of the AI yet. It's in the plan, but not done yet. As are so many other things... :(

As for your last paragraph, the AI does take retaliation into account when it moves the leader away from the keep, but not for other units yet. So the code is there, but I'll have to think about whether that can be implemented in a more general sense. It's very expensive (in terms of computation time). Also, the whole automated decision process is always a problem, of course.
But on a more basic level, I don't think that I have worked out the attack/retreat/defensive line thing yet in a way that I am happy with. That's what I need to do first, I think...

Noted your point about village grabbing vs. retreating as well.

Btw, you said a while ago that you'd be interested in experimenting with other AI applications to MP, but I don't remember you telling me any specifics. I might have just forgotten...

User avatar
Alarantalara
Art Contributor
Posts: 782
Joined: April 23rd, 2010, 8:17 pm
Location: Canada

Re: Exercises in Formula and Lua AI

Post by Alarantalara » October 6th, 2012, 10:31 pm

Ron has a new recruit CA on github.
Here Ron loses to Fred in 30 turn game. It should be reasonably representative of how both AIs play at the moment.
2p_—_The_Freelands_replay.gz
(31.97 KiB) Downloaded 141 times
Edit: To be fair, I also have a game where Ron beats Fred.
2p_—_The_Freelands_replay.gz
(21.16 KiB) Downloaded 138 times

mattsc
Posts: 1068
Joined: October 13th, 2010, 6:14 pm
Location: Wandering, mostly aimlessly

Re: Exercises in Formula and Lua AI

Post by mattsc » October 7th, 2012, 4:22 am

Alarantalara wrote:Ron has a new recruit CA on github.
And so that you do not have to go to github, we just released v0.11.1 which includes that new recruit CA for the generic grunt rush AI (Ron). Alarantalara has made a lot of improvements to it, most notably with the result that it now works not only with any of the mainline factions, but with any recruit list.

Rigor: this means that it should now be possible to use Ron as is for World Conquest.

Fred has mostly seen refactoring, and only minor changes to his behavior since the last release.
Changelog for v0.11.1

Code: Select all

0.11.1, 6 Oct 2012
- Generic Rush:
  - New recruit algorithm
    - Can counter recruit
    - Recruits scouts based on map size
    - Can handle multiple allies and opponents
    - Should work with any faction (though non-standard abilities may not be accounted for or mishandled)
  - No longer freezes when trying to poison units with ghouls
  - Now able to keep playing after leader death
  - Leaders who can poison no longer wander away from their keep
- Freelands Side 1 Grunt Rush:
  - More refactoring, but so far only small changes to behavior

Post Reply