food trough

The worst monsters in the Hearthlands warp the fabric of space and time..

Re: food trough

Postby Gauteamus » Thu Jan 21, 2010 12:44 pm

The obvious way to solve this would be to store the fodder quality as a floating point number instead of as a (trunkated) integer, and have the trunkating take place on eating instead. This may of course be more of a mess than it sounds, programming wise.

*puh, managed not to make silly puns on trunkating/troughs!
Image<<Bottleneck>>
What if Rosa Parks had a car?
User avatar
Gauteamus
 
Posts: 858
Joined: Fri May 29, 2009 7:16 pm

Re: food trough

Postby 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.
User avatar
Sever
 
Posts: 723
Joined: Fri Aug 28, 2009 8:38 pm
Location: Elsewhere

Re: food trough

Postby Gauteamus » Thu Jan 21, 2010 10:36 pm

Well, in order to raise the average quality (Q), you need to put one point of quality "on top" of each fodder unit already there (N) in addition you have to supply the average quality + one "on top" of the fodder unit to put in. If you manage to do this, you have raised quality by one. X >= Q + N + 1

Nice piece of arithmetics!
Image<<Bottleneck>>
What if Rosa Parks had a car?
User avatar
Gauteamus
 
Posts: 858
Joined: Fri May 29, 2009 7:16 pm

Previous

Return to Bugs

Who is online

Users browsing this forum: No registered users and 1 guest