Complete.Org: Mailing Lists: Archives: freeciv-dev: September 2003:
[Freeciv-Dev] Re: (PR#6094) assert in path finding
Home

[Freeciv-Dev] Re: (PR#6094) assert in path finding

[Top] [All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index] [Thread Index]
To: ue80@xxxxxxxxxxxxxxxxxxxxx
Subject: [Freeciv-Dev] Re: (PR#6094) assert in path finding
From: "Gregory Berkolaiko" <Gregory.Berkolaiko@xxxxxxxxxxxx>
Date: Wed, 10 Sep 2003 08:19:02 -0700
Reply-to: rt@xxxxxxxxxxxxxx

On Wed, 10 Sep 2003, Jason Short wrote:

> Looks like a bug.  moves_left_initially is 24, but move_rate is 18.
> 
> The base rate for the transport is 5, +1 for the "fast boat" tech.  This 
> is the origin of 18.
> 
> I'm not sure why the transport has 8 moves, though.

We found out that the transport was acquired this turn with the city by 
incitement from Croations who have Magellan.  Thus it is a subcase of the 
newly reported 6127.

I have made a separate patch for PF though, which should deal with such 
cases robustly.  Jason, could you check this patch with your "display 
number of turns in PF" patch please?

I think both this fix and a fix (although incomplete) to 6127 should be 
committed after a proper review.

G.

? pf_robust.diff
Index: common/aicore/path_finding.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/common/aicore/path_finding.c,v
retrieving revision 1.12
diff -u -r1.12 path_finding.c
--- common/aicore/path_finding.c        2003/09/01 18:45:45     1.12
+++ common/aicore/path_finding.c        2003/09/10 15:03:50
@@ -120,11 +120,14 @@
 /* =================== manipulating the cost ===================== */
 
 /********************************************************************
-  Number of turns required to reach node
+  Number of turns required to reach node.
+  Negative cost can happen, when a unit initially has more MP than 
+  it's move-rate (due to wonders transfer etc).  Although this is a bug, 
+  we better be ready.
 ********************************************************************/
 static int get_turn(const struct pf_map *pf_map, int cost)
 {
-  return (cost / pf_map->params->move_rate);
+  return (cost < 0 ? 0 : cost / pf_map->params->move_rate);
 }
 
 /********************************************************************
@@ -132,7 +135,8 @@
 ********************************************************************/
 static int get_moves_left(const struct pf_map *pf_map, int cost)
 {
-  return (pf_map->params->move_rate - (cost % pf_map->params->move_rate));
+  return (cost < 0 ? pf_map->params->move_rate - cost
+          : pf_map->params->move_rate - (cost % pf_map->params->move_rate));
 }
 
 /********************************************************************
@@ -300,9 +304,6 @@
       /* Total cost at xy1 */
       cost += node->cost;
 
-      /* check for overflow */
-      assert(cost >= 0);
-
       /* Evaluate the extra cost of the destination,
        * if it's relevant */
       if (pf_map->params->get_EC) {
@@ -396,7 +397,6 @@
    * need to subtract this value before we return cost to the user */
   pf_map->lattice[pf_map->index].cost = pf_map->params->move_rate
       - pf_map->params->moves_left_initially;
-  assert(pf_map->lattice[pf_map->index].cost >= 0);
   pf_map->lattice[pf_map->index].extra_cost = 0;
   if (pf_map->params->is_pos_dangerous) {
     /* The starting point is safe */

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