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
mattsc
Posts: 1109
Joined: October 13th, 2010, 6:14 pm
Location: Hidden on the hex behind Fred

Re: Exercises in Formula and Lua AI

Post by mattsc » June 14th, 2013, 1:59 pm

Thanks for testing and posting the replays, Coffee & Anonymissimus! Even though you crushed Fred, I do see a lot of things he does better than he used to. But, of course, there are still plenty of serious problems. The biggest ones I see are:
  • Distribution of units over the three areas of the Freelands map. He emphasizes attacking on the right, which is good, but (still) doesn't protect the left (which is where the player should attack) correctly. And from my own tests: he doesn't protect the middle very well either, if you rush up through there.
  • Staying away from the map borders. The reason for that creep down the side is that the AI tries to minimize counter attack danger from the enemy, which is usually lowest at the edges (because, often, fewer units can attack there and because there are fewer hexes to attack from).
  • I actually think Fred's a little too scared at the moment...
  • Finally, the turns taking so long needs, of course, be fixed.
There are plenty of other things that need to be worked on too, of course, but those are the big ones as seen in your replays. So much to do, so little time ... Thanks again, it does help a lot with motivation to see that people are still interested in this!

PS: Coffee: I know I told you to check out Fred "in a couple weeks" several months ago. Unfortunately, that couple of weeks of work has not happened yet... :P

name
Posts: 396
Joined: January 6th, 2008, 3:32 am

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

Post by name » November 8th, 2013, 7:38 pm

Ron seems to be broken in 1.11.6, at least in part due to file/directory changes to micro ai(s) it depends on.

In addition to not recruiting, Ron spits out a number of lua errors:

Code: Select all

20131108 14:02:13 warning config: add-on 'AI-demos' has no _info.cfg; cannot read version info
20131108 14:02:48 error scripting/lua: ...erdata/data/add-ons/AI-demos/lua/generic_rush_engine.lua:15: bad argument #1 to 'require' (file not found)
stack traceback:
	[C]: in function 'require'
	...erdata/data/add-ons/AI-demos/lua/generic_rush_engine.lua:15: in function <...erdata/data/add-ons/AI-demos/lua/generic_rush_engine.lua:2>
	(...tail calls...)
20131108 14:02:48 error ai/engine/cpp: side 2 : UNABLE TO CREATE engine[lua]
20131108 14:02:48 error scripting/lua: [string "return (...):stats_eval()"]:1: attempt to call method 'stats_eval' (a nil value)
stack traceback:
	[string "return (...):stats_eval()"]:1: in main chunk
20131108 14:02:48 error scripting/lua: [string "return (...):recruit_rushers_eval()"]:1: attempt to call method 'recruit_rushers_eval' (a nil value)
stack traceback:
	[string "return (...):recruit_rushers_eval()"]:1: in main chunk
20131108 14:02:48 error scripting/lua: [string "return (...):castle_switch_eval()"]:1: attempt to call method 'castle_switch_eval' (a nil value)
stack traceback:
	[string "return (...):castle_switch_eval()"]:1: in main chunk
20131108 14:02:48 error scripting/lua: [string "return (...):retreat_injured_units_eval()"]:1: attempt to call method 'retreat_injured_units_eval' (a nil value)
stack traceback:
	[string "return (...):retreat_injured_units_eval()"]:1: in main chunk
20131108 14:02:48 error scripting/lua: [string "return (...):grab_villages_eval()"]:1: attempt to call method 'grab_villages_eval' (a nil value)
stack traceback:
	[string "return (...):grab_villages_eval()"]:1: in main chunk
20131108 14:02:48 error scripting/lua: [string "return (...):spread_poison_eval()"]:1: attempt to call method 'spread_poison_eval' (a nil value)
stack traceback:
	[string "return (...):spread_poison_eval()"]:1: in main chunk
20131108 14:02:48 error scripting/lua: [string "return (...):place_healers_eval()"]:1: attempt to call method 'place_healers_eval' (a nil value)
stack traceback:
	[string "return (...):place_healers_eval()"]:1: in main chunk
