Complete.Org: Mailing Lists: Archives: freeciv-dev: February 2002:
[Freeciv-Dev] Re: Cache win_chance in get_defender(attacker) (PR#1269)
Home

[Freeciv-Dev] Re: Cache win_chance in get_defender(attacker) (PR#1269)

[Top] [All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index] [Thread Index]
To: rf13@xxxxxxxxxxxxxxxxxxxxxx
Cc: freeciv-dev@xxxxxxxxxxx, bugs@xxxxxxxxxxxxxxxxxxx
Subject: [Freeciv-Dev] Re: Cache win_chance in get_defender(attacker) (PR#1269)
From: Gregory Berkolaiko <gberkolaiko@xxxxxxxxxxx>
Date: Fri, 22 Feb 2002 20:33:18 +0000 (GMT)

 --- Raimar Falke <hawk@xxxxxxxxxxxxxxxxxxxxxxx> wrote: 
> On Fri, Feb 22, 2002 at 10:00:31AM -0800, Gregory Berkolaiko wrote:
> >  --- Gregory Berkolaiko <gberkolaiko@xxxxxxxxxxx> wrote: 
> > >  --- Raimar Falke <hawk@xxxxxxxxxxxxxxxxxxxxxxx> wrote: 
> > > > On Fri, Feb 22, 2002 at 03:34:10PM +0100, Petr Baudis wrote:
> > > > 
> > > > > +             get_total_attack_power(patt, punit) *
> > > > > +             get_total_attack_power(punit, pdef)
> > > > 
> > > > Can't this test be replaced with win_chance?
> > > 
> > > Mmmm, I got so carried away with the idea that win_chance takes too much
> > > CPU,
> > > that I didn't notice that here it won't be more costly...
> > > 
> > > If, that is, we modify get_attacker and get_defender slightly to cache
> the
> > > value of the winchance.  Because all win probabilities were already
> computed
> > > in there.
> > 
> > And a patch to enable this.
> > 
> > This will pave a road for a very simple patch which will make autoattack
> > _significantly_ better.
> > 
> > Of course we don't have to cache the win_chance but it is a big fat
> function
> > to call (and we would need to call it if we want to get the attack profit
> > equation absolutely right).
> 
> How will this be used? I don't see this from the patch.

Obviously in the patch I didn't make any structural changes.

you would use it like this:
patt = get_attacker(nasty_enemy, x, y, &attack_success_chance);

and then use attack_success_chance in want equations or just to compare with
0.5 or some other constant.

you asked whether win_chance can be used in findvictim
the answer is yes and it should be used but you can call win_chance or
get it from get_attacker or get_defender which would've computed it by now.

> If I would do such thing I would do it different from this.
> 
> I would make a cache indexed by the arguments of win_chance and place
> the cache (using a hash) manage code in win_chance. This would provide
> a transparent benefit for all. First and foremost however some
> profiling has to be made. I haven't done profiling in a long time.

think about it a bit more
in my patch you are just passing back (optionally) a value that is already
there and can be used further, and discarding everything that is useless.  
you are going to save result of every computation and then what, search them?
you would index it by what?  pointers to units?  but units move and loose
health and get upgraded...
altogether there are 6 parameters to real win_chance: (firepower, hp, power)*2
some of them don't vary much, but some do.

in findvictim it would be used like this:

/* chances of our successful attack/defence */
int, att_chance;

patt = get_attacker(punit, , , &def_chance);
pdef = get_defender(punit, , , &att_chance);

....

/* Consider defending */
if (map_get_city(x, y) && 
    def_chance > att_chance
    unit_list_size(&(map_get_tile(punit->x, punit->y)->units)) < 2 && 
    get_total_attack_power(patt, punit)) { 

Much nicer than the big inequality, isn't it.

__________________________________________________
Do You Yahoo!?
Everything you'll ever need on one web page
from News and Sport to Email and Music Charts
http://uk.my.yahoo.com


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