;; class_die.l ;; CSC 416 - Graci ;; Jacob Peck ;; 20101015 ;; defines the die class and associated methods ;; class die ;; slots: face - current top face ;; sides - number of sides ;; history - history of faces (defclass die () ( (face :accessor die-face :initarg :face :initform 1) (sides :accessor die-sides :initarg :sides :initform 6) (history :accessor die-history :initform ()) ) ) ;; roll method ;; rolls a die and adds value to history (defmethod roll ((d die)) (setf (die-face d) (+ 1 (random (die-sides d)))) (setf (die-history d) (append (die-history d) (list (die-face d)))) NIL ) ;; display method ;; displays the current face, and the history list (defmethod display ((d die)) (format t "[~A,~A]" (die-face d) (write-to-string (die-history d))) ) ;; forget method ;; resets the die's history (defmethod forget ((d die)) (setf (die-history d) ()) )