[Freeciv-Dev] (PR#8474) clean up road_bonus()
[Top] [All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index] [Thread Index]
To: |
undisclosed-recipients: ; |
Subject: |
[Freeciv-Dev] (PR#8474) clean up road_bonus() |
From: |
"James Canete" <use_less@xxxxxxxxxxx> |
Date: |
Thu, 8 Apr 2004 04:52:13 -0700 |
Reply-to: |
rt@xxxxxxxxxxx |
<URL: http://rt.freeciv.org/Ticket/Display.html?id=8474 >
In trying to figure out how to fix autosettlers, I had a look at
road_bonus() in server/settlers.c.
My first reaction was "gak." :) Does this even work with iso-maps? It
seems to treat cardinal directions differently from diagonals for some
reason.
I did find one comment for it in the old changelog: Wrote road_bonus so
that the AI blazes trails and doesn't just build randomly.
As far as I can tell, it checks around a tile for where roads/railroads
are and will be, and if an adjacent road to the tile doesn't fork if we
build a road here, and there is somewhere to go in a arc in that
direction, add to the bonus. <-- that might make a good comment to the
function, more descriptive than "Calculate the attractiveness"
I tried my hand at translating the numbers in the last two blocks of ifs
to directions. A double direction means two steps in that direction.
rd() means there's a road there, te() means that direction is impassible.
if (rd(NW) && !rd(N) && !rd(W) && (!rd(NE) || !rd(NN)) &&
(!te(NE) || !te(E) || !te(SE) || !te(S) || !te(SW))) m++;
if (rd(NE) && !rd(N) && !rd(E) && (!rd(SE) || !rd(EE)) &&
(!te(NW) || !te(W) || !te(SE) || !te(S) || !te(SW))) m++;
if (rd(SW) && !rd(S) && !rd(W) && (!rd(SW) || !rd(SS)) &&
(!te(NE) || !te(E) || !te(SE) || !te(N) || !te(NW))) m++;
if (rd(SE) && !rd(S) && !rd(E) && (!rd(NW) || !rd(WW)) &&
(!te(NE) || !te(W) || !te(NW) || !te(N) || !te(SW))) m++;
if (rd(N) && !rd(E) && !rd(W) && (!te(SW) || !te(S) || !te(SE))) m++;
if (rd(W) && !rd(N) && !rd(S) && (!te(NE) || !te(E) || !te(SE))) m++;
if (rd(E) && !rd(N) && !rd(S) && (!te(NW) || !te(W) || !te(SW))) m++;
if (rd(S) && !rd(E) && !rd(W) && (!te(NW) || !te(N) || !te(NE))) m++;
This seems to be a very emergent-behaviour type solution to building a
network of roads, though it encourages running a road farther and
farther away in a sort of meandering fashion. (though the other tile
valuations ensure that doesn't happen) The obvious question is, is this
good behaviour or should the AI think about connecting up its cities
directly?
-James Canete
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [Freeciv-Dev] (PR#8474) clean up road_bonus(),
James Canete <=
|
|