20131108 14:02:49 error scripting/lua: [string "return (...):stats_eval()"]:1: attempt to call method 'stats_eval' (a nil value)
stack traceback:
	[string "return (...):stats_eval()"]:1: in main chunk
20131108 14:02:49 error scripting/lua: [string "return (...):recruit_rushers_eval()"]:1: attempt to call method 'recruit_rushers_eval' (a nil value)
stack traceback:
	[string "return (...):recruit_rushers_eval()"]:1: in main chunk
20131108 14:02:49 error scripting/lua: [string "return (...):castle_switch_eval()"]:1: attempt to call method 'castle_switch_eval' (a nil value)
stack traceback:
	[string "return (...):castle_switch_eval()"]:1: in main chunk
20131108 14:02:49 error scripting/lua: [string "return (...):retreat_injured_units_eval()"]:1: attempt to call method 'retreat_injured_units_eval' (a nil value)
stack traceback:
	[string "return (...):retreat_injured_units_eval()"]:1: in main chunk
20131108 14:02:49 error scripting/lua: [string "return (...):grab_villages_eval()"]:1: attempt to call method 'grab_villages_eval' (a nil value)
stack traceback:
	[string "return (...):grab_villages_eval()"]:1: in main chunk
20131108 14:02:49 error scripting/lua: [string "return (...):spread_poison_eval()"]:1: attempt to call method 'spread_poison_eval' (a nil value)
stack traceback:
	[string "return (...):spread_poison_eval()"]:1: in main chunk
20131108 14:02:49 error scripting/lua: [string "return (...):place_healers_eval()"]:1: attempt to call method 'place_healers_eval' (a nil value)
stack traceback:
	[string "return (...):place_healers_eval()"]:1: in main chunk
20131108 14:02:49 error scripting/lua: [string "return (...):village_hunt_eval()"]:1: attempt to call method 'village_hunt_eval' (a nil value)
stack traceback:
	[string "return (...):village_hunt_eval()"]:1: in main chunk
20131108 14:02:49 error scripting/lua: [string "return (...):stats_eval()"]:1: attempt to call method 'stats_eval' (a nil value)
stack traceback:
	[string "return (...):stats_eval()"]:1: in main chunk
20131108 14:02:49 error scripting/lua: [string "return (...):recruit_rushers_eval()"]:1: attempt to call method 'recruit_rushers_eval' (a nil value)
stack traceback:
	[string "return (...):recruit_rushers_eval()"]:1: in main chunk
20131108 14:02:49 error scripting/lua: [string "return (...):castle_switch_eval()"]:1: attempt to call method 'castle_switch_eval' (a nil value)
stack traceback:
	[string "return (...):castle_switch_eval()"]:1: in main chunk
20131108 14:02:49 error scripting/lua: [string "return (...):retreat_injured_units_eval()"]:1: attempt to call method 'retreat_injured_units_eval' (a nil value)
stack traceback:
	[string "return (...):retreat_injured_units_eval()"]:1: in main chunk
20131108 14:02:49 error scripting/lua: [string "return (...):grab_villages_eval()"]:1: attempt to call method 'grab_villages_eval' (a nil value)
stack traceback:
	[string "return (...):grab_villages_eval()"]:1: in main chunk
20131108 14:02:49 error scripting/lua: [string "return (...):spread_poison_eval()"]:1: attempt to call method 'spread_poison_eval' (a nil value)
stack traceback:
	[string "return (...):spread_poison_eval()"]:1: in main chunk
20131108 14:02:49 error scripting/lua: [string "return (...):place_healers_eval()"]:1: attempt to call method 'place_healers_eval' (a nil value)
stack traceback:
	[string "return (...):place_healers_eval()"]:1: in main chunk
