Complete.Org: Mailing Lists: Archives: freeciv-ai: December 2002:
[freeciv-ai] Re: stop infinite loops in ai_unit_rampage()
Home

[freeciv-ai] Re: stop infinite loops in ai_unit_rampage()

[Top] [All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index] [Thread Index]
To: "Per I. Mathisen" <per@xxxxxxxxxxx>
Cc: freeciv-ai@xxxxxxxxxxx
Subject: [freeciv-ai] Re: stop infinite loops in ai_unit_rampage()
From: Jordi Negrevernis i Font <jorneg@xxxxxxxxxxx>
Date: Wed, 04 Dec 2002 23:57:03 +0100


   I think is not enough.

What happens when an ai wants to enter in a city this a military unit, but that civilization is in Neutral state with the other?

   Just check if the unit has moved.

   Proposed function:

static struct unit *ai_military_rampage(struct unit *punit, int threshold)
{
 int x, y, id = punit->id;
 int last_moves_left;

 while (punit && punit->moves_left > 0
        && ai_military_findvictim(punit, &x, &y) >= threshold) {
   last_moves_left = punit->moves_left;
   ai_unit_attack(punit, x, y);
   punit = find_unit_by_id(id);
   /* ai do a movement that can't do, aaaaahhhhh!!! */
   if ( punit) {
     if ( last_moves_left == punit->moves_left ) {
freelog(LOG_DEBUG, "%s#%d@(%d,%d) can't do that movement so give up!",
           unit_type(punit)->name, punit->id, punit->x, punit->y);
       break;
     }
   }
 }
 return punit;
}



En/na Per I. Mathisen ha escrit:

In very rare circumstances, ai_unit_rampage() can go into an endless loop
because we find a good target which is not a unit (hut or city) but are
unable to enter it because we are not in the right activity to move.

This patch fixes it. It may be desirable to put a better failsafe into the
aforementioned function, as well, to prevent future infinite loops from
happening, since their causes are rather hard to track down.

 - Per

Index: ai/aitools.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/ai/aitools.c,v
retrieving revision 1.63
diff -u -r1.63 aitools.c
--- ai/aitools.c        2 Dec 2002 22:48:13 -0000       1.63
+++ ai/aitools.c        4 Dec 2002 22:27:59 -0000
@@ -281,6 +281,7 @@
  pmove.x = x;
  pmove.y = y;
  pmove.unid = punit->id;
+  handle_unit_activity_request(punit, ACTIVITY_IDLE);
  handle_move_unit(unit_owner(punit), &pmove);

  if (find_unit_by_id(sanity) && same_pos(x, y, punit->x, punit->y)) {








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