[Freeciv-Dev] Re: [PATCH] Cleaned up magic code ingotohand.c (PR#944)
[Top] [All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index] [Thread Index]
"Ross W. Wetmore" wrote:
>
> dir_ok and straightest direction are both buggy in the same way.
Actually, I think straightest_direction has an extra bug. Even if
you're moving directly in a cardinal direction, it will move you
diagonally if possible.
> The best thing is to replace them, not fix magic numbers and then
> throw out the fixes when you replace the whole routine :-).
They definitely need to be replaced. However, fixing the magic numbers
is so easy there's no reason not to do it first.
> However, I wouldn't even do this patch until you apply the rotation
> direction patch, as it doen't really gain you anything.
Huh? Do you mean this patch I submitted? It gets rid of the magic
numbers, making the code more stable and easier to read.
> 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.
Well, that's a good algorithm. It's hard to understand from your
diagram and paragraph, but I agree entirely with what you're saying.
straightest_direction has units currently moving like this for goto
routes:
X is a unit
Y is the target
* is the route
X Y
* *
* *
*
In other words, it strongly prefers to move on a diagonal. Your
algorithm would correct this behavior.
However, I think an even better algorithm might be possible. Your
algorithm is a huge improvement, but will still result in the unit
traveling in either a cartesian direction or a diagonal one to get to a
place where it's a straight cartesian/diagonal route:
X****
*
*
Y
or
X
*
*
*
***Y
The "best" algorithm, I think, would have a unit traveling into as close
to a straight line as possible:
X
**
**
**
Y
I believe this algorithm would be substantially more complicated,
though, whereas yours should still be pretty simple.
jason
|
|