20131108 14:02:49 error scripting/lua: [string "return (...):village_hunt_eval()"]:1: attempt to call method 'village_hunt_eval' (a nil value)
stack traceback:
	[string "return (...):village_hunt_eval()"]:1: in main chunk
20131108 14:02:49 error scripting/lua: [string "return (...):stats_eval()"]:1: attempt to call method 'stats_eval' (a nil value)
stack traceback:
	[string "return (...):stats_eval()"]:1: in main chunk
20131108 14:02:49 error scripting/lua: [string "return (...):recruit_rushers_eval()"]:1: attempt to call method 'recruit_rushers_eval' (a nil value)
stack traceback:
	[string "return (...):recruit_rushers_eval()"]:1: in main chunk
20131108 14:02:49 error scripting/lua: [string "return (...):castle_switch_eval()"]:1: attempt to call method 'castle_switch_eval' (a nil value)
stack traceback:
	[string "return (...):castle_switch_eval()"]:1: in main chunk
20131108 14:02:49 error scripting/lua: [string "return (...):retreat_injured_units_eval()"]:1: attempt to call method 'retreat_injured_units_eval' (a nil value)
stack traceback:
	[string "return (...):retreat_injured_units_eval()"]:1: in main chunk
20131108 14:02:49 error scripting/lua: [string "return (...):grab_villages_eval()"]:1: attempt to call method 'grab_villages_eval' (a nil value)
stack traceback:
	[string "return (...):grab_villages_eval()"]:1: in main chunk
20131108 14:02:49 error scripting/lua: [string "return (...):spread_poison_eval()"]:1: attempt to call method 'spread_poison_eval' (a nil value)
stack traceback:
	[string "return (...):spread_poison_eval()"]:1: in main chunk
20131108 14:02:49 error scripting/lua: [string "return (...):place_healers_eval()"]:1: attempt to call method 'place_healers_eval' (a nil value)
stack traceback:
	[string "return (...):place_healers_eval()"]:1: in main chunk
20131108 14:02:49 error scripting/lua: [string "return (...):village_hunt_eval()"]:1: attempt to call method 'village_hunt_eval' (a nil value)
stack traceback:
	[string "return (...):village_hunt_eval()"]:1: in main chunk
20131108 14:02:49 error scripting/lua: [string "return (...):move_to_enemy_eval()"]:1: attempt to call method 'move_to_enemy_eval' (a nil value)
stack traceback:
	[string "return (...):move_to_enemy_eval()"]:1: in main chunk
Regarding the file not found error, line 15 of generic_rush_engine.lua is:

Code: Select all

local HS = wesnoth.require "ai/micro_ais/cas/ca_healer_move.lua"
This directory doesn't seem to exist anymore in 1.11.6, in fact I don't think ca_healer_move.lua exists anymore (as a separate file).

mattsc
Posts: 1109
Joined: October 13th, 2010, 6:14 pm
Location: Hidden on the hex behind Fred

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

Post by mattsc » November 8th, 2013, 9:56 pm

Thanks for the report, Cold Steel. You didn't say which version of AI-demos you are using, but based on the error message I assume it's a very recent version taken from the github site?
Cold Steel wrote:This directory doesn't seem to exist anymore in 1.11.6, in fact I don't think ca_healer_move.lua exists anymore (as a separate file).
Actually, it's the other way around. This directory does not yet exist in 1.11.6. As you say, I've been making a lot of changes to the Micro AIs (the biggest one being that no engine definitions are needed any more and MAIs can be combined at will without extra code) and, believe it or not, also to Fred. But in the process I made some changes to Ron that are incompatible with 1.11.6. Sorry for that, I didn't think about that.

I just made a couple commits that should make Ron and Fred work again in 1.11.6. If you get the last version from github and you still get errors, please let me know. I didn't think anybody was interested in Ron or Fred at the moment given the lack of recent progress, so this is nice to know. :)


