AoE2 units are a lot smarter than you think
Vložit
- čas přidán 3. 07. 2021
- Choosing new targets may seem like a pretty simple decision, but it's not always straight forward, and it turns out AoE2 units have some excellent decision-making skills.
0:25 How units pick targets 99% of the time
0:55 What if two units are EXACTLY the same distance away?
2:38 Are armor, hills, and bonus damage factored in?
5:05 Any difference for ranged units or size?
5:40 How units choose which building to attack?
6:50 "Samurai seek out the strongest enemy units"?
_____________________________________________________________________
Patreon: / spiritofthelaw
Background music from Epidemic Sound: www.epidemicsound.com
Game: Age of Empires II Definitive Edition - Hry
Step 1: Just attack the closest guy
Step 2: Analyze the armor, the amount of health left, the civilization, the hill bonus, the windspeed, the water depth, the time of day, the technological advancements, the time and date of birth, the alignment of the stars, and attack the one you'd kill the fastest.
They did that with priority fire on tanks in WW2. Shoot the vehicle that is a threat but will be destroyed easiest first. That's why the US army put the Sherman M4A3E2 Jumbo tank at the head of the column - it looked like a regular M4A3, but had much thicker armour.
Step 2 is actually run the damage function on every equidistant unit and pick the highest % damage. That's why it takes everything into account.
@@sniperdubey Yeah, the math for that is nothing for the game, considering that it's going to have to do that math any time a unit strikes another one, so doing the math a few times in the case of a tie to get the damage amount, then calculating how many hits it takes to kill the unit and picking the smallest one seems like a very good and simple way to go about doing this.
I wonder what "the closest" is considered in the actual game. In the actual game units can't be placed with 0 pexel difference.
Props to "@ILickToesAtNight" for making spirit say that at the end of all his videos.
But the real question is - do they?
Can you explain how he managed to do that?
@@AnimeCritical I assume it isn't his own toes - but the name doesn't clarify.
@@AnimeCritical if you support him on patreon he reads out your name at the end of the videos. someone named themselves that and so he has to say that
...I heard it as " I lactose at night"......
AoE2 units: I can do complex calculations in my head in a fraction of a second, but I'll be damned if I can figure out how to walk around this villager.
Agree. They should probably build in a 2 tile range and de prioritize pure distance--run the complex calculus with units in your area, not just the exact tied for closest ones, you dummy.
@@RevWoody That would make larger battles horrendous. Imagine your units trying to go to the weakest enemy unit 2 tiles across, getting blocked by other units while itself is beeing attacked. No way.
i will also block my comrades
XD
Units are smart but pathfinding make them look dumb.
I want to say that 100% of the awesome unit AI is from the programmers (such as Dave Pottinger & co.) and zero is from the designers (such as me).
oh i think we got a crossover over here
Real life Barracks: How to wield a sword, to attack, knowledge about art of war until you call yourself a soldier.
AoE2 Barracks: How to know about hit points, armor, hill bonus, bonus damage and the biggest knowledge of all: Having no respect towards elders.
Indeed
filial piety is a useless value
@@Cecilia-ky3uw "Children, obey your parents in the Lord, for this is just. Honour thy father and thy mother, which is the first commandment with a promise: *That it may be well with thee, and thou mayest be long lived upon earth.* And you, fathers, provoke not your children to anger; but bring them up in the discipline and correction of the Lord." Ephesians 6:1-4.
Nah they’re the same.
In a real Barracks you’ll be taught about target prioritization, how to identify an enemies armor, the benefits of fighting from the high ground, how to counter an enemies advantage (such as a swordsman switching to a mordhau grip to better handle plate armor), and off the battlefield, soldiers don’t give a damn who’s the oldest and who has the most experience, they’re all just in the Army.
@@jaspermay5813 I am no christian
The targeting priority for building is understandable as towers, castles and TCs have a certain thing in common other buildings don't: They attack back
Still should imo at least target unit producing buildings over houses as well at least
@@GummieI
ai: "No population, no production!"
@@RheaMainz Mongols "Nope".
@@azh698 Huns!
@@RheaMainz Huns don't build houses, Mongols do but if you research their unique technology they don't lose pop cap if they get destroyed.
They "think" more than I do while chosing targets.
hard to say, your brain is not an algorithm but it does do some impressive things, most of the time intuitively without your awareness.
@bustedoas i like that u said this
They don't think nearly as much as you think. In the big mess that is a battle, the "weakest unit" target priority will rarely come up.
so you micro down siege rams when other units are around?
@@kooroshrostami27 Well, yeah. Those are expensive, big and slow. It catches people's attention faster.
Samurai: "I am the strongest warrior. I will prove this by crushing the enemy with my superior strength, starting with their weakest and ending with their strongest."
Samurai: "Ah yes, an enemy samurai. What a weakling. I'll start here and work my way up to something that poses a real challenge. Like that spearman, for example."
I can't imagine a more fitting piece of characteristic Japanese pride/delusion/lack of self-esteem
They seek duel first then the strongest i
@@sethheristal9561 that's a bit xenophobic
@@ichtyorniscretace9624 maybe. I don't think it's offensive nor I have issues with it tho :D
Weak samurai fears the superior reach of the pointy stick. Glorious ashigaru win yet again.
I'd assume the preference for the oldest units (all other things being equal) is simply because units get added to some sort of list in code which gets iterated through for checking things like which unit to attack, and if there's nothing else to distinguish between it just takes the first unit it comes to in the list.
The rule of attacking the closest sinks all of their expertise though...
Your army worths when lands a hit
It is irrelevant the life of your opponent if you can not reach him, if he can out run you
So the criteria of going to the closest one is indeed a better argument than going for the one with less life
At first, yes. But once the two armies interlock and the first victims fall down this deciding mechanism will do its work just fine.
If they actually do this complex calculation for all the units it won't work for 90s computer.
@@namekiannameless2752 Its not really that hard a calculation, just some basic arithmetic.
@@TheMuffinman191 calculate distance between target unit and all other, choose those that has min. If >1 Then for all them calculate number needed to kill and choose min if>1 use id.
AOE units are so smart they even tricked us by singing: "I'm bad, I'm bad!".
The amount of work you put into these is very appreciated. "The more you know"
There's plenty of things I've changed in my gameplay from SotL videos. Unless I expect a game to go super long, I don't research crop rotation or the final wood upgrade. I use his advice on when to get wheelbarrow etc.
Imagine being angry at someone but he's equally distant to an old man so you just punch him instead.
"Omg I have so many reasons to attack this guy! Oh wait, that other guy is 2 inches closer."
Even after all this time I learn new things about this game...
Yea this game is actually deeper than dota or.just as deep
Maybe this explains how laggy it gets in the late game. Units aren't just calculating unit damage interactions, but also hypothetical unit damage interactions every time a choice has to be made. I bet the developers wish they could redo some of the optimization bottlenecks in that code...
While every little bit adds up I think computationally speaking the equation is fairly fast and computers are very efficient at these things, especially now a days, in fact I would even go as far to say the damage calculation is way faster than the distance calculation it has to do at first since that is comparatively more costly.
This seems very likely now that you mentioned it D:
I wonder if the pro players know this optimization the devs made and would appreciate it more
They do those calcs only when two or more enemies are exactly equidistant. So the code is probably slower due to other reasons. As for what this does in practice, it probably only adds a few lines of code inside an if loop that is never used.
I forgot to say that this would not actually lag the game because chances are units are almost never getting to this calculation in the code because 99.9% of the time there is one unit that is closest and as long as one is closer than the others there is no need for it to do the math. So no this isn't increasing lag.
I assume that decision is on an IF, so it's not all getting evaluated unless the distance check is a tie. So 99.9% of the time it's probably not an issue.
I'm so proud of my son, the Champion. He's always been a straight A's student. It brings a tear to my eye
a duellant who picks a badly wounded opponent over a healthy one. What a coward!
genius*
@@kooroshrostami27 atleast being a coward will make him live whereas your brave men are rotting in the ground while their families sob!
That champion has more brain cells than me in my maths test
We all know that during a math test the amount of active braincells temporarily reduces drastically
Meanwhile... Archers : Lets kill that RAM.
No wonder it always crashes
Nah, archers only prefer to atk a ram over the other units if it stays in front of enemies units. In the end they still stick with the 1st rule always attack the closest one
ram close
archer far
therefore:
MUST SHOOT RAM
We can still target other units right? why is this become a problem? I'm new to AoE, pls help
@@affanhasby822 you have to click each enemy unit at a time, which is not useful in large battle, cuz you will highly overkill
There's a small book that came with my brother's version of the game that has a lot of information, and it says that Samurai "sought out high-ranking enemies on the battlefield for personal duels" Maybe that's what you remember, but it's written in the historical part of their description, and it doesn't seem to be talking about gameplay at all.
This Champion's name was Albert Einstein
Yes.
More like Da Vinci
And then everybody clapped
Yes, that guy again.
The priority of the buildings is actually the most interesting thing. I assume they always attack TCs first even if they don't shoot arrows at them? Or do they always prioritize the buildings attacking them?
I don't like that bombard cannons prefere units over buildings.
@@peterfrenzke6251 It makes sense, bombards are commonly utilized against archers and other siege. Microing them to attack units over buildings is much more difficult than microing them to attach buildings over units.
@@DecagonPorygon in a recent multiplayer team game, I killed 2000 units with (Portugese) bombard cannons 11. They are very important on Amazon Tunnel.
I honestly believe the aoe2 AI should be THE example onto how to make AI for strategy games.
Yes, it comeswith the huge caviat of needing the players to find optimal strategies, so the AI can learn from them (aka the programmers tell it what to do based on what human players do)
But that still leads to extreemly good results!!
You have to remember that it has taken almost 20 years to get to this point, really what we learnt was that if you make your AI easy to mod, the community will create a really good AI.
Unless you are talking about the pathing in which case dear god
It would be a lot more interesting if it wasn't just a tie breaker, i would bet that in practice this almost never happens in real games since the probability of having the 2 closest enemies at the exact same distance is close to 0.
Yes, like if units would consider going walking slightly further for an easy kill.
I’ve noticed this in big patrol fights before, when sometimes units actually change their targets mid-fight to prioritise killing the lower HP unit first. Provided they are equidistant.
I’m always in awe at how well you deliver extremely clever jokes while maintaining perfect flow as if they’re simply fact.
Looking at ranged units would have been interesting as well. Because knowing all this, it seems like an oversight that rams can be used to counter archers although there are weaker units in range and the archer know this as well
good point. maybe it's on purpose because ranged units would be too powerful if they automatically picked the perfect targets.
If the logic showcased in the video applies to all military units, then the Archers will target whichever unit is closest, so it makes sense for them to hit the ram. They will only target the unit that is faster to kill if it's at the same distance as the ram or closer.
@@zerothveratross9975 yes the rule applies to archers as well. but since the rule was probably invented to prevent melee units chasing low hp enemies it makes no sense that the same set of rules apply to both melee and ranged units equally
@@claudius6527 I think the essentially free micro from the AI choosing the targets differently for ranged units would be a balance issue, as well as take out some of the potential depth of the game
To expand on this even more - how do units with minimum range (like skirms) behave. My guess would be that they still attack a viable target, even if another unit is right next to them.
Love your thorough experimentation.
This has been very informative. This helps with my variable calculations with regards to attack move/patrol, vs directed action.
I was just thinking how addicted I am to this game on this rainy sunday and about to sit at my computer to have some multiplayer brawls
What about this scenario:
A) Unit that is close but surrounded, so it cannot be attacked
B) Unit that is close and can be attacked
Or:
A) Unit that is close but surrounded
B) Unit that is further away but can be attacked
Is there any anti-bump built into units?
Great examples, also I'd like to see if they will follow a fleeing unit that was originally closer, but goes away, or if they will switch targets.
To add to that, do they use the nominal distance or actual pathing distance? For example if there's an obstacle between a unit and one of its target, is that one still the closest?
If the pathing is completely blocked I think it just skips to the next unit but what if the closer one is only mostly surrounded so the distance walked to reach it ends up being longer than the next closest one. In gameplay it seems like permanent obstacles factor in but if it's with units it could be different.
distance isnt measured directly ... but pathfinded around all obstacles
so if you make maze it will still find shortest way
if theres no way unit is ignored in favor of any other
@@alanea5860 Do non permanent obstacles get factored in the same way though?
brilliant video :D every time i saw one experiment and though "that's cool, but i wonder if-" the very next experiment answered my question
I am telling you. We are a fan of SOTL video's fonts more than his actual content. What beautiful font Sir!!!
Always nice to get a new SoL video.
Great video!! That's very detailed video indeed
Great video!
Thank you for the info.
I work in a QA job and honestly I wish I had your mindset. You take everything into account.
Great video dood. From now on, I gonna leave my units to decide their attacks !
The auto generated subtitles here are just amazing!
at 2:42 :
weather has just do it well and motivate them with interviews with social workers
It's topics like these that are actually really important but nobody ever seriously thinks about because it all happens automatically i find very - sometimes even most - interesting. It's also a reason why i love Sotl's channel so much, despite all the math
Great vid Spirit
All of this is really cool to know. Thank you.
Thank you. That is really useful information.
I guess with the age thing is they lock on the moment something enters their range and dont swap unless certain conditions are met such as weaker or closer. Did you test putting the enemies down first then spawning the champion in the middle to theoretically remove that element?
They might also be choosing from a global list of enemy units.
Nice analysis! From it i can imagine and recreate target seeking logic in code if needed
However, i'd like to add considering distance into account too.
Been watching for like 2 years even though I didn't play AoE2 anymore. Picked up Definitive in the Steam summer sale and while your videos have helped take a bit of the edge off learning everything I can safely say I am still awful XD Thanks for the awesome content though Spirit!
noticed archers doing it as well, probably another rabbithole there too Spirit, sometimes they even chase a bit the weakest guy before reengaging closer ones
The fact that you thought to be aware of artifacts in the software in terms of the unit placement priority raises my estimation of your abilities.
Just the fact that hills give a modifier blew my mind already, I never knew this when I played this back then
I was sure you would be right, after reading the title, but now I'm more impressed with the unit behaviour than I thought I'd be.
In online multiplayer games, determinism can be quite good. Taking the oldest unit in a tie can be an easy way to get that determinism. It also makes sense programmatically if it is iterating through all units to find the one to attack. It reaches the oldest one first decides to attack it, and then gets no better target.
aah spirit, you always know exacly what game mechanic I did not know I needed to klnow about, but did. Well done sir!
wow. genius for figuring this out. me, i didnt even bother which unit my unit attacks during clashes
Amazing video!
Based on this I would love to see a battle where the 1st step is removed, that is units DON'T attack the closest one. I imagine a 60 v 60 champion fight to actually never finish and it all being a formation match where units keep on realigning themselves and choosing new targets
Great video!
So they think in distance and 'hits'. Nice.
Awesome content keep it going 😉
Whoa, this was amazing to know!
I swear, every time I watch one of your videos, I want to learn how to play OpenTTD. It has such good music
Thats seriously impressive
with my time when i was Younger and played this game after school up until now i have thousands of hours and still had absolutely no clue how impressive the AI actually is
another reason to love AOE2 and to be hyped for AOE4 ( since i didnt like AOE3 )
Great content mate ^^
this fight in the end was beautiful
Super interesting, although I imagine many of us would prefer the targeting to prefer how quickly it would kill over nearest unit within reason. Taking into account damage that could be done to you would be helpful too.
Good video
You forgot in the building target one very important unit trap, they auto target above *all* (except an enemy unit that pass really close to them, or even that not, I'm not sure) an enemy farm they're standing on, if they happen to just have killed another unit while on the farm
Well thought out
So you're telling me the game has this amazingly well-structured priority focus system that would make macro significantly more benefitial... only for them to prioritise closest targets anyway? lol what
Try the same experiment with 200 units on the battle field and remove the closest mechanic. I did once. Completely stopped the AI army with 17 archers.
How does one "remove" that mechanic?
I'd have thought this would be some form of graph search function like Dijkstra or A*, with nodes weighted by distance, type, hp, armour, or any other relevant property. If not, it would be super fun to refactor into one of the afformentioned, nice problem to solve!
Love the video SotL! I assume its the same for Gia? The Boar always picks my weak villagers, or at least that's what it feels like!
Wow these champions are really well educated, they must have been taught by ancient AOE gold sages
This has really made me appreciate my units more!
Great video, thanks :)
OMG this is amazing, great video man. I'm a science person and this is incredible, keep them coming!
I'm getting really emotionally invested in this champion.
Glad to know that even AI prefers to attack to old and weak people xD
"even"?
I am worried for all the elders around you...
This is the most satisfying video you have ever made.
I also noticed that buildings like castles now instantly hit important buildings on the same radio of attack first, for example a tower or enemy tc instead of a closer house. Sadly they still get bugged and dont redirect the attack automatically to passing units, meaning you have to manually target them yourself
You could make a vid on building target priority for trebs as well.
The order seems to go something like
TC
towers
castles
everything else
Great video, as always! But have you ever thought how random "MegaRandom" actually is? Are there any rules the map generation follows, if so, what´s the limit? What is generally the best civ for random and why? I was wondering about that because Megarandom was added to the ranked queue again so I thought about it and couldn´t really settle on a civ I want to pick in case my enemy doesn't want to go random.
The endscreen Transport Tycoon musik is so nostalgic.
That's why I'm subscribed, nice
love these details
The target selection being entirely deterministic is very clearly a design goal of the process, in order for multiplayer to work correctly!
Maybe something you could look into is what is actually random during an Age 2 match.
What about ranged units? Does proximity matter if there are multiple units within range? My hunch is that it does not matter, unless they have to move to get within range of a target, but that's not based on anything.
Yes, good question. Would be interesting to see how ranges units pick their targets in another video.
I noticed even trebuchets will automatically attack important targets (TC and castles). Although it stops right after they finished those, and they start attacking mining camps instead of military buildings that are at equal distance
This is actually super cool information. One thing I would prefer to see from the unit AI, though, is to see a 'buffer zone' for the closest unit rule. Like if you have a 1-hit unit like 3 steps further than the full hp equivalent, that it would go for the 1-hit unit. Something to consider the efficiency of dropping off a unit that might take only an extra game second to reach.
Spirit of the law champion: calculating hp armor hill and bonus damage.
Mine champion: following the same trade cart for 15 minutes.
Those guys are philosophers! Starter than me!!
The strengths and weaknesses of AI compared to humans in games are always very interesting. It reminds me of developing builds for the AI Heroes in Guild Wars 1. They weren't as smart as people but because they had perfect information they played like absolute gods at very specific things like Curses, where they would always know exactly which enemies had debuffs applied to them and would always refresh them the instant they ran out.
here is an issue with the wonder logic: the decision tree might be based on the game mode it was defaulted to, so them not choosing a wonder might depend on that + it might actually depend on unit type and the type of damage it deals to different targets
some developer must be incredibly happy that his effort is finally recognized
Super smart tie-breakers there. Some interesting stuff. As always, great job SOTL.
Would love your take on more practical game stuff from yourself. Like how much damage do you have to do to make a trush worth it... given you're sending 4 or 5 vills across the map. That'd be a nice series. Same can go for drush and scouts, etc. as you're investing military and could have just gone up to castle. How much damage do you need to do in order to make a drush or scout rush worth it? Another could be about laming - how much damage do you have to get in to make laming with a villager worth it... given Goth/Mayan/Chinese get loom first/immediately. Going forward with a vill and laming round resources. Similar comparisons.
A final one... how much does forcing opponent to quickwall reduce their resources through inefficiency (like if they quickwall round berries or wood). Would love your stats and take on those.
I'm not sure if you already have, but could you make a video explaining how the Saracen market bonus works and compare it to how the Guilds tech works? Thank you for fun and enlightening content.
Hmm... makes sense. I remember in AoE1 and its expansion, the CPU's units also frequently targeted my injured units. The logic there seemed flawed and seems to have been improved kinda. Those units would also prefer to hit ranged units if engaged by them first, ignoring others on their way even when taking hits from them. Even if shot first by another ranged unit, the enemy unit seemed likely to target another nearby unit, once it gets close, that is injured (if available). This is what I remember... was some time ago now, haha. More than some time actually...
Yesterday I realised that the trebuchet did target Malay Habour as a priority target, then generic barracks.
Maybe SOTL may make a video discussing the full Hierarchy of siege unit targeting? This time should include all buildings like habour, tower, TC, Castle, krepost, donjons.
5:20 it may work not exactly on the size of the unit, but how the distance is calculated between units.
In some games it takes the distance to the center of another unit, in others it considers the distance to the edge. If the 2nd method is the case, when both enemy Champion and Elephant were at the same distance to the edge, the other factors (like effective health or order of placement) should be observed.
do ranged units always attack the closest one too, or do they target the weakest one in their range?
also it feels kinda impressive that they'd put so much work on something that would hardly ever matter in an actual match, since it's extremely rare for 2 units to be the perfectly exact distance from each other
What about multiple units working together? Does potential damage from other friendly units factor into the decision of what unit to target? For example assume two blue champions (A1 and A2), and three red (B1, B2 and B3). Space these units out so that A1 is of an equal distance to B1 and B2, and A2 is of an equal distance to B2 and B3. Would the blue champions figure out to focus-fire B2, or would they chose their targets independently from each other?
I ponder a guess that it attacks top then left when given a forced choice, oxymoron lol, I postulate that it is because the program is crunching the numbers including sub pixels and such in a way that includes the angle at which the game is played at, and it somehow takes that into account
This is amazing by the way, quite a lot of complexity added simply to create a mechanic that has extremely little impact on gameplay (such that 20 years later most of us are unaware of its existence).
As an aside, it is kind of true that samurai do target stronger units. At least relative to other units and to the extent that uniques are strong. As their bonus will make them comparatively faster to kill.
Should have included trebuchet's target selection as well in this video. Seemingly my trebs always prefer to bring down enemy market first when I leave them unpacked in the middle of the enemy's base.