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: rf13@xxxxxxxxxxxxxxxxxxxxxx
Cc: freeciv-dev@xxxxxxxxxxx
Subject: [Freeciv-Dev] Re: [RFC] Caching AI values
From: Gregory Berkolaiko <Gregory.Berkolaiko@xxxxxxxxxxxx>
Date: Tue, 19 Mar 2002 14:47:28 +0000 (GMT)

On Tue, 19 Mar 2002, Raimar Falke wrote:

> 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".

let's say "it adapts itself to the spagetti AI".
unfortunately, some aspects of AI are inherently spagetti.

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

Yes, it is a bit coarse but if you refine it further, these values will be 
recalculated too often to give you any time saving.

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

You probably mean "whenever environment changes".  It is a very good 
approach.  But again there are arguments against it:
- too complicated: go trace all events which lead to "cnahge in 
environment"
- you might be doing all this in vain --- how do you know that these 
values will ever be accessed?

To implement 3 we would have to rewrite half of Freeciv to be event-driven 
system.





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