Complete.Org: Mailing Lists: Archives: freeciv-dev: May 2005:
[Freeciv-Dev] Re: (PR#12946) FACTOR in consider_settler_action
Home

[Freeciv-Dev] Re: (PR#12946) FACTOR in consider_settler_action

[Top] [All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index] [Thread Index]
To: bdunstan149@xxxxxxxxx
Subject: [Freeciv-Dev] Re: (PR#12946) FACTOR in consider_settler_action
From: "Peter Schaefer" <peter.schaefer@xxxxxxxxx>
Date: Sun, 1 May 2005 16:35:41 -0700
Reply-to: bugs@xxxxxxxxxxx

<URL: http://bugs.freeciv.org/Ticket/Display.html?id=12946 >

Well, I looked into road_bonus in settlers by accident, trying to
follow your discussion.

If the following FIXME is still interesting:

  /*
   * Consider the following tile arrangement (numbered in hex):
   *
   *   8
   *  012
   * 93 4A
   *  567
   *   B
   *
   * these are the tiles defined by the (dx,dy) arrays above.
   *
   * Then the following algorithm is supposed to determine if it's a good
   * idea to build a road here.  Note this won't work well for hex maps
   * since the (dx,dy) arrays will not cover the same tiles.
   *
   * FIXME: if you can understand the algorithm below please rewrite this
   * explanation!
   */
  if (has_road[0]
      && !has_road[1] && !has_road[3]
      && (!has_road[2] || !has_road[8])
      && (!is_slow[2] || !is_slow[4] || !is_slow[7]
          || !is_slow[6] || !is_slow[5])) {
    bonus++;
  }

Then I'd just suggest applying DeMorgans law and rewriting the code,
after which it is understandable, at least to me(might even be
nanoseconds faster due to less negations):

  if (has_road[0]
      && !has_road[1] && !has_road[3]
      && !(has_road[2] && has_road[8])
      && !(is_slow[2] && is_slow[4] && is_slow[7]
          && is_slow[6] && is_slow[5])) {
    bonus++;
  }

So as a comment, that would mean
"If there is a road on 0, and there is not a road over 8, 2, and not
all of the tiles on the other side are deadends, then this is a good
place for a road. The case of a road over 0,9,5 is handled by the
condition starting with a road in 5, so this is symmetric."

Also, since || short-circuits on true while && short-circuits on
false, this is of similar performance.
Please check above code, I might have forgotten a ! somewhere.


On 5/1/05, Brian Dunstan <bdunstan149@xxxxxxxxx> wrote:
> 
> <URL: http://bugs.freeciv.org/Ticket/Display.html?id=12946 >
> 
> --- Benoit Hudson <bh@xxxxxxxxxxxxxxxxxxx> wrote:
> >
> > <URL:
> > http://bugs.freeciv.org/Ticket/Display.html?id=12946
> > >
> >
> > On Sun, May 01, 2005 at 04:10:42AM -0700, Benedict
> > Adamson wrote:
> > > Those multipliers are used so we can use integer
> > arithmetic, which in
> > > turn is done because integer arithmetic is faster
> > than floating-point
> > > arithmetic (right?). But it introduces bugs like
> > this (I have a vague
> > > recollection of similar bugs previously). But is
> > this 'optimisation'
> > > really worthwhile? Is the performance gain large
> > enough to justify the
> > > decreased reliability? I would not be surprised if
> > the gain were small.
> >
> > There's more than one reason to be wary of floating
> > point, such as:
> >         1e-8 != (1.0 + 1e-8) - 1.0
> > Also, Intel boxes have different floating-point
> > (80-bit inside the FPU,
> > 64-bit in memory) than the rest of the world (64-bit
> > everywhere), which
> > means that client and server may disagree on certain
> > things if they run
> > on different platforms.
> >
> > But generally I agree that floating point should be
> > used more often.
> >
> >         -- Beno�t
> 
> I wonder if maybe we should decide on a common way of
> handling numerical issues, and include that in
> CodingStyle?
> 
> In particular, I think a standard unit of economic
> value would be a good thing for freeciv.
> 
> 
> __________________________________________________
> Do You Yahoo!?
> Tired of spam?  Yahoo! Mail has the best spam protection around
> http://mail.yahoo.com
> 
>





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