PS: Fred isn't worth checking out quite yet. I just made a major change to how defensive unit placement is done. I hope that this will mean some real improvement in the end, but at the moment the rating system is so out of whack that he barely manages to win against the RCA AI. :shock: I hope to have this sorted out by the time 1.11.7 comes out and will then also release a new version of AI-demos for the add-ons server.

name
Posts: 396
Joined: January 6th, 2008, 3:32 am

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

Post by name » November 9th, 2013, 12:52 am

Bah, how could I forget to mention the version. :doh: But you are correct, I did use the latest from github. For some reason, it hadn't occurred to me to look on the add-on server for stable releases of the AIs instead. I should probably post the error log for my brain next...

Ron works fine now on 1.11.6 with your latest changes, thanks!
mattsc wrote: I didn't think anybody was interested in Ron or Fred at the moment given the lack of recent progress, so this is nice to know. :)

PS: Fred isn't worth checking out quite yet. I just made a major change to how defensive unit placement is done. I hope that this will mean some real improvement in the end, but at the moment the rating system is so out of whack that he barely manages to win against the RCA AI. :shock: I hope to have this sorted out by the time 1.11.7 comes out and will then also release a new version of AI-demos for the add-ons server.
Cool, I very much look forward to it. It is so great finally having work done on an AI that aims to do more than always rushing in and attacking regardless of the conditions.

mattsc
Posts: 1109
Joined: October 13th, 2010, 6:14 pm
Location: Hidden on the hex behind Fred

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

Post by mattsc » November 9th, 2013, 6:42 pm

Cold Steel wrote:For some reason, it hadn't occurred to me to look on the add-on server for stable releases of the AIs instead.
I wouldn't use the version that is currently on the add-ons server, it's really old. I haven't updated it in a long time because I don't feel that I had made sufficient progress. I think that I am getting close though. And I just need to remember to test that the current github version also works with the latest Wesnoth release, not just with trunk, whenever I make any significant changes.
Cold Steel wrote:Cool, I very much look forward to it. It is so great finally having work done on an AI that aims to do more than always rushing in and attacking regardless of the conditions.
Well, don't expect too much. The more I work on this, the harder it seems to get -- and the more I appreciate how good the default AI actually is as a general purpose AI. But I'll keep trying...

name
Posts: 396
Joined: January 6th, 2008, 3:32 am

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

Post by name » November 10th, 2013, 6:37 am

mattsc wrote: Well, don't expect too much. The more I work on this, the harder it seems to get -- and the more I appreciate how good the default AI actually is as a general purpose AI. But I'll keep trying...
Well you have done a fine job already. Even in what you say is a crippled state, I saw Fred beat Ron in 13 turns by encircling, capturing villages and perhaps even by playing more defensively and retreating the injured a bit more reliably (it seemed like). And Ron in turn beats RCA with equal efficiency.

Further, skimming through Fred's lua script, I see a wider array of deeper 'evaluations' that previously only human players would consider (leaving AI players to make quite frequent, obvious blunders) as well as what looks like strategic spacial thinking (defined by 'zones' and perhaps also 'corridors' if I am not misreading it). Strategic spacial thinking is major because this enables effective defensive play.

It doesn't matter that the strategic regions have to be hand-defined per map. Because once you have this working well on a few maps, it will be a stepping stone to having these defined in the map editor. This will allow maps to quickly be outfitted, tested and refined for Fred and his successors.

That in turn could be a stepping stone to a procedural strategy mapper, because there will be a good set of well designed man-made AI mapping to inspire the rules and test the output of this procedural mapper against, visually.

So long story short, I believe you are heading down the right path with this.

mattsc
Posts: 1109
Joined: October 13th, 2010, 6:14 pm
Location: Hidden on the hex behind Fred

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

Post by mattsc » November 11th, 2013, 4:09 am

