Complete.Org: Mailing Lists: Archives: freeciv-dev: March 2002:
[Freeciv-Dev] Re: [PATCH] get rid of floating point calculations (PR#130
Home

[Freeciv-Dev] Re: [PATCH] get rid of floating point calculations (PR#130

[Top] [All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index] [Thread Index]
To: Gregory Berkolaiko <Gregory.Berkolaiko@xxxxxxxxxxxx>
Cc: Markus Linnala <maage@xxxxxxxxx>, freeciv-dev@xxxxxxxxxxx, bugs@xxxxxxxxxxxxxxxxxxx
Subject: [Freeciv-Dev] Re: [PATCH] get rid of floating point calculations (PR#1309)
From: Raimar Falke <hawk@xxxxxxxxxxxxxxxxxxxxxxx>
Date: Fri, 15 Mar 2002 14:08:11 +0100
Reply-to: rf13@xxxxxxxxxxxxxxxxxxxxxx

On Fri, Mar 15, 2002 at 12:23:07PM +0000, Gregory Berkolaiko wrote:
> On Fri, 15 Mar 2002, Raimar Falke wrote:
> 
> > On Tue, Mar 12, 2002 at 07:17:29PM +0100, Raimar Falke wrote:
> > > On Sun, Mar 10, 2002 at 07:45:53AM -0800, Markus Linnala wrote:
> > > > 
> > > > Try to get rid of floating point calculations.
> > > 
> > > Some/all of these get cleaned up with the defense calculation cleanup
> > > patch. The patch will be committed in the next few days.
> > 
> > Attached is a an updated patch for this and 1320.
> 
> It looks fine but I wouldn't mind an explanation for the division by 1.5 
> in this bit:
> ==========================================================
> diff -u -r1.187 aiunit.c
> --- ai/aiunit.c 2002/03/13 11:49:19     1.187
> +++ ai/aiunit.c 2002/03/15 08:01:02
> @@ -1118,7 +1118,9 @@
>      }
>      d_val *= POWER_DIVIDER;
>      d_val /= (unit_type(punit)->move_rate / SINGLE_MOVE);
> -    if (unit_flag(punit, F_IGTER)) d_val /= 1.5;
> +    if (unit_flag(punit, F_IGTER)) {
> +      d_val = (d_val * 2) / 3;
> +    }
>      freelog(LOG_DEBUG,
>             "%s@(%d,%d) looking for bodyguard, d_val=%d, my_val=%d",
>             unit_type(punit)->name, punit->x, punit->y, d_val,
> ==========================================================

I don't know. From cvs diff -r 1.46 -r 1.47 -u ai/aiunit.c:
@@ -508,6 +586,8 @@
           unit_types[d_type].attack_strength;
       d_val += j;
     }
+    d_val /= (unit_types[punit->type].move_rate / 3);
+    if (unit_flag(punit->type, F_IGTER)) d_val /= 1.5;
 /*printf("%s@(%d,%d) looking for bodyguard, d_val=%d, my_val=%d\n",
 unit_types[punit->type].name, punit->x, punit->y, d_val, punit->hp *
 (punit->veteran ? 15 : 10) * unit_types[punit->type].defense_strength);*/
@@ -548,7 +628,7 @@
           punit->goto_dest_y = dest_y;
           set_unit_activity(punit, ACTIVITY_SENTRY); /* anything but GOTO!! */
           if (!is_transporter_with_free_space(pplayer, punit->x, punit->y)) {
-printf("All aboard!\n");
+/*printf("All aboard!\n");*/
 /* perhaps this should only require two passengers */
             unit_list_iterate(ptile->units, mypass)
               if (mypass->ai.ferryboat == ferryboat->id) {

And the log msg:
----------------------------
revision 1.47
date: 1998/08/16 01:53:44;  author: freeciv;  state: Exp;  lines: +280 -71
Adding util funct tile_is_accessible so explorers don't keep banging
their heads into a ZOC-brick-wall.  Doing tricky things to unit_bellig
because get_attack_power is 99% worthless.  Writing invasion_funct,
whose purpose is to force the AI to send warships where its infantry are,
and to send its infantry where its warships are.  In reality, it tends
not to make enough ground troops, but it's at least tolerable now.
Writing is_my_turn so that units in a stack attack in order;
previously the invader would attack before the battleships sometimes.
Hacking findvic so that units defending cities attack pests more
ambitiously.  Hacking d_val so that fast units don't think they need
bodyguards.  Keeping invaders on boats longer so they don't disembark
and die.  Preventing warships from looking for charge, since eight
of them would often suddenly try to defend one city.  The real problem
is elsewhere, but this kluge is adequate and much easier to program.
Treating fieldunits as non-defenders in findjob.  Faking targets in
f_s_t_k so that x and y are set even if there's nothing to kill so that
the AI will understand that steam engine allows actually useful warships.
Doing lots of weird invasion stuff.  Removing +40 city-kill bonus for
air/sea units unless ground/heli units are included in the invasion.
Hacking sanity so that very long intracontinental trips allow ferryboats.
Preventing long rides by trireme.  Adding 'g' to attacker-want equation
so that the AI sends enough units to flatten a city in one turn.  Kluging
so that the AI won't build units just to kill caravans, since that never
actually works.  Using funky fprime variable instead of f in the denom,
so that def=1 units are penalized correctly.  Adding find_nearest_friendly_port
and telling bored ferryboats and wounded warships to go there.  Teaching the
AI that frigates are primarily warships.  Not letting units aboard ferries
fortify because weird things happen in cities then.  -- Syela
----------------------------

> And in the last bit, please format the conditions in "if" properly, if you 
> are already adding braces {}

Ok.

        Raimar

-- 
 email: rf13@xxxxxxxxxxxxxxxxx
  Microsoft does have a year 2000 problem. I'm part of it. I'm running Linux.


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