Commits

Arne Babenhauserheide  committed 49419ae

Fixed bordercase skill- and attribute value calculation errors (i.e. float to int conversion problems for 1/3 + 1/3 + 1/3…).

  • Participants
  • Parent commits 6274777

Comments (0)

Files changed (1)

File d6/charbase.py

 
     >>> _attvalue2cost(12)
     0
+    >>> _attvalue2cost(13)
+    1
+    >>> _attvalue2cost(14)
+    2
+    >>> _attvalue2cost(15)
+    3
+    >>> _attvalue2cost(16)
+    5
+    >>> _attvalue2cost(18)
+    9
+    >>> _attvalue2cost(11)
+    -1
+    >>> _attvalue2cost(9)
+    -3
+    >>> _attvalue2cost(8)
+    -5
     """
     cost = 0
     step = 1
     val = 12
-    if abs(value) > 0:
-        valtarget = 12 + int(abs(value)+0.000001) - 12
+    if value >= 0:
+        valtarget = 12 + abs(int(abs(value)+0.000001) - 12)
     else:
-        valtarget = 12 + int(abs(value)+0.000001) - 12
+        valtarget = 12 + abs(int(abs(value)+0.999999) - 12)
     # not so nice hacks for avoiding floating point to int errors…
     while int(val+0.00001) != valtarget:
         val += 1/step # reduce if < 0
     >>> _skillvalue(1/3)
     6
     >>> _skillvalue(2/3)
-    6
+    8
     >>> _skillvalue(1/3 + 1/3)
-    6
+    8
     >>> _skillvalue(1)
     9
     >>> _skillvalue(1/3 + 1/3 + 1/3)
     12
 
     """
-    if cost < 3:
-        if cost < 1:
+    # not so nice hacks for avoiding floating point to int errors…
+    floatadjust = 0.00001
+    if cost < 3 - floatadjust:
+        if cost < 1 - floatadjust:
             if cost < 1/3: return 3
             if cost < 2/3: return 6
-            if cost < 0.99999: return 8
-        if cost < 5/3: return 9
-        if cost <7/3: return 10
+            return 8
+        if cost < 5/3 - floatadjust: return 9
+        if cost <7/3 - floatadjust: return 10
         return 11
     return _attvalue(cost) - 3