Hello again and thanks for the comments and encouragement. Yes, that is all pretty much how we're imagining it happening. Start by making it work for one map (Freelands) for Side 1 and Northerners only, and then generalize it piece by piece until it is able to play any map by itself, but with the option of providing map-specific instructions by the user if desired. Unfortunately, I am still stuck on the first step, but I do think that we're making progress, even if very slowly. The next step, I think, is to have Fred consider more than one unit at a time when setting up defensive positions. Unfortunately, playing through all possible combinations takes too long, so I am currently trying to see if I can come up with an approximate method that does almost as good a job.

Well, so much for now, I'll check back in if/when there's progress on this ... In any case, thanks again for the comments, it's very motivating to know that people are still interested in this.

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 » November 11th, 2013, 3:06 pm

well of course we are. everybody wants to see the AI play smartassly and own noob&intermediate players, especially where human map knowledge is used to its utmost advantage. i dont see a problem telling the AI where good spots are when the humans playing the map do. generic map building might be a too hard rock to lift, for now lets see hwo fast matt will program whatever he can in his spare time. ur alone at the moment i gather correctly? gj for what uve managed already!

mattsc
Posts: 1109
Joined: October 13th, 2010, 6:14 pm
Location: Hidden on the hex behind Fred

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

Post by mattsc » November 12th, 2013, 12:13 am

Thanks, Rigor. And you're right of course, I was pretty certain that people are still interested in this in general, but there's just been so little perceptible progress in almost a year now, that things feel kind of ... dormant. Yeah, I am pretty much alone in this at the moment. Alarantalara is around and helps out on and off, but he has even less time than I do. As for me, I think I am done with most of the Micro AI development work, so I have a little more time for Fred again.

I do hope that all the refactoring I have done will eventually pay of, but this defensive unit positioning thing is still something I have not figured out. Looking around on the Internet, nobody really seems to be doing this (which probably means that it is difficult). When people talk about AI formations, they usually mean advancing units in formation. And "defensive play" simply means not attacking. If anybody has any pointers to articles, blog post, whatever dealing with actual defensive line formation (while taking terrain into account), please let me know. In the meantime, I'll continue with trial and error...

name
Posts: 396
Joined: January 6th, 2008, 3:32 am

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

Post by name » November 12th, 2013, 6:00 pm

mattsc wrote: If anybody has any pointers to articles, blog post, whatever dealing with actual defensive line formation (while taking terrain into account), please let me know.
Have you looked into Edge Detection? Because what you are describing sounds basically the same. Consider the map as an image; each coordinate is a pixel with a value representing the tenability of the terrain at that point. Then edge detection techniques are used on it to find lines of strong contrast between high defense and low defense terrain. Any lines that are not close to perpendicular to the direction of conflict are thrown out.

mattsc
Posts: 1109
Joined: October 13th, 2010, 6:14 pm
Location: Hidden on the hex behind Fred

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

Post by mattsc » November 12th, 2013, 6:23 pm

Cold Steel wrote:Have you looked into Edge Detection? Because what you are describing sounds basically the same. Consider the map as an image; each coordinate is a pixel with a value representing the tenability of the terrain at that point. Then edge detection techniques are used on it to find lines of strong contrast between high defense and low defense terrain. Any lines that are not close to perpendicular to the direction of conflict are thrown out.
Yes, I have, though that was quite some time ago, so I should revisit this. Thanks for the reminder. :)

If you check out the "Prune Cart" scenario in AI-demos (choose "let AIs fight it out" and "stationary cart"), that does pretty much that. Unfortunately, it doesn't quite work that well on small MP maps with much fewer units for a variety of reasons (which I'm happy to discuss if you're interested, but don't have time for right now). Btw, if you'd like to discuss these kinds of things interactively, we usually do so on the #wesnoth-umc-dev irc channel. It's been sadly quiet there lately and I always learn something from those discussions, so it would be great to have those again occasionally.

Thanks again!

name
Posts: 396
Joined: January 6th, 2008, 3:32 am

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

Post by name » November 16th, 2013, 12:53 am

mattsc wrote: If you check out the "Prune Cart" scenario in AI-demos (choose "let AIs fight it out" and "stationary cart"), that does pretty much that.
Nice! I didn't expect to see dynamic defensive positioning work this well.

