Complete.Org: Mailing Lists: Archives: freeciv-ai: January 2005:
[freeciv-ai] Re: [Freeciv-Dev] (PR#11777) Cleanup of AI tech code
Home

[freeciv-ai] Re: [Freeciv-Dev] (PR#11777) Cleanup of AI tech code

[Top] [All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index] [Thread Index]
Subject: [freeciv-ai] Re: [Freeciv-Dev] (PR#11777) Cleanup of AI tech code
From: "Per I. Mathisen" <per@xxxxxxxxxxx>
Date: Sat, 22 Jan 2005 13:09:34 -0800
Reply-to: bugs@xxxxxxxxxxx

<URL: http://bugs.freeciv.org/Ticket/Display.html?id=11777 >

On Sun, 9 Jan 2005, Gregory Berkolaiko wrote:
> Killing most of the aitech.c code is very sensible.

Here is the patch for the 'great culling'. Some related code which serves
no purpose with the aitech.c code also went the way of the dodo.  Remains
to be done is to cull all nations for irrelevant AI stuff that nobody ever
knew how worked (well, it didn't, so no wonder there), and which is now
also not even read.

  - Per

Index: ai/aihand.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/ai/aihand.c,v
retrieving revision 1.99
diff -u -r1.99 aihand.c
--- ai/aihand.c 22 Jan 2005 19:45:38 -0000      1.99
+++ ai/aihand.c 22 Jan 2005 21:06:22 -0000
@@ -351,11 +351,19 @@
   /* Crank up tech want */
   if (get_invention(pplayer, ai->goal.govt.req) == TECH_KNOWN) {
     return; /* already got it! */
+  } else if (ai->goal.govt.val > 0) {
+    /* We have few cities in the beginning, compensate for this to ensure
+     * that we are sufficiently forward-looking. */
+    int want = MAX(ai->goal.govt.val, 100);
+
+    if (pplayer->government == game.default_government) {
+      want += 25 * game.turn;
+    }
+    pplayer->ai.tech_want[ai->goal.govt.req] += want;
+    TECH_LOG(LOG_DEBUG, pplayer, ai->goal.govt.req, "+ %d for %s in "
+             "ai_manage_government", want,
+             get_government_name(ai->goal.govt.idx));
   }
-  pplayer->ai.tech_want[ai->goal.govt.req] += ai->goal.govt.val;
-  TECH_LOG(LOG_DEBUG, pplayer, ai->goal.govt.req, "+ %d for %s in "
-           "ai_manage_government", ai->goal.govt.val,
-           get_government_name(ai->goal.govt.idx));
 }
 
 /**************************************************************************
Index: ai/aitech.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/ai/aitech.c,v
retrieving revision 1.50
diff -u -r1.50 aitech.c
--- ai/aitech.c 22 Jan 2005 19:45:38 -0000      1.50
+++ ai/aitech.c 22 Jan 2005 21:06:22 -0000
@@ -39,67 +39,6 @@
 };
 
 /**************************************************************************
-  Returns tech corresponding to players wonder goal from nations[],
-  if it makes sense, and wonder is not already built and not obsolete.
-  Otherwise returns A_UNSET.
-**************************************************************************/
-static Tech_Type_id get_wonder_tech(struct player *plr)
-{
-  Impr_Type_id building = get_nation_by_plr(plr)->goals.wonder;
-  
-  if (improvement_exists(building)
-      && is_great_wonder(building)
-      && !great_wonder_was_built(building)
-      && !improvement_obsolete(plr, building)) {
-    Tech_Type_id tech = improvement_types[building].tech_req;
-
-    if (tech_is_available(plr, tech) 
-        && get_invention(plr, tech) != TECH_KNOWN) {
-      return tech;
-    }
-  }
-  return A_UNSET;
-}
-
-/**************************************************************************
-  Puts into choice the closest (in terms of unknown techs needed) of
-    - national tech goals,
-    - requirements for the national wonder goal
-**************************************************************************/
-static Tech_Type_id ai_next_tech_goal_default(struct player *pplayer)
-{
-  struct nation_type *prace = get_nation_by_plr(pplayer);
-  int bestdist = A_LAST + 1;
-  int dist, i;
-  Tech_Type_id goal = A_UNSET;
-  Tech_Type_id tech;
-
-  /* Find the closest of the national tech goals */
-  for (i = 0 ; i < MAX_NUM_TECH_GOALS; i++) {
-    Tech_Type_id j = prace->goals.tech[i];
-    if (!tech_is_available(pplayer, j) 
-        || get_invention(pplayer, j) == TECH_KNOWN) {
-      continue;
-    }
-    dist = num_unknown_techs_for_goal(pplayer, j);
-    if (dist < bestdist) { 
-      bestdist = dist;
-      goal = j;
-      break; /* remove this to restore old functionality -- Syela */
-    }
-  } 
-
-  /* Find the requirement for the national wonder */
-  tech = get_wonder_tech(pplayer);
-  if (tech != A_UNSET 
-      && num_unknown_techs_for_goal(pplayer, tech) < bestdist) {
-    goal = tech;
-  }
-
-  return goal;
-}
-
-/**************************************************************************
   Massage the numbers provided to us by ai.tech_want into unrecognizable 
   pulp.
 
@@ -215,64 +154,6 @@
 }
 
 /**************************************************************************
-  Choose our next tech goal.  Called by the server when a new tech is 
-  discovered to determine new goal and, from it, the new tech to be 
-  researched, which is quite stupid since ai_manage_tech sets a goal in 
-  ai.tech_goal and we should either respect it or not bother doing it.
-
-  TODO: Kill this function.
-**************************************************************************/
-void ai_next_tech_goal(struct player *pplayer)
-{
-  struct ai_tech_choice goal_choice = {0, 0, 0};
-
-  ai_select_tech(pplayer, NULL, &goal_choice);
-
-  if (goal_choice.want == 0) {
-    goal_choice.choice = ai_next_tech_goal_default(pplayer);
-  }
-  if (goal_choice.choice != A_UNSET) {
-    pplayer->ai.tech_goal = goal_choice.choice;
-    freelog(LOG_DEBUG, "next_tech_goal for %s is set to %s",
-           pplayer->name, get_tech_name(pplayer, goal_choice.choice));
-  }
-}
-
-/**************************************************************************
-  Use AI tech hints provided in governments.ruleset to up corresponding 
-  tech wants.
-
-  TODO: The hints structure is too complicated, simplify.
-**************************************************************************/
-static void ai_use_gov_tech_hint(struct player *pplayer)
-{
-  int i;
-
-  for (i = 0; i < MAX_NUM_TECH_LIST; i++) {
-    struct ai_gov_tech_hint *hint = &ai_gov_tech_hints[i];
-    
-    if (hint->tech == A_LAST) {
-      break;
-    }
-    
-    if (get_invention(pplayer, hint->tech) != TECH_KNOWN) {
-      int steps = num_unknown_techs_for_goal(pplayer, hint->tech);
-
-      pplayer->ai.tech_want[hint->tech] += 
-       city_list_size(pplayer->cities)
-       * (hint->turns_factor * steps + hint->const_factor);
-      if (hint->get_first) {
-       break;
-      }
-    } else {
-      if (hint->done) {
-       break;
-      }
-    }
-  }
-}
-
-/**************************************************************************
   Key AI research function. Disable if we are in a team with human team
   mates in a research pool.
 **************************************************************************/
@@ -291,18 +172,16 @@
     }
   } players_iterate_end;
 
-  ai_use_gov_tech_hint(pplayer);
-
   ai_select_tech(pplayer, &choice, &goal);
   if (choice.choice != pplayer->research.researching) {
     /* changing */
     if ((choice.want - choice.current_want) > penalty &&
        penalty + pplayer->research.bulbs_researched <=
        total_bulbs_required(pplayer)) {
-      freelog(LOG_DEBUG, "%s switching from %s to %s with penalty of %d.",
-             pplayer->name,
-             get_tech_name(pplayer, pplayer->research.researching),
-             get_tech_name(pplayer, choice.choice), penalty);
+      TECH_LOG(LOG_DEBUG, pplayer, choice.choice, "new research, was %s, "
+               "penalty was %d", 
+               get_tech_name(pplayer, pplayer->research.researching),
+               penalty);
       choose_tech(pplayer, choice.choice);
     }
   }
Index: common/government.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/common/government.c,v
retrieving revision 1.48
diff -u -r1.48 government.c
--- common/government.c 9 Dec 2004 20:17:46 -0000       1.48
+++ common/government.c 22 Jan 2005 21:06:22 -0000
@@ -27,39 +27,8 @@
 
 #include "government.h"
 
-/* TODO:
- * o Update and turn on government evaluation code.
- * o Check exact government rules vs Civ1,Civ2.
- * o The clients display wrong upkeep icons in the city display,
- *   not sure what to do here.  (Does the new terrain-ruleset code
- *   have icons that could be used here?)
- * o When change government, server should update cities and unit
- *   upkeep etc and send updated info to client.
- * o Implement actual cost for unit gold upkeep.
- * o Possibly remove ai_gov_tech_hint stuff?
- *   (See usage in ai_manage_cities() in aicity.c)
- * o Update help system, including dynamic help on governments.
- * o Test the new government evaluation code (AI).
- *   [ It seems fine to me, although it favours Democracy very early
- *   on. This is because of the huge trade bonus. -SKi ]
- * o Implement the features needed for fundamentalism:
- *   - A diplomatic penalty modifier when international incidents occur.
- *     (Spy places nuke in city, goes to war, etc).
- *     [ Is this one of those Civ II "features" best be ignored?  I am
- *     inclined to think so -SKi ]
- */
-
-/*
- * WISHLIST:
- * o Features needed for CTP-style rules, just more trade, science and
- *   production modifiers.  (Just counting CTP governments, only
- *   basics).
- */
-
 struct government *governments = NULL;
 
-struct ai_gov_tech_hint ai_gov_tech_hints[MAX_NUM_TECH_LIST];
-
 static const char *flag_names[] = {
   "Build_Veteran_Diplomats", "Revolution_When_Unhappy", "Has_Senate",
   "Unbribable", "Inspires_Partisans", "Rapture_City_Growth",
Index: common/government.h
===================================================================
RCS file: /home/freeciv/CVS/freeciv/common/government.h,v
retrieving revision 1.37
diff -u -r1.37 government.h
--- common/government.h 9 Dec 2004 20:17:46 -0000       1.37
+++ common/government.h 22 Jan 2005 21:06:22 -0000
@@ -41,13 +41,6 @@
 };
 #define G_FIRST_FLAG G_BUILD_VETERAN_DIPLOMAT
 
-enum government_hint_id {
-  G_IS_NICE=0,                 /* spaceship auto-placement, among others */
-  G_FAVORS_GROWTH,
-  G_LAST_HINT
-};
-#define G_FIRST_HINT G_IS_NICE
-
 /* each government has a list of ruler titles, where at least
  * one entry should have nation=DEFAULT_TITLE.
  */
@@ -132,22 +125,8 @@
   char *helptext;
 };
 
