[Freeciv-Dev] Re: [RFC] Caching AI values
[Top] [All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index] [Thread Index]
On Tue, Mar 19, 2002 at 02:47:28PM +0000, Gregory Berkolaiko wrote:
> 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"
We already capsulate common events like got new tech, unit moved, city
build, ... IMHO update_research is a good example for this. It also
calculate values which are cached.
> - you might be doing all this in vain --- how do you know that these
> values will ever be accessed?
Do it lazy.
> To implement 3 we would have to rewrite half of Freeciv to be event-driven
> system.
I don't think so but this depends on the type of the events.
Raimar
--
email: rf13@xxxxxxxxxxxxxxxxx
"Life is too short for reboots."
- [Freeciv-Dev] [RFC] Caching AI values, Gregory Berkolaiko, 2002/03/19
- [Freeciv-Dev] Re: [RFC] Caching AI values, Raimar Falke, 2002/03/19
- [Freeciv-Dev] Re: [RFC] Caching AI values, Gregory Berkolaiko, 2002/03/19
- [Freeciv-Dev] Re: [RFC] Caching AI values,
Raimar Falke <=
- [Freeciv-Dev] Re: [RFC] Caching AI values, Tony Stuckey, 2002/03/19
- [Freeciv-Dev] Re: [RFC] Caching AI values, Gregory Berkolaiko, 2002/03/19
- [Freeciv-Dev] Re: [RFC] Caching AI values, Raimar Falke, 2002/03/19
- [Freeciv-Dev] Re: [RFC] Caching AI values, Gregory Berkolaiko, 2002/03/20
- [Freeciv-Dev] Re: [RFC] Caching AI values, Raimar Falke, 2002/03/21
- [Freeciv-Dev] Re: [RFC] Caching AI values, Gregory Berkolaiko, 2002/03/21
- [Freeciv-Dev] Re: [RFC] Caching AI values, Raimar Falke, 2002/03/21
- [Freeciv-Dev] Re: [RFC] Caching AI values, Ross W. Wetmore, 2002/03/22
- [Freeciv-Dev] Re: [RFC] Caching AI values, Gregory Berkolaiko, 2002/03/23
|
|