From c8ab406749124d2e762ad5cf53963070113afd0f Mon Sep 17 00:00:00 2001 From: Tom Ryder Date: Wed, 5 Apr 2017 20:06:39 +1200 Subject: Apply runtime shebanging to POSIX shell --- games/aaf | 3 --- games/aaf.sh | 3 +++ games/dr | 36 ------------------------------------ games/dr.sh | 36 ++++++++++++++++++++++++++++++++++++ games/rndn | 43 ------------------------------------------- games/rndn.sh | 43 +++++++++++++++++++++++++++++++++++++++++++ games/xyzzy | 6 ------ games/xyzzy.sh | 6 ++++++ 8 files changed, 88 insertions(+), 88 deletions(-) delete mode 100755 games/aaf create mode 100644 games/aaf.sh delete mode 100755 games/dr create mode 100644 games/dr.sh delete mode 100755 games/rndn create mode 100644 games/rndn.sh delete mode 100755 games/xyzzy create mode 100644 games/xyzzy.sh (limited to 'games') diff --git a/games/aaf b/games/aaf deleted file mode 100755 index 4f1825c6..00000000 --- a/games/aaf +++ /dev/null @@ -1,3 +0,0 @@ -#!/bin/sh -curl http://www.asciiartfarts.com/random.cgi | -pup -p 'table[cellpadding]' pre text{} diff --git a/games/aaf.sh b/games/aaf.sh new file mode 100644 index 00000000..4f1825c6 --- /dev/null +++ b/games/aaf.sh @@ -0,0 +1,3 @@ +#!/bin/sh +curl http://www.asciiartfarts.com/random.cgi | +pup -p 'table[cellpadding]' pre text{} diff --git a/games/dr b/games/dr deleted file mode 100755 index e1db163d..00000000 --- a/games/dr +++ /dev/null @@ -1,36 +0,0 @@ -#!/bin/sh -# Roll D&D-style dice in a ndn+n formula, e.g. 10d6+2 - -# Need exactly one argument -[ "$#" -eq 1 ] || exit 2 - -# Arcane string chopping -n=1 a=0 -nd=${1%+*} -d=${nd#*d} -[ "${nd%d*}" != "" ] && n=${nd%d*} -[ "${1#*+}" = "$1" ] || a=${1#*+} - -# Check number of roles and addendum make sense -[ "$((n > 0 && a >= 0))" -eq 1 ] || exit 2 - -# Check this is a real die you can actually roll -case $d in - 4|6|8|10|12|20) : ;; - *) exit 2 ;; -esac - -# Roll the dice the appropriate number of times using rndi(1df) -i=0 t=0 -while [ "$i" -lt "$n" ] ; do - seed=$(rnds) - r=$(rndi 1 "$d" "$seed") - t=$((t + r)) - i=$((i + 1)) -done - -# Add the addendum -t=$((t + a)) - -# Print it -printf '%u\n' "$t" diff --git a/games/dr.sh b/games/dr.sh new file mode 100644 index 00000000..e1db163d --- /dev/null +++ b/games/dr.sh @@ -0,0 +1,36 @@ +#!/bin/sh +# Roll D&D-style dice in a ndn+n formula, e.g. 10d6+2 + +# Need exactly one argument +[ "$#" -eq 1 ] || exit 2 + +# Arcane string chopping +n=1 a=0 +nd=${1%+*} +d=${nd#*d} +[ "${nd%d*}" != "" ] && n=${nd%d*} +[ "${1#*+}" = "$1" ] || a=${1#*+} + +# Check number of roles and addendum make sense +[ "$((n > 0 && a >= 0))" -eq 1 ] || exit 2 + +# Check this is a real die you can actually roll +case $d in + 4|6|8|10|12|20) : ;; + *) exit 2 ;; +esac + +# Roll the dice the appropriate number of times using rndi(1df) +i=0 t=0 +while [ "$i" -lt "$n" ] ; do + seed=$(rnds) + r=$(rndi 1 "$d" "$seed") + t=$((t + r)) + i=$((i + 1)) +done + +# Add the addendum +t=$((t + a)) + +# Print it +printf '%u\n' "$t" diff --git a/games/rndn b/games/rndn deleted file mode 100755 index 18c34218..00000000 --- a/games/rndn +++ /dev/null @@ -1,43 +0,0 @@ -#!/bin/sh -# Esoteric random number generator - -# Single optional argument is a random seed, otherwise use rnds(1df) -s=${1:-"$(rnds)"} - -# Validate s -case $s in - *[!0-9]*) - printf >&2 'rndn: Seed must be non-negative integer\n' - exit 2 - ;; -esac - -# Helper functions -t() { - printf %u "$1" | cut -c -"$2" -} -l() { - printf %u "$1" | wc -c -} -c() { - printf %u "$1" | cut -c "$2" -} - -# Apply algorithm; you are not expected to understand this -s=$(t "$((s + 10))" 32) i=1 t=0 -while [ "$i" -le "$(l "$s")" ] ; do - d=$(c "$s" "$i") - t=$((t + d)) i=$((i + 1)) -done -p=$((s - t)) -while [ "$(l "$p")" -gt 1 ] ; do - j=1 q=0 - while [ "$j" -le "$(l "$p")" ] ; do - d=$(c "$p" "$j") - q=$((q + d)) j=$((j + 1)) - done - p=$q -done - -# Print result -printf '%u\n' "$p" diff --git a/games/rndn.sh b/games/rndn.sh new file mode 100644 index 00000000..18c34218 --- /dev/null +++ b/games/rndn.sh @@ -0,0 +1,43 @@ +#!/bin/sh +# Esoteric random number generator + +# Single optional argument is a random seed, otherwise use rnds(1df) +s=${1:-"$(rnds)"} + +# Validate s +case $s in + *[!0-9]*) + printf >&2 'rndn: Seed must be non-negative integer\n' + exit 2 + ;; +esac + +# Helper functions +t() { + printf %u "$1" | cut -c -"$2" +} +l() { + printf %u "$1" | wc -c +} +c() { + printf %u "$1" | cut -c "$2" +} + +# Apply algorithm; you are not expected to understand this +s=$(t "$((s + 10))" 32) i=1 t=0 +while [ "$i" -le "$(l "$s")" ] ; do + d=$(c "$s" "$i") + t=$((t + d)) i=$((i + 1)) +done +p=$((s - t)) +while [ "$(l "$p")" -gt 1 ] ; do + j=1 q=0 + while [ "$j" -le "$(l "$p")" ] ; do + d=$(c "$p" "$j") + q=$((q + d)) j=$((j + 1)) + done + p=$q +done + +# Print result +printf '%u\n' "$p" diff --git a/games/xyzzy b/games/xyzzy deleted file mode 100755 index d262c0e6..00000000 --- a/games/xyzzy +++ /dev/null @@ -1,6 +0,0 @@ -#!/bin/sh -if [ -e "$HOME"/.xyzzy ] ; then - printf >&2 '%s\n' 'Nothing happens.' - exit 1 -fi -printf '%s\n' 'I see no cave here.' > "$HOME"/.xyzzy diff --git a/games/xyzzy.sh b/games/xyzzy.sh new file mode 100644 index 00000000..d262c0e6 --- /dev/null +++ b/games/xyzzy.sh @@ -0,0 +1,6 @@ +#!/bin/sh +if [ -e "$HOME"/.xyzzy ] ; then + printf >&2 '%s\n' 'Nothing happens.' + exit 1 +fi +printf '%s\n' 'I see no cave here.' > "$HOME"/.xyzzy -- cgit v1.2.3