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
mattsc
Inactive Developer
Posts: 1217
Joined: October 13th, 2010, 6:14 pm

Re: Exercises in Formula and Lua AI and AI-demos add-on feed

Post by mattsc »

Thanks for testing the new version too, Rigor, and for the comments and replays! I’m on the road and need to keep it short, so just saying briefly that I hear what you’re saying and will be working on it. Just picking one of the points: I agree that the leaving units stranded after attacks and village grabbing is a problem. It’s better than it used to be, but I’ve not figured that one out yet and will keep working on it. As for this:
Rigor wrote:matt, how much prior info for freelands is in that script of yours? could i try it in world conquest i wonder (i tried but cant see the smart AI playing because theres too much of the AI and too few vills)? whats required to make it work? is there some quick fix to make it work quick and dirty style? :lol:
Oh, right, I meant to reply to your previous related question along and forgot. :P
Rigor wrote:On another note, Id like to know how well does an integration of critical map specific position influence the behaviour? something like "this is important, try to hold it at more cost than you would any other position"? i think this would be key to improving the behaviour by prior knowledge. every smart player can tell you where a retreat makes no sense or where one should move to squeeze the life out of the opponent.
Essentially what I am telling the AI at the moment is: here are the three “zones” of the map, each of them has one or two “key hexes” and a direction (or directions, for the “bent” zones) in which to advance in it. The key hexes aren’t specifically protected, they are in order to figure out how big the threat in that zone is, but there is a simplistic "weight map" for where in the zone you would want to be, if all else (terrain, enemy threats, etc.) were equal. The AI then figures out on its own where to prioritize, how far to advance, and what the best hexes for forming a defensive line are. In addition, there are two map-wide zones, one for protecting the own leader, and one for (eventually) moving in on the enemy leader.

So to answer your two question: I’m sure the behavior could be improved with additional map-specific information. I’ve been trying not to do this too much (because I do want Fred to be able to play other maps, in the end), but there’s certainly enough in there (because it’s hard to make the AI figure it all our by itself) that putting Fred on other maps at this stage won’t work very well at all. It’s my goal to get there, eventually, but it’s not ready for that yet, even quick and dirty style.
name
Posts: 575
Joined: January 6th, 2008, 3:32 am

Re: Exercises in Formula and Lua AI and AI-demos add-on feed

Post by name »

Speaking of the zones, I suggest significantly reducing the priority of the center zone. It is not at all a hard place to defend and the lack of villages makes it a low value target anyway. Even one defender deployed to the northern village could be enough unless and until the enemy gets heavily involved there. And then only committing the defenders needed to hold the line should be best because this presents an opportunity to attack the eastern villages.

Against RCA, this priority shift might mean Fred only wins 297 out of 300 games, because slightly more gryphon or horseman assassination attempts actually get through, but against an intelligent opponent, much greater peril comes from unit and village attrition on the sides of the map.
User avatar
Rigor
Posts: 941
Joined: September 27th, 2007, 1:40 am

Re: Exercises in Formula and Lua AI and AI-demos add-on feed

Post by Rigor »

I remember the beginning of this AI experiment, and how we discussed how to tell the AI to go all in or not. Not was what makes this AI so special. It was a very interesting thought that the AI should kind of try to estimate to "do it" or "leave it". As the code grew more sophisticated, other options came up, but this is still a central theorem for both AI and human player alike.

If i recall correctly, we were either counting total firepower given to the units to kill stuff, or the total HP of the enemy, or the total probability to get one or more safe kills, which is what makes an assault really successful. Half-dead units are good for nothing and the reason why the AI always dies, and the same is true for noobs who think they just wore down the enemy only to find the enemy fights back :lol: with 1-10 hp units, kills stuff and hides his weaklings behind the full hp units standing on dead soldiers. one of my fav strategies :eng: So this would be my approach to stop the AI from losing one or two units for nothing just because CTK was high.

you can find a similar idea here: https://software.intel.com/en-us/articl ... es-part-3/

Image
Figure: Borrowed this from http://www.raywenderlich.com/24824/intr ... -for-games

Code: Select all

    Type of conflict. Units, buildings, or both
    Capabilities of units. Hits ground or air or both
    Numbers. How many where encountered
    Strength. How much damage potential is in this area
sounds familiar?

so what i want to say here is, this has not been completely resolved yet. human players evaluate the situation, sometimes for the better and sometime for the worse, but the AI doesnt do that properly. How could this work then?

check time of day for enemy player. if disadvantageous to alignment, reconsider options (stronger input of dont do it code)
if thats fine,

check CTK on one particular unit. If its over (and this could vary to make the AI less predictable) 65%, attack. If below, just dont attack it.
if thats fine,

check total HP in a certain area where the battle takes place. lets say on one hex as epicenter, 6 hexes are counted to all sides, and the units in this area have 200 HP. Then, the AI evaluates own troop strength if it moves all troops into an attack. This would work like this: The troop closest to the enemy (count hexes) is used as epicenter for HP evaluation. And now: The unit hex-hexes to enemy is used to calculate how the local power will look like, lets say 150 only. So a good chance to beat one unit would no longer be an incentive to try to kill it when you know there are 10 other units behind it. :evil: Working with an epicenter-of-target-approach this might work also for chaotic maps without a particular shape.

