Complete.Org: Mailing Lists: Archives: freeciv-dev: August 2004:
[Freeciv-Dev] (PR#9887) AI defense code

[Freeciv-Dev] (PR#9887) AI defense code

[Top] [All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index] [Thread Index]
To: undisclosed-recipients: ;
Subject: [Freeciv-Dev] (PR#9887) AI defense code
From: "Per I. Mathisen" <per@xxxxxxxxxxx>
Date: Tue, 31 Aug 2004 11:20:28 -0700
Reply-to: rt@xxxxxxxxxxx

<URL: >

The attached patch improves logging of AI defense and also adds a ceiling
for grave danger usage in stay_and_defend(). The ceiling does not do all
that much yet, because even though it improves sanity, insanity awaits a
few lines further down in findjob anyway. I'm going to commit this patch
right away, but I intend this ticket for a more complete fix.

Basically, the AI algorithm for which units stay and defend sucks big
time. It has three of them, all in findjob. Two of them are pretty much
unreadable Syealisms. The basic logic is so-so and a bit primitive. In
particular, only the most offensive unit in a city can leave the city, but
if all units in the city are equally offensive, none can leave. Also, how
many units will leave may depend on the order of the unit list. Duh.

What we should have is to first go through all defenders in a city, and
set the best defenders to AIUNIT_DEFEND_HOME and the other to not this
role. Do this for all units, before we get on with ai_manage_units(), then
omit all units with this role set. This simplifies things a great deal.

Another thing is that the AI does not know that units now spend all their
movement landing. Whenever units are in the ocean, all land cities with
rail panic totally. This means they hog all units that are in them, and
won't let them attack or reinforce less defended coastal cities.

  - Per

Index: ai/aiunit.c
RCS file: /home/freeciv/CVS/freeciv/ai/aiunit.c,v
retrieving revision 1.331
diff -u -r1.331 aiunit.c
--- ai/aiunit.c 31 Aug 2004 15:35:31 -0000      1.331
+++ ai/aiunit.c 31 Aug 2004 18:12:17 -0000
@@ -364,8 +364,9 @@
   /* Treat grave danger anyway if danger is over threshold, which is the
-   * number of units currently in the city. */
-  if (pcity->ai.grave_danger > units) {
+   * number of units currently in the city.  However, to avoid AI panics
+   * (this is common when enemy is huge), add a ceiling. */
+  if (pcity->ai.grave_danger > units && units <= 2) {
     ai_unit_new_role(punit, AIUNIT_DEFEND_HOME, pcity->x, pcity->y);
     return TRUE;
@@ -1066,6 +1067,7 @@
   if (pcity && q > 0 && pcity->ai.urgency > 0) {
+    UNIT_LOG(LOG_DEBUG, punit, "decides to camp at home in %s", pcity->name);
     ai_unit_new_role(punit, AIUNIT_DEFEND_HOME, pcity->x, pcity->y);
@@ -1112,6 +1114,8 @@
     val = look_for_charge(pplayer, punit, &aunit, &acity);
   if (pcity && q > val) {
+    UNIT_LOG(LOG_DEBUG, punit, "decided not to go anywhere, sits in %s",
+             pcity->name);
     ai_unit_new_role(punit, AIUNIT_DEFEND_HOME, pcity->x, pcity->y);
@@ -1128,6 +1132,7 @@
       (pcity && !same_pos(pcity->x, pcity->y, punit->x, punit->y))) {
      ai_unit_new_role(punit, AIUNIT_ATTACK, -1, -1);
   } else {
+    UNIT_LOG(LOG_DEBUG, punit, "nothing to do, sit where we are");
     ai_unit_new_role(punit, AIUNIT_DEFEND_HOME, -1, -1); /* for default */

[Prev in Thread] Current Thread [Next in Thread]
  • [Freeciv-Dev] (PR#9887) AI defense code, Per I. Mathisen <=