ソースを参照

Implement dF.1 and dF.2

Ryan C. Thompson 6 年 前
コミット
b589349ece
2 ファイル変更12 行追加6 行削除
  1. 1 3
      README.mkdn
  2. 11 3
      roll.py

+ 1 - 3
README.mkdn

@@ -8,8 +8,7 @@ to roll them on (or for new players who want to try out RPGs without
 having to spend money on dice first). It supports almost everything in
 the ["Standard Notation"][2] section of the Wikipedia page on dice
 notation, as well as the syntax in this online [RPG Dice Roller][3]
-and this [Android App][4]. (One notable exception is non-standard Fate
-dice, i.e. "dF.1", which are not supported.)
+and this [Android App][4].
 
 [1]: http://geekandsundry.com/shows/critical-role/
 [2]: https://en.wikipedia.org/wiki/Dice_notation#Standard_notation
@@ -132,4 +131,3 @@ lets you figure out how much of each damage type was dealt.
   take effect, such as exploding a d6 on 7 (i.e. `d6!=7)
 * Error messages are pretty much just reported as is, with no attempt
   to explain or contextualize them.
-* Nonstandard Fate dice (i.e. "dF.1") are not supported.

+ 11 - 3
roll.py

@@ -47,7 +47,7 @@ class IntegerValidator(object):
         return x
 
 def normalize_die_type(x):
-    if x == 'F':
+    if x in ('F', 'F.1', 'F.2'):
         return x
     elif x == '%':
         return 100
@@ -116,7 +116,7 @@ count_spec = Group(
 roll_spec = Group(
     (positive_int | ImplicitToken(1)).setResultsName('dice_count') +
     CaselessLiteral('d') +
-    (positive_int | oneOf('% F')).setResultsName('die_type') +
+    (positive_int | oneOf('% F F.1 F.2')).setResultsName('die_type') +
     Optional(reroll_spec ^ drop_spec) +
     Optional(count_spec)
 ).setResultsName('roll')
@@ -139,9 +139,17 @@ Supports any valid integer number of sides as well as 'F' for a fate
 die, which can return -1, 0, or 1 with equal probability.
 
     '''
-    if sides == 'F':
+    if sides in ('F', 'F.2'):
         # Fate die = 1d3-2
         return roll_die(3) - 2
+    elif sides == 'F.1':
+        d6 = roll_die(6)
+        if d6 == 1:
+            return -1
+        elif d6 == 6:
+            return 1
+        else:
+            return 0
     else:
         return randint(1, int(sides))