Is there a test scenario for this defense AI on a smaller map with fewer units like you said? It would be interesting to see how it operates in its worst circumstances.

mattsc
Posts: 1109
Joined: October 13th, 2010, 6:14 pm
Location: Hidden on the hex behind Fred

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

Post by mattsc » November 16th, 2013, 4:15 am

Cold Steel wrote:Is there a test scenario for this defense AI on a smaller map with fewer units like you said? It would be interesting to see how it operates in its worst circumstances.
There isn't. I tried it and it simply didn't work. That's also the reason why I never really finished the Prune Cart scenario, the method used in it is simply to rigid, even for a scenario with such clear lines between good and bad terrain. My hope is that, at some point, I will come back with what I learn through Fred and make this scenario work well (enough) with a moving cart as well.

mattsc
Posts: 1109
Joined: October 13th, 2010, 6:14 pm
Location: Hidden on the hex behind Fred

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

Post by mattsc » November 17th, 2013, 1:14 am

I figured that with Wesnoth 1.11.7 being released this weekend, I should publish an AI-demos version that works with that. So:

AI-demos v0.12.4 has been released on the add-ons server. This is a work-in-progress update, so there aren't any super exciting changes. I guess it is worth noting that Ron and Fred are now available as an MP modification and that the Micro AIs have been removed from AI-demos as they are now all in mainline and the main development work on them is done. Lots of other smaller (or at least less visible) changes have been made since the last release, the full changelog is attached below.

Note that v0.12.4 requires Wesnoth 1.11.7, but that I tagged a version (v0.4.12-1.11.6) that still works with Wesnoth 1.11.6 and has identical functionality. You can get v0.4.12-1.11.6 from here if you cannot or do not want to update to 1.11.7 yet.

As for Fred: I've done a lot of internal changes to Fred's algorithms and I do believe that at least some of them are improvements, but he's still not playing as well or stably as I would like him to. The main issues I want to concentrate on next are:
  • Defensive positioning is still not working as desired. There's some improvement in some areas, but going along with apparently worse positioning in others.
  • Attack selection, esp. poisoning, needs some work. E.g. don't kill off trapped and poisoned units if there are other targets that are just as good. But that's not the only issue.
  • Village grabbing is a bit too "predictable"
  • When there are many enemies getting close to Fred's leader, he still gets very, very slow.
I am planning to work on these issues (roughly in that order) over the next few weeks/months and update a bit more frequently than I have done so far this year.
Complete changelog for AI-demos 0.12.4 and 0.12.4-1.11.6

Code: Select all

0.12.4, 16 November 2013
- This is the real release of Version 0.12.4 (for the add-ons server)
  - Dropped support for Wesnoth 1.11.6
  - *** This version now requires Wesnoth 1.11.7 ***

0.12.4-1.11.6, 16 November 2013
- *** This is a special release set up to work with Wesnoth 1.11.6 ***
  - Wesnoth 1.11.7 will be required immediately following this
- MP AIs:
  - Add an AI-Demos [modification], so you can use the MP AIs in other eras
  - Add 'Generic Recruit' and 'Default + Move to Enemy' MP AIs to computer player selection menu
  - Change descriptions of the MP AIs to indicate that they are part of AI-demos
  - Hide machine-learning MP AIs in the computer player selection menu (until Seattledad is back
    and can maintain them again)
- Freelands Side 1 Grunt Rush (Fred)
  - Lots of adjusting of attack, zone holding and village grabbing parameters and tweaks of behavior
  - Zone holding system switched to use corridor/path maps and two-tier rating system
    (Note: *** this is not fully balanced yet in this release ***)
- Test scenario
  - Use new wesnoth.debug_ai functionality
- Switch some of the AIs to using external CAs (which are now fully usable)
  - Ron and Fred are not going to be switched until they are in a more stable state
- Remove all the Micro AI demo scenarios:
  - They have now been in mainline for quite some time and can be called from there.
  - This also includes removing all the animal units
