Page 1 of 2

Bright Spark

Posted: Sun Jul 24, 2022 2:58 pm
by Bandit1990
Hello!

I would like to share the AI that I have been working on over the past few years - Bright Spark!

What games does it play on?

Bright Spark plays on Definitive Edition.
Game Mode: Random Map
Maps: Should play on any map connected by land - if you find one that doesn't work, then please let me know and I can add it in :)
Victory Condition: Standard or Conquest
Pop: 200+
Civs: Any, including expansions
Difficulty: Any - I haven't built in difficulty levels yet so it will behave the same regardless. In tests it seems to have fairly even wins and losses vs the DE AI on Hard, so that's where I'd place it's level.

What's the story behind Bright Spark?

6/7 years ago, my wife introduced me to AoE2 with the old disk she still had from when she played it growing up. I was terrible, and she won easily all the time. In the box I found the guide to writing custom AIs in AoE, so I joked that while I wasn't good enough to beat my wife at the game, I would create an AI that would. After trial and error (and some help from BearTheGreat's tutorial) I put together an AI that could beat my wife at the game, but it was also able to beat us both 2 vs 1 working together (we were fairly beginner level back then). Thus began a tradition of us playing co-op together to beat the AI, and when we did, I would work on it to improve it further, and then jump back in the ring.

Later on we discovered our friends also played AoE 2, but the HD version, so we moved over to that and played with them. Not all of our friends liked PvP, so Bright Spark was used as a sparring partner for friendly co-op games with our mates.

When the pandemic hit and we were all in lockdown, our co-op games became a weekly event and quite frankly kept us all sane as a few of us lived alone at the time. That weekly game has continued on and we still play, and as you can imagine us and Bright Spark have improved lots over that time.

At the start of this year we switched over to DE and I've made a start of using DUC which has started to help it improve a lot. In it's first iteration, Bright Spark would go about just spamming spearmen + skirmishers and going attack-now - now it adapts to its opponents, takes into consideration what civs are on its team, and it can now do some early raids while (mostly) avoiding TC fire. I'm at the point now that I think it is worth sharing, and possibly entering the ring against some other AIs in the community. It's definitely not finished and I know of places it can improve, but I also know I will be better off having feedback from more people rather than carry on working on Bright Spark in isolation :)

Thank yous

A big thank you to BearTheGreat and interlepus for helping me improve from the base paperwork and for those who created the AI Scripting Encyclopedia (I wasn't sure if it was just Leif Ericson or a team of people), I only just discovered it a couple of months ago and it's been so so helpful (I was using the userpatch reference guide before that and not everything worked XD)!

Finally thank you for the kind welcome to the AI Scripters Discord channel too!

I hope you enjoy playing against Bright Spark and if you have any feedback then please let me know.

Best wishes,
Bandit

Update - October 9th 2022

Major update for Bright Spark, which should be a stronger foundation for later updates. Here is what has changed:

- DUC villagers: villagers are now commanded by the script rather than default behaviour. This wastes less food and spreads villagers out better across resources. In practice this means sometimes a slower feudal age but with a stronger food economy and a much stronger Castle and Imperial age.

- Improved fast castle: Reduced castle time for fast castle strategy from an average of 18:00-20:00 to 15:30-17:30.

- Arena strategy.

- Prioritise upgrades: Unit production will halt temporarily to get upgrades quicker.

- Quicker castle-age aggression.

- Improved siege in late game.

- Improved assault mode (units will guard siege and not just throw themselves at castles).

- Bright Spark will now cul...send unproductive villagers to an improvement programme when reaching pop cap to make room for larger military.

- Bright Spark no longer sends its army after deer.

- Updated counter system to adapt to Indian civ unique units.

- Burgundians can now research Flemish Revolution.

- Improved decision making when building farms.

- Bright Spark will lock gates on Arena when enemies are near.

- Improved market placement.

- Improved trade.

- Improved villager allocation to optimise military production.

- Bright Spark will queue villagers in Dark Age to get an extra villager by age up.

- Bright Spark no longer "counters" Genoese Crossbowmen with spearmen.

- Villager allocation changes when stone and gold are off the map, improving late game eco.

- Altered scouting on Arena so scouts didn't get stuck on trees.

- Pause villager production when rushing to Imperial Age.

- Villager production can now borrow from escrow sources, maintaining better villager production.

- Will free resources or buy them to build camps when required.

- Slight adjustment to how Bright Spark understands team bonuses.

The villager DUC is a big change and so I have added the latest version of (Bright Spark 22) as a separate file should people prefer the old version (which is actually Bright Spark 14). There are a couple of issue below that I know about and am working on:

Update - October 31st 2022

This update only changes a few things but seems to have made a big impact on Arena. Bright Spark can now compete with DE AI on Extreme Difficulty on Arena. Here are the changes:

- Faster fast-castle

- Alternative starts for Mongols and Malay

- Siege pathing has been improved and no longer likes walls as much

- Siege protection improved

- Improved eco balance

- Bright Spark no longer builds scorpions or mangonels without other units for cover

- Some castle and TC avoidance (just started this, not great)

- An attempt at mangonel fire avoidance for archers, cav archers and hand-cannoneers (again not great as just starting with this)

- Bright Spark now builds more mills, lumber-camps and mining-camps to keep vills closer to resources

- Held back a bit on the villager culling

- When losing, Bright Spark will hide units in buildings rather than trickle them out

- Fixed bug where Bright Spark was trying to train Condottieri when they weren't Italians, or at imp.

- Better assault targeting on team games and free for all.

As always if you have any feedback then please let me know :)

