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
Quitch
Posts: 69
Joined: January 10th, 2006, 2:32 pm

Re: Exercises in Formula and Lua AI

Post by Quitch »

One thing I noticed in my most recent game is that the AI doesn't appear to take beserk into account when considering threat. The undead kept placing dark adepts within range of my beserkers and giving me free XP as it couldn't fight back.
name
Posts: 575
Joined: January 6th, 2008, 3:32 am

Re: Exercises in Formula and Lua AI

Post by name »

Quitch wrote: Also thanks to you, and all the others, working on this as well. People like me greatly appreciate your efforts :)
Same here!

I can't imagine a more massively better way to improve Wesnoth from where it is now, than by working towards such big improvements in the AI. I started getting excited about this when I saw so many of the GSOC proposals were for AIs, with so many focused on improving defense, and now they are starting to get integrated.
User avatar
Crow_T
Posts: 851
Joined: February 24th, 2011, 4:20 am

Re: Exercises in Formula and Lua AI

Post by Crow_T »

One thing I noticed in my most recent game is that the AI doesn't appear to take beserk into account when considering threat. The undead kept placing dark adepts within range of my beserkers and giving me free XP as it couldn't fight back.
Spoiler:
Also, it seems that allied ai has a tendency to take a bath- they always seem to end up in the water against land opponents.
mattsc
Inactive Developer
Posts: 1217
Joined: October 13th, 2010, 6:14 pm

Re: Exercises in Formula and Lua AI

Post by mattsc »

Hey all, thanks for the continued comments. You're right, neither of the new AIs (Experimental AI, Ron, Fred) take berserk (or drain) into account yet, other than through the parts that are taken from the default Wesnoth (RCA) AI. The RCA AI attack calculation actually does take it into account, but only for rating attacks relative to each other. So if the best attack comes out to be one of the situations you describe, it will (generally) do that one. Berserk and drain considerations are on the list of things to be added to Ron/Fred soon.

As a side note, a lot of the situations you describe deal with placing units so that counter attacks on the next enemy turn do the least damage. That's really hard to do correctly (not in principle, but for computation time reasons because there are so many possible combinations). We're working on faster, approximate methods of dealing this (some moves do already, such as those involving the side leader), but it's also still work in progress.
User avatar
Crow_T
Posts: 851
Joined: February 24th, 2011, 4:20 am

Re: Exercises in Formula and Lua AI

Post by Crow_T »

Crow_T: Thanks. As for maps, the different AIs use all kinds of maps. There are sub-maps that simply split up the scenario maps into sections, such as what's happening on Freelands (as Rigor describes). Then there are maps that do ratings based on terrain, own and enemy strength, distance from something, etc. Some of them are pre-defined, some of them the AIs figure out themselves. Ideally, we'll eventually have an AI that can figure it out all by itself to some extent, but where the scenario designer has the option of adding pre-defined maps in order to improve play on a certain map. So I think that (some of) this is along the lines of what you are thinking. If you have more concrete ideas, by all means, please let us know.
I can give a graphical mockup if that's what you are asking, code-wise I'm pretty much useless :|
User avatar
Alarantalara
Art Contributor
Posts: 786
Joined: April 23rd, 2010, 8:17 pm
Location: Canada

Re: Exercises in Formula and Lua AI

Post by Alarantalara »

Ron now takes advantage of the healer support micro AI to a small extent. While it wasn't enough to win in this game, it did manage to heal some units that would otherwise remained injured.
Attachments
2p_—_Hamlets_replay.gz
(24.64 KiB) Downloaded 458 times
User avatar
Crow_T
Posts: 851
Joined: February 24th, 2011, 4:20 am

Re: Exercises in Formula and Lua AI

Post by Crow_T »

This healer support thing is huge, lately I've been playing UMCs where the white mages/druids/etc. get thrown to the front lines only to get slaughtered the next turn. Is there a way to get them to attack a unit only if there is both a high chance to kill, and a high chance to be defended afterwords?
User avatar
Alarantalara
Art Contributor
Posts: 786
Joined: April 23rd, 2010, 8:17 pm
Location: Canada

Re: Exercises in Formula and Lua AI

Post by Alarantalara »