I do still believe expert knowledge should be integrated in the AI code for 1v1 maps but a movement to generic maps such as in WC is possible in the future. Just dont give it up =) i am sure it will be possible and we all will love the results :))) :D
User avatar
UnwiseOwl
Posts: 516
Joined: April 9th, 2010, 4:58 am

Re: Exercises in Formula and Lua AI and AI-demos add-on feed

Post by UnwiseOwl »

It's been a while and maybe I was doing it wrong, but I fired up Fred vs Ron on 1.11.16 today and after the first turn Fred forgot how to recruit. Version problem, or user issue?
Attachments
2p_—_Hamlets_replay.gz
(16.59 KiB) Downloaded 542 times
Maintainer of the Imperial Era and the campaigns Dreams of Urduk, Epic of Vaniyera, Up from Slavery, Fall of Silvium, Alfhelm the Wise and Gali's Contract.
But perhaps 'maintainer' is too strong a word.
mattsc
Inactive Developer
Posts: 1217
Joined: October 13th, 2010, 6:14 pm

Re: Exercises in Formula and Lua AI and AI-demos add-on feed

Post by mattsc »

Hi UnwiseOwl. Good to see that you are back!

I'm confused though. Hamlets? How did you get Fred to play anything but Side 1 on Freelands? I just tried and he tells me that he doesn't know how to do that, so you shouldn't even be able to start the game. This is with Wesnoth 1.11.16 and AI-demos 0.13.3 (+dev, but that should not make a difference for this).
User avatar
UnwiseOwl
Posts: 516
Joined: April 9th, 2010, 4:58 am

Re: Exercises in Formula and Lua AI and AI-demos add-on feed

Post by UnwiseOwl »

Whoa, wrong file! Sorry!
'twas Freelands, file attached.
Attachments
2p_—_The_Freelands_replay.gz
(14.61 KiB) Downloaded 542 times
Maintainer of the Imperial Era and the campaigns Dreams of Urduk, Epic of Vaniyera, Up from Slavery, Fall of Silvium, Alfhelm the Wise and Gali's Contract.
But perhaps 'maintainer' is too strong a word.
mattsc
Inactive Developer
Posts: 1217
Joined: October 13th, 2010, 6:14 pm

Re: Exercises in Formula and Lua AI and AI-demos add-on feed

Post by mattsc »

Hey All: I wrote a first attempt at a custom AI that deals with the well-known "feature" that the default AI does not attack enemy units 1 XP from leveling. It is posted in a different thread where this problem was raised for a specific mainline scenario, but I thought I mention it here also as those of you following this thread seem interested in AI issues ...

PS: UnwiseOwl: Oops, I had not noticed yet that you have now posted the correct replay. I will look at that sometime (soon, I hope) ...
mattsc
Inactive Developer
Posts: 1217
Joined: October 13th, 2010, 6:14 pm

Re: Exercises in Formula and Lua AI and AI-demos add-on feed

Post by mattsc »

Hey folks,

So after taking almost a year off from Fred, I got back to him a couple months ago. Sometimes taking a break helps. I changed a lot of things, and Fred isn't the same orc (or troll) any more that he once was. For the first time ever (well, since the early very simple versions, at least), I am not unhappy with what I am seeing, at least when he's playing against the Default AI. Sure, he still makes mistakes, some worse than others, but he is much more consistent and does not make the really bad mistakes all the time any more. On the other hand, he is definitely not a grunt rush AI any more.

So I think it is time to introduce Fred to a larger audience and have opened another thread in the Multiplayer Development forum.

I'll leave it at that for now. I'd still like to keep technical discussions of Fred - as well as discussions of other AIs - here, but hope that the other thread will encourage a few new people to do some play testing.

Cheers,
mattsc

v0.14.0 changelog

Code: Select all

- Fred (Freelands AI for Northerners, Side 1):
  - Complete overhaul with huge changes to both the overall strategy and the
    individual actions, as well as to many of the utility functions
  - AI id renamed from 'grunt_rush_Freelands' to 'fred', as it really is not a
    grunt rush any more
  - Reintroduce restriction that Fred can only play Northerners. This is
    technically not necessary, but I want to concentrate on that faction for now.
    This restriction will be removed again later.
  - Lift fog at beginning of MP game if it is on. This is also a temporary
    measure for testing right now.
  - Set name and id of side leader to 'Fred' in MP game
  - Add menus at SP scenario start to choose human player/AI and enemy gold
  - Have Fred's messages show up in both MP game and SP scenario
  - Add some trash talk easter eggs
- Fast Micro AI:
  - New version that uses fred_attack_utils and gamestate functions rather than
    battle_calcs.lua. This is faster in many cases.
- High XP Attack Micro AI:
  - Added first version of an AI that deals with attacks on enemy units that are
    very close to leveling
- Test scenario:
  - New flag 'exec_loop'
- Miscellaneous:
  - Rename the AIs in the MP setup menus
  - All AIs: don't include mainline AI macros if they have already been loaded
  - ai_helper: only display checked action error message in debug mode
  - Many other changes, some visible, some internal. See git repository for details.
Post Reply