Help with testing Fred - Freelands MP Custom AI v0.14.15

Discussion of all aspects of multiplayer development: unit balancing, map development, server development, and so forth.

Moderator: Forum Moderators

Post Reply
mattsc
Inactive Developer
Posts: 1217
Joined: October 13th, 2010, 6:14 pm

Re: Help with testing Fred - Freelands MP Custom AI v0.14.2

Post by mattsc »

virtue: thank you for the replay and the comments! Yeah, not defending the villages correctly is part of what I think is currently Fred's limiting factor: placement and distribution of units on the map. It's what I am working on (we'll see how successful I will be) and I will use that situation from your game as one of the test cases. Thanks.

Unfortunately, work on Fred is (almost) on hold at the moment due to real life interfering with my fantasy world. I hate when that happens! I am always hoping to get back to it soon. It will happen at some point...
Tauriel
Posts: 12
Joined: February 5th, 2016, 7:30 pm

Re: Help with testing Fred - Freelands MP Custom AI v0.14.2

Post by Tauriel »

I've tried Fred and it's an excellent AI with much potential, good work so far!

I did some interesting research with this AI.

Because of I hate the Default AI and I'm tired of Orcs and Freelands map, I was curious how Fred would play as other factions and on other maps, so with a bit technical work I forced Fred to do that, and I was happily surprised by the results. I matched Fred up against a Default AI on Caves of the Basilisk and Den of Onis (Fred playing Elves and Undead) and he wiped the Default AI out on both maps. I also tested a few other maps I designed myself, with the same results.

I slightly increased Fred's gold income and challenged him myself on Caves of the Basilisk (me Undead, Fred Elves) and he wiped me out as well.

So my conclusion is that Fred can play any map, but he will not play quite as good as he does in Freelands. Still, when playing another map, he will beat the crap out of the Default AI, and he is a challenge to a experienced human player if he get a little bit gold advantage.

The difference seems to be that in Freelands, Fred is more careful with his terrain planning during the whole game, and he acts faster to defend farms. Still, on other maps he will take advantage of important terrain areas, line up defensive unit lines, and protect injured units, which makes him far superior and more fun to play against than the Default AI on any map.

I will do more tests with Fred on different maps, settings and factions. Meanwhile I can't wait for next version of Fred :)
mattsc
Inactive Developer
Posts: 1217
Joined: October 13th, 2010, 6:14 pm

Re: Help with testing Fred - Freelands MP Custom AI v0.14.2

Post by mattsc »

Hi Tauriel,

Thank you for the post, and especially for all the testing and experimenting you have been doing! I’m glad to hear that you are getting some good results and that Fred is doing so well in general settings already.

Just to give you some background, our goal with this AI work was to start with a very specific, well defined setting, and then to make it more and more general. The first version of Fred was a pretty simple and straightforward grunt rush on the Freelands map. That AI was only about 400 lines of code back then and a lot of things were hard-coded. If I remember correctly, even the recruiting sequence on the first turn was hard-coded.

Since then, we’ve been adding more and more actions and analyses, and the code is getting more and more general. It does not surprise me very much that Fred does pretty well with all factions. There shouldn’t be much left in the code that is specific to Northerners. In fact, we had all factions enabled at some point already, and then removed it again. Not because he was doing badly, but because it is hard enough to figure out if a change improves things or not when playing just one faction. So essentially that was done in order to “keep the noise down.” Measurement noise, not people noise. ;) The main problem with other factions is probably that abilities like healing or leadership are not taken advantage of at this time.

As for playing different maps, I’m pleasantly surprised that he does so well already. There are certainly things in the code (definitions of key hexes or areas, number of units per village to send in certain directions, etc.) that are specific to the Freelands map. However, those are kept as configuration parameters at the beginning of the code (I don’t know if you changed those in the adaptation to your maps), while the code evaluating the action is kept as general as possible using those parameters as inputs. In the end, I hope that Fred well be able to play any map in one of two ways: 1. Having Fred figure out by himself how to play the map, and 2. giving the scenario designer the option to specify configuration parameters customized for a map/scenario. [Btw, currently there are a lot of these parameters, simply because I do not know what works best yet. I am sure that these can be reduced significantly in the end.]