- Switchboard scenario: only show the story screen the first time
- Remove Liberty - The Raid scenario: has been moved to mainline
- ai_helper:
  - get_attacks: internal rewrite; this version is much faster than the previous
  - put_labels: add optional show_coords= and keys= parameters
  - get_enemy_dst_src: add optional parameter 'enemies'
  - remove unused function get_1_11()
- battle_calcs:
  - best_defense_map: add optional ignore_these_units= parameter
- CA debug mode:
  - Fixed and functional again for Fred
  - Add hotkeys for the right-click menu options
- General:
  - Some changes to internal syntax to keep up with mainline development

mattsc
Posts: 1109
Joined: October 13th, 2010, 6:14 pm
Location: Hidden on the hex behind Fred

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

Post by mattsc » June 13th, 2014, 3:00 pm

At long last, AI-demos v0.13.0 is out, featuring a completely reworked Freelands AI “Fred”.

Well, the way how Fred works in general is still the same, but pretty much all parts have been rewritten (at least) twice. Once to (I hope) improve behavior, and once for speed. I cannot say that I am super happy with everything I am seeing now, but I am certainly happier than I have been, so I uploaded the new version to the 1.12 and 1.13 add-on server.

The biggest caveat right now is that, simply for time reasons, I do almost all of my testing against the default (RCA) AI. Fred does very well in that case (see below), but we all know that that has limited applicability to playing against human players. So, we’re at the point where some help with play testing by others would be really helpful.

Version requirement: I tested yesterday that Fred works with Wesnoth 1.11.7 (the minimum requirement), but there was some problem with the resultant replay file. If possible, I’d suggest always using the most recent version (that is, 1.11.15 or 1.13.0-dev at the moment).

I’ll leave it at that for the general text and put all of the rest into sections, so that you can pick and choose the bits you’re interested in. Thanks in advance for any feedback and help with the testing!
Batch testing against the RCA AI
I ran 300 games of Fred vs. the RCA AI with 100 gold each, 50 games for each default faction for the opponent. Of those, Fred won 299. In the one game he lost, he had twice as many units (11 units with 412 HP combined) as the RCA AI (5 units with 208 HP) so he was winning, but must not have been protecting his leader well enough. It was a game against Loyalists, so my guess is that some horsies got to him (these tests are run in no-gui mode, so I cannot tell what really happened).

I also ran a smaller batch of 60 games in which I gave the RCA AI 150 gold vs. Fred’s 100. Fred won 55 of those.
Reminder: How to use Fred
MP mode:
  • Start an MP game
  • Select either era “Default+Experimental AI” or the “Experimental AI” modification
  • Select the Freelands map
  • Select “Computer Player” and “AI-demos: Freelands Rush AI (Fred - Side 1 only)” for Side 1
  • Select Northerners for Side 1
There is now also a Fred test scenario that can be started either
  • from the campaign’s switchboard scenario or
  • from the command line with ‘wesnoth -t fred’
  • You can choose the enemy faction, but it is currently hard-coded to give the enemy 125 gold and have the RCA AI play it. It should be trivial to hack into the scenario file and change that, if you want.
If you want to do some playtesting
Of course, you can playtest any way you want. However, if you want it to be most useful for me ...
  • Play with fog off: The goal is not to see if you can beat Fred. Of course you can! This is just a stupid AI after all. Instead, I would like you to tell me what Fred does wrong or right (from the beginning), and you cannot do that if you can’t see it. Besides, Fred plays with fog off himself too.
  • Stupid mistakes: Fred still makes plenty stupid mistakes and, frankly, that is not going to change. In fact, I have by now convinced myself that he will always make more stupid mistakes than the RCA AI (which, by definition, does not make mistakes). So, please let me know what the worst individual mistakes are, but more useful than knowing about individual blunders would be behavior patterns that he consistently gets wrong.
  • Pounding on the biggest weakness: I know this is how you’re supposed to play against a human in order to win and it’s fun to do so, but all it will tell me is what this biggest weakness is. If you identify that weakness and then keep playing around it, we will also learn other things.
  • Long evaluation times: Fred is much faster overall than he used to be, but occasionally attack evaluations still take a long time (tens of seconds). If you encounter such a situation, could you send me a savefile (or replay) of it, please? I am working on it myself also, but I am sure that I won’t find all instances.
  • Lua errors: Very infrequently, there’s some sort of Lua error happening. I have not encountered one of them recently (in the 360 batch games described above, it happened twice, so it is really hard to track them down), so if you see an error message on the screen, please send me the savegame from the beginning of the turn and a replay, if possible. I need to be able to reproduce the error, otherwise I can’t fix it.
