[Freeciv-Dev] Re: [FreeCiv-Cvs] per: Abort possibly infinite loop in ai_
[Top] [All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index] [Thread Index]
To: |
freeciv-dev@xxxxxxxxxxx |
Subject: |
[Freeciv-Dev] Re: [FreeCiv-Cvs] per: Abort possibly infinite loop in ai_unit_rampage... |
From: |
"Per I. Mathisen" <per@xxxxxxxxxxx> |
Date: |
Mon, 9 Dec 2002 01:48:22 +0000 (GMT) |
On Sun, 8 Dec 2002 freeciv@xxxxxxxxxxxxxxxxxxx wrote:
> Abort possibly infinite loop in ai_unit_rampage() when we are unable to
> move or attack our target.
>
> Patch by Jordi Negrevernis i Font <jorneg@xxxxxxxxxxx> with changes by
> me.
Ooops. Investigating this more properly, I realize that this will give a
number of false positives because we can railroad into empty cities (no
movement spent).
Still, a way to identify and break potential infinite loops in
ai_unit_rampage() is sorely needed. Suggestion pasted below.
In any case, the proper fix for the current infinite loops is pasted
below. Will be committed.
- Per
Index: ai/aitools.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/ai/aitools.c,v
retrieving revision 1.64
diff -u -r1.64 aitools.c
--- ai/aitools.c 8 Dec 2002 23:42:37 -0000 1.64
+++ ai/aitools.c 9 Dec 2002 01:43:51 -0000
@@ -279,6 +279,10 @@
pmove.x = x;
pmove.y = y;
pmove.unid = punit->id;
+ if (punit->activity != ACTIVITY_IDLE
+ && punit->activity != ACTIVITY_GOTO) {
+ 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)) {
Index: ai/aiunit.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/ai/aiunit.c,v
retrieving revision 1.235
diff -u -r1.235 aiunit.c
--- ai/aiunit.c 9 Dec 2002 00:32:12 -0000 1.235
+++ ai/aiunit.c 9 Dec 2002 01:46:59 -0000
@@ -1057,20 +1057,14 @@
**************************************************************************/
static struct unit *ai_military_rampage(struct unit *punit, int
threshold)
{
- int x, y, moves_left, id = punit->id;
+ int x, y, id = punit->id;
+ int count = punit->moves_left + 1; /* break any infinite loops */
- while (punit && punit->moves_left > 0
+ while (punit && punit->moves_left > 0 && count-- > 0
&& ai_military_findvictim(punit, &x, &y) >= threshold) {
moves_left = punit->moves_left;
ai_unit_attack(punit, x, y);
punit = find_unit_by_id(id);
- if (punit) {
- if (moves_left == punit->moves_left) {
- /* We were unable to move - avoid infinite loop! */
- UNIT_LOG(LOG_ERROR, punit, "Unable to move/attack at (%d, %d)", x, y);
- return punit;
- }
- }
}
return punit;
}
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [Freeciv-Dev] Re: [FreeCiv-Cvs] per: Abort possibly infinite loop in ai_unit_rampage...,
Per I. Mathisen <=
|
|