Complete.Org: Mailing Lists: Archives: freeciv-dev: September 2001:
[Freeciv-Dev] Re: [PATCH] Cleaned up magic code in gotohand.c (PR#944)
Home

[Freeciv-Dev] Re: [PATCH] Cleaned up magic code in gotohand.c (PR#944)

[Top] [All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index] [Thread Index]
To: rf13@xxxxxxxxxxxxxxxxxxxxxx
Cc: jdorje@xxxxxxxxxxxxxxxxxxxxx, freeciv-dev@xxxxxxxxxxx, bugs@xxxxxxxxxxxxxxxxxxx
Subject: [Freeciv-Dev] Re: [PATCH] Cleaned up magic code in gotohand.c (PR#944)
From: "Ross W. Wetmore" <rwetmore@xxxxxxxxxxxx>
Date: Mon, 10 Sep 2001 00:03:18 -0400

dir_ok and straightest direction are both buggy in the same way.

They are both essentially the same function, except that dir_ok 
returns a TRUE/FALSE value if the direction is the opposite with
a little wiggle room on either side (i.e. the back 3 octants) if
you do it right.

They should not be written as two completely different algorithms.

The best thing is to replace them, not fix magic numbers and then
throw out the fixes when you replace the whole routine :-).

But to put through the rotationally ordered directions, you need
to make changes here, and if you aren't going to use something
like the fixes in the corecleanup patches, replacing magic numbers
is one way to do this.

However, I wouldn't even do this patch until you apply the rotation 
direction patch, as it doen't really gain you anything.

Cheers,
RossW
=====

The algorithm in the corecleanups works by dividing the full square
into 8 octants using the 2x+y, 2y+x, 2x-y and 2y-x lines as borders.

    + c c c c d d d d d
    + c c 2x+yd d d d d
    + c c c d d d d d d
    + c c d d d d d d d
    + c c d d d d d d d
    y c d dx+yd d dy+2x
    + c d d d d d c c c
    + d d d d c c c c c
    + d d c c c c c c c
    + + + + x + + + + +

This is the picture you want with any point in the "d" space taking
a diagonal straightest direction, and any in the "c" space taking a
cartesian straightest direction as their next step. There are 51 "c"
and 49 "d" in the current 10x10 grid (I think). This gives the 
diagonals a slight overall edge, that reflects the fact that you
move diagonally when the diagonal (x+y) and cartesian (+x|+y) are
exactly equal. You will still make the final move from a cartesian
adjacent tile as with the current system. (You of course weren't
fooled by the 51 to 49, because the axis values are shared between 
two quarters, so it is really 41 to 49 in the 19x19=361 full square
with 8 separate directional pies, then you have to remember the 
centre to give the 41*4 + 49*4 + 1 total).

The current routines have "c" only along the axes where the "+" values
are with non-axis values being all "d", weighting 324 "d" to 37 "c"
which is quite a bias away from "straight".


At 09:14 AM 01/09/09 +0200, Raimar Falke wrote:
>On Sat, Sep 08, 2001 at 09:15:16PM -0700, jdorje@xxxxxxxxxxxxxxxxxxxxx wrote:
>> This tiny patch simply replaces the magic numbers for directions in
>> gotohand.c (dir_ok/straightest_direction) with the enumeration values.
>> 
>> I haven't fixed the bug in straightest_direction, but I made a comment
>> about it.  Once this goes through I'll provide a patch to fix it (or I
>> can provide the patch now, but the two issues are separate).
>> 
>> This shouldn't be at all controversial (unless I substituted the numbers
>> wrong :-).
>
>See no problems with this. Ross?
>
>       Raimar
>
>-- 
> email: rf13@xxxxxxxxxxxxxxxxx
>  Living on earth may be expensive, but it includes an annual free trip
>  around the sun.




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