Anyways, I’m just rambling. Most of that is probably obvious to you anyway. We’re a long way from that final goal, at the moment I am still trying to figure out how to do things just on the Freelands map. And, as I said in my previous post, I don’t have much time for poor neglected Fred at the moment. I will definitely get back to all this though, hopefully soon!

So, yeah, your findings are a nice confirmation of what we have been trying to do. They are maybe even a bit better than what I’ve been expecting for this stage. That’s great to hear. Thank you! Looking forward to what else you find.
Tauriel
Posts: 12
Joined: February 5th, 2016, 7:30 pm

Re: Help with testing Fred - Freelands MP Custom AI v0.14.2

Post by Tauriel »

mattsc wrote:The main problem with other factions is probably that abilities like healing or leadership are not taken advantage of at this time.
Yes I noticed healing and leadership are ignored by Fred, and partly that is the reason I was so happily surprised. Fred was playing very well as Elves without those advantages, then imagine how well he would play if all that was taken into account.

Also the fact that Fred plays other maps quite well is also happily surprising considering he is not officially designed to play any other maps than Freelands (yet). Yes, there are a few flaws on other maps with him, but he is still somewhat a challenge and easily beats the Default AI. Then imagine what a nightmare he could be if those few flaws were fixed for general map playing.

Some of the flaws on other maps are stuff like Fred perform worse on very small maps (he is weak to being rushed), units sometimes getting "stuck" in the cave in map "Caves of the Basilisk" and Fred sometimes sends a lonely unit too close enemy armies. However I need to test Fred more before I will draw any safe conclusions and possibly reasons behind his acts. I could come up with more detailed documentations of Fred's behaviour on other maps, but I'm not sure if I should bother you with that at this moment if you want to focus on Freelands for now?
mattsc wrote:As for playing different maps, I’m pleasantly surprised that he does so well already. There are certainly things in the code (definitions of key hexes or areas, number of units per village to send in certain directions, etc.) that are specific to the Freelands map. However, those are kept as configuration parameters at the beginning of the code (I don’t know if you changed those in the adaptation to your maps), while the code evaluating the action is kept as general as possible using those parameters as inputs.
I actually did not touch Fred's parameters when I were testing him on other maps, so you can feel proud that he was still doing quite well. :) But since you mentioned it, I could try changing those parameters and see if he plays even better.
mattsc wrote:In the end, I hope that Fred well be able to play any map in one of two ways: 1. Having Fred figure out by himself how to play the map, and 2. giving the scenario designer the option to specify configuration parameters customized for a map/scenario. [Btw, currently there are a lot of these parameters, simply because I do not know what works best yet. I am sure that these can be reduced significantly in the end.]
I think that is a question best decided by you since you have experience and know your own code best.

If I may, I would however suggest that map designers should be able to tell Fred where important areas are. There could be new AI layers added to the map editor that a designer can put around the map. For example there could be a layer named "AI Farm Defence", if you put that on a farm hex Fred will send more troops to defend it and not retreat so easily. Perhaps you could also be able to configure a prioritize number in the editor for each layer, so if you have 2 or more defence layers, you can tell the AI which one is most important.

Of course, if you can make Fred generate all those decisions by himself on foreign maps in a good way, that would be great also :).
mattsc wrote:And, as I said in my previous post, I don’t have much time for poor neglected Fred at the moment. I will definitely get back to all this though, hopefully soon!
Don't rush, programming games on free time is meant to be fun. Take your time :)

I will end this post with a general feedback on Fred. I have noticed that he is very often way too defensive. I have been in situations were Fred is stronger than me in unit number and he could easily wipe me out if he did a full attack, still he is just being defensive which makes games unnecessarily long. So if you could make him more aggressive when he has better conditions to win a fight, that would be great :)
mattsc
Inactive Developer
Posts: 1217
Joined: October 13th, 2010, 6:14 pm

Re: Help with testing Fred - Freelands MP Custom AI v0.14.2

