summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLuke Shumaker <LukeShu@sbcglobal.net>2011-08-04 19:32:50 -0400
committerLuke Shumaker <LukeShu@sbcglobal.net>2011-08-04 19:32:50 -0400
commit01413023fcd6a87159b43bd5a80b9848bbe50bd6 (patch)
treefdda52a3caa3276672b01121856c32ed32f6b8fd
parent4dcae3738b30dc14812a6dc27684c66fd20141ec (diff)
I wrote a "roll" tool to use while playing Dungeons and Dragons.
-rw-r--r--Makefile1
-rw-r--r--roll.php21
2 files changed, 22 insertions, 0 deletions
diff --git a/Makefile b/Makefile
index 8c1c72c..a6866ab 100644
--- a/Makefile
+++ b/Makefile
@@ -8,6 +8,7 @@ BINFILES = \
arg \
ord \
urldecode \
+ roll \
v-www-browser \
v-editor \
whatismyip \
diff --git a/roll.php b/roll.php
new file mode 100644
index 0000000..0d8aa25
--- /dev/null
+++ b/roll.php
@@ -0,0 +1,21 @@
+#!/usr/bin/env php
+<?php
+
+$string = $argv[1];
+
+preg_match('/([0-9]*)d([0-9]+)(([+-][0-9]+))?/', $string, $matches);
+$dice = (int)$matches[1];
+$die_size = (int)$matches[2];
+$mod = (int)$matches[3];
+
+if ($dice<1) $dice = 1;
+
+$total = 0;
+for ($i=0; $i < $dice; $i++) {
+ $v = mt_rand(1, $die_size);
+ echo $v.'+';
+ $total += $v;
+}
+echo $mod;
+$total += $mod;
+echo ' = '.$total."\n";