From: Alex Williams[SysOp]
Subject: CLISP: Code difficulty
Date: 
Message-ID: <ZsR8ac1w165w@runic.via.mind.org>
 I'm having a bit of trouble modeling a certain behaviour of a dice
 roll, automating the rolling in a certain RPG (yes, its trivial, but
 leave me my hobbies ;) ):

 The roll is based around 20-sided die.  A skill is an integer > 0.
 A catastrophic failure is a roll greater than %10 of the chance to
 simply fail on a roll.  Success is determined by rolling under or
 equal to the given skill.  However, catastrophic failure for skills
 > 20 is handled a bit differently.

 If a skill > 20 is given, then the possibility for catastrophic
 failure is invoked on a roll of 20.  If a 20 is rolled, then one
 rolls the die again.  On a simple failure, a catastrophic effect is
 the result.

 This holds true in pattern for skills > 40.  First, a natural 20 is
 rolled, then a second die, checked for a /second/ natural 20.  If it
 exists, then the check is made for a simple failure.

 What follows is my attempts at creating the code for a generalized
 die moddeler, including the areas I've already mentioned.  Any help
 would be appreciated.

 -----------------------------------------------------------
; Die roller system

(provide 'die-roller)

(in-package 'DIE-ROLLER :nicknames '(:DIE :DICE))

(export '(die doubling-die multi-die multi-doubling-die sum-dice
	      kult-skill-throw-perfect-value
              kult-skill-throw-flunked-value))

(defun die (&optional (sides 10)) 
  (1+ (random sides)))

(defun doubling-die (&optional (sides 10)) 
  (let ((die-roll (die sides))) 
    (if (= die-roll sides) 
	(+ die-roll (doubling-die sides)) die-roll)))

(defun multi-die (num &optional (sides 10))
  (let ((dice nil))
    (dotimes (x num dice)
	     (push (die sides) dice))))

(defun multi-doubling-die (num &optional (sides 10))
  (let ((dice nil))
    (dotimes (x num dice)
	     (push (doubling-die sides) dice))))

(defun sum-dice (dice)
  (apply '+ dice))

(defun kult-skill-throw-perfect-value (skill)
  (car (multiple-value-list (ceiling (/ skill 10)))))

(defun kult-skill-throw-flunked-value (skill)
  (if (< skill 20) (- 20 (round (/ (- 20 skill) 10)))
       20))

(defun kult-skill-throw-perfect-p (skill die)
  (if (<= (kult-skill-perfect-throw-value skill) die) 
      t
    nil))


;; This is the specific function I am having the most trouble with.
;; Skills < 20 are easy...  Its when the necessary multiple d20
;; checksoccur that I'm unsure how to proceed, iteratively or
;; recursively.

;(defun kult-skill-throw-flunked-p (skill die)
;  (cond ((<= skill 20)
;	 (if (>= (kult-skill-flunked-throw-value skill) die)
;	     t
;	   nil))
;	(t 

(defun kult-skill-throw-failed-p (skill die)
  (if (> skill die)
      t
    nil))

(in-package "USER")
 ------------------------------------------------------------------

 Your help is much appreciated.


-- 
·······@runic.via.mind.org (Paul Williams [SysOp]) |  PGP 2.0 Key avail
...!emory!uumind!runic!thantos                     |      upon request.
-----------------------------------------------------------------------
  Wyvern/Hasturian Enterprises: The Corporation that's Fun to Dispell
-----------------------------------------------------------------------