525 points · by danso · 3y ago · 208 comments
"This was caused by a floating point rounding error. A unit switching jobs internally becomes a different unit (i.e. a monk with a relic becomes a monk without a relic), and when doing that, HP is scaled proportionally based on the old and new max HP using 32-bit floating point maths."
And there are YouTube videos about this https://www.youtube.com/watch?v=MytWNbpnAVY
> Due to floating point rounding errors, convert_hp(1, 55, 55) equals 0.999999940395355224609375, which is less than 1, which means the unit dies.
Ahh. The old "Multiplying and dividing is associative... for the set of reals, not for the subset that you can actually afford to compute with." So it should have been `(new_maxhp * old_hp) / old_maxhp`. ffmpeg has a whole AVRational class for the same type of problem when converting timestamps accurately between 2 timebases.
Reminds me of the TF2 ammo boxes that give 40 metal on Linux and 41 on Windows https://www.youtube.com/watch?v=QzZoo1yAQag&pp=ygUfdGYyIGhlY...
Apparently the compiler used on Linux chose a less-accurate multiply instruction for 0.2 * 200.
Two wrongs make a right - After being less accurate but rounding up where you don't need to, the Linux binary correctly arrives at 40, and the Windows binary arrives at 41.
For percents (and dollars) I always do everything in cents and divide by 100 at the very end. "20 * 200 / 100" can be done with pure ints, and f32 can represent i16 exactly.
The more I write code, the more I notice how rarely one truly should want floats in most kinds of programs and how they almost always carry a whole bag of problems with them.
It's 2023: I'm still surprised that so many new languages/platforms still only provide only basic integer and IEEE-754 types for numerics: Rust, C#, Java, Swift and others still lack built-in, runtime-provided, nor even standard-library-provided rational types, which I assume really should be the preferred type for most business/domain/application values, exactly for things like RTS game unit health, for example. (and Java's lack of operator overloading makes this even more painful).
----
On a related note, can we agree that an application-programming language today should also include signed-and-unsigned "money-safe" decimal types, and IEEE-754 types should be smarter about when NaN can happen - and it should support interval types (and evaluating interval-type-based contract invariants): this would eliminate whole classes of bugs in the first place (too many programmers think single/double is appropriate for storing currency values, ugh).
"Oh, the solution is obvious: you should simply round that to an approximate fraction..." — yes, and that's floating-point arithmetic. Point is, you can't use either with thinking, about numerical representations and their possible failure modes.
It doesn't feel immediately like there ought to be a problem, but witness, mathematically almost all of the reals are Normal and unfortunately Normal doesn't mean "normal" it's a technical mathematical word, that for our purposes means roughly "completely batshit".
Normal numbers are non-computable, so we definitely don't want to try to use them in software, which is a problem because again, almost all of the reals are Normal.
This! Imho you more or less never want floats under "normal" conditions.
Also in most application domains it makes exactly no difference that floats have HW support, as the bottlenecks are there usually elsewhere. And in case you really need real fast floating point math (say for simulations) you would do it anyway on the GPU nowadays.
The only langue I know of that is sane in this regard is Pyret:
[CTRL-F: Pyret has numbers]
I'm still baffled no other new language thought about something so basic like number ever again. Everybody is just using what the HW provides natively since the year of yore. As a result there is no motivation for HW vendors to update the status quo form the state of the art of the 60's of the last century. Imho having support for rationals and (fixpoint) decimal numbers in std. hardware is long overdue! But it would only happen if there would be serous demand form the runtime / language vendors. Classical chicken egg problem.
Enter the typical floating point types that do some of that work already: float/double. These let you not think (as much) about the memory your math might take up, but they still need you to think about rounding, which almost no one does.
This is a long winded way of saying that if you set up your arbitrary precision arithmetic library to use 4 bytes and the same rounding mode (the default is round to nearest) as was used here, you'd reproduce the bug. You'd also reproduce the 64-bit bug moving up sizes, and the 128/256/etc bug. You gotta round.
The good news, though, is that actually solves it! You can even use floats for money!
Why can’t they store HP internally as “millihealth” integers, do integer arithmetic (including division), and then divide that by 1000 purely for display?
If killing unit takes X attacks, user buys 10% attack damage upgrade, and it still takes X attacks they will be annoyed. If rounding down takes that to x-1 attacks it might be preferable.
That being said you're absolutely right. just use HP*100 in calculations and display HP/100 to the user, and when you need to round into specific direction do it explicitly
bool is_alive(const Entity* unit) {
return unit->hp > ZERO_FLOAT;
}
Super easy…Likewise I’m with you, the more I code, the more I see these kinds of things as bad design choices. If you’re going to deal with a type, keep it that type. If you’re going to convert, you need to take care of edge cases like OP. And don’t just add 0.0001f; that’s an exploit waiting to happen by someone with a macro to pickup/drop relics.
Modern CPUs can effectively emulate whole subroutines in microcode, but somehow we got stuck with that useless binary floating point standard for numbers. And on top of that, languages provide them as a default numeric system for all new software.
This is exactly why heroes won't die in Dota2 when toggling off armlet while having 1 hp
Rationals have a big problem where under multiplication and division they need to be re-normalized periodically, and that re-normalization is slow (running gcd). Under addition and subtraction, rationals are great.
*the one big difference is that division rounding is different
Psstt... Dividing is not associative for the reals.
Is it because 55/55 != 1, or 1*1 != 1?
I understand float can't store certain integer/finite decimal precisely, but why would a/a not be 1 if both numerator and denominator are the same (imprecise) number?
for an easier to follow example, say you can only work with two decimal places, hp was 1, old max hp was 3 and new max hp was also 3. if you do (3 * 1) / 3 you get 3 / 3 = 1 as intended. if instead you do 3 * (1 / 3) you get 3 * 0.33 = 0.99 which is less than 1
I don't see how that couldn't run into similar problems. I would use `clamp(old_hp * (new_maxhp / old_maxhp), 1, new_maxhp)` (assuming that old_hp >= 1).
Otherwise you get loss from the division and then multiply that loss (by >1).
I told my GF that last night I had insomnia and found myself researching why Aztec monks die when picking up a relic, and that doing so resulted in plumbing the depths of an important computer science topic.
She said "Sounds like you were reading Hacker News". She knows me so well now :)
Blizzard ought to take note. A few years back they announced “Warcraft 3 reforged” with great fanfare: a remastered version of the classic Warcraft 3, updated for modern systems with improved graphics etc. It looked/sounded fantastic!
But despite it being a paid upgrade, what they released was a buggy mess that did little justice to the classic original. Then they immediately abandoned it and have released no updates or fixes since.
This is subjective, but I liked some of the old unit designs more than the new ones. For example Teutonic Knights and Cataphracts looked better in my opinion. The Teutonic Knight looked leaner and taller, while it now looks a bit like a walking barrel. OK, somewhere they need to carry all that armor ... but still I liked the old ones better.
Also I would have been completely fine with units having only 8 or whatever directions in which they can look. I don't need 360° all-around rendering of units. It even substracts a little from AoE2's abstract character.
What I do like is, that they added more civs.
But you don't have it anyway? I assumed the game is still actually isometric and not 3d but even if it is the camera is still fixed.
https://news.blizzard.com/en-gb/warcraft3/23896791/warcraft-...
I'll have to take another look now that this has been released.
But still, there was a 2 year stretch between 2020 and 2022 when the game was in a very crappy state and absolutely nothing was done to improve it or address the issues.
The Forgotten Empires team is brilliant and I can't be more grateful to them for bringing back a childhood favorite.
For a 24 year old game!
A bunch of guys in my company play it. Most of them were 3 or 4 years when the game was released. A couple of them weren't even born.
Real kudos to the team maintaining it. They constantly listen to player feedback and keep updating the various unit stats and bonuses to keep the game balanced.
For even more abstract ones I cannot recommend enough the Dwarf Fortress Bugs Twitter account[0]
The last of which is
> Flying creatures keep exploding into pieces and dying: Are they crashing into trees?
[0]sadly no Mastodon, https://twitter.com/DwarfFortBugs
- Handsome and lustful men now also populate the cabins in the wild for the pleasures of people who find them attractive.
- Characters who love their spouses very much are now less likely to join holy orders.
- Paranoid parents should no longer worry about potential plots against dead children.
- Fixed that bedtime stories can no longer be told to dead children
- You no longer punish yourself when a prisoner tries to flee from your prison by charming the guard.
- The Orthodox Patriarch is now concerned if Orthodox rulers have heathens in their court.
- Discovering two vassals of the same sex engaging in carnal activities during pagan feasts no longer let's the liege join in on the fun.
- Ambitious claimant adventurers now move out of the realm if they are targetting their liege
- No longer possible to banish your spouse or concubine
- Decreased monthly decadence gain.
[0]: https://forum.paradoxplaza.com/forum/threads/patch-2-4-chang...
And I wonder about dead children. I remember one game where there could be no dead children.
>And I wonder about dead children. I remember one game where there could be no dead children.
Probably Skyrim, though it's not rare. Crusader Kings somewhat encourages infanticide, as your brother's bastard could stop your character from inheriting a title.
As an aside, while I understand the motivation for this kind of thing, I remember finding a child's body after a firefight in Deus Ex and having a moment of moral anxiety as I wondered whether it had been one of my stray bullets or someone else's (or even unrelated to the fight).
Although I'm not sure why a threesome during a pagan festival has become illegal, I'd have considered that a feature, not a bug.
T90 is probably the strongest dedicated commentator / announcer / caster in this community.
Fun fact: In the early days (I think the first 6 months or so) of GW there were some item attribute modifiers that I think allowed for going as low as 5 hp, making the character basically invincible, as all damage was rounded down.
Beat RTS ever in my opinion.
Check out big tournament to get an idea of the current scene: https://youtu.be/6krbA4jTUqE
Also I didn't play multiplayer until last month, most of that 600 hours was spent in the many many excellent single player campaigns
They don't use floating points.
He didn't mention (IIRC) the possibility of rounding bugs; the reason he cited was something a bit more interesting: Floating points are not deterministic, which makes multiplayer challenging, as they simulate game state on each client's computers and only send commands across the wire.
One wonders if the "out of sync" errors that plagued Age of Empires in my youth were partially explained by FP determinism issues!
I'm pretty sure you could get the compiler to warn you about this stuff though.
Build orders will absolutely change this patch. Though I guess that only matters if you were hoping to get to a competitive level.
Definitive Edition does have a very good tutorial mode for people interested in online combat, and "Extreme" AI is 100% legitimate (AoE2 Extreme does NOT cheat, you're fighting it fair-and-square, but Extreme does a proper build order so it just "feels" quick if you haven't studied build orders yet)
EDIT: case in point. Vikings, a civilization with numerous infantry buffs, was played as an Archer civ in practice because even with all their infantry buffs, XBow / Arbalest was considered stronger.
The biggest change this patch is a new tech for +1 pierce armor to the Longswords line, which can be researched in Castle Age. Furthermore, the entire line of infantry can upgrade faster, and cheaper. Finally, most infantry civs (Malians, Goths, etc. etc.) have gotten significant economy buffs to make them even stronger. Whether or not its enough for infantry to shine is to be seen.
Theve been trying to push infantry with small buffs , and this is patch has seen some more buffs to infantry and infantry civs.
They have been releasing expansion adding new civilizations every ~6 months or so together with a bunch of balance changes.
> stay popular
It didn't. Not too such an extent as it is now. For years it had only community support and a fairly small player base. Microsoft resurrected it not so long ago.
There wasn't any real balance patch. Just people who have gotten much better at luring deer to improve early build orders. Like 3 years ago, you'd just assume 2x Boar + 8x sheep as your early food source. But today, people are adding 2x or even 3x deer to that.
As deer + boars collect food at the fastest rate, you can more consistently go up at lower villager counts. There's also much more precision: killing boars / deer / sheep under the town center more consistently today than before.
--------
TL;DR: Skill improved, people can do 18 pop today even though its always been possible. So people are just getting faster and more optimized.
The goal of the April patch was to make organ guns more of an anti-unit shotgun, and less of a wall destroyer. So you'll see fewer organ guns on Arena (one of the few maps that start off fully stone walled).
Sigh
Seems to work fine with Wine and Crossover.
Also you could probably just install ARM Windows in a VM, not sure how good is the Windows translation thing compared to Rosetta though you might end up with a worse experience than just by using Wine.
These historical games have two ways of doing things. Staying historically correct (which is unbalanced... such as Hearts of Iron where Soviets + Germany will likely crush Poland in the first move every game), or you balance the game so that everyone has a fair chance like AoE2. But balancing the game naturally introduces significant ahistorical aspects.
--------
AOE2's historical campaigns are pretty good though, and somewhat representative of famous battles throughout history.
* The linked-to patch notes? https://www.ageofempires.com/news/age-of-empires-ii-definiti...
* The particular comment explaining this bug fix? https://old.reddit.com/r/Games/comments/12jbb9d/age_of_empir...
(the official patch notes don't explain the bug)