What’s next for Fred?
Folks, honestly, I think I have reached pretty much the end of the line of what I am able to do with this. Of course, I will keep trying to improve little things, and sometimes little things make a big difference, but I doubt that there will be huge changes/improvements to Fred on Freelands any more. Instead, I am going to work mostly on trying to get him to work on different maps and single player settings as well.

Specific tasks:
  • Improve how trapping and poison attacks are handled, esp. in combination. Fred’s pretty good at trapping and poisoning units, but he’s “too eager”, trying to poison already poisoned units or those that cannot be, double trapping enemies, killing off trapped/poisoned units when the AI units could better attack elsewhere, etc.
  • Add more randomness. Having him rush down the left and center is already built into the code, but it doesn’t work very well yet, needs to be “rebalanced”. Add random elements to other parts of the behavior as well.
  • Add endgame behavior. Fred’s currently horrible at this. There’s no defensive endgame (when he’s losing) at all, and the offensive endgame is left to the RCA AI once he’s overwhelmingly stronger than the enemy. In between behavior when he is getting close to the enemy leader is really crappy.
  • Speed up some attack calculations. Fred’s much faster than he used to be, but there are still some situations when attack calculations take a long time.
  • Make Fred work with different factions and as side 2 on Freelands (I think that’s trivial after the changes I made recently, but I need to test it)
  • Make Fred work on different MP maps. Suggestions with which I should start?
  • Make Fred work more generally in SP settings as well. I will probably try to do this by seeing if I can get him to play the player’s side all the way through HttT (on easy).
v0.13.0 changelog

Code: Select all

0.13.0, 12 June 2014
- *** This is an abbreviated changelog since it has been so long since the last release ***
  - Only major (general) changes are summarized, without details about the specifics
  - Check out the AI-demos github site for all the details
- Freelands Side 1 Grunt Rush (Fred)
  - Fred has been completely overhauled.  Pretty much all parts of Fred were rewritten twice,
    once to improve behavior and then again to increas evaluation speed.  In the process,
    many bugs were fixed.
  - There is a new Fred test scenario that can be started from the switchboard scenario or
    from the command line with ‘wesnoth -t fred’
  - In honor of the “new Fred”, the minor version number of this release is changed to 13
- Helper libraries:
  - ai_helper:
    - New functions get_units_with_moves(), get_units_with_attacks(), checked_attack(), checked_move_full(),
      checked_move(), checked_recruit(), checked_stopunit_all(), checked_stopunit_attacks(),
      checked_stopunit_moves(), get_direction_index(), get_cardinal_directions(),
      get_intercardinal_directions(), get_hex_facing(), put_fgumap_labels()
    - Removed ai_helper.random()
  - battle_calcs: largely rewritten, but not used in Fred any more.  Instead we now have:
  - New helper libraries fred_attack_utils, fred_gamestate_utils, fred_gamestate_utils_incremental
- Generic recruit engine:
  - Add option to evaluate pre-recruiting at another castle reachable on the current turn
- All AIs and helper functions:
  - Many bug fixes, code cleanup changes and efficiency/speed improvements
- Switch to external CAs for most AIs (but not yet for the MP AIs (Fred, Ron, …)

Post Reply