Complete.Org: Mailing Lists: Archives: freeciv-ai: September 2004:
[freeciv-ai] Re: [Freeciv-Dev] (PR#10084) city advisor for human players
Home

[freeciv-ai] Re: [Freeciv-Dev] (PR#10084) city advisor for human players

[Top] [All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index] [Thread Index]
To: jdorje@xxxxxxxxxxxxxxxxxxxxx
Subject: [freeciv-ai] Re: [Freeciv-Dev] (PR#10084) city advisor for human players isn't good
From: "Per I. Mathisen" <per@xxxxxxxxxxx>
Date: Fri, 24 Sep 2004 14:35:46 -0700
Reply-to: rt@xxxxxxxxxxx

<URL: http://rt.freeciv.org/Ticket/Display.html?id=10084 >

On Mon, 13 Sep 2004, Jason Short wrote:
> The AI city advisor for human players is currently pretty broken. It
> just picks a building at random.

Patch to fix it.

  - Per

Index: ai/aicity.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/ai/aicity.c,v
retrieving revision 1.172
diff -u -r1.172 aicity.c
--- ai/aicity.c 23 Sep 2004 19:50:46 -0000      1.172
+++ ai/aicity.c 24 Sep 2004 21:30:17 -0000
@@ -506,7 +506,7 @@
 /************************************************************************** 
   Prime pcity->ai.building_want[]
 **************************************************************************/
-static void ai_manage_buildings(struct player *pplayer)
+void ai_manage_buildings(struct player *pplayer)
 /* TODO:  RECALC_SPEED should be configurable to ai difficulty. -kauf  */
 #define RECALC_SPEED 5
 {
Index: ai/aicity.h
===================================================================
RCS file: /home/freeciv/CVS/freeciv/ai/aicity.h,v
retrieving revision 1.25
diff -u -r1.25 aicity.h
--- ai/aicity.h 13 Sep 2004 15:54:49 -0000      1.25
+++ ai/aicity.h 24 Sep 2004 21:30:17 -0000
@@ -21,6 +21,7 @@
 struct ai_choice;
 
 void ai_manage_cities(struct player *pplayer);
+void ai_manage_buildings(struct player *pplayer);
 
 Unit_Type_id ai_choose_defender_versus(struct city *pcity, Unit_Type_id v);
 int ai_eval_calc_city(struct city *pcity, struct ai_data *ai);
Index: server/cityturn.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/server/cityturn.c,v
retrieving revision 1.265
diff -u -r1.265 cityturn.c
--- server/cityturn.c   24 Sep 2004 20:33:34 -0000      1.265
+++ server/cityturn.c   24 Sep 2004 21:30:19 -0000
@@ -52,7 +52,6 @@
 #include "aicity.h"
 #include "aidata.h"
 #include "ailog.h"
-#include "aitools.h"           /* for ai_advisor_choose_building/ai_choice */
 
 #include "cityturn.h"
 
@@ -559,18 +558,28 @@
 void advisor_choose_build(struct player *pplayer, struct city *pcity)
 {
   Impr_Type_id id = -1;
+  int val = 0;
 
-  /* Build something random, undecided. */
+  /* See what AI has to say */
   impr_type_iterate(i) {
-    if (can_build_improvement(pcity, i)
-       && !building_has_effect(i, EFT_CAPITAL_CITY)) {
+    if (pcity->ai.building_want[i] > val
+        && can_build_improvement(pcity, i)) {
+      val = pcity->ai.building_want[i];
       id = i;
-      break;
     }
   } impr_type_iterate_end;
   if (id >= 0 && id < B_LAST) {
     change_build_target(pplayer, pcity, id, FALSE, E_IMP_AUTO);
+    return;
   }
+
+  /* Build something random, undecided. */
+  impr_type_iterate(i) {
+    if (can_build_improvement(pcity, i)
+       && !building_has_effect(i, EFT_CAPITAL_CITY)) {
+      change_build_target(pplayer, pcity, i, FALSE, E_IMP_AUTO);
+    }
+  } impr_type_iterate_end;
 }
 
 /**************************************************************************
Index: server/srv_main.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/server/srv_main.c,v
retrieving revision 1.198
diff -u -r1.198 srv_main.c
--- server/srv_main.c   21 Sep 2004 05:51:12 -0000      1.198
+++ server/srv_main.c   24 Sep 2004 21:30:19 -0000
@@ -96,6 +96,7 @@
 
 #include "advdiplomacy.h"
 #include "advmilitary.h"
+#include "aicity.h"
 #include "aidata.h"
 #include "aihand.h"
 #include "aisettler.h"
@@ -515,6 +516,7 @@
            pplayer->player_no, pplayer->name);
     /* human players also need this for building advice */
     ai_data_turn_init(pplayer);
+    ai_manage_buildings(pplayer);
   } players_iterate_end;
 
   players_iterate(pplayer) {

[Prev in Thread] Current Thread [Next in Thread]
  • [freeciv-ai] Re: [Freeciv-Dev] (PR#10084) city advisor for human players isn't good, Per I. Mathisen <=