Of course there is. The full healer support AI only attacks if there is nothing to heal though it doesn't do anything special about attacking. Fred tries for more complete integration of attacking and defending so does a better job of keeping units defended though there isn't anything special about healers there yet. Some combination of both is needed to do what you want.
AI
Developer
Posts: 2396
Joined: January 31st, 2008, 8:38 pm

Re: Exercises in Formula and Lua AI

Post by AI »

Replay using Fred 64ce829 and wesnoth 1.11.2-131-gc30e960, versus RCA AI with +4 income. Fred is making quite a few mistakes with the positioning of units near villages (but, of course, wins anyway).
Attachments
2p_—_The_Freelands_replay.bz2
(17.1 KiB) Downloaded 472 times
mattsc
Inactive Developer
Posts: 1217
Joined: October 13th, 2010, 6:14 pm

Re: Exercises in Formula and Lua AI

Post by mattsc »

Thanks, AI. I will extract those situations for test cases.

A comment to those of you who don't follow the discussion on IRC: Fred 64ce829 is an intermediate development version that has known problems. I've made some changes to the inner workings and am getting back to trying to improve the actual behavior. AI's replay contains specific examples of things going wrong for me to work with. I am hopeful that we'll be able to release a new version soon(ish).
Anonymissimus
Inactive Developer
Posts: 2461
Joined: August 15th, 2008, 8:46 pm
Location: Germany

Re: Exercises in Formula and Lua AI

Post by Anonymissimus »

lossless victory me vs Fred v0.12.2-301-gb56311b on wesnoth 1.11.2-282-g116778e
I think it doesn't cope quite well with my defensive style. On my right side it looked as if it wanted to rush all the time but never did.
things to improve:
-Throughout the game, from the point on when it first decided to not attack, the candidate action zone_control took very long to process (sometimes more than 100 secs). It's kind of painful.
-It completely left alone its leader in the end by sneaking the surviving units along the map edges.
Attachments
2S_–_Freies_Land_Wiederholung_anzeigen.zip
(22.8 KiB) Downloaded 428 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 »

AI-demos v0.12.3 has been released.

The main reason for this release is that some of the mainline Micro AI syntax was changed in a non backwards compatible way from Wesnoth 1.11.2 to 1.11.4 and that some of the MAI scenarios of AI-demos v0.12.2 do not work with 1.11.4 any more. Of course, the opposite is now true too: these scenarios now require 1.11.4 or later to work. All of this only affects (some of) the MAI test scenario, the MP AIs should be unaffected.

The main reason why it's been so long since the last release is that none of us has much time at the moment to work on the AIs, so Fred is still not doing as well as we'd like him to do. Don't get me wrong, lots of progress has been made and things are getting better, but there are still plenty of problems, such as those observed by Anonymissimus. We are (very) slowly working on this...

A lot of other changes, additions and improvements have been made. A few notable examples:
  • Two new Micro_AIs (which are already in mainline): Goto and Zone Guardian
  • A simple Lua AI Demo scenario that can be used as a template for people who want to write their own Lua AIs. (This might be separated out to its own add-on at some point.)
  • The test scenario can now be started from the command line using the -t aid_test option.
Full changelog for v.0.12.3

Code: Select all

0.12.3, 6 June 2013
- Generic Rush (Ron)
  - Improve village grabbing by leader when lacking gold to recruit
  - New Retreat CA based on ideas from Fred
    - Covers all regenerating units
    - Moves to any healing terrain (like oases)
    - Accounts for unit defense (so aquatic villages are not taken when alternatives exist for land units)
    - Does not cover multi-turn movement to healing
  - New Move to Enemy CA if enemy has no visible leader and we already have all villages
  - New Village Hunt CA to prioritize villages when AI doesn't have an advantage in villages
  - Use healer support micro AI to improve healer placement
- Freelands Side 1 Grunt Rush (Fred)
  - Changed retreat logic to match that of the generic rush
  - Remove north-south dependence of various CAs -> in principle Fred is now able to play any map
  - Add an "enemy_leader" zone that takes care of any unit not moved in one of the other zones
  - Add approximate method for counter attack calculation (much faster than exact method)    
  - Take exposure to counter attacks into account for units other than side leader for most possible moves
  - Don't retreat injured units at beginning of zone moves, unless they can retreat to a safe healing location (village)
  - Lots of adjusting, fine-tuning and bug fixes of rating functions throughout the CAs
  - Add stop_unit CA that takes MP and attacks away from units at end of custom (non_RCA) CAs, so that the 
    RCA AI doesn't do something we don't want with them.
