Author: sveinung
Date: Thu Nov  3 16:09:06 2016
New Revision: 34357

URL: http://svn.gna.org/viewcvs/freeciv?rev=34357&view=rev
Log:
Add an action probability to [0, 1] converter.

Introduce action_prob_to_0_to_1_pessimist(). It converts an act_prob struct
to a double from 0 to 1. When an action probability represents a range it
will return the minimum probability.

See patch #7911

Modified:
    trunk/common/actions.c
    trunk/common/actions.h

Modified: trunk/common/actions.c
URL: 
http://svn.gna.org/viewcvs/freeciv/trunk/common/actions.c?rev=34357&r1=34356&r2=34357&view=diff
==============================================================================
--- trunk/common/actions.c      (original)
+++ trunk/common/actions.c      Thu Nov  3 16:09:06 2016
@@ -3384,6 +3384,33 @@
 }
 
 /**************************************************************************
+  Returns double in the range [0-1] representing the minimum of the given
+  action probability.
+**************************************************************************/
+double action_prob_to_0_to_1_pessimist(const struct act_prob ap)
+{
+  struct act_prob my_ap;
+
+  /* The action probability is real. */
+  fc_assert(!action_prob_not_relevant(ap));
+
+  /* Convert any signals to ACTPROB_NOT_KNOWN. */
+  if (action_prob_is_signal(ap)) {
+    /* Assert that it is OK to convert the signal. */
+    fc_assert(action_prob_not_impl(ap));
+
+    my_ap = ACTPROB_NOT_KNOWN;
+  } else {
+    my_ap = ap;
+  }
+
+  /* The action probability now has a math friendly form. */
+  fc_assert(!action_prob_is_signal(my_ap));
+
+  return (double)my_ap.min / (double) ACTPROB_VAL_MAX;
+}
+
+/**************************************************************************
   Returns ap1 with ap2 as fall back in cases where ap1 doesn't happen.
   Said in math that is: P(A) + P(A') * P(B)
 

Modified: trunk/common/actions.h
URL: 
http://svn.gna.org/viewcvs/freeciv/trunk/common/actions.h?rev=34357&r1=34356&r2=34357&view=diff
==============================================================================
--- trunk/common/actions.h      (original)
+++ trunk/common/actions.h      Thu Nov  3 16:09:06 2016
@@ -450,6 +450,8 @@
 int action_prob_cmp_pessimist(const struct act_prob ap1,
                               const struct act_prob ap2);
 
+double action_prob_to_0_to_1_pessimist(const struct act_prob ap);
+
 struct act_prob action_prob_fall_back(const struct act_prob *ap1,
                                       const struct act_prob *ap2);
 


_______________________________________________
Freeciv-commits mailing list
Freeciv-commits@gna.org
https://mail.gna.org/listinfo/freeciv-commits

Reply via email to