diff options
-rw-r--r-- | loot.lsp | 132 |
1 files changed, 30 insertions, 102 deletions
diff --git a/loot.lsp b/loot.lsp index 857c7af..4dfb2c8 100644 --- a/loot.lsp +++ b/loot.lsp @@ -4,110 +4,38 @@ (defconstant +max-probability+ 1000) ;; Because this is a simple enum and not a full sum/product type, ;; I use symbols instead of CLOS. -(defconstant +loot-type+ (vector 'bloodstone 'copper 'emeraldite 'gold - 'heronite 'platinum 'shaownite 'silver - 'soranite 'umbrarite 'cobalt 'iron - 'nothing)) +(defconstant +loot-type+ #(bloodstone copper emeraldite gold + heronite platinum shadownite silver + soranite umbrarite cobalt iron + nothing)) (defclass <looter> () ((probabilities :accessor probabilities))) (defgeneric choose (self)) (defmethod choose ((self <looter>)) - (let ((random-value (random (- +max-probability+ 1)))) - (for ((loop 0 (+ loop 1))) - ((>= (elt (probabilities self) (mod loop 13)) random-value) (elt +loot-type+ (mod loop 13)))))) + (let ((random-value (random (- +max-probability+ 1)))) + (for ((loop 0 (+ loop 1))) + ((>= (elt (probabilities self) (mod loop 13)) random-value) (elt +loot-type+ (mod loop 13)))))) (defmethod initialize-object :after ((self <looter>) initargs) - (setf (probabilities self) (vector 10 77 105 125 142 159 172 200 201 202 216 282 +max-probability+ (case l - ((bloodstone) "Bloodstone") - ((copper) "Copper") - ((emeraldite) "Emeraldite") - ((gold) "Gold") - ((heronite) "Heronite") - ((platinum) "Platinum") - ((shadownite) "Shadownite") - ((silver) "Silver") - ((soranite) "Soranite") - ((umbrarite) "Umbrarite") - ((cobalt) "Cobalt") - ((iron) "Iron") - (t ""))) + (setf (probabilities self) (vector 10 77 105 125 142 159 172 200 201 202 216 282 +max-probability+))) +(defun as-string (l) + ;; Could use assoc here, but this is closer to the original. + ;; Also saves translating nil to "". + (case l + ((bloodstone) "Bloodstone") + ((copper) "Copper") + ((emeraldite) "Emeraldite") + ((gold) "Gold") + ((heronite) "Heronite") + ((platinum) "Platinum") + ((shadownite) "Shadownite") + ((silver) "Silver") + ((soranite) "Soranite") + ((umbrarite) "Umbrarite") + ((cobalt) "Cobalt") + ((iron) "Iron") + (t ""))) (defun main () - (let ((loot (create (class <looter>))) (for ((n 0 (+ n 1))) - - ((> n 99)) - (format (standard-output) "~A~%" (as-string (choose loot)))))) - - -. /usr/local/plan9/bin/9.rc -if (test -d /usr/local/bin) { - path = (/usr/local/bin $path) -} -if (test -d /usr/local/opt/emacs-plus/bin) { - path = ($path /usr/local/opt/emacs-plus/bin) -} -if (test -d $home/bin) { - path = ($path $home/bin) -} -if (test -d $home/opt/GNAT/2020/bin) { - path = ($home/opt/GNAT/2020/bin $path) -} - -OPENLISP = $home/openlisp-11.0.0 -if (test -d $OPENLISP) { - path = ($path $OPENLISP) -} - -# These break some commands like man. -# Use the new names instead. -#fn grep { rg $* } -#fn ls { exa $* } -#fn find { fd $* } -#fn cat { bat $* } -#fn more { bat $* } -#fn xterm { alacritty $* } - -#prompt = ('$ ' '$ ') -REFER = $home/lsp/doc/refs - -if (test -d $home/.cargo/bin) { - path = ($home/.cargo/bin $path) -} - -if (test -d /usr/local/opt/tcl-tk/bin) { - path = (/usr/local/opt/tcl-tk/bin $path) -} - -if (test -d $home/obnc/usr/local/bin) { - path = ($path $home/obnc/usr/local/bin) -} - -if (test -d $home/.emacs.d/bin) { - path = ($path $home/.emacs.d/bin) -} -fn doom { u doom $* } -if (test -d /Applications/Emacs.app/Contents/MacOS/bin) { - path = ($path /Applications/Emacs.app/Contents/MacOS/bin) -} -if (test -f /Applications/Emacs.app/Contents/MacOS/Emacs) { - EMACS = /Applications/Emacs.app/Contents/MacOS/Emacs - fn emacs { u $EMACS -nw $* } -} -if (test -f /Applications/Emacs.app/Contents/MacOS/bin/emacsclient) { - fn emacsclient { u /Applications/Emacs.app/Contents/MacOS/bin/emacsclient $* } -} - -LANG = en_IE.UTF-8 -TZ = Europe/Dublin -LESS_IS_MORE = t -MORE = '-SEXIER' -POSIXLY_CORRECT = t -REFER = $home/lsp/doc/refs - -if (test -d $home/context/tex/texmf-osx-64/bin) { - path = ($path $home/context/tex/texmf-osx-64/bin) -} - -if (test -d $home/Library/Python/3.8/bin) { - path = ($path $home/Library/Python/3.8/bin) -} - -TCLLIBPATH = $home/lib/tklib0.7 - + (let ((loot (create (class <looter>)))) + (for ((n 0 (+ n 1))) + ((> n 99)) + (format (standard-output) "~A~%" (as-string (choose loot)))))) +(main) |