by Sever » Thu Jan 21, 2010 8:59 pm
I did the math of what it would take at the very least to increase or decrease quality by 1.
Where N is the number of units of fodder already in the trough, Q is the current fodder quality, and X is the quality of the food you are adding, and Y is the new quality:
Y = integer[ ((N * Q) + X) / (N + 1) ]
In words, you have the quality and quantity of the fodder in the trough, and they are both integers. In order to properly average this way, you multiply the quality of the fodder by the number of units, which represents the sum of the quality of all the units of fodder that have been collected. To this, you add the quality of the piece of food you are now adding to the trough. Since you want the average again, and the amount of food has gone up by one, you divide the sum quality of all the food by N + 1, which gives you the new average. The kicker that causes this whole mess is the integer[] function, which just cuts off anything after the decimal point.
I'm not sure how quality is accessed, but I doubt it's simple to just store it as a float, but there is a problem with the way this functions that merits a fix.
This is the formula for increasing quality:
(NQ + X) / (N + 1) - Q >= 1
and decreasing:
(NQ + X) / (N + 1) - Q < 0
That is, the new average minus the old quality has to be greater than or equal to 1 in order to increase quality. It must be less than 0 to decrease it.
The thing is, if you simplify those conditions:
decreasing --> (NQ + X) / (N + 1) < Q --> NQ + X < Q(N + 1) --> X < Q(N + 1) - NQ --> X < NQ + Q - NQ --> X < Q
So, whenever the quality you're adding is less than the average quality, it decreases by at least 1. How entrophic. On the other hand, increasing is weird.
increasing --> (NQ + X) / (N + 1) - Q >= 1 --> NQ + X >= (Q + 1)(N + 1) --> X >= NQ + Q + N + 1 - NQ --> X >= Q + N + 1
and since we're dealing with only integers here, you can instead say basically X > Q + N
What.
Side by side:
X < Q in order to decrease quality.
X > Q + N in order to increase quality.
What exactly does the amount of fodder in the trough have to do with the quality of the fodder I'm adding?
Come back two hours earlier.