Complete.Org: Mailing Lists: Archives: freeciv-dev: April 2002:
[Freeciv-Dev] Re: server/settlers.c cleanup 3
Home

[Freeciv-Dev] Re: server/settlers.c cleanup 3

[Top] [All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index] [Thread Index]
To: Markus Linnala <maage@xxxxxxxxx>
Cc: freeciv-dev@xxxxxxxxxxx
Subject: [Freeciv-Dev] Re: server/settlers.c cleanup 3
From: Gregory Berkolaiko <Gregory.Berkolaiko@xxxxxxxxxxxx>
Date: Tue, 16 Apr 2002 12:50:12 +0100 (BST)

On 16 Apr 2002, Markus Linnala wrote:

> "Ross W. Wetmore" <rwetmore@xxxxxxxxxxxx> writes:
> 
> > A good way to handle weighting functions is to make all your input
> > calculations run in a fixed range, then pass the final result through
> > an array lookup where the array is pre-computed for the set of values
> > and that particular weighting function.
> 
> int amortize(int benefit, int delay)
> 
> I made quick test (added debug log and ran a game) and seems
> that benefit had range 0 - 11857, but only had 1596 distinct
> values. Delay had range between 0 - 396525, but effective range
> was between 0 and 234 because if delay is big amortize goes to
> 0.

Since the result is benefit * something^delay
all we need is precomputed array of 235 floats and then the code would be


int amortize(int benefit, int delay)
{
  static float amort_factorp[235] = 
    {1, 0.99, 0.976, ....}

  if (delay < 0 || delay > 234) return 0;

  return (int) benefit * amort_factor[delay];
}

where I have probably commited some capital crimes by treating FP number 
improperly.


This, however, does not provide the possibility of varying MORT, so I 
guess it's of little use.

G.

> 
> Because benefit is 10 times bigger than another benefit, value
> is also 10 times that. So we need only fixed range of 10, 100 or
> 1000 precomputed values at benefit. First scale benefit or down
> and later scale value back.
> 
> Guess we need precomputed array of size about 100k
> (100*256*sizeof(int)).
> 
> 
> We could also check if delay is bigger than some value, return
> zero. We in the earth we need to amortize something that has
> delay over 1000? Bug somewhere maybe?
> 
> 



[Prev in Thread] Current Thread [Next in Thread]