Post by mattsc »

Tauriel wrote:Yes I noticed healing and leadership are ignored by Fred, and partly that is the reason I was so happily surprised. Fred was playing very well as Elves without those advantages, then imagine how well he would play if all that was taken into account.
Yeah, I'll get to that, eventually. We even wrote a Healer Support AI already that can be used as a basis for this (it's not possible to simply bind this into Fred though). Leadership is a bit harder, but I have some ideas how to go about that too.
Tauriel wrote:Also the fact that Fred plays other maps quite well is also happily surprising considering he is not officially designed to play any other maps than Freelands (yet).
Agreed. The reason why that works at all is probably because Fred goes through three stages each turn:
  1. Deal with threats caused by enemy units close to own leader.
  2. Do Freelands map specific stuff.
  3. Use remaining units to advance toward enemy leader (this does not mean just strictly advancing, but also attacks, village grabbing, retreating of injured units, etc. taking the whole map into account)
Without looking into more details, my guess is that on other maps, Fred will, for the most part, skip the second stage, with the first and third stages still providing actions that are better than the default AI in many (but not all) settings.

I would also assume that some (but again not all) of the flaws you mention are caused by him trying to do Freelands specific stuff on other maps, where at best they are not ideal, but sometimes will probably result in very bad moves.

Other things, such as him exposing individual units too much fall more into the sort of issues that I am currently working on. At the moment, Fred does some general map analyses at the beginning of a turn that answer top-level questions like how much power is needed in different areas of the map. However, all actions are then evaluated individually with (almost) no coordination between them (although some actions involve several units moving together). What I am currently trying to work out is how to add more instructions about coordination between actions to the overall strategy layer of the AI without running into impossibly long evaluation times. If successful, that should help with several of Fred's current shortcomings. Of course, I have not figured out how to do that yet. :P
Tauriel wrote:I could come up with more detailed documentations of Fred's behaviour on other maps, but I'm not sure if I should bother you with that at this moment if you want to focus on Freelands for now?
It's probably not worth your time at the moment — not because it would bother me, but because a lot of it is probably caused by the Freelands specific code and will therefore not apply any more once we start generalizing the AI to other maps.
Tauriel wrote:If I may, I would however suggest that map designers should be able to tell Fred where important areas are. There could be new AI layers added to the map editor that a designer can put around the map. For example there could be a layer named "AI Farm Defence", if you put that on a farm hex Fred will send more troops to defend it and not retreat so easily. Perhaps you could also be able to configure a prioritize number in the editor for each layer, so if you have 2 or more defence layers, you can tell the AI which one is most important.

Of course, if you can make Fred generate all those decisions by himself on foreign maps in a good way, that would be great also :).
Well, my guess is that having Fred figure it out himself will never quite be as good as giving him specific instructions. So my expectation is that we'll have a version that can play a map on its own, but with the option of adding additional information to improve on that. Which, as a concept, is really how the default AI works also. How well either version will play ... well, time will tell.
Tauriel wrote:I will end this post with a general feedback on Fred. I have noticed that he is very often way too defensive. I have been in situations were Fred is stronger than me in unit number and he could easily wipe me out if he did a full attack, still he is just being defensive which makes games unnecessarily long. So if you could make him more aggressive when he has better conditions to win a fight, that would be great :)
Thank, yes, I am aware of that and it is actually one of the main reasons why I am currently working on the overall strategy layer. Something like that is, in fact, already built into the current version, but it is too simplistic to work well enough in all, or maybe even most, situations.

Thanks again for all the feedback. It's great to hear all this. :)
SigurdFireDragon
Developer
Posts: 546
Joined: January 12th, 2011, 2:18 am
Location: Pennsylvania, USA

Re: Help with testing Fred - Freelands MP Custom AI v0.14.2

Post by SigurdFireDragon »