-/* This should possibly disappear; we don't bother sending these to client;
- * See code in aitech.c for what the fields mean */
-struct ai_gov_tech_hint {
-  int tech;
-  int turns_factor;
-  int const_factor;
-  bool get_first;
-  bool done;
-};
-
 extern struct government *governments;
 
-extern struct ai_gov_tech_hint ai_gov_tech_hints[MAX_NUM_TECH_LIST];
-/* like game.rtech lists, A_LAST terminated (for .tech)
-   and techs before that are guaranteed to exist */
-
 struct government *get_government(int gov);
 struct government *get_gov_pplayer(const struct player *pplayer);
 struct government *get_gov_pcity(const struct city *pcity);
Index: common/nation.h
===================================================================
RCS file: /home/freeciv/CVS/freeciv/common/nation.h,v
retrieving revision 1.34
diff -u -r1.34 nation.h
--- common/nation.h     12 Dec 2004 03:44:47 -0000      1.34
+++ common/nation.h     22 Jan 2005 21:06:22 -0000
@@ -92,14 +92,6 @@
   /* Items given to this nation at game start.  Server only. */
   int init_techs[MAX_NUM_TECH_LIST];
   int init_buildings[MAX_NUM_BUILDING_LIST];
-
-  /* Following basically disabled -- Syela */
-  /* Note the client doesn't use/have these. */
-  struct {
-    int tech[MAX_NUM_TECH_GOALS];               /* tech goals     */
-    int wonder;                                 /* primary Wonder */
-    int government;
-  } goals;
 };
 
 struct team {
Index: server/plrhand.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/server/plrhand.c,v
retrieving revision 1.354
diff -u -r1.354 plrhand.c
--- server/plrhand.c    22 Jan 2005 20:31:11 -0000      1.354
+++ server/plrhand.c    22 Jan 2005 21:06:23 -0000
@@ -550,20 +550,8 @@
 {
   int sub_goal;
 
-  if (plr->ai.control) {
-    ai_next_tech_goal(plr);    /* tech-AI has been changed */
-  }
   sub_goal = get_next_tech(plr, plr->ai.tech_goal);
 
-  if (sub_goal == A_UNSET) {
-    if (plr->ai.control || plr->research.techs_researched == 1) {
-      ai_next_tech_goal(plr);
-      sub_goal = get_next_tech(plr, plr->ai.tech_goal);
-    } else {
-      plr->ai.tech_goal = A_UNSET;     /* clear goal when it is achieved */
-    }
-  }
-
   if (sub_goal != A_UNSET) {
     plr->research.researching = sub_goal;
     return TRUE;
Index: server/ruleset.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/server/ruleset.c,v
retrieving revision 1.226
diff -u -r1.226 ruleset.c
--- server/ruleset.c    6 Jan 2005 00:35:51 -0000       1.226
+++ server/ruleset.c    22 Jan 2005 21:06:24 -0000
@@ -1698,7 +1698,6 @@
 static void load_ruleset_governments(struct section_file *file)
 {
   int i, j, nval;
-  char *c;
   char **sec, **slist;
   const char *filename = secfile_filename(file);
 
@@ -1849,41 +1848,6 @@
     title->female_title = title->female_title_orig;
   } government_iterate_end;
 
-  /* ai tech_hints: */
-  j = -1;
-  while((c = secfile_lookup_str_default(file, NULL,
-                                       "governments.ai_tech_hints%d.tech",
-                                       ++j))) {
-    struct ai_gov_tech_hint *hint = &ai_gov_tech_hints[j];
-
-    if (j >= MAX_NUM_TECH_LIST) {
-      freelog(LOG_FATAL, "Too many ai tech_hints in %s", filename);
-      exit(EXIT_FAILURE);
-    }
-    hint->tech = find_tech_by_name(c);
-    if (hint->tech == A_LAST) {
-      freelog(LOG_FATAL, "Could not match tech %s for gov ai_tech_hint %d 
(%s)",
-             c, j, filename);
-      exit(EXIT_FAILURE);
-    }
-    if (!tech_exists(hint->tech)) {
-      freelog(LOG_FATAL, "For gov ai_tech_hint %d, tech \"%s\" is removed 
(%s)",
-             j, c, filename);
-      exit(EXIT_FAILURE);
-    }
-    hint->turns_factor =
-      secfile_lookup_int(file, "governments.ai_tech_hints%d.turns_factor", j);
-    hint->const_factor =
-      secfile_lookup_int(file, "governments.ai_tech_hints%d.const_factor", j);
-    hint->get_first =
-      secfile_lookup_bool(file, "governments.ai_tech_hints%d.get_first", j);
-    hint->done =
-      secfile_lookup_bool(file, "governments.ai_tech_hints%d.done", j);
-  }
-  if (j<MAX_NUM_TECH_LIST) {
-    ai_gov_tech_hints[j].tech = A_LAST;
-  }
-
   free(sec);
   section_file_check_unused(file, filename);
   section_file_free(file);
@@ -2159,9 +2123,9 @@
   char *bad_leader, *g;
   struct nation_type *pl;
   struct government *gov;
-  int dim, val, i, j, k, nval;
+  int dim, i, j, k, nval;
   char temp_name[MAX_LEN_NAME];
-  char **techs, **leaders, **sec, **civilwar_nations;
+  char **leaders, **sec, **civilwar_nations;
   const char *filename = secfile_filename(file);
 
   (void) check_ruleset_capabilities(file, "+1.9", filename);
@@ -2321,72 +2285,6 @@
     lookup_building_list(file, sec[i], "init_buildings", pl->init_buildings,
                         filename);
 
-    /* AI techs */
-
-    techs = secfile_lookup_str_vec(file, &dim, "%s.tech_goals", sec[i]);
-    if( dim > MAX_NUM_TECH_GOALS ) {
-      freelog(LOG_VERBOSE,
-             "Only %d techs can be used from %d defined for nation %s",
-             MAX_NUM_TECH_GOALS, dim, pl->name_plural);
-      dim = MAX_NUM_TECH_GOALS;
-    }
-    /* Below LOG_VERBOSE rather than LOG_ERROR so that can use single
-       nation ruleset file with variety of tech ruleset files: */
-    for( j=0; j<dim; j++) {
-      val = find_tech_by_name(techs[j]);
-      if(val == A_LAST) {
-       freelog(LOG_VERBOSE, "Could not match tech goal \"%s\" for the %s",
-               techs[j], pl->name_plural);
-      } else if (!tech_exists(val)) {
-       freelog(LOG_VERBOSE, "Goal tech \"%s\" for the %s doesn't exist",
-               techs[j], pl->name_plural);
-       val = A_LAST;
-      }
-      if(val != A_LAST && val != A_NONE) {
-       freelog(LOG_DEBUG, "%s tech goal (%d) %3d %s", pl->name, j, val, 
techs[j]);
-       pl->goals.tech[j] = val;
-      }
-    }
-    freelog(LOG_DEBUG, "%s %d tech goals", pl->name, j);
-    if(j==0) {
-      freelog(LOG_VERBOSE, "No valid goal techs for %s", pl->name);
-    }
-    while( j < MAX_NUM_TECH_GOALS )
-      pl->goals.tech[j++] = A_UNSET;
-    if (techs) free(techs);
-
-    /* AI wonder & government */
-
-    sz_strlcpy(temp_name, secfile_lookup_str(file, "%s.wonder", sec[i]));
-    val = find_improvement_by_name(temp_name);
-    /* Below LOG_VERBOSE rather than LOG_ERROR so that can use single
-       nation ruleset file with variety of building ruleset files: */
-    /* for any problems, leave as B_LAST */
-    if(val == B_LAST) {
-      freelog(LOG_VERBOSE, "Didn't match goal wonder \"%s\" for %s", 
temp_name, pl->name);
-    } else if(!improvement_exists(val)) {
-      freelog(LOG_VERBOSE, "Goal wonder \"%s\" for %s doesn't exist", 
temp_name, pl->name);
-      val = B_LAST;
-    } else if(!is_great_wonder(val)) {
-      freelog(LOG_VERBOSE, "Goal wonder \"%s\" for %s not a wonder", 
temp_name, pl->name);
-      val = B_LAST;
-    }
-    pl->goals.wonder = val;
-    freelog(LOG_DEBUG, "%s wonder goal %d %s", pl->name, val, temp_name);
-
-    sz_strlcpy(temp_name, secfile_lookup_str(file, "%s.government", sec[i]));
-    gov = find_government_by_name(temp_name);
-    if(!gov) {
-      /* LOG_VERBOSE rather than LOG_ERROR so that can use single nation
-        ruleset file with variety of government ruleset files: */
-      freelog(LOG_VERBOSE, "Didn't match goal government name \"%s\" for %s",
-             temp_name, pl->name);
-      val = game.government_when_anarchy;  /* flag value (no goal) (?) */
-    } else {
-      val = gov->index;
-    }
-    pl->goals.government = val;
-
     /* read "normal" city names */
 
     pl->city_names = load_city_name_list(file, sec[i], ".cities");

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