Re: Bright Spark

Posted: Mon Jul 25, 2022 10:13 am
by MrElephant
Hello,

So I just tested out this AI. However, it does require some setup- and doesnt appear to function right off the bat for DE. You have to rename some of the folders to Bright Spark\filename in the "Spark - Bolt On Exp 3" and "DUC Raid Test 6" files in addition to the "Bright Spark.per" file. My suggestion would be to include a DE version separately if this is an HD version. Oh, and for DE you have to rename all of the .per2 to .per extensions.

Overall thoughts- this is a great ai. Pretty strong. Only tested it once, but it does have a strong quick attack with militiamen and archers. I like its strategy. Plus it does retreat from the TC.

-Mr.Elephant

Re: Bright Spark

Posted: Mon Jul 25, 2022 1:18 pm
by Bandit1990
Thanks Mr Elephant!

Apologies, to you and those who downloaded already and had to tinker to make it work. I copied the files before compressing so when I tested it, it must have referred to the usual files so I missed the errors.

I have saved all files as .per rather than .per2 and all references to load files are now correct (and I just sent it to a friend to check and it worked fine this time!)

Thanks for testing - I downloaded Thanatos and Charon earlier today and aim to play some games against them this week! :)

Re: Bright Spark

Posted: Mon Jul 25, 2022 6:07 pm
by MrElephant
It's all good. Glad you were able to update the files. Bandit is a great AI, and I am happy you found your way to aiscripters!

Re: Bright Spark

Posted: Wed Jul 27, 2022 8:55 am
by Leif Ericson
This is an aggressive AI and it's fun to watch. One recurring thing I found is that the AI can be late to upgrade to man-at-arms. In one of my tests it researched Supplies before Man-at-arms. I'm not a pro, but my guess is that stopping militia training and the Supplies tech until the man at arms upgrade is at least research-pending might improve the AI's strength.

Re: Bright Spark

Posted: Thu Jul 28, 2022 12:50 am
by Bandit1990
Leif Ericson wrote:
Wed Jul 27, 2022 8:55 am
This is an aggressive AI and it's fun to watch. One recurring thing I found is that the AI can be late to upgrade to man-at-arms. In one of my tests it researched Supplies before Man-at-arms. I'm not a pro, but my guess is that stopping militia training and the Supplies tech until the man at arms upgrade is at least research-pending might improve the AI's strength.
Thanks Leif and good point, that might explain some of the inconsistency when it picks Militia to rush. On a similar note it also sometime researches padded armour before fletching if it goes into skirms or archers so having a similar rule for them I imagine will also help.

I've added them to the list to add for next update, thank you :)

Re: Bright Spark

