[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]
On Fri, Feb 22, 2002 at 08:33:18PM +0000, Gregory Berkolaiko wrote:
> --- 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.
I just want that we thing about a good interface before we add some
non-straightforward way to get an intermediate result for speed.
What about a function
double win_chance_against_stack_at_tile(punit, target_x, target_y)
? This function would built on top of win_chance. This is IMHO also
what we try here to approximate: unit against stack.
> > 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.
But these 6 ints can form a key for a hash.
> 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.
Ack. But the way you got these values is ugly. For example you don't
need the patt anymore.
Raimar
--
email: rf13@xxxxxxxxxxxxxxxxx
What's nice about GUI is that you see what you manipulate.
What's bad about GUI is that you can only manipulate what you see.
- [Freeciv-Dev] Cache win_chance in get_defender(attacker) (PR#1269), Gregory Berkolaiko, 2002/02/22
- [Freeciv-Dev] Re: Cache win_chance in get_defender(attacker) (PR#1269), Raimar Falke, 2002/02/22
- [Freeciv-Dev] Re: Cache win_chance in get_defender(attacker) (PR#1269), Gregory Berkolaiko, 2002/02/22
- [Freeciv-Dev] Re: Cache win_chance in get_defender(attacker) (PR#1269), Raimar Falke, 2002/02/23
- [Freeciv-Dev] Unit-vs-stack sim (was: Cache win_chance), Gregory Berkolaiko, 2002/02/23
- [Freeciv-Dev] Re: Unit-vs-stack sim (was: Cache win_chance), Raimar Falke, 2002/02/23
- [Freeciv-Dev] Re: Unit-vs-stack sim (was: Cache win_chance), Gregory Berkolaiko, 2002/02/23
- [Freeciv-Dev] Re: Unit-vs-stack sim (was: Cache win_chance), Raimar Falke, 2002/02/23
- [Freeciv-Dev] Re: Unit-vs-stack sim (was: Cache win_chance), Gregory Berkolaiko, 2002/02/23
|
|