Tauriel wrote:...I was curious how Fred would play as other factions and on other maps, so with a bit technical work I forced Fred to do that, and I was happily surprised by the results...
Could you post a summary of what you did to accomplish this?
Co-Author of Winds of Fate
My Add-ons: Random Campaign, Custom Campaign, Ultimate Random Maps, Era of Legends, Gui Debug Tools
Erfworld: The comic that lead me to find Wesnoth.
mattsc
Inactive Developer
Posts: 1217
Joined: October 13th, 2010, 6:14 pm

Re: Help with testing Fred - Freelands MP Custom AI v0.14.2

Post by mattsc »

SigurdFireDragon wrote:
Tauriel wrote:...I was curious how Fred would play as other factions and on other maps, so with a bit technical work I forced Fred to do that, and I was happily surprised by the results...
Could you post a summary of what you did to accomplish this?
I assume this was meant for Tauriel, but I can answer also. The code does not actually disable you setting up a MP game on other maps or with other factions, it simply ends the game right after it starts if it detects different choices. So all you need is to disable that check:
  • Open file lua/fred_events.lua
  • Close to the end of the file, find the line starting with

    Code: Select all

    if (not can_recruit_grunts) or ...
    In the current version that's line 62. Comment out the content of the block of code inside that if statement. Note for those unfamiliar with Lua: a comment in Lua is done with --, see a few lines above this one.
I believe that that is all you have to do.

Keep in mind though that, as I said above, some of the Freelands specific code might actually be counterproductive on other maps. So Fred might do some things that are not only not better than the default AI, but actually worse.
Tauriel
Posts: 12
Joined: February 5th, 2016, 7:30 pm

Re: Help with testing Fred - Freelands MP Custom AI v0.14.2

Post by Tauriel »

mattsc wrote: Agreed. The reason why that works at all is probably because Fred goes through three stages each turn:
  1. Deal with threats caused by enemy units close to own leader.
  2. Do Freelands map specific stuff.
  3. Use remaining units to advance toward enemy leader (this does not mean just strictly advancing, but also attacks, village grabbing, retreating of injured units, etc. taking the whole map into account)
Without looking into more details, my guess is that on other maps, Fred will, for the most part, skip the second stage, with the first and third stages still providing actions that are better than the default AI in many (but not all) settings.

I would also assume that some (but again not all) of the flaws you mention are caused by him trying to do Freelands specific stuff on other maps, where at best they are not ideal, but sometimes will probably result in very bad moves.
Yes I got the impression Fred is probably doing some Freelands related stuff on other maps.

I will try to make my own personal version of Fred, where he will not do Freelands related stuff, and perhaps fix some other issues. (Just so I will have a better AI (than Default) to play with while Fred is not officially supported for other maps) :P
mattsc wrote:Other things, such as him exposing individual units too much fall more into the sort of issues that I am currently working on. At the moment, Fred does some general map analyses at the beginning of a turn that answer top-level questions like how much power is needed in different areas of the map. However, all actions are then evaluated individually with (almost) no coordination between them (although some actions involve several units moving together). What I am currently trying to work out is how to add more instructions about coordination between actions to the overall strategy layer of the AI without running into impossibly long evaluation times. If successful, that should help with several of Fred's current shortcomings. Of course, I have not figured out how to do that yet. :P
In professional Chess games with AI, the difficulty of the AI depends on how powerful CPU you have and how long you allow it to evaluate (as less evaluation time as easier AI gets, obviously). So, (not very seriously meant, even if possible), Fred's difficulty could depend on time setting and CPU power :P

But more seriously, yes would be good if you figure out something better :P
mattsc wrote:Well, my guess is that having Fred figure it out himself will never quite be as good as giving him specific instructions. So my expectation is that we'll have a version that can play a map on its own, but with the option of adding additional information to improve on that.
Yes, ok. Sounds good to me.
mattsc wrote:Thank, yes, I am aware of that and it is actually one of the main reasons why I am currently working on the overall strategy layer. Something like that is, in fact, already built into the current version, but it is too simplistic to work well enough in all, or maybe even most, situations.
Nice to hear that you priority that issue right now :)
Last edited by Tauriel on February 12th, 2016, 4:55 pm, edited 2 times in total.
Tauriel
Posts: 12
Joined: February 5th, 2016, 7:30 pm

