Complete.Org: Mailing Lists: Archives: freeciv-dev: March 2002:
[Freeciv-Dev] Re: Another application for kill_desire equation. (PR#1325
Home

[Freeciv-Dev] Re: Another application for kill_desire equation. (PR#1325

[Top] [All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index] [Thread Index]
To: Gregory Berkolaiko <Gregory.Berkolaiko@xxxxxxxxxxxx>
Cc: freeciv-dev@xxxxxxxxxxx, bugs@xxxxxxxxxxxxxxxxxxx
Subject: [Freeciv-Dev] Re: Another application for kill_desire equation. (PR#1325)
From: Petr Baudis <pasky@xxxxxxxxxxx>
Date: Wed, 13 Mar 2002 17:08:01 +0100

Dear diary, on Wed, Mar 13, 2002 at 04:14:17PM CET, I got a letter,
where Gregory Berkolaiko <Gregory.Berkolaiko@xxxxxxxxxxxx> told me, that...
> On Wed, 13 Mar 2002, Petr Baudis wrote:
> 
> > Dear diary, on Wed, Mar 13, 2002 at 01:45:24PM CET, I got a letter,
> > where Gregory Berkolaiko <Gregory.Berkolaiko@xxxxxxxxxxxx> told me, that...
> > > --- ai/aiunit.c   2002/03/13 11:49:19     1.187
> > > +++ ai/aiunit.c   2002/03/13 12:24:45
> > > @@ -1698,8 +1698,15 @@
> > >            c = (n + m - 1) / m;
> > >            if (!is_ground_unit(punit) && d == 0) b0 = 0;
> > >            else if (c > THRESHOLD) b0 = 0;
> > > -          else b0 = ((b * a - f * d) * SHIELD_WEIGHTING / (a + d)) - 
> > > -            c * (unhap ? SHIELD_WEIGHTING + 2 * TRADE_WEIGHTING : 
> > > SHIELD_WEIGHTING);
> > > +          else {
> > > +     b0 = kill_desire(b, a, f, d, 1);
> > > +     /* Take into account maintainance of the unit */
> > > +     /* FIXME: Depends on the government */
> > > +     b0 -= c * SHIELD_WEIGHTING;
> > > +     /* Take into account unhappiness 
> > > +      * (costs 2 luxuries to compensate) */
> > > +     b0 -= (unhap ? 2 * c * TRADE_WEIGHTING : 0);
> > 
> > We don't need to use ternary operator. I'm also dreaming (obviously in some
> > other patch) about special function like assess_unhappiness(unhap, c), which
> > would unify all those unhappy checks, as there's a lot of them around all 
> > the
> > code.
> 
> Ternary operator (1) is in the original code and (2) I prefer it to 
> the three line if construct:
> if (unhap) {
>   b0 -= 2 * c * TRADE;
> }
> which is just a waste of spce.

I think forcing the braces around each block, even if it's just one command, is
not so great practice, and I like block w/o brackets more than this ternary
thing, but that's matter of taste ;).

> I agree with you completely on the assess_unhappiness(punit, c) function
> (note the different args).  unhap, as it is now, is broken, as it will not
> take into account the unhappiness created when the unit leaves the city it is
> in now...  But that's a different patch definitely.

True :). Usage of punit will be probably better.

> > > +   }
> > >            e = military_amortize(b0, MAX(1, c), fprime);
> > >            if (e > best && ai_fuzzy(pplayer, TRUE)) {
> > >  #ifdef DEBUG
> > 
> > It looks ok otherwise (aside the fact that you use tabs ;).
> 
> maybe I'll hack emacs C mode... :(

.oO(echo ":set expandtabs" >>~/.vimrc; vim aiunit.c)

-- 

                                Petr "Pasky" Baudis

* elinks maintainer                * IPv6 guy (XS26 co-coordinator)
* IRCnet operator                  * FreeCiv AI hacker
.
"If you have acquired knowledge, what do you lack?
    If you lack knowledge, what have you acquired?"
Lev. R. 1:6
.
Public PGP key && geekcode && homepage: http://pasky.ji.cz/~pasky/


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