Complete.Org: Mailing Lists: Archives: freeciv-dev: October 2001:
[Freeciv-Dev] Re: PATCH: rand_pos function and usage (PR#1017)
Home

[Freeciv-Dev] Re: PATCH: rand_pos function and usage (PR#1017)

[Top] [All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index] [Thread Index]
To: jdorje@xxxxxxxxxxxxxxxxxxxxx
Cc: freeciv-dev@xxxxxxxxxxx, bugs@xxxxxxxxxxxxxxxxxxx
Subject: [Freeciv-Dev] Re: PATCH: rand_pos function and usage (PR#1017)
From: Raimar Falke <hawk@xxxxxxxxxxxxxxxxxxxxxxx>
Date: Thu, 18 Oct 2001 11:31:46 +0200
Reply-to: rf13@xxxxxxxxxxxxxxxxxxxxxx

On Wed, Oct 17, 2001 at 10:01:24PM -0700, jdorje@xxxxxxxxxxxxxxxxxxxxx wrote:
> The attached patch creates a function, rand_pos(&x, &y) that determines
> a random map position.  It also uses it in place of all similar code.
> 
> There are two reasons such a change is needed:
> 
> 1. Current code just does
> 
>   x = myrand(map.xsize);
>   y = myrand(map.ysize);
> 
> and assumes that (x,y) is now a valid position.  Under arbitrary
> topologies, this will not be the case.  It is necessary to check the
> point for validity:
> 
>   do {
>     x = myrand(map.xsize);
>     y = myrand(map.ysize);
>   while (!is_normal_map_pos(x, y));
> 
> This is cleaner and easier to enforce if it is encapsulated within the
> rand_pos function.
> 
> 2. Checks are needed for some of the random position generation.  For
> instance there is code like
> 
>   x = myrand(map.xsize);
>   y = myrand(map.ysize-2) + 1;
> 
> to generate a random non-polar position.  This code will not work under
> arbitrary topologies, since the definition of polar may change (for
> instance, under an iso-rectangular map the north polar region runs along
> the top left diagonal).  We therefore need to generate the position
> first and then check it for validity, for instance:
> 
>   do {
>     rand_pos(&x, &y);
>   } while(y==0 || y==map.ysize-1);
> 
> Later, a different check may be replaced for (y==0||y==map.ysize-1) that
> is topology-dependent.
> 
> This could have efficiency problems if we were looking for a very small
> subset of positions on the map.  Fortunately, there is no such code
> right now.

I'm also converned about efficiency problems. Can't rand_pos take the
range of allowed distances from north. Which now are from
0..map.ysize-1 and latter come from 0..height-1.

        Raimar

-- 
 email: rf13@xxxxxxxxxxxxxxxxx
 "From what I am reading Win98 and NT5.0 will be getting rid of all that
  crap anyway. Seems that Microsoft has invented something called TCP/IP and
  another really revolutionary concept called DNS that eliminates the
  netbios crap too. All that arping from browsers is going to go away.
  I also hear rumors that they are on the verge of breakthrough discoveries
  called NFS, and LPD too. Given enough time and money, they might
  eventually invent Unix."
    -- George Bonser in linux-kernel


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