Re: Help with testing Fred - Freelands MP Custom AI v0.14.2

Post by Tauriel »

mattsc wrote:
SigurdFireDragon wrote:
Could you post a summary of what you did to accomplish this?
I assume this was meant for Tauriel, but I can answer also. The code does not actually disable you setting up a MP game on other maps or with other factions, it simply ends the game right after it starts if it detects different choices. So all you need is to disable that check:
  • Open file lua/fred_events.lua
  • Close to the end of the file, find the line starting with

    Code: Select all

    if (not can_recruit_grunts) or ...
    In the current version that's line 62. Comment out the content of the block of code inside that if statement. Note for those unfamiliar with Lua: a comment in Lua is done with --, see a few lines above this one.
I believe that that is all you have to do.
Yes that is approximately what I did, though I deleted all columns of code from the Undead warning and down. The only important thing is that you keep wesnoth.fire_event("fred_setup_events") to fire somewhere.
mattsc
Inactive Developer
Posts: 1217
Joined: October 13th, 2010, 6:14 pm

Re: Help with testing Fred - Freelands MP Custom AI v0.14.2

Post by mattsc »

Just a few more quick comments:
Tauriel wrote:I will try to make my own personal version of Fred, where he will not do Freelands related stuff, and perhaps fix some other issues. (Just so I will have a better AI (than Default) to play with while Fred is not officially supported for other maps) :P
Cool, let me know how that goes. Btw, the main reason why I have not moved to other maps yet is not because I don't want to. I do, believe me, but I have too many problems making things work the way I want even on Freelands. And, as we've discussed, some of that is currently done by hard-coding config tables for the map. Those tables will definitely change based on what I am doing at the moment (as in, not just the values in them, but also what kind of information is stored). I do not want to add this for other maps, or write more general code that figures it out automatically, before I know what actually works. I do hope to reach the "good enough" stage sometime "soon" though.
Tauriel wrote:In professional Chess games with AI, the difficulty of the AI depends on how powerful CPU you have and how long you allow it to evaluate (as less evaluation time as easier AI gets, obviously). So, (not very seriously meant, even if possible), Fred's difficulty could depend on time setting and CPU power :P
I guess we could. :P Currently I feel like I am more limited by concepts than computing power though (although some stupid mistakes could probably be avoided by evaluating more options). And yes, I heard that you weren't very serious about it. :)
Tauriel wrote:Yes that is approximately what I did, though I deleted all columns of code from the Undead warning and down.
Wait, what? Undead warning? That was already removed for 0.14.1 and we're now up to 0.14.2. What version of Fred are you using? Or am I missing something?
Tauriel
Posts: 12
Joined: February 5th, 2016, 7:30 pm

Re: Help with testing Fred - Freelands MP Custom AI v0.14.2

Post by Tauriel »

mattsc wrote:
Tauriel wrote:I will try to make my own personal version of Fred, where he will not do Freelands related stuff, and perhaps fix some other issues. (Just so I will have a better AI (than Default) to play with while Fred is not officially supported for other maps) :P
Cool, let me know how that goes.
I don't know if I will success though, learning someone else’s rather complex code may be very time consuming (I honestly may not have the time or patience), especially as I'm new to the Wesnoth engine and have little knowledge about it also. However if I would get a general understanding of your Fred code structure and functions, it may be enough to change a couple of things based on my desire, I guess.

I'll let you know if I'd do any successful progress :P
mattsc wrote:Btw, the main reason why I have not moved to other maps yet is not because I don't want to. I do, believe me, but I have too many problems making things work the way I want even on Freelands. And, as we've discussed, some of that is currently done by hard-coding config tables for the map. Those tables will definitely change based on what I am doing at the moment (as in, not just the values in them, but also what kind of information is stored). I do not want to add this for other maps, or write more general code that figures it out automatically, before I know what actually works. I do hope to reach the "good enough" stage sometime "soon" though.
I fully support your strategy, better to take the time and create a well thought out fun AI with quality, rather then rush a mediocre half-funny AI. Don't mind me, I just have bad patience, this is why I will try to edit Fred into that mediocre half-funny AI, while waiting for the high-quality versions :lol:

