Bug - Fixed KoLmafia (and Wiki) formula wrong for Temporary Lycanthropy

Veracity

Developer
Staff member
Wiki says this:

The formula for the Muscle gain (in percent) is: round(10+(20*sqrt(X))), where X is the number of "lit moon segments," as defined on the moons page.

The exact effect is as follows:
Lit Segments Bonus
0 10%
1 30%
2 38%
3 45%
4 50%
5 55%
6 59%
7 63%
8 67%
(I love that: "the exact effect is".)

KoLmafia's formula:

Code:
	public static final int getBloodEffect( final int ronaldPhase, final int grimacePhase, final int hamburglarPosition )
	{
		return (int) Math.round( 10.0f + 20.0f *
			Math.sqrt( (float) HolidayDatabase.getMoonlight(
				ronaldPhase, grimacePhase, hamburglarPosition ) ) );
	}
which agrees with the Wiki.

So, when I look at the Effect duration today, what does KoL say?

Code:
<html><head><title>Effect Description</title></head><body bgcolor=white text=black link=black alink=black vlink=black><div id="description"><font face=Arial,Helvetica size=2><center><img src="http://images.kingdomofloathing.com/itemimages/lycanth.gif" width=30 height=30><p><b>Temporary Lycanthropy</b><p></center><blockquote>Your veins are polluted with the blood of the Wereseal.  Your Muscles wax and wane with the moons.<p><i>Oh, no, Paul!  You is a Warsil!</i></blockquote><center><font color=blue><b>Muscle +62%<br></b></font></center></font></font></div></body></html>

Muscle +62%
I could swear that I've seen discrepancies on other days, too, when I've run "checkeffects". Today, that command reports:

# *** modifier Muscle Percent: evaluates to 63 but description says 62
Temporary Lycanthropy Muscle Percent:

Either KoL is reporting the wrong number in the Effect Description, or the Wiki and KoLmafia are wrong.

I know where my money is.
 

Yendor

Member
I have 2538 base Muscle; the effect gives +1597, or 62.92%. So the percentage is not being rounded.

Either KoL is reporting the wrong number in the Effect Description, or the Wiki and KoLmafia are wrong.

I know where my money is.

I hope it was on "all of the above".
 

Veracity

Developer
Staff member
That is very interesting.

I have an AT with base Muscle of 1395. KoL says my adjusted muscle is 2633.

When I remove the "round" from the HolidayDatabase.getBloodEffect(), modtrace muscle says:

Order of the Silver Wossname: +11.00
crumpled felt fedora = +5% (total +5%)
Hodgeman's lobsterskin pants = +20% (total +25%)
Temporary Lycanthropy = +62.92% (total +87.92%)

> ash (11.00 + 1.8792 * 1395)

Returned: 2632.484
So, if KoL is not flooring/truncating/rounding/ceiling the percent modifiers before applying them to muscle, that is what I get.

> ash ceil(11.00 + 1.8792 * 1395)

Returned: 2633
If I apply ceil (or round) to the resulting Muscle value to get an integer, it agrees with what KoL displays for me.

> ash (11.00 + 1.88 * 1395)

Returned: 2633.6
Whereas if I use the Wiki/KoLmafia formula and round the muscle percentage first, you'd have to floor or truncate adjusted Muscle to get an integer that agrees with KoL.

> ash (1.8792 * (1395+11))

Returned: 2642.1552
This shows that you have to multiply by percent modifiers before adding fixed modifiers; otherwise the resulting muscle is way too high.
 

Veracity

Developer
Staff member
Probably. It solves my problem - checkitems evaluates the expression and comes up with something different than KoL's item description - but do we really undesttand where KoL itself applies round() or ceil() to a floating point value to make it into an integer? That's probably a bigger problem than this bug report. It deserves further spading, but this is not the place for it.

I think this is fixed.
 

Veracity

Developer
Staff member
(I love that: "the exact effect is".)
For your amusement, an anecdote speaking to this comment:

A number of years ago, I was trying to solve a bug report in somebody else's code. I tracked down the issue to a single line which performed an erroneous calculation. The comment describing this line?

"This is the correct way to do this."

Priceless. This my go-to example of why I am instantly suspicious when something (the Wiki, in this case) outright tells me that the calculation they are presenting is correct. What is this: "proof by assertion" or "proof by I say so"? :)
 

Bale

Minion
I edited the corrections into the wiki, so that it can be more exact by being approximate.
 
Top