tureptor / terraoptifind

Finds optimal NPC housing combinations for Terraria
MIT License
3 stars 4 forks source link

Some equivalent solutions not recognized #3

Closed bryanclst closed 2 years ago

bryanclst commented 2 years ago

To reproduce, don't select any pylons, and unselect Santa Claus, Tax Collector, Demolitionist, and Tavernkeep (simplifies solutions). There is only 1 solution, but the Steampunker and Cyborg should have a setup where they're in the Desert. In the Snow, their values are 0.84/0.84. In the Desert (you can check this by upping Steampunker's weight), they would be 0.79/0.89, the average of which is equivalent.

Before rounding, Steampunker's 0.84 -> 0.79 decrease from being in the Desert is actually 0.0504, while Cyborg's 0.89 -> 0.84 decrease from being in the Snow is 0.0534. I'm guessing the calculator prioritizes the Cyborg here because of that.

tureptor commented 2 years ago

Great spot, a fix is out. Your guess is close. The calculator rounds the pricing modifier for each NPC before doing further calculations, so the decrease is correctly treated as 0.05 for both, BUT, with JavaScript's floating point implementation, 0.79+0.84 is more(!) than 0.84+0.84 (as you can see below), so the desert biome is seen as worse. The fix is to round it to 8 decimal places after addition to get rid of that …0000002. image