Basically the one important feature I like about Fred in his current state is that he knows what defence is apart from that rushing Default AI who does nothing but blindly feeds you with units. I'm happy if I just could get an AI that knows the basics about defending for general map playing :P (which is likely possible with Fred right now, even though the result would be mediocre).
mattsc wrote:
Tauriel wrote:Yes that is approximately what I did, though I deleted all columns of code from the Undead warning and down.
Wait, what? Undead warning? That was already removed for 0.14.1 and we're now up to 0.14.2. What version of Fred are you using? Or am I missing something?
Ops, I forgot that I did those edits in 0.14.0 when I wrote that post.

I edit in 0.14.0 because it plays a little bit better than 0.14.2 on general maps (from my tests so far), probably because it's much more aggressive, and doesn't defend most of the times. It also makes 0.14.0 more fun to play against. So I decided if I'm going to edit the AI, it will be for 0.14.0. :)
mattsc
Inactive Developer
Posts: 1217
Joined: October 13th, 2010, 6:14 pm

Re: Help with testing Fred - Freelands MP Custom AI v0.14.2

Post by mattsc »

Tauriel wrote:Ops, I forgot that I did those edits in 0.14.0 when I wrote that post.

I edit in 0.14.0 because it plays a little bit better than 0.14.2 on general maps (from my tests so far), probably because it's much more aggressive, and doesn't defend most of the times. It also makes 0.14.0 more fun to play against. So I decided if I'm going to edit the AI, it will be for 0.14.0. :)
Ah, okay, that makes sense.

Other than that, I don't have much to add, other than that that all sounds good and thanks for the interest and feedback! :)


PS: All, the Freelands specific stuff is (or should be, at least) at the beginning of file lua/fred.lua, essentially everything before function fred:analyze_map_set_tables_turn(). Be warned though, if you do in fact look at it, you'll see that it's a horrendous mess and very redundant. As I said, once I figure out what actually works, I'll clean that up and I am sure that I can significantly reduce the amount and complexity of parameters used. Until then, I just remind you of what I said in the first post of this thread:

What not to do: Don't check out the code.

Or if you do, do so at your own risk. :lol:
SigurdFireDragon
Developer
Posts: 546
Joined: January 12th, 2011, 2:18 am
Location: Pennsylvania, USA

Re: Help with testing Fred - Freelands MP Custom AI v0.14.2

Post by SigurdFireDragon »

Thanks for the replies, mattsc & Tauriel.

Fred certainly does make you work for the victory more than Default RCA. And it does take longer to play him. So far, I've only tried him on Hamlets with him Northerners & me Drakes. I'll try him on Freelands at some point as well.
Co-Author of Winds of Fate
My Add-ons: Random Campaign, Custom Campaign, Ultimate Random Maps, Era of Legends, Gui Debug Tools
Erfworld: The comic that lead me to find Wesnoth.
Tauriel
Posts: 12
Joined: February 5th, 2016, 7:30 pm

Re: Help with testing Fred - Freelands MP Custom AI v0.14.2

Post by Tauriel »

mattsc wrote:PS: All, the Freelands specific stuff is (or should be, at least) at the beginning of file lua/fred.lua, essentially everything before function fred:analyze_map_set_tables_turn().
Thanks, giving brief hints about the code structure actually helps me a lot in this horrendous mess. :)
mattsc wrote:Be warned though, if you do in fact look at it, you'll see that it's a horrendous mess and very redundant.
I've already checked most of the code, so I know what you mean. :doh:
mattsc wrote:What not to do: Don't check out the code.

Or if you do, do so at your own risk. :lol:
On my own risk? If I knew that I would have signed an insurance for various smashed computer parts due to frustration.. :x .. ^_^
sacredceltic
Posts: 55
Joined: October 20th, 2013, 4:07 pm

Re: Help with testing Fred - Freelands MP Custom AI v0.14.2

Post by sacredceltic »

What is the procedure to upgrade Fred on my machine?

Thank you
Post Reply