Complete.Org: Mailing Lists: Archives: freeciv-ai: November 2004:
[freeciv-ai] [Freeciv-Dev] (PR#10694) AI Builds Doomed Ferries and Passe
Home

[freeciv-ai] [Freeciv-Dev] (PR#10694) AI Builds Doomed Ferries and Passe

[Top] [All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index] [Thread Index]
Subject: [freeciv-ai] [Freeciv-Dev] (PR#10694) AI Builds Doomed Ferries and Passengers
From: "Benedict Adamson" <badamson@xxxxxxxxxxx>
Date: Wed, 10 Nov 2004 15:22:41 -0800
Reply-to: rt@xxxxxxxxxxx

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

So I could better understand what is happening, I made the attached 
modifications (applicable to the CVS development version of 2004-11-09) 
to log requests for bodyguards, and used the attached script to run a 
test auto game, which is also attached.

The results were rather surprising.
* No sea units become bodyguards at any point in the game, although 
there are plenty of warships.
* No ferries request bodyguards at any point in the game.
* Even Battleships and Mech. Inf. request bodyguards.

diff -ruN -Xfreeciv.PR10694-3/diff_ignore vendor.freeciv.current/ai/Makefile.am 
freeciv.PR10694-3/ai/Makefile.am
--- vendor.freeciv.current/ai/Makefile.am       2004-10-22 23:16:37.000000000 
+0100
+++ freeciv.PR10694-3/ai/Makefile.am    2004-11-10 23:17:34.000000000 +0000
@@ -17,6 +17,8 @@
                advspace.h      \
                aiair.c         \
                aiair.h         \
+               aiguard.h       \
+               aiguard.c       \
                aicity.c        \
                aicity.h        \
                aidata.c        \
diff -ruN -Xfreeciv.PR10694-3/diff_ignore vendor.freeciv.current/ai/aiferry.c 
freeciv.PR10694-3/ai/aiferry.c
--- vendor.freeciv.current/ai/aiferry.c 2004-11-09 22:06:31.000000000 +0000
+++ freeciv.PR10694-3/ai/aiferry.c      2004-11-10 23:17:34.000000000 +0000
@@ -27,6 +27,7 @@
 
 #include "aidata.h"
 #include "aiexplorer.h"
+#include "aiguard.h"
 #include "ailog.h"
 #include "aitools.h"
 #include "aiunit.h"
@@ -419,7 +420,7 @@
       boatid = aiferry_find_boat(punit, 2, &path_to_ferry);
       if (boatid <= 0) {
         UNIT_LOG(LOGLEVEL_GOBYBOAT, punit, 
-                "in ai_gothere cannot find any boats.");
+                "in aiferry_find_boat cannot find any boats.");
         return FALSE;
       }
 
@@ -511,7 +512,7 @@
         if (!goto_is_sane(bodyguard, punit->tile, TRUE)
             || !ai_unit_goto(punit, punit->tile)) {
           /* Bodyguard can't get there or died en route */
-          punit->ai.bodyguard = BODYGUARD_WANTED;
+         aiguard_request_guard(punit);
           bodyguard = NULL;
         } else if (bodyguard->moves_left <= 0) {
           /* Wait for me, I'm cooooming!! */
@@ -520,7 +521,7 @@
         } else {
           /* Crap bodyguard. Got stuck somewhere. Ditch it! */
           UNIT_LOG(LOGLEVEL_GOBYBOAT, punit, "ditching useless bodyguard");
-          punit->ai.bodyguard = BODYGUARD_WANTED;
+         aiguard_request_guard(punit);
           ai_unit_new_role(bodyguard, AIUNIT_NONE, NULL);
           bodyguard = NULL;
         }
diff -ruN -Xfreeciv.PR10694-3/diff_ignore vendor.freeciv.current/ai/aiguard.c 
freeciv.PR10694-3/ai/aiguard.c
--- vendor.freeciv.current/ai/aiguard.c 1970-01-01 01:00:00.000000000 +0100
+++ freeciv.PR10694-3/ai/aiguard.c      2004-11-10 23:17:34.000000000 +0000
@@ -0,0 +1,34 @@
+/********************************************************************** 
+ Freeciv - Copyright (C) 2004 - The Freeciv Project
+   This program is free software; you can redistribute it and/or modify
+   it under the terms of the GNU General Public License as published by
+   the Free Software Foundation; either version 2, or (at your option)
+   any later version.
+
+   This program is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+   GNU General Public License for more details.
+***********************************************************************/
+
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
+
+#include "log.h"
+#include "unit.h"
+
+#include "ailog.h"
+#include "aiguard.h"
+ 
+
+
+/**************************************************************************
+  Request a bodyguard for the unit.
+**************************************************************************/
+void aiguard_request_guard(struct unit *punit)
+{
+    UNIT_LOG(LOG_DEBUG, punit, "requests a guard.");
+    punit->ai.bodyguard = BODYGUARD_WANTED;
+
+}
diff -ruN -Xfreeciv.PR10694-3/diff_ignore vendor.freeciv.current/ai/aiguard.h 
freeciv.PR10694-3/ai/aiguard.h
--- vendor.freeciv.current/ai/aiguard.h 1970-01-01 01:00:00.000000000 +0100
+++ freeciv.PR10694-3/ai/aiguard.h      2004-11-10 23:17:34.000000000 +0000
@@ -0,0 +1,27 @@
+/********************************************************************** 
+ Freeciv - Copyright (C) 2002 - The Freeciv Project
+   This program is free software; you can redistribute it and/or modify
+   it under the terms of the GNU General Public License as published by
+   the Free Software Foundation; either version 2, or (at your option)
+   any later version.
+
+   This program is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+   GNU General Public License for more details.
+***********************************************************************/
+#ifndef FC__AIGUARD_H
+#define FC__AIGUARD_H
+
+#include "shared.h"            /* bool type */
+
+#include "fc_types.h"
+
+enum bodyguard_enum {
+  BODYGUARD_WANTED=-1,
+  BODYGUARD_NONE
+};
+
+void aiguard_request_guard(struct unit *punit);
+
+#endif /* FC__AIGUARD_H */
diff -ruN -Xfreeciv.PR10694-3/diff_ignore vendor.freeciv.current/ai/aitools.c 
freeciv.PR10694-3/ai/aitools.c
--- vendor.freeciv.current/ai/aitools.c 2004-11-03 19:46:36.000000000 +0000
+++ freeciv.PR10694-3/ai/aitools.c      2004-11-10 23:17:34.000000000 +0000
@@ -48,6 +48,7 @@
 #include "aicity.h"
 #include "aidata.h"
 #include "aiferry.h"
+#include "aiguard.h"
 #include "ailog.h"
 #include "aiunit.h"
 
@@ -191,7 +192,7 @@
       UNIT_LOG(LOGLEVEL_BODYGUARD, punit, 
                "want bodyguard @(%d, %d) danger=%d, my_def=%d", 
                dest_tile, danger, my_def);
-      punit->ai.bodyguard = BODYGUARD_WANTED;
+      aiguard_request_guard(punit);
     } else {
       punit->ai.bodyguard = BODYGUARD_NONE;
     }
diff -ruN -Xfreeciv.PR10694-3/diff_ignore vendor.freeciv.current/ai/aitools.h 
freeciv.PR10694-3/ai/aitools.h
--- vendor.freeciv.current/ai/aitools.h 2004-11-03 19:46:36.000000000 +0000
+++ freeciv.PR10694-3/ai/aitools.h      2004-11-10 23:17:34.000000000 +0000
@@ -32,11 +32,6 @@
 #define CHECK_UNIT(punit) assert(TRUE)
 #endif
 
-enum bodyguard_enum {
-  BODYGUARD_WANTED=-1,
-  BODYGUARD_NONE
-};
-
 int military_amortize(struct player *pplayer, struct city *pcity, 
                       int value, int delay, int build_cost);
 int stack_cost(struct unit *pdef);
diff -ruN -Xfreeciv.PR10694-3/diff_ignore vendor.freeciv.current/ai/aiunit.c 
freeciv.PR10694-3/ai/aiunit.c
--- vendor.freeciv.current/ai/aiunit.c  2004-10-22 23:16:37.000000000 +0100
+++ freeciv.PR10694-3/ai/aiunit.c       2004-11-10 23:17:34.000000000 +0000
@@ -53,6 +53,7 @@
 #include "aidiplomat.h"
 #include "aiexplorer.h"
 #include "aiferry.h"
+#include "aiguard.h"
 #include "aihand.h"
 #include "aihunt.h"
 #include "ailog.h"
@@ -2142,7 +2143,7 @@
    * fine. If we had one and lost it, ask for a new one. */
   if (!bodyguard && punit->ai.bodyguard > BODYGUARD_NONE) {
     UNIT_LOG(LOGLEVEL_BODYGUARD, punit, "lost bodyguard, asking for new");
-    punit->ai.bodyguard = BODYGUARD_WANTED;
+    aiguard_request_guard(punit);
   }  
 
   if (punit->moves_left <= 0) {
diff -ruN -Xfreeciv.PR10694-3/diff_ignore vendor.freeciv.current/diff_ignore 
freeciv.PR10694-3/diff_ignore
--- vendor.freeciv.current/diff_ignore  2004-10-22 23:16:37.000000000 +0100
+++ freeciv.PR10694-3/diff_ignore       2004-11-10 23:17:35.000000000 +0000
@@ -17,6 +17,7 @@
 *~
 .#*
 .deps
+.svn
 CVS
 Freeciv.h
 Makefile
#!/bin/sh
# runtest
rm test.log test.gamelog
server/civserver -r ref.fc -l test.log -g test.gamelog -d 4:ailog.c,119,167
#diff -u ref.log test.log
diff -u ref.gamelog test.gamelog
echo
echo "Guards:"
sed \
   -e '/changing role from [0-9]* to 7/!d' \
   -e 's/\[.*//' \
   -e "s/.*'s //" \
   test.log | sort -u > test.role.guard
cat test.role.guard
echo

echo "Requesters:"
sed \
   -e '/requests a guard/!d' \
   -e 's/\[.*//' \
   -e "s/.*'s //" \
   test.log | sort -u > test.requests.guard
cat test.requests.guard
echo
set gameseed 23
set mapseed 17

set size 1
set generator 2
set startpos 1
set aifill 3
set specials 1000
set startunits cccccxxxx
set dispersion 4
set researchcost 4
set foodbox 5
set huts 0
set barbarians 0
normal

set timeout -1
create Caesar
create Itzcoatl
create Hannibal
start

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