Complete.Org: Mailing Lists: Archives: freeciv-dev: February 2002:
[Freeciv-Dev] Re: build_cost_prime (PR#1194)
Home

[Freeciv-Dev] Re: build_cost_prime (PR#1194)

[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: build_cost_prime (PR#1194)
From: Gregory Berkolaiko <gberkolaiko@xxxxxxxxxxx>
Date: Thu, 7 Feb 2002 20:09:40 +0000 (GMT)

Updated build_cost_prime patch.
I hope I answered Raimars suggestions.

 --- Raimar Falke <hawk@xxxxxxxxxxxxxxxxxxxxxxx> wrote: 
> On Thu, Jan 03, 2002 at 05:45:37AM -0800, Gregory Berkolaiko wrote:
> > Hi,
> > 
> > the variable with an expressive name "fprime" is calculated in the
> > same
> > way in 3 different places.  I propose to separate the calculation
> > into a
> > function and supply it with a comment.  The patch is attached.
> 
> Can you create a better name? Or can you explain the "prime"?

I tried.  build_cost_balanced was the result.

> You may also remove the fprime variable in the callers.

This I will not do as it is the job of the poor soul who will be cleaning
find_a_victim and like.  My patch is very localised, I don't want to
expand it.

> > +int build_cost_prime(Unit_Type_id i)
> > +{
> > +  int res;
> > +
> > +  res = 2 * unit_types[i].build_cost * unit_types[i].attack_strength
> > /
> > +    (unit_types[i].attack_strength +
unit_types[i].defense_strength);
> > +  return res;
> > +}
> 
> Make it a simple return statement.

Done.

Hopefully it can go in now and to releive me from the stress of
maintaining it ;)

G.


__________________________________________________
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
Index: ai/advmilitary.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/ai/advmilitary.c,v
retrieving revision 1.83
diff -u -r1.83 advmilitary.c
--- ai/advmilitary.c    2002/02/07 17:23:30     1.83
+++ ai/advmilitary.c    2002/02/07 20:03:19
@@ -608,9 +608,7 @@
           !unit_type_flag(i, F_IGWALL) && !city_got_citywalls(acity)) d *= 9; 
 
       f = unit_types[i].build_cost;
-      fprime = f * 2 * unit_types[i].attack_strength /
-           (unit_types[i].attack_strength +
-            unit_types[i].defense_strength);
+      fprime = build_cost_balanced(i);
 
       if (acity) g = unit_list_size(&(map_get_tile(acity->x, 
acity->y)->units)) + 1;
       else g = 1;
@@ -809,9 +807,7 @@
     if (is_ground_unit(myunit) && !sanity && !boatid)
       needferry = 40; /* cost of ferry */
     f = unit_types[v].build_cost;
-    fprime = f * 2 * unit_types[v].attack_strength /
-           (unit_types[v].attack_strength +
-            unit_types[v].defense_strength);
+    fprime = build_cost_balanced(v);
 
     if (acity) g = unit_list_size(&(map_get_tile(acity->x, acity->y)->units)) 
+ 1;
     else g = 1;
Index: ai/aiunit.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/ai/aiunit.c,v
retrieving revision 1.162
diff -u -r1.162 aiunit.c
--- ai/aiunit.c 2002/02/07 17:23:30     1.162
+++ ai/aiunit.c 2002/02/07 20:03:22
@@ -415,6 +415,21 @@
   return 0;
 }
 
+/*********************************************************************
+In the words of Syela: "Using funky fprime variable instead of f in
+the denom, so that def=1 units are penalized correctly."  
+Translation (GB): build_cost_balanced is used in the denominator of 
+the want equation (see, e.g.  find_something_to_kill) instead of just
+build_cost to make AI build more balanced units (with def > 1).
+*********************************************************************/
+int build_cost_balanced(Unit_Type_id i)
+{
+  return 2 * unit_types[i].build_cost 
+    * unit_types[i].attack_strength 
+    / (unit_types[i].attack_strength + unit_types[i].defense_strength);
+}
+
+
 /**************************************************************************
 ...
 **************************************************************************/
@@ -1249,9 +1264,7 @@
   if (unit_flag(punit, F_IGTER)) m *= SINGLE_MOVE;
   maxd = MIN(6, m) * THRESHOLD + 1;
   f = unit_type(punit)->build_cost;
-  fprime = f * 2 * unit_type(punit)->attack_strength /
-           (unit_type(punit)->attack_strength +
-            unit_type(punit)->defense_strength);
+  fprime = build_cost_balanced(punit->type);
 
   generate_warmap(map_get_city(*x, *y), punit);
                              /* most flexible but costs milliseconds */
Index: ai/aiunit.h
===================================================================
RCS file: /home/freeciv/CVS/freeciv/ai/aiunit.h,v
retrieving revision 1.27
diff -u -r1.27 aiunit.h
--- ai/aiunit.h 2002/02/07 10:24:13     1.27
+++ ai/aiunit.h 2002/02/07 20:03:22
@@ -32,6 +32,7 @@
                             int *x, int *y);
 int find_beachhead(struct unit *punit, int dest_x, int dest_y, int *x, int *y);
 
+int build_cost_balanced(Unit_Type_id i);
 int unit_belligerence_basic(struct unit *punit);
 int unit_belligerence(struct unit *punit);
 int unit_vulnerability_basic(struct unit *punit, struct unit *pdef);

[Prev in Thread] Current Thread [Next in Thread]
  • [Freeciv-Dev] Re: build_cost_prime (PR#1194), Gregory Berkolaiko <=