[Freeciv-Dev] (PR#11354) log(0.0) causes a server crash
[Top] [All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index] [Thread Index]
<URL: http://bugs.freeciv.org/Ticket/Display.html?id=11354 >
I think everyone can agree that _this_ patch is much better.
Instead of taking the log of most_desirable / BEST_POSSIBLE_RESULT, we
back up to take the base desirability, pull out the extra factor and
only look at the diff. The math is explained in the patch. The only
part I'm not sure about is the rounding.
jason
? core.8326
Index: ai/aiexplorer.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/ai/aiexplorer.c,v
retrieving revision 1.5
diff -u -r1.5 aiexplorer.c
--- ai/aiexplorer.c 29 Sep 2004 02:24:18 -0000 1.5
+++ ai/aiexplorer.c 10 Dec 2004 00:09:40 -0000
@@ -249,7 +249,7 @@
struct tile *ptile = punit->tile;
/* The want of the most desirable tile, given nearby water, cities, etc. */
- float most_desirable = 0;
+ double most_desirable = 0;
/* The maximum distance we are willing to search. It decreases depending
* on the want of already discovered tagets. It is defined as the distance
@@ -274,7 +274,7 @@
map = pf_create_map(¶meter);
while (pf_next(map)) {
- float desirable;
+ double desirable, base_desirable;
struct pf_position pos;
pf_next_get_position(map, &pos);
@@ -287,6 +287,7 @@
/* Totally non-desirable tile. No need to continue. */
continue;
}
+ base_desirable = desirable;
desirable *= pow(DIST_FACTOR, pos.total_MC);
if (desirable > most_desirable) {
@@ -295,11 +296,17 @@
/* We want to break when
* most_desirable > BEST_POSSIBLE_SCORE * DIST_FACTOR^dist
* which is equivalent to
- * most_desirable/BEST_POSSIBLE_SCORE > DIST_FACTOR^dist
- * log(most_desirable/BEST_POSSIBLE_SCORE) > dist * log(DIST_FACTOR)
- * log(most_desirable/BEST_POSSIBLE_SCORE)/log(DIST_FACTOR) > dist
+ * base_desirable * D_F ^ mc > B_P_S * D_F ^ dist
+ * base_desirable / B_P_S > D_F^(dist-mc)
+ * log(base_desirable/B_P_S) > (dist - mc) * log(D_F)
+ * log(base_desirable/B_P_S)/log(D_F) + mc > dist
+ *
+ * Note that we want to round max_dist up.
*/
- max_dist = log(most_desirable / BEST_POSSIBLE_SCORE) / log(DIST_FACTOR);
+ assert(base_desirable / BEST_POSSIBLE_SCORE > 0);
+ max_dist = log(base_desirable
+ / BEST_POSSIBLE_SCORE) / log(DIST_FACTOR) + 0.999;
+ max_dist += pos.total_MC;
}
if (pos.total_MC > max_dist) {
|
|