Posted: Fri Jul 29, 2022 12:50 pm
by FireBall37
Played a test game vs Bright Spark and Shadow, and Bright Spark at one point was still in Feudal while Shadow was Castle Age, and said that he was stopping production to age up, but then later kept producing units and never got to Castle at all. I notice several AI's do this, being indecisive about whether to maintain age equality or military equality.

Also, very happy to see him on the forums! So far looks like a great opponent :)

Re: Bright Spark

Posted: Sun Jul 31, 2022 2:56 am
by Bandit1990
FireBall37 wrote:
Fri Jul 29, 2022 12:50 pm
Played a test game vs Bright Spark and Shadow, and Bright Spark at one point was still in Feudal while Shadow was Castle Age, and said that he was stopping production to age up, but then later kept producing units and never got to Castle at all. I notice several AI's do this, being indecisive about whether to maintain age equality or military equality.

Also, very happy to see him on the forums! So far looks like a great opponent :)
Thanks Fireball!

Ah yes it has a chat for halting production but not resuming production in Feudal. What I think is happening is after a certain game time it tries to age up provided it’s not at a certain disadvantage in military pop. If Shadow has a strong military presence Bright Spark will try to catch up, then once it does will halt production again which I’m guessing during that time loses its troops or Shadow has generated more quickly.

May post this question on Discord too but do you have any advice on when to halt production to age up? I could add a second layer to the rule where if the game time is over a later amount just halt production regardless of military, but I would imagine that would leave it open to a fatal attack (though at that point it might be gg anyway I guess).

Re: Bright Spark

Posted: Sun Jul 31, 2022 8:45 am
by FireBall37
Bandit1990 wrote:
Sun Jul 31, 2022 2:56 am
May post this question on Discord too but do you have any advice on when to halt production to age up? I could add a second layer to the rule where if the game time is over a later amount just halt production regardless of military, but I would imagine that would leave it open to a fatal attack (though at that point it might be gg anyway I guess).
Well, it is a complicated question. I’d say the biggest factor is the level of your defenses. Going up to Castle is of course just better, but if you will die before getting there it is no good. So against a flushing opponent FCing often fails because AIs do not wall well. Now for a flush, I would say the sooner you can go up, the better. What I would say is, if you are ahead in Feudal, upping to Castle will put you even further ahead; and if you are behind in Feudal, staying in Feudal longer only puts the nail in the coffin for sure, while upping to Castle and trying to weather the storm gives you some chances of coming back into the game. I’ve found that towers are a great way of preparing for going to Castle safely.

That was long, but those are some thoughts. Anyone feel free to correct me if you see an issue :lol:

Re: Bright Spark

Posted: Mon Aug 01, 2022 4:01 am
by Bandit1990
FireBall37 wrote:
Sun Jul 31, 2022 8:45 am
Bandit1990 wrote:
Sun Jul 31, 2022 2:56 am
May post this question on Discord too but do you have any advice on when to halt production to age up? I could add a second layer to the rule where if the game time is over a later amount just halt production regardless of military, but I would imagine that would leave it open to a fatal attack (though at that point it might be gg anyway I guess).
Well, it is a complicated question. I’d say the biggest factor is the level of your defenses. Going up to Castle is of course just better, but if you will die before getting there it is no good. So against a flushing opponent FCing often fails because AIs do not wall well. Now for a flush, I would say the sooner you can go up, the better. What I would say is, if you are ahead in Feudal, upping to Castle will put you even further ahead; and if you are behind in Feudal, staying in Feudal longer only puts the nail in the coffin for sure, while upping to Castle and trying to weather the storm gives you some chances of coming back into the game. I’ve found that towers are a great way of preparing for going to Castle safely.

That was long, but those are some thoughts. Anyone feel free to correct me if you see an issue :lol:
Thanks for writing up your thoughts on this!

I think for the next update I’ll add in a secondary age up switch that doesn’t turn off and see how that goes. Perhaps when an opponent has been in castle for x amount of time then lock into aging up. If I make some changes so that I can shorten how long it takes to save up those resources then that should minimise the time it’s vulnerable.

The wall point is interesting, Bright Spark does have code to build walls using buildings but I turned it off before release because it occasionally got in the way of building gold mines. I need to revisit camp and mine building rules anyway so I might experiment with walls again to see if that will help as a buffer.

Thanks for testing! :)