Complete.Org: Mailing Lists: Archives: freeciv-dev: March 2002:
[Freeciv-Dev] Re: [RFC] Caching AI values
Home

[Freeciv-Dev] Re: [RFC] Caching AI values

[Top] [All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index] [Thread Index]
To: Gregory Berkolaiko <Gregory.Berkolaiko@xxxxxxxxxxxx>
Cc: freeciv-dev@xxxxxxxxxxx
Subject: [Freeciv-Dev] Re: [RFC] Caching AI values
From: Raimar Falke <hawk@xxxxxxxxxxxxxxxxxxxxxxx>
Date: Tue, 19 Mar 2002 15:17:47 +0100
Reply-to: rf13@xxxxxxxxxxxxxxxxxxxxxx

On Tue, Mar 19, 2002 at 01:39:34PM +0000, Gregory Berkolaiko wrote:
> While doing flying stuff, AI computes a few values which should be cached 
> (like the number of air targets around a city).  I can see 2 approaches to 
> such caching:
> 
> 1. Compute these values at the start of the AI player's turn.
> 
> 2. Compute these values as needed and then record them into a struct 
> together with the time they were computed.
> 
> I favour the second approach greatly.  First, you don't have to trace the
> spagetti AI calls to see to it that the values are initialized before
> being accessed.  Second, you don't have to decide beforehand if you should
> waste CPU initializing them at all or it's too earely in the game to do
> that (doesn't make much sense to count the number of air targets before
> you discover Flight): in approach 2 they would be initialized as needed.
> 
> But to execute 2nd approach efficiently, one has to have the "time"  
> concept.  I remember Raimar and Co talking about game.turn variable or
> somethign like this.  My time has to be a bit more precise, I think: there
> are two AI movement phases per turn and "time" should distinguish
> between "turn 10 start-turn" and "turn 10 end-turn".
> 
> Please provide me with insightful remarks and great suggestion on these 
> matters.

IMHO the second approach favors the spagetti AI. I can image a
description like "if foo is called from bar with option X than the
value is updated else the value is set by foobar".

IMHO the granularity of pre-turn, post-turn is too coarse. But this
depends on exactly what you try to measure.

There is another solution possible:
 3. Update the value whenever this is necessary

        Raimar

-- 
 email: rf13@xxxxxxxxxxxxxxxxx
  "The primary purpose of the DATA statement is to give names to
   constants; instead of referring to pi as 3.141592653589793 at every
   appearance, the variable PI can be given that value with a DATA
   statement and used instead of the longer form of the constant. This
   also simplifies modifying the program, should the value of pi
   change."
    -- FORTRAN manual for Xerox Computers


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