[freeciv-ai] Re: New settler code
[Top] [All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index] [Thread Index]
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!
G.
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.
[..]
- [freeciv-ai] Re: New settler code, (continued)
- [freeciv-ai] Re: New settler code, Ross Wetmore, 2003/04/16
- [freeciv-ai] Re: New settler code, Raimar Falke, 2003/04/17
- [freeciv-ai] Re: New settler code, Jason Dorje Short, 2003/04/14
- [freeciv-ai] Re: New settler code, Mike Kaufman, 2003/04/14
- [freeciv-ai] Re: New settler code, Raimar Falke, 2003/04/14
- [freeciv-ai] Re: New settler code, Per I. Mathisen, 2003/04/14
- [freeciv-ai] Re: New settler code, Per I. Mathisen, 2003/04/26
- [freeciv-ai] Re: New settler code, Gregory Berkolaiko, 2003/04/11
- [freeciv-ai] Re: New settler code, Per I. Mathisen, 2003/04/12
- [freeciv-ai] Re: New settler code, Gregory Berkolaiko, 2003/04/12
[freeciv-ai] Re: New settler code,
Gregory Berkolaiko <=
|
|