;; die_empirical_methods.l ;; CSC 416 - Graci ;; Jacob Peck ;; 20101015 ;; defines methods for rolling and determining emprical statistics ;; load in class_die.l and class_accumulator.l (load "class_die.l") (load "class_accumulator.l") ;; roll-for-pair method ;; rolls a pair of dice until they match faces (defmethod roll-for-pair ((d1 die) (d2 die)) (roll d1) (roll d2) (if (not (= (die-face d1) (die-face d2))) (roll-for-pair d1 d2) ) ) ;; roll-for-sum method ;; rolls a pair of dice until the faces sum to the given integer (defmethod roll-for-sum ((d1 die) (d2 die) (v integer)) (roll d1) (roll d2) (if (not (= (+ (die-face d1) (die-face d2)) v)) (roll-for-sum d1 d2 v) ) ) ;; ep-pair method ;; rolls two dice in trials to determine the empirical probability ;; of rolling a pair (defmethod ep-pair ((d1 die) (d2 die) (trials integer)) (let (a) (setf a (make-instance 'accumulator)) (dotimes (x trials) (ep-pair-trial d1 d2 a) ) (/ (accumulator-value a) (float trials)) ) ) ;; ep-pair-trial method ;; runs a single trial of ep-pair (defmethod ep-pair-trial ((d1 die) (d2 die) (a accumulator)) (forget d1) (forget d2) (roll-for-pair d1 d2) (inc a (length (die-history d1))) ) ;; ep-sum method ;; rolls two dice in trials to determine the empirical probability ;; of rolling a certain sum (defmethod ep-sum ((d1 die) (d2 die) (v integer) (trials integer)) (let (a) (setf a (make-instance 'accumulator)) (dotimes (x trials) (ep-sum-trial d1 d2 a v) ) (/ (accumulator-value a) (float trials)) ) ) ;; ep-sum-trial method ;; runs a single trial of ep-sum (defmethod ep-sum-trial ((d1 die) (d2 die) (a accumulator) (v integer)) (forget d1) (forget d2) (roll-for-sum d1 d2 v) (inc a (length (die-history d1))) ) ;; ep-7-11-doubles method ;; rolls two dice in trials to determine the empirical probability ;; of rolling either a sum of 7 or 11, or a pair (defmethod ep-7-11-doubles ((d1 die) (d2 die) (trials integer)) (let (a) (setf a (make-instance 'accumulator)) (dotimes (x trials) (ep-7-11-doubles-trial d1 d2 a) ) (/ (accumulator-value a) (float trials)) ) ) ;; ep-7-11-doubles-trial method ;; runs a single trial of ep-7-11-doubles (defmethod ep-7-11-doubles-trial ((d1 die) (d2 die) (a accumulator)) (forget d1) (forget d2) (roll-for-7-11-doubles d1 d2) (inc a (length (die-history d1))) ) ;; roll-for-7-11-doubles method ;; rolls a pair of dice until either the sum of the faces is 7 or 11, or ;; the faces match (defmethod roll-for-7-11-doubles ((d1 die) (d2 die)) (roll d1) (roll d2) (if (not (or (= (die-face d1) (die-face d2)) ; doubles (= 7 (+ (die-face d1) (die-face d2))) ; 7's (= 11 (+ (die-face d1) (die-face d2))) ; 11's )) (roll-for-7-11-doubles d1 d2) ) )