Complete.Org: Mailing Lists: Archives: freeciv-dev: November 2001:
[Freeciv-Dev] Re: RFC: Fixing movement code

[Freeciv-Dev] Re: RFC: Fixing movement code

[Top] [All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index] [Thread Index]
To: Raahul Kumar <raahul_da_man@xxxxxxxxx>
Cc: freeciv development list <freeciv-dev@xxxxxxxxxxx>
Subject: [Freeciv-Dev] Re: RFC: Fixing movement code
From: Petr Baudis <pasky@xxxxxxxxxxx>
Date: Fri, 23 Nov 2001 14:35:03 +0100

> > > what the hell is b? 
> > >           b = unit_type(pdef)->build_cost;
> > /* bonus restored 980804 -- Syela */ - so b == bonus?
> > > b = (b + 40) * punit->hp / unit_type(punit)->hp;
> > and finally..
> > e = ((b * a - f * d) * SHIELD_WEIGHTING / (a + d) - c * SHIELD_WEIGHTING);
> > (final calculation)
> > 
> > i see no other usage of it. looks really like bonus enemy unit has against
> > our
> > one.
> >
> What bonus? Where does this come from? What exactly is this bonus, what 
> effects
> it etc? All I can see is that if an enemy unit is in a city this bonus 
> applies.
> Bizarre. What the hell does build-cost have to do with bonuses?
Basic bonus is 'price' of the victim (build_cost), how valuable it is. In the
city, we increase the bonus by 40, and modified by the health of our unit
(* punit->hp / unit_type(punit)->hp). I don't get why it is corrected by the
health of our unit only in the city, that looks very misterious.. I would think
it would be more correct to do this everytime, i think i will try that and run
some tests..

In the coeficient, bonus is used in the numerator, multiplied by agressivity,
so it looks it is something as 'appetency' of the victim, how nice it would be
to destroy. Larger price, enemy will have worse loss. If it is in the city,
loss will be even worse. And as I think about it now... it looks that we correct
it with our health because there may be more units in the city stacked, and we
won't destroy them all, so in the next turn they may attack us. So we shouldn't
do this with injured units. Obviously, to be more precise, we should check for
that everytime, however that would be too expensive.

> > c is zero everytime, no other assigment, so we can safely remove it imho.
> >
> Maybe, maybe not. c is used in other ai functions.
Removed c and the assigment and it compiles fine for me. It really looks this
function was originally just copy of an older one, who knows.. However 'c'
looks like purely historical thing.

> > a is most misterious. however, after some study of code, it seems to me it
> > is kinda 'aggressivity'. in the mind comes that we can pre-compute
> > something before, so it will speed things a bit.
> >
> Can you define aggressivity? We need some comments.
It is like the contrary to vulnerability, that is clear after look at coef.
It is computed from belligerence (which is real vulnerability contrary), and
we add value of possibly reinforcements which may come to it. And at last
we make a square of it. So it is the ability of destroying the enemy, the
morale of soldiers there ;-).

Looking at the formula more carefully...

            coef = ((bonus * agress - unit_type(punit)->build_cost * vuln) * 
                    (agress + vuln) * SHIELD_WEIGHTING);

This looks to me as it is broken:

        (appetency - danger) * S_W
coef = ---------------------------- * S_W
              agress + vuln                    <- i don't get that too :-)

that means, we do SHIELD_WEIGHTING^2 in practice. Not sure, if that is correct,
as I have not very clear idea, how exactly S_W is used, however if it is 
we should make the formula more clear anyway, like:

            coef = ((bonus * agress - unit_type(punit)->build_cost * vuln) /
                    (agress + vuln) * SHIELD_WEIGHTING * SHIELD_WEIGHTING);

or, if it is meant in another way, like:

            coef = ((bonus * agress - unit_type(punit)->build_cost * vuln) *
                    (SHIELD_WEIGHTING / (agress + vuln)) * SHIELD_WEIGHTING);

note that this three formulas are mathematically equivalent.

>                                                     You seem to understand
> this code suspiciously well. Are you one of the original ai writers?
Nope, i just have read the code. well, the first code in freeciv i'm looking in
more carefully at all ;-).

> >           /* arguable that I should use reinforcement_cost here?? -- Syela 
> > */
> >           if (a && is_my_turn(punit, pdef)) {
           if (agress && is_my_turn(punit, pdef)) {
sorry :)

> Petr Baudis Email pasky@xxxxxxxxxxx
> Changed  ai_military_find_victim
yup, only rather pasky@xxxxx, please, thanks.. :)


                                Petr "Pasky" Baudis

UN*X programmer, UN*X administrator, hobbies = IPv6, IRC
Real Users hate Real Programmers.
Public PGP key, geekcode and stuff:

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