Complete.Org: Mailing Lists: Archives: freeciv-ai: April 2003:
[freeciv-ai] Re: New settler code

[freeciv-ai] Re: New settler code

[Top] [All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index] [Thread Index]
To: Freeciv AI development <freeciv-ai@xxxxxxxxxxx>
Subject: [freeciv-ai] Re: New settler code
From: Gregory Berkolaiko <Gregory.Berkolaiko@xxxxxxxxxxxx>
Date: Mon, 7 Apr 2003 23:17:22 +0100 (BST)

Regarding optimization:

You can easily cache the result of these lines (provided (i,j) != (2,2))
/* Food */
cache->tile[i][j].food = base_city_get_food_tile(i, j, pcity, FALSE);

/* Shields */
cache->tile[i][j].shield = base_city_get_shields_tile(i, j, pcity, FALSE);

/* Trade */
cache->tile[i][j].trade = base_city_get_trade_tile(i, j, pcity, FALSE);

sum = (cache->tile[i][j].food * ai->food_priority
       + cache->tile[i][j].trade * ai->science_priority
       + cache->tile[i][j].shield * ai->shield_priority);
if (cache->tile[i][j].food >= 2) {
  sum *= 2; /* we need this to grow */

You can cache it for one find_best_city_placement operation or you can 
even cache it for the duration of one turn.  There is very little to 
invalidate the result of this calculation: only terrain improvements, but 
even that can wait for one turn.

The only time I can see this cache to be wrong is when we have some weird 
continent-wide wonders and a tile is going to be exploited by a city on 
another continent.  But this is too esoteric.  Continent-wide wonders 
should be banned anyway ;)

But before trying to do the caching I guess we should check if this
calculation is expensive right now.  I guess it is, since for a
mid-continent tile it is repeated up to 20 times!


On Mon, 7 Apr 2003, Per I. Mathisen wrote:

> Important points to notice:
>  -> There is no cacheing. I gave up on that. Still, my code is just a
> handful percentages slower than the current code.

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