Live data from Hacker News

Aztec monks with 1/55 HP no longer die when picking up or dropping a relic

reddit.com

251–260 of 267 posts

Re: Aztec monks with 1/55 HP no longer die when picking up or dropping a relic

#256
post #29

Earlier quoted context omitted.

it's because the calculation (1/ 55) is less than the real number 1/55, so when you multiply it by 55 you get a result less than 1. 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

This effect becomes more pronounced, when substracting (but probably also adding) small amounts from big amounts, because more bits are needed to store the big number's more significant digits and floats then lose bits for the less significant digits. That is why, if one needs precision, needs to sort numbers first and then start calculating with the smallest numbers first, working ones way up to the bigger numbers.

Knuth has an entire chapter dedicated to floats, error ranges and such, which includes pretty much that (a+b)+c != a+(b+c) for floats, which in turn breaks tons of things on the math side already. That is such a large issue that it has some serious consequences in the real world, e.g. constructions failing, or I remember the Patriot missile system having problems from that side.

Re: Aztec monks with 1/55 HP no longer die when picking up or dropping a relic

#258

Earlier quoted context omitted.

> IMO the best approach for business logic values is picking the smallest meaningful unit and representing it with integers. How would you design an RTS unit stats system to avoid this AoE Monk HP bug using only integer types?

How much health precision do you need? Make hp an int. Or like a /64 fixed point.

Congratulations, you just introduced a new damage threshold / resistance threshold / etc where things effectively do no damage.

Fixed point would not have helped here. Integer would only have helped because dividing first would break immediately.

Re: Aztec monks with 1/55 HP no longer die when picking up or dropping a relic

#259
post #165
post #157

Earlier quoted context omitted.

> why wouldn’t you also change the damage and other related numbers (such as damage reduction and so on) to percentages as well? Because a sword might do 5HP of damage, not 10% of anyone's damage (whether they've got 50 or 5000HP). Otherwise, hit points are meaningless: 10 attacks with a 10%-damage weapon kills a lowly serf or a mighty dragon. And because damage reduction might reduce a fixed amount of damage from an…

Obviously a dragon doesn’t get damaged at all by a puny little sword. You can’t just say that hitting a dragon with a sword a thousand times would kill it, when none of the attacks can get through the dragon’s armored hide. On the other hand, it will die immediately if pierced by an arrow provided that arrow hits the one spot where the hide is missing a scale. The dragon has 100% DR, except in that one spot.

> Obviously a dragon doesn’t get damaged at all by a puny little sword. You can’t just say that hitting a dragon with a sword a thousand times would kill it, when none of the attacks can get through the dragon’s armored hide.

https://www.youtube.com/watch?v=9VDvgL58h_Y

Re: Aztec monks with 1/55 HP no longer die when picking up or dropping a relic

#260

I don’t understand why they didn’t just use an integer. You can’t have half a HP in AoE and nothing has HP so high that it would overflow a 32 bit integer. Seems like it would avoid a lot of problems.

I had a really fascinating conversation with the lead architect at Frost Giant the other day. They're making the next StarCraft, basically. 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…

Floating point numbers are deterministic, they just depend on thread-global state which has different defaults on differen platforms and can be changed by third-party libraries (including injected ones) at any point.
Post reply on HN