- ai_helper:
  - get_attack_combos: Use much more efficient method to find list of possible attacks
  - get_attack_combos_subset: new method for finding attack combinations (it selects fewer combos and is 
    configurable with a number of cutoff criteria)
  - New functions print_ts() and print_ts_delta()
- Micro AIs
  - Remove code that is now also in mainline and use mainline functionality instead
  - Switch syntax for SUFs/SLFs to [filter]/[filter_location] and variants thereof (requires BfW 1.11.4)
- Healer Support MAI: add optional SUF for healers
- New Goto and Zone Guardian Micro AIs
- New scenarios:
  - Liberty - The Raid: test scenario for mainline scenario with new AI for wolf rider side
  - Simple Lua AI Demo: meant as template for people to use for Lua AI development
- Test scenario:
  - Can now be started from commandline with 'wesnoth -t aid_test'
  - Add test engine and candidate action
- Switchboard scenario
  - Indicate which AIs are in mainline and which are not
  - Add signpost and right-click options for new scenarios/AIs
- General:
  - Add tags for all releases
  - Change to new 1.11.2 and later syntax and functionality:
    - AI_CA_LEADER_SHARES_KEEP macro
    - leader_shares_keep CA
    - ai_default_rca for RCA AI
    - wesnoth.get_time_stamp()
  - Run wmllint, fix problems found and add exceptions, where necessary
  - Clean up textdomain definition and bindings
User avatar
doofus-01
Art Director
Posts: 4128
Joined: January 6th, 2008, 9:27 pm
Location: USA

Re: Exercises in Formula and Lua AI

Post by doofus-01 »

Hi,

Using 1.11.4, so this may already be fixed, but it looks like there is a problem with "return guardian" micro_ai. I got this with your test scenario ("wesnoth -t micro_ai_test", not an add-on), I think it happened because I blocked the AI troll from returning to its post on the turn after it attacked, but I'm not sure.

I don't know what this means, so I don't know if it is enough to be helpful, but this is what I got:

Code: Select all

20130610 17:40:20 error scripting/lua: /usr/local/share/wesnoth1114/data/ai/lua/ai_helper.lua:959: attempt to index local 'x' (a nil value)
stack traceback:
        /usr/local/share/wesnoth1114/data/ai/lua/ai_helper.lua:959: in function 'movefull_stopunit'
        ...esnoth1114/data/ai/micro_ais/ais/mai_guardian_engine.lua:130: in function 'return_guardian_exec'
        [string "(...):return_guardian_exec({ ["id"] = "return..."]:1: in main chunk
BfW 1.12 supported, but active development only for BfW 1.13/1.14: Bad Moon Rising | Trinity | Archaic Era |
| Abandoned: Tales of the Setting Sun
GitHub link for these projects
mattsc
Inactive Developer
Posts: 1217
Joined: October 13th, 2010, 6:14 pm

Re: Exercises in Formula and Lua AI

Post by mattsc »

doofus-01: The return hex being blocked was indeed the reason why this happened and it had not been fixed yet. And yes, that error message together with your description was exactly what I needed. Thanks for reporting!

It's fixed in trunk now and will be in the next release (1.11.5).
User avatar
Coffee
Inactive Developer
Posts: 180
Joined: October 12th, 2010, 8:24 pm

Re: Exercises in Formula and Lua AI

Post by Coffee »

I'd like to say that the work here is excellent, mattsc.

With a currentish 1.11.4+dev(git) version and the latest default+experimental era I found some interesting (buggy) play with ExpAI Fred: Rush AI for Freelands Side 1. Attached is a replay from a game where AI plays side 1 and I play side 2 with only half the gold of the AI. The AI plays poorly and I win without losing a unit. My RAM was maxed out by the end turns and the AI steadily took longer for each move, taking about 10 seconds for each move at the end. Mabye it is similar to what Anonymissimus has posted.
Attachments
2p_—_The_Freelands_replay_vs_AI.gz
(17.01 KiB) Downloaded 414 times
Post Reply