Complete.Org: Mailing Lists: Archives: freeciv-ai: June 2005:
[freeciv-ai] Re: A TODO item
Home

[freeciv-ai] Re: A TODO item

[Top] [All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index] [Thread Index]
Cc: freeciv-ai@xxxxxxxxxxx
Subject: [freeciv-ai] Re: A TODO item
From: Jordi Negrevernis i Font <jnegrevernis@xxxxxxxxxxxxxxxxx>
Date: Thu, 02 Jun 2005 22:07:03 +0200


   New patch. Comments below.

Benoit Hudson wrote:

Generally a good idea.  I thought the AI already did it, but I guess I'm
wrong :)
   Is in the TODO list of items in a post of Per...

There's a number of WAGs here that should be documented and made in to
constants so we can play with them more easily.
   There is only a WAG now.

+  tech_want = MAX(2, tech_want / 20);

this is mysterious: why 20? why 2?
   Now it only has a division by 20.
The idea here is to not interfere so much with the tech want code distributed all around.

+            /* now, we rise want for prerequisites */
+           tech_type_iterate(k) {
+             if (is_tech_a_req_for_goal(pplayer, k, tech_obs)) {
+                pplayer->ai.tech_want[k] += tech_want / 2;

why tech_want / 2  rather than tech_want ?
Here, the idea is to only influence a little the tech decision code with respect to the prerequisites of the obsoleting tech.

diff -b -ruN -Xfreeciv-2.0.1/diff_ignore freeciv-2.0.1/ai/aitech.c 
freeciv-2.0.1-ai_research/ai/aitech.c
--- freeciv-2.0.1/ai/aitech.c   2005-04-01 06:10:17.000000000 +0200
+++ freeciv-2.0.1-ai_research/ai/aitech.c       2005-06-02 11:35:29.000000000 
+0200
@@ -260,6 +260,100 @@
 }
 
 /**************************************************************************
+  This function does 2 things:
+  1. Stimulate research want of obsoleting techs for enemy wonders
+  2. Decrease research want of obsoleting techs for our wonders
+**************************************************************************/
+static void ai_modify_wonders_tech_want(struct player *pplayer)
+{ int city_id = 0;
+  struct city *pcity;
+  int tech_obs = 0, tech_want = 0, i = 0;
+
+  if (is_barbarian(pplayer)|| !pplayer->is_alive) {
+    return;
+  }
+
+#define TURNS_TECH_WANT_INCR 20
+  /* calculate the want incr. for obsoleting tech */
+  tech_type_iterate(i) {
+    if (pplayer->ai.tech_want[i] > tech_want) {
+      tech_want = pplayer->ai.tech_want[i];
+    }
+  } tech_type_iterate_end;
+  tech_want = tech_want / TURNS_TECH_WANT_INCR;        /* we've got it */
+#undef TURNS_TECH_WANT_INCR
+
+  /* searching for the obsoleting techs of current enemy wonders */
+  for (i = 0; i <= B_LAST; i++) {
+    if (improvement_exists(i) && is_wonder(i) && !wonder_obsolete(i)) {
+      city_id = game.global_wonders[i];
+      pcity = find_city_by_id(city_id);
+      if (pcity) {
+        if (pplayers_at_war(pplayer, city_owner(pcity))) {
+          tech_obs = improvement_types[i].obsolete_by;
+         if (tech_exists(tech_obs) && tech_is_available(pplayer, tech_obs)) {
+           pplayer->ai.tech_want[tech_obs] += tech_want;
+            freelog(LOG_NORMAL, "ai_modify_wonders_tech_want of %s "
+                               "stimulating %s with %d (%d)",
+                    pplayer->name, get_tech_name(pplayer, tech_obs), tech_want,
+                   pplayer->ai.tech_want[tech_obs]);
+
+            /* now, we rise want for prerequisites */
+           tech_type_iterate(k) {
+             if (is_tech_a_req_for_goal(pplayer, k, tech_obs)) {
+                pplayer->ai.tech_want[k] += tech_want / 2;
+                freelog(LOG_NORMAL, "ai_modify_wonders_tech_want of %s "
+                                   "stimulating prereq %s with %d (%d)",
+                        pplayer->name, get_tech_name(pplayer, k), tech_want / 
2,
+                       pplayer->ai.tech_want[k]);
+             }
+           } tech_type_iterate_end;
+
+          }
+       }
+      }
+    }
+  }
+
+  /* searching for the obsoleting techs of current owned wonders */
+  for (i = 0; i <= B_LAST; i++) {
+    if (improvement_exists(i) && is_wonder(i) && !wonder_obsolete(i)) {
+      city_id = game.global_wonders[i];
+      pcity = find_city_by_id(city_id);
+      if (pcity) {
+        if (pplayer == city_owner(pcity)) {
+          tech_obs = improvement_types[i].obsolete_by;
+         if (tech_exists(tech_obs) && tech_is_available(pplayer, tech_obs)) {
+           if (pplayer->ai.tech_want[tech_obs] >= 0) {
+             pplayer->ai.tech_want[tech_obs] -= tech_want;
+           }
+            freelog(LOG_NORMAL, "ai_modify_wonders_tech_want of %s "
+                               "decreasing %s with %d (%d)",
+                    pplayer->name, get_tech_name(pplayer, tech_obs), tech_want,
+                   pplayer->ai.tech_want[tech_obs]);
+
+            /* now, we decrise want for prerequisites */
+           tech_type_iterate(k) {
+             if (is_tech_a_req_for_goal(pplayer, k, tech_obs)) {
+                if (pplayer->ai.tech_want[k] >= 0) {
+                 pplayer->ai.tech_want[k] -= tech_want / 2;
+               }
+                freelog(LOG_NORMAL, "ai_modify_wonders_tech_want of %s "
+                                   "decreasing prereq %s with %d (%d)",
+                        pplayer->name, get_tech_name(pplayer, k), tech_want / 
2,
+                       pplayer->ai.tech_want[k]);
+             }
+           } tech_type_iterate_end;
+
+          }
+       }
+      }
+    }
+  }
+
+}
+
+/**************************************************************************
   Key AI research function. Disable if we are in a team with human team
   mates in a research pool.
 **************************************************************************/
@@ -278,6 +372,9 @@
     }
   } players_iterate_end;
 
+  /* we instruct the AI to count on the wonders before selecting a tech */
+  ai_modify_wonders_tech_want(pplayer);
+
   ai_use_gov_tech_hint(pplayer);
 
   ai_select_tech(pplayer, &choice, &goal);

[Prev in Thread] Current Thread [Next in Thread]
  • [freeciv-ai] Re: A TODO item, Jordi Negrevernis i Font <=