;


;*****************************************************************
;                     EMULATION CODE
;*****************************************************************
;Load this before ClearAll because don't need to reset this stuff after each "subject"

; This function provides the control structure for setting the model to loop through a certain number of 
; subjects, with each subject completing a certain number of scenarios.

; Load the model (which loads the emulation), then type (collect-data-fd-model) in the Listener.
; To run the model with a certain # of subjects, say 10, type (collect-data-fd-model :subjects 10)

; If you want to run it with a trace of each subject, type (collect-data-fd-model :subjects 10 :subject-trace t)

(defvar *scenario-limit* 4)

(defvar *scenario-list* nil)

(defvar *current-scenario*)

(defvar *current-subject*)

(defvar *subject-trace* nil)

;;; variables for the the STAT LADY EMULATION

(defvar *text-info*)

(defvar *current-text*)

(defvar *scenario-info*)

(defvar *current-state*)

(defvar *cell-count*)


(defvar *scenario-count*)

(defvar *instruction-text*)

(defvar *instruction-pos-fdbk-txt*)

(defvar *pos-fdbk*)

(defvar *begin-time*)
(defvar *done-button-count*)



;;;;;;;;;;;;;;;;;; code for the web interface

(defparameter *results-fd-model* '((4.0 1.75 1.5 53) (2 1 .75 38) (2 .25 .25 36) (1.75 .5 .25 30)))
(defvar *blc* 5)
(defvar *egn* 1)
(defvar *num-subjects* 1)
(defvar *v* nil)
(defvar *text* t)
(defvar *graphic* nil)
(defvar *sub-trace* nil)
(defvar *bar-graph* t)
(defvar *line-graph* nil)

(defun display-results-fd-model (data sim)
  (when sim
    (format *standard-output* "~%~%Parameters for run: (~S ~S ~S)~%~%" *blc* *egn* *num-subjects*))
  (when  *text*
    (format *standard-output* "~%~%~A Average Results:~%" (if sim "Simulation" "Experimental"))
    (dotimes (i 4)
      (format *standard-output* "~%Scenario - ~D" (1+ i))
      (format *standard-output* "~%~6,3F readings of instruction text. " (nth 0 (nth i data)))
      (format *standard-output* "~%~6,3F readings of instruction text in pos feedback. " (nth 1 (nth i data)))
      (format *standard-output* "~%~6,3F readings of pos feedback text. " (nth 2 (nth i data)))
      (format *standard-output* "~%Time was ~6,3F~%" (nth 3 (nth i data))))
    (format *standard-output* "~%~%")
    (unless (or (null sim) *graphic*) (format *standard-output* 
                              "~%</pre>If your browser supports JAVA, you 
                               can display the data in a graph by checking 
                               the Graphic output box on the interface page.<pre>~%~%")))


  (when (and sim *graphic*)
    
    (when *line-graph*
      (dotimes (i 3)
        (draw-graph-2-fd-model (mapcar #'(lambda (x) (nth i x)) data) i)))

    (when *bar-graph*
      (dotimes (i 4)
        (draw-graph-fd-model (nth i data) i)))

     (when *line-graph*
       (format *standard-output* " 
        <applet 
        code = \"DansGraphs.class\" 
        width = 400 
        height = 400> 
        <PARAM name=\"title\" value=\"Completion Times\">
        <PARAM name=\"xmin\" value=\"1\">
        <PARAM name=\"xmax\" value=\"4\">
        <PARAM name=\"ymax\" value=\"80\">
        <PARAM name=\"ymin\" value=\"20\">
        <PARAM name=\"ydiv\" value=\"5\">
        <PARAM name=\"yspacing\" value=\"10\">
        <PARAM name=\"xspacing\" value=\"1\">
        <PARAM name=\"xval0\" value=\"1;2;3;4;\">
        <PARAM name=\"xval1\" value=\"1;2;3;4;\">
        <PARAM name=\"lstyle0\" value=\"2\">
        <PARAM name=\"lstyle1\" value=\"6553\">
        <PARAM name=\"xname\" value=\"Scenario\">
        <PARAM name=\"yname\" value=\"Time\">
        <PARAM name=\"numlines\" value=\"2\">
        <PARAM name=\"longestline\" value=\"4\">
        <PARAM name=\"name0\" value=\"Simulation Data\">
        <PARAM name=\"name1\" value=\"Experiment Data\">")
    
    (format *standard-output* "<PARAM name=\"yval0\" value=\"")
    
    (dotimes (i 4)
      (format *standard-output* "~s;" (nth 3 (nth i data))))
    
    (format *standard-output* "\">")
    
    (format *standard-output* "<PARAM name=\"yval1\" value=\"")
    (dotimes (i 4)
      (format *standard-output* "~s;" (nth 3 (nth i *results-fd-model*))))
    
    (format *standard-output* "\">")
    
    (format *standard-output* "
             <HR> Either your browser does not support JAVA, or this graph has scrolled out of the window.~%
             </HR></applet>"))

     (when  *bar-graph*
       (format *standard-output* " 
        <applet 
        code = \"DansGraphs.class\" 
        width = 400 
        height = 400> 
        <PARAM name=\"title\" value=\"Completion Times\">
        <PARAM name=\"ymax\" value=\"80\">
        <PARAM name=\"ymin\" value=\"20\">
        <PARAM name=\"xmax\" value=\"5\">
        <PARAM name=\"xmin\" value=\"0\">
        <PARAM name=\"ydiv\" value=\"5\">
        <PARAM name=\"yspacing\" value=\"10\">
        <PARAM name=\"xspacing\" value=\"1\">
        <PARAM name=\"xval0\" value=\"0.8;0.8;\">
        <PARAM name=\"xval1\" value=\"1.2;1.2;\">
        <PARAM name=\"xval2\" value=\"1.8;1.8;\">
        <PARAM name=\"xval3\" value=\"2.2;2.2;\">
        <PARAM name=\"xval4\" value=\"2.8;2.8;\">
        <PARAM name=\"xval5\" value=\"3.2;3.2;\">
        <PARAM name=\"xval6\" value=\"3.8;3.8;\">
        <PARAM name=\"xval7\" value=\"4.2;4.2;\">
        <PARAM name=\"numlines\" value=\"8\">
        <PARAM name=\"longestline\" value=\"2\">
         <PARAM name=\"name0\" value=\"Simulation\">
        <PARAM name=\"name1\" value=\"Experiment\">
         <PARAM name=\"lcolor0\" value=\"0\">
        <PARAM name=\"lcolor1\" value=\"1\">
        <PARAM name=\"lcolor2\" value=\"0\">
        <PARAM name=\"lcolor3\" value=\"1\">
        <PARAM name=\"lcolor4\" value=\"0\">
        <PARAM name=\"lcolor5\" value=\"1\">
        <PARAM name=\"lcolor6\" value=\"0\">
        <PARAM name=\"lcolor7\" value=\"1\">
        <PARAM name=\"lstyle0\" value=\"2\">
        <PARAM name=\"lstyle1\" value=\"6553\">
        <PARAM name=\"lstyle2\" value=\"2\">
        <PARAM name=\"lstyle3\" value=\"6553\">
        <PARAM name=\"lstyle4\" value=\"2\">
        <PARAM name=\"lstyle5\" value=\"6553\">
        <PARAM name=\"lstyle6\" value=\"2\">
        <PARAM name=\"lstyle7\" value=\"6553\">
         <PARAM name=\"xname\" value=\"Scenario\">
        <PARAM name=\"yname\" value=\"Time\">
        "
               )
    
    
    (dotimes (i 4)
      (format *standard-output* "<PARAM name=\"yval~S\" value=\"20;~s;\">" (* i 2) (nth 3 (nth i data))))
    
    (dotimes (i 4)
      (format *standard-output* "<PARAM name=\"yval~S\" value=\"20;~s;\">" (1+ (* i 2)) (nth 3 (nth i *results-fd-model*))))
 
     
    (format *standard-output* "
             <HR> Either your browser does not support JAVA, or this graph has scrolled out of the window.~%
             </HR></applet>")))

)

(defun draw-graph-2-fd-model (data num)
  (format *standard-output* " 
        <applet 
        code = \"DansGraphs.class\" 
        width = 400 
        height = 400> 
        <PARAM name=\"title\" value=\"Number of readings - ~a\">
        <PARAM name=\"ymax\" value=\"6\">
        <PARAM name=\"ymin\" value=\"0\">
        <PARAM name=\"xmax\" value=\"4\">
        <PARAM name=\"xmin\" value=\"1\">
        <PARAM name=\"ydiv\" value=\".5\">
        <PARAM name=\"yspacing\" value=\"1\">
        <PARAM name=\"xval0\" value=\"1;2;3;4;\">
        <PARAM name=\"xval1\" value=\"1;2;3;4;\">
        <PARAM name=\"xname\" value=\"Scenario\">
        <PARAM name=\"xspacing\" value=\"1\">
        <PARAM name=\"yname\" value=\"Readings\">
        <PARAM name=\"numlines\" value=\"2\">
        <PARAM name=\"longestline\" value=\"4\">
        <PARAM name=\"name0\" value=\"Simulation\">
        <PARAM name=\"name1\" value=\"Experiment\">
        <PARAM name=\"lcolor0\" value=\"0\">
        <PARAM name=\"lcolor1\" value=\"1\">
        <PARAM name=\"lstyle0\" value=\"2\">
        <PARAM name=\"lstyle1\" value=\"6553\">
        <PARAM name=\"lstyle2\" value=\"2\">
        <PARAM name=\"yval0\" value=\"~S;~s;~s;~s;\">
        <PARAM name=\"yval1\" value=\"~S;~s;~s;~s;\">
        
" 
            (case num (0 "Instructions") (1 "Instructions (feedback)") (2 "Feedback"))
            (nth 0 data) (nth 1 data) (nth 2 data) (nth 3 data)
            (nth num (nth 0 *results-fd-model*))
            (nth num (nth 1 *results-fd-model*))
            (nth num (nth 2 *results-fd-model*))
            (nth num (nth 3 *results-fd-model*))
            )
    
   (format *standard-output* "
             <HR> Either your browser does not support JAVA, or this graph has scrolled out of the window.~%
             </HR></applet>")
)


(defun draw-graph-fd-model (data num)
  (format *standard-output* " 
        <applet 
        code = \"DansGraphs.class\" 
        width = 400 
        height = 400> 
        <PARAM name=\"title\" value=\"Number of readings - Scenario ~s\">
        <PARAM name=\"ymax\" value=\"6\">
        <PARAM name=\"ymin\" value=\"0\">
        <PARAM name=\"xmax\" value=\"4\">
        <PARAM name=\"xmin\" value=\"0\">
        <PARAM name=\"ydiv\" value=\".5\">
        <PARAM name=\"yspacing\" value=\"1\">
        <PARAM name=\"xval0\" value=\"0.4;0.4;\">
        <PARAM name=\"xval1\" value=\"0.6;0.6;\">
        <PARAM name=\"xval2\" value=\"1.9;1.9;\">
        <PARAM name=\"xval3\" value=\"2.1;2.1;\">
        <PARAM name=\"xval4\" value=\"3.4;3.4;\">
        <PARAM name=\"xval5\" value=\"3.6;3.6;\">
        <PARAM name=\"xname\" value=\"Text Type\">
        <PARAM name=\"yname\" value=\"Readings\">
        <PARAM name=\"numxlabels\" value=\"9\">
        <PARAM name=\"numlines\" value=\"6\">
        <PARAM name=\"longestline\" value=\"2\">
        <PARAM name=\"xlabels\" value=\";Instr.;;;Instr. (feedback);;;Feedback;;\">
        <PARAM name=\"widestxlabel\" value=\"WWWWWWWWWWWWWWWW\">
        <PARAM name=\"name0\" value=\"Simulation\">
        <PARAM name=\"name1\" value=\"Experiment\">
         <PARAM name=\"lcolor0\" value=\"0\">
        <PARAM name=\"lcolor1\" value=\"1\">
        <PARAM name=\"lcolor2\" value=\"0\">
        <PARAM name=\"lcolor3\" value=\"1\">
        <PARAM name=\"lcolor4\" value=\"0\">
        <PARAM name=\"lcolor5\" value=\"1\">
        <PARAM name=\"lstyle0\" value=\"2\">
        <PARAM name=\"lstyle1\" value=\"6553\">
        <PARAM name=\"lstyle2\" value=\"2\">
        <PARAM name=\"lstyle3\" value=\"6553\">
        <PARAM name=\"lstyle4\" value=\"2\">
        <PARAM name=\"lstyle5\" value=\"6553\">
        <PARAM name=\"yval0\" value=\"0;~s;\">
        <PARAM name=\"yval1\" value=\"0;~s;\">
        <PARAM name=\"yval2\" value=\"0;~s;\">
        <PARAM name=\"yval3\" value=\"0;~s;\">
        <PARAM name=\"yval4\" value=\"0;~s;\">
        <PARAM name=\"yval5\" value=\"0;~s;\">
" 
            (1+ num) (nth 0 data) (nth 0 (nth num *results-fd-model*))
            (nth 1 data) (nth 1 (nth num *results-fd-model*))
            (nth 2 data) (nth 2 (nth num *results-fd-model*)))
    
   (format *standard-output* "
             <HR> Either your browser does not support JAVA, or this graph has scrolled out of the window.~%
             </HR></applet>")
)

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;
;;; This section contains the interface for the WWW using the
;;; ACT-R on the Web application by Elmar Schwarz

(defvar *WWW-interface*)

(setf  *WWW-interface* 
      '((:heading "Frequency Distribution model" 2)
         (:table)
        (:table)
        
        "Base level constant: "          (:string :sy *blc*   5)  (:new-row)
        "Expected gain noise:"           (:string :sy *egn* 1)     (:new-row)
        "Number of subjects (1-1000): "  (:string :sy *num-subjects*    100)
        (:table-end)
         (:table)
        (:checkbox "Model Trace" :sy *v*  nil)                (:new-row)
        (:checkbox "Subject Trace" :sy *sub-trace*  nil)                (:new-row)
        (:checkbox "Text output" :sy *text*  t)         (:new-row)
        (:checkbox "Graphic output (bar graphs)" :sy *bar-graph*  nil) (:new-row)
        (:checkbox "Graphic output (line graphs)" :sy *line-graph*  nil) (:new-row)
        (:table-end)
       (:table-end)
        
        (:new-para)
        (:button "Show Experiment Results" "(display-results-fd-model *results-fd-model* nil)")
       
        (:new-para)
        
        
        (:button "Run model" "(if (and (numberp *blc*)  
                                       (numberp *egn*) (numberp *num-subjects*))
                                  (progn (setf *graphic* (or *bar-graph* *line-graph*))
                                  (collect-data-fd-model :subjects (min 1000 (max 1 *num-subjects*)) :subject-trace *sub-trace*))
                                  (format *standard-output* \"All parameters must be numbers~%\"))")
        (:reset "Default values")
        (:button "Production Rules" "(let ((prods (no-output (pp))))
                                       (dolist (x prods)
                                         (pp-fct (list x))
                                         (spp-fct (list x))
                                         (format *standard-output* \"~%\")))")
        (:button "Chunk types" "(chunk-type)")
        (:button "Chunks" "(dm)")
        (:new-para)
        "TIME and SIZE:"
        (:new-para)
        "- It usually takes about 1 minute for a 100 subjects run"
        (:new-line)
        "- The trace of a 1 subject run is approximatly 25k (15 pages) in size"
        (:new-para)))



(defun set-params-fd-model ()
  (sgp-fct (list 
            :era T
            :blc *blc*
            :egn *egn*
            :v *v*
            ))
  (setf *text-info* '((TEXT1 TEXT2 TEXT3 TEXT4 TEXT5) (TEXT6 TEXT7 TEXT8 TEXT9 TEXT10) 
                    (TEXT11 TEXT12) (TEXT13 TEXT14 TEXT15 TEXT16 TEXT17) (TEXT18 TEXT19)
                    (TEXT18 TEXT19) (TEXT18 TEXT19) (TEXT18 TEXT19) (TEXT18 TEXT19 TEXT20)
                    (TEXT21 TEXT22 TEXT23 TEXT24)))
(setf *current-text* 'TEXT0)
(setf *scenario-info* '(amusement-park burger-place restaurants shopping-mall football))
(setf *current-state* 'scenario-choices)
(setf *cell-count* 0)
(setf *scenario-count* 1)
(setf *instruction-text* 0)
(setf *instruction-pos-fdbk-txt* 0)
(setf *pos-fdbk* 0)
(setf *done-button-count* 0)
)


;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;









(defun average-lists-fd-model (length lists number)
  (let ((average (make-list length :initial-element 0.0)))
    (dolist (list lists (mapcar #'(lambda (sum) (/ sum number)) average))
      (setf average (mapcar #'+ average list)))))

(defun collect-data-fd-model (&key (subjects 4) (scenarios 4) (subject-trace nil))
  (let ((scenario-list (make-list scenarios :initial-element nil)))
    (setf *subject-trace* subject-trace)
    (setf *current-subject* 1)
    (dotimes (i subjects)
      (format *subject-trace* "~%~%SUBJECT ~D" *current-subject*)
      (reset)  ; reset returns everything after ClearAll in the Model file to its initial state
      (set-params-fd-model)
      (setf *scenario-limit* scenarios)
      (setf *scenario-list* nil)
      (setf *current-scenario* 1)
      (run)
      (setf scenario-list (mapcar #'cons (nreverse *scenario-list*) scenario-list))
      (incf *current-subject*))
    (format *output-trace* "~%~%AVERAGE OF ~D SUBJECTS.~%" subjects)
    (let ((results nil))
      (dotimes (scenario scenarios)
      (setf *scenario-list* (average-lists-fd-model scenarios (pop scenario-list) subjects))
      (push *scenario-list* results))
      (display-results-fd-model (reverse results) t))
#|(dotimes (scenario scenarios)
      (setf *scenario-list* (average-lists-fd-model scenarios (pop scenario-list) subjects))
      (format *output-trace* "~%Scenario - ~D" (1+ scenario))
      (format *output-trace* "~%~6,3F readings of instruction text. " (pop *scenario-list*))
      (format *output-trace* "~%~6,3F readings of instruction text in pos feedback. " (pop *scenario-list*))
      (format *output-trace* "~%~6,3F readings of pos feedback text. " (pop *scenario-list*))
      (format *output-trace* "~%Time was ~6,3F" (pop *scenario-list*)))))
|#
))




;********************************************************

; HERE BEGINS THE STAT LADY EMULATION



(defun statgirl-fd-model (action &optional (arg nil))
  (setf *current-state* action)
  (cond ((eq action 'next-scenario)(do-ns-fd-model))
        ((eq action 'new-directions)(do-nd-fd-model arg))
        ((eq action 'done-button)(do-db-fd-model))
        ((eq action 'click-red-?)(do-rq-fd-model arg))
        ((eq action 'fill-frequency)(do-ff-fd-model arg))
        ((eq action 'enter-value)(do-ev-fd-model arg))
;        ((eq action 'column-heading)(do-ch arg))
        ((eq action 'instruction)(do-ins-fd-model))
        ((eq action 'inst-posfeed)(do-ins-pfdbk-fd-model))
        ((eq action 'posfeed)(do-pos-fd-model))
        ((eq action 'reset-scenario)(do-reset-scenario-fd-model))
 ))

;; Instruction
(defun do-ins-fd-model ()
  (incf *instruction-text*))

;; Instruction in Pos. Feedback
(defun do-ins-pfdbk-fd-model ()
  (incf *instruction-pos-fdbk-txt*))

;; Positive Feedback
(defun do-pos-fd-model ()
  (incf *pos-fdbk*))

;; Next Text
(defun next-text-fd-model ()
(if (listp (car *text-info*)) (setf *current-text* (car *text-info*))
    (setf *current-text* (list (car *text-info*))))
;  (format *output-trace* "~%~S appears on screen.  " *current-text*)
  (setf *text-info* (cdr *text-info*))
  (dolist (tmp *current-text*)
  (mod-chunk-fct (get-safe-wme tmp) (list 'on-screen 'yes))))


;; Next Scenario
(defun do-ns-fd-model ()
  (format *subject-trace* "~%Scenario ~S chosen.  " (car *scenario-info*))
  (setf *current-scenario* (car *scenario-info*))
  (setf *scenario-info* (cdr *scenario-info*))
  (mod-chunk text0 on-screen no)
  (mod-focus previous sort-descending)
  (setf *begin-time* (actr-time))
  (next-text-fd-model)
  (sdp (text1 text2 text3 text4 text5) :creation-time -1 :references 10)
  (cond ((equal 1 *scenario-count*)
           (add-table-fd-model *current-scenario*)))
  (cond ((> *scenario-count* 1)
           (mod-chunk question-mark-1 value red-question-mark)
           (mod-chunk question-mark-2 value gray-question-mark)
           (mod-chunk cell-1 value empty)
           (mod-chunk cell-2 value empty)
           (mod-chunk cell-3 value empty)
           (mod-chunk cell-4 value empty)
           (mod-chunk cell-5 value empty)
           (mod-chunk cell-6 value empty)
           (mod-chunk cell-7 value empty)
           (mod-chunk cell-8 value empty)
           (mod-chunk cell-9 value empty)
           (mod-chunk cell-10 value empty)
           (mod-chunk cell-11 value empty)
           (mod-chunk cell-12 value empty)
           (mod-chunk cell-13 value empty)
           (mod-chunk cell-14 value empty)
           (mod-chunk cell-15 value empty)
           (mod-chunk cell-16 value empty)
           (mod-chunk cell-17 value empty)
           (mod-chunk cell-18 value empty)
           (mod-chunk cell-19 value empty)
           (sdp (question-mark-1 question-mark-2) :creation-time -1 :references 10))))



;; Done button
(defun do-db-fd-model ()
    (mod-chunk done-button active nil)
    (cond ((equal *done-button-count* 0) (progn
                             (setf *current-state* 'fill-button)
                             (hide-symbol-pad-fd-model)
                             (mod-chunk fill-button active yes)
                             (sdp fill-button :creation-time -1 :references 10)
                             (mod-chunk question-mark-1 value X)
;                             (format *output-trace* "~%Fill button appears on screen.")
                             (incf *done-button-count*)))
          ((equal *done-button-count* 1) (progn
                           (mod-chunk question-mark-2 value f)
                           (next-text-fd-model)
                           (hide-symbol-pad-fd-model)
                           (sdp (text13 text14 text15 text16 text17) :creation-time -1 :references 10)
                           )))
    (cond ((equal *current-state* 'fill-button) (progn
                                                  (next-text-fd-model)
                                                  (sdp (text6 text7 text8 text9 text10) :creation-time -1 :references 10)
                                                  ))))


;; Red Question Mark
(defun do-rq-fd-model (obj)
;    (format *output-trace* "~%Symbol Pad appears on screen.")
    (show-symbol-pad-fd-model)
    (cond ((equal obj 'variable) (progn
                              (mod-focus current use-symbol-pad-variable)
;                              (format *output-trace* "~%I see the symbol pad and change my goal to select a symbol.")
                              ))
          ((equal obj 'frequency) (progn
                                    (mod-chunk text12 on-screen no)
                                    (mod-focus current use-symbol-pad-frequency)))))

;; Symbol Pad
(defun show-symbol-pad-fd-model ()
    (mod-chunk symbol-pad active yes)
    (mod-chunk done-button active yes)
    (mod-chunk X active yes)
    (mod-chunk f active yes)
    (mod-chunk N active yes)
    (mod-chunk p active yes)
    (mod-chunk Y active yes)
    (mod-chunk E active yes)
    (mod-chunk * active yes)
    (mod-chunk / active yes)
    (mod-chunk + active yes)
    (mod-chunk - active yes)
    (mod-chunk clear-button active yes)
    (sdp (done-button clear-button X f N p Y E * / + -) :creation-time -1 :references 10))

(defun hide-symbol-pad-fd-model ()
    (mod-chunk symbol-pad active nil)
    (mod-chunk done-button active nil)
    (mod-chunk X active nil)
    (mod-chunk f active nil)
    (mod-chunk N active nil)
    (mod-chunk p active nil)
    (mod-chunk Y active nil)
    (mod-chunk E active nil)
    (mod-chunk * active nil)
    (mod-chunk / active nil)
    (mod-chunk + active nil)
    (mod-chunk - active nil)
    (mod-chunk clear-button active nil))



;; Enter Value
(defun do-ev-fd-model (obj)
  (format *output-trace* "~%Typing in ~S.  " obj))


;; Fill f Column
(defun do-ff-fd-model (number)
  (format *output-trace* "~%Clicking cell in ~S row, frequency column.  " number)
  (if (< *cell-count* 5)
    (format *output-trace* "~%Calculator appears on screen.  ")
    (and (addwm (fill-button-2 isa button name fill active yes))(format *output-trace* "~%Stat Lady beeps.  ")))
  (incf *cell-count*))


;; New Directions
(defun do-nd-fd-model (obj)
  (cond ((eq obj 'add-qm2) (progn 
                                (add-variable-values-fd-model *current-scenario*)
                                (setf *current-state* 'frequency-header)
                                (modify-text-1-fd-model)
                                (next-text-fd-model)
                                (sdp (text11 text12) :creation-time -1 :references 10)
                                (mod-chunk fill-button active nil)
;                                (format *output-trace* "~%Column filled.  ")
                            )
         )
   )
)

;; Reset Scenario

(defun do-reset-scenario-fd-model ()
  (if (<= *scenario-count* *scenario-limit*) (progn
                  (format *subject-trace* "~%~%Current scenario - ~a" *scenario-count*)
                  (dolist (tmp '(text1 text11 text13 text14 text15 text16 text17))
                    (mod-chunk-fct (get-safe-wme tmp) (list 'on-screen 'nil 'already-read 'nil)))
                  (mod-chunk text1 on-screen nil already-read nil)
                  (mod-chunk text2 on-screen nil already-read nil)
                  (mod-chunk text3 on-screen nil already-read nil)
                  (mod-chunk text4 on-screen nil already-read nil)
                  (mod-chunk text5 on-screen nil already-read nil)
                  (mod-chunk text6 on-screen nil already-read nil)
                  (mod-chunk text7 on-screen nil already-read nil)
                  (mod-chunk text8 on-screen nil already-read nil)
                  (mod-chunk text9 on-screen nil already-read nil)
                  (mod-chunk text10 on-screen nil already-read nil)
                  (mod-chunk text11 on-screen nil already-read nil)
                  (mod-chunk text12 on-screen nil already-read nil)
                  (setf *text-info* '((TEXT1 TEXT2 TEXT3 TEXT4 TEXT5) (TEXT6 TEXT7 TEXT8 TEXT9 TEXT10) 
                    (TEXT11 TEXT12) (TEXT13 TEXT14 TEXT15 TEXT16 TEXT17) (TEXT18 TEXT19)
                    (TEXT18 TEXT19) (TEXT18 TEXT19) (TEXT18 TEXT19) (TEXT18 TEXT19 TEXT20)
                    (TEXT21 TEXT22 TEXT23 TEXT24)))
                  (setf *current-text* 'text0)
                  (setf *scenario-info* '(amusement-park burger-place restaurants shopping-mall football))
                  (setf *current-state* 'scenario-choices)
                  (setf *done-button-count* 0)
                  (pop-goal)
                  (mod-focus previous instruction-section current choose-next-scenario)
                  (format *subject-trace* "~%~S readings of instruction text. " *instruction-text*)
                  (format *subject-trace* "~%~S readings of instruction text in pos feedback. " *instruction-pos-fdbk-txt*)
                  (format *subject-trace* "~%~S readings of pos feedback text. " *pos-fdbk*)
                  (format *subject-trace* "~%Time was ~6,3F" (- (actr-time) *begin-time*))
                  (push (list *instruction-text* *instruction-pos-fdbk-txt* *pos-fdbk* (- (actr-time) *begin-time*))
                        *scenario-list*)
                  (setf *instruction-text* 0)
                  (setf *instruction-pos-fdbk-txt* 0)
                  (setf *pos-fdbk* 0)
;                  (actr-time 300)
;                  (delete-chunk-fct '(question-mark-1 question-mark-2 cell-1 cell-2 cell-3
;                                       cell-4 cell-5 cell-6 cell-7 cell-8 cell-9 cell-10 cell-11
;                                       cell-12 cell-13 cell-14 cell-15 cell-16 cell-17 cell-18
;                                       cell-19 cell-20 cell-21 cell-22 cell-23 cell-24 cell-25
;                                       cell-26 cell-27 cell-28 cell-29 cell-30 cell-31 cell-32
;                                       cell-33 cell-34 cell-35 cell-36 cell-37 cell-38
;                                       data1 data2 data3 data4 data5 data6 data7 data8 data9
;                                       data10 data11 data12 data13 data14))
                  (if (= *scenario-count* *scenario-limit*)
                    (progn
                      (clear-goal-stack)
                      (pop-goal)))))
  (incf *scenario-count*))

;; Add Table
(defun add-table-fd-model (which)
  (cond ((eq which 'amusement-park)
         (addwm (question-mark-1 isa cell in-table frequency-table row header column variable value red-question-mark)
                (question-mark-2 isa cell in-table frequency-table row header column frequency value gray-question-mark)
                (cell-1 isa cell in-table frequency-table row first column variable value empty next second)
                (cell-2 isa cell in-table frequency-table row second column variable value empty next third)
                (cell-3 isa cell in-table frequency-table row third column variable value empty next fourth)
                (cell-4 isa cell in-table frequency-table row fourth column variable value empty next fifth)
                (cell-5 isa cell in-table frequency-table row fifth column variable value empty next sixth)
                (cell-6 isa cell in-table frequency-table row sixth column variable value empty next seventh)
                (cell-7 isa cell in-table frequency-table row seventh column variable value empty next eighth)
                (cell-8 isa cell in-table frequency-table row eighth column variable value empty next ninth)
                (cell-9 isa cell in-table frequency-table row ninth column variable value empty next tenth)
                (cell-10 isa cell in-table frequency-table row tenth column variable value empty next eleventh)
                (cell-11 isa cell in-table frequency-table row eleventh column variable value empty next twelfth)
                (cell-12 isa cell in-table frequency-table row twelfth column variable value empty next thirteenth)
                (cell-13 isa cell in-table frequency-table row thirteenth column variable value empty next fourteenth)
                (cell-14 isa cell in-table frequency-table row fourteenth column variable value empty next fifteenth)
                (cell-15 isa cell in-table frequency-table row fifteenth column variable value empty next sixteenth)
                (cell-16 isa cell in-table frequency-table row sixteenth column variable value empty next seventeenth)
                (cell-17 isa cell in-table frequency-table row seventeenth column variable value empty next eighteenth)
                (cell-18 isa cell in-table frequency-table row eighteenth column variable value empty next bottom)
                (cell-19 isa cell in-table frequency-table row bottom column variable value empty)
                (cell-20 isa cell in-table frequency-table row bottom column frequency value empty next eighteenth)
                (cell-21 isa cell in-table frequency-table row eighteenth column frequency value empty next seventeenth)
                (cell-22 isa cell in-table frequency-table row seventeenth column frequency value empty next sixteenth)
                (cell-23 isa cell in-table frequency-table row sixteenth column frequency value empty next fifteenth)
                (cell-24 isa cell in-table frequency-table row fifteenth column frequency value empty next fourteenth)
                (cell-25 isa cell in-table frequency-table row fourteenth column frequency value empty next thirteenth)
                (cell-26 isa cell in-table frequency-table row thirteenth column frequency value empty next twelfth)
                (cell-27 isa cell in-table frequency-table row twelfth column frequency value empty next eleventh)
                (cell-28 isa cell in-table frequency-table row eleventh column frequency value empty next tenth)
                (cell-29 isa cell in-table frequency-table row tenth column frequency value empty next ninth)
                (cell-30 isa cell in-table frequency-table row ninth column frequency value empty next eighth)
                (cell-31 isa cell in-table frequency-table row eighth column frequency value empty next seventh)
                (cell-32 isa cell in-table frequency-table row seventh column frequency value empty next sixth)
                (cell-33 isa cell in-table frequency-table row sixth column frequency value empty next fifth)
                (cell-34 isa cell in-table frequency-table row fifth column frequency value empty next fourth)
                (cell-35 isa cell in-table frequency-table row fourth column frequency value empty next third)
                (cell-36 isa cell in-table frequency-table row third column frequency value empty next second)
                (cell-37 isa cell in-table frequency-table row second column frequency value empty next first)
                (cell-38 isa cell in-table frequency-table row first column frequency value empty next header)
                (data1 isa cell in-table data-table value three)
                (data2 isa cell in-table data-table value four)
                (data3 isa cell in-table data-table value four)
                (data4 isa cell in-table data-table value seven)
                (data5 isa cell in-table data-table value eight)
                (data6 isa cell in-table data-table value nine)
                (data7 isa cell in-table data-table value ten)
                (data8 isa cell in-table data-table value ten)
                (data9 isa cell in-table data-table value eleven)
                (data10 isa cell in-table data-table value twelve)
                (data11 isa cell in-table data-table value twelve)
                (data12 isa cell in-table data-table value twelve)
                (data13 isa cell in-table data-table value fourteen)
                (data14 isa cell in-table data-table value eighteen))
         (sdp (question-mark-1 question-mark-2 cell-20) :creation-time -1 :references 10)
         )))


(defun add-variable-values-fd-model (which)
  (cond ((eq which 'amusement-park)
         (mod-chunk question-mark-2 value red-question-mark)
         (mod-chunk cell-1 value twenty)
         (mod-chunk cell-2 value nineteen)
         (mod-chunk cell-3 value eighteen)
         (mod-chunk cell-4 value seventeen)
         (mod-chunk cell-5 value sixteen)
         (mod-chunk cell-6 value fifteen)
         (mod-chunk cell-7 value fourteen)
         (mod-chunk cell-8 value thirteen)
         (mod-chunk cell-9 value twelve)
         (mod-chunk cell-10 value eleven)
         (mod-chunk cell-11 value ten)
         (mod-chunk cell-12 value nine)
         (mod-chunk cell-13 value eight)
         (mod-chunk cell-14 value seven)
         (mod-chunk cell-15 value six)
         (mod-chunk cell-16 value five)
         (mod-chunk cell-17 value four)
         (mod-chunk cell-18 value three)
         (mod-chunk cell-19 value two)
)))

(defun modify-text-1-fd-model ()
       (mod-chunk text2 on-screen nil)
       (mod-chunk text3 on-screen nil)
       (mod-chunk text4 on-screen nil)
       (mod-chunk text5 on-screen nil)
       (mod-chunk text6 on-screen nil)
       (mod-chunk text7 on-screen nil)
       (mod-chunk text8 on-screen nil)
       (mod-chunk text9 on-screen nil)
       (mod-chunk text10 on-screen nil)
)





;*****************************************************************
;*****************************************************************
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;


(ClearAll)

(sgp
  :era T
  :blc 5
  :egn 1
  :pl t
  :v nil
)

;(setf *pop-upon-failure* nil)

;;Goal Chunk-Types
(Chunk-Type complete-tutor previous current)
(Chunk-Type get-next previous current scan)
(Chunk-Type action previous current update)
(Chunk-Type rehearsal chunk)

;;Declarative knowledge Chunk-Types
(Chunk-Type descriptive-chunk)
(Chunk-Type (symbol (:include descriptive-chunk)) meaning active)
(Chunk-Type (stats-knowledge (:include descriptive-chunk)))
(Chunk-Type (status (:include descriptive-chunk)))
(Chunk-Type formula meaning)
(Chunk-Type nth)
(Chunk-Type text-type)

;;Visual objects (encoded) Chunk-Types
(Chunk-Type visual-wme location-x location-y in-window active on-screen noticed)
(Chunk-Type (text (:include visual-wme)) type utility already-read encoded-as prior value length)
(Chunk-Type (tool (:include visual-wme)) tool-type contains)
(Chunk-Type (cell (:include visual-wme)) row column in-table value counted next)
(Chunk-Type (button (:include visual-wme)) name pressed)

(Add-DM
   (instruction-window isa visual-wme)
   (feedback-window isa visual-wme)
   (answer isa status)
   (yes isa status)
   (no isa status)
   (empty isa status)
   (done isa status)
   (ready-to-start isa status)
   (failure isa status)
   (instruction isa text-type)
   (instruction-posfeed isa text-type)
   (posfeed isa text-type)
   (descriptive isa text-type)
   (directive isa text-type)
   (symbol-pad isa tool)
   (calculator isa tool)
   (done-button isa button name done)
   (fill-button isa button name fill)
   (clear-button isa button name clear)
   (clear isa action)
   (complete-tutor isa action)
   (select-scenario isa action)
   (complete-worksheet isa status)
   (notice-table isa action)
   (next-page isa action)
   (x-symbol-for-left-column isa action)
   (f-symbol-for-frequency-column isa action)
   (use-symbol-pad isa action)
   (use-symbol-pad-variable isa action)
   (use-symbol-pad-frequency isa action)
   (done-symbol-pad isa action)
   (done-tool isa action)
   (fill-x isa action)
   (click-fill-column-button isa action)
   (fill-column isa action)
   (fill-frequency-cells isa action)
   (click-next-page isa action)
   (fill isa action)
   (click-on-done isa action)
   (title isa text)
   (red-question-mark isa text)
   (gray-question-mark isa text)
   (correct-answer isa text)
   (table-complete isa text)
   (header isa stats-knowledge)
   (frequency-table isa stats-knowledge)
   (frequency-distribution isa stats-knowledge)
   (data-table isa stats-knowledge)
   (bottom isa cell)
   (top isa cell)
   (choose-next-scenario isa action)
   (click-red-? isa action)
   (click-red-?-2 isa action)
   (click-fill-for-x isa action)
   (enter-frequencies isa action)
   (sort-descending isa action)
   (enter-x isa action)
   (click-done isa action)
   (enter-f isa action)
   (click-done-2 isa action)
   (variable isa stats-knowledge)
   (X isa symbol meaning variable)
   (frequency isa stats-knowledge)
   (f isa symbol meaning frequency)
   (Y isa symbol)
   (sigma isa stats-knowledge)
   (E isa symbol meaning sigma)
   (percent isa stats-knowledge)
   (% isa symbol meaning percent)
   (proportion isa stats-knowledge)
   (p isa symbol meaning proportion)
   (sample-size isa stats-knowledge)
   (N isa symbol meaning sample-size)
   (* isa symbol)
   (/ isa symbol)
   (+ isa symbol)
   (- isa symbol)
   (instruction-section isa stats-knowledge)
   (question-mark isa text)
   (? isa symbol meaning question-mark)
   (scenario isa stats-knowledge)
   (goal isa complete-tutor previous instruction-section current choose-next-scenario)
)

;*****************************************************************
;                     INTEGERS.ACT-R
;*****************************************************************

;; This standard ACT-R file defines the types:
;;    INTEGER with slot VALUE
;;    ADDITION-FACT with slots ARG1, ARG2 and SUM
;;    MULTIPLICATION-FACT with slots ARG1, ARG2 and PRODUCT
;; and by default the wmes:
;;    ZERO to EIGHTY-ONE of type number, with values 0 to 81
;;    ZERO+ZERO to NINE+NINE of type addition-fact,
;;        with appropriate integer slot values
;;    ZERO*ZERO to NINE*NINE of type multiplication-fact,
;;        with appropriate integer slot values

(WMEType integer value)
(WMEType addition-fact arg1 arg2 sum)
(WMEType multiplication-fact arg1 arg2 product)

(addwm
 (ZERO ISA INTEGER VALUE 0) (ONE ISA INTEGER VALUE 1) (TWO ISA INTEGER VALUE 2)
 (THREE ISA INTEGER VALUE 3) (FOUR ISA INTEGER VALUE 4)
 (FIVE ISA INTEGER VALUE 5) (SIX ISA INTEGER VALUE 6)
 (SEVEN ISA INTEGER VALUE 7) (EIGHT ISA INTEGER VALUE 8)
 (NINE ISA INTEGER VALUE 9) (TEN ISA INTEGER VALUE 10)
 (ELEVEN ISA INTEGER VALUE 11) (TWELVE ISA INTEGER VALUE 12)
 (THIRTEEN ISA INTEGER VALUE 13) (FOURTEEN ISA INTEGER VALUE 14)
 (FIFTEEN ISA INTEGER VALUE 15) (SIXTEEN ISA INTEGER VALUE 16)
 (SEVENTEEN ISA INTEGER VALUE 17) (EIGHTEEN ISA INTEGER VALUE 18)
 (NINETEEN ISA INTEGER VALUE 19) (TWENTY ISA INTEGER VALUE 20)
 (TWENTY-ONE ISA INTEGER VALUE 21) (TWENTY-TWO ISA INTEGER VALUE 22)
 (TWENTY-THREE ISA INTEGER VALUE 23) (TWENTY-FOUR ISA INTEGER VALUE 24)
 (TWENTY-FIVE ISA INTEGER VALUE 25) (TWENTY-SIX ISA INTEGER VALUE 26)
 (TWENTY-SEVEN ISA INTEGER VALUE 27) (TWENTY-EIGHT ISA INTEGER VALUE 28)
 (TWENTY-NINE ISA INTEGER VALUE 29) (THIRTY ISA INTEGER VALUE 30)
 (THIRTY-ONE ISA INTEGER VALUE 31) (THIRTY-TWO ISA INTEGER VALUE 32)
 (THIRTY-THREE ISA INTEGER VALUE 33) (THIRTY-FOUR ISA INTEGER VALUE 34)
 (THIRTY-FIVE ISA INTEGER VALUE 35) (THIRTY-SIX ISA INTEGER VALUE 36)
 (THIRTY-SEVEN ISA INTEGER VALUE 37) (THIRTY-EIGHT ISA INTEGER VALUE 38)
 (THIRTY-NINE ISA INTEGER VALUE 39) (FORTY ISA INTEGER VALUE 40)
 (FORTY-ONE ISA INTEGER VALUE 41) (FORTY-TWO ISA INTEGER VALUE 42)
 (FORTY-THREE ISA INTEGER VALUE 43) (FORTY-FOUR ISA INTEGER VALUE 44)
 (FORTY-FIVE ISA INTEGER VALUE 45) (FORTY-SIX ISA INTEGER VALUE 46)
 (FORTY-SEVEN ISA INTEGER VALUE 47) (FORTY-EIGHT ISA INTEGER VALUE 48)
 (FORTY-NINE ISA INTEGER VALUE 49) (FIFTY ISA INTEGER VALUE 50)
 (FIFTY-ONE ISA INTEGER VALUE 51) (FIFTY-TWO ISA INTEGER VALUE 52)
 (FIFTY-THREE ISA INTEGER VALUE 53) (FIFTY-FOUR ISA INTEGER VALUE 54)
 (FIFTY-FIVE ISA INTEGER VALUE 55) (FIFTY-SIX ISA INTEGER VALUE 56)
 (FIFTY-SEVEN ISA INTEGER VALUE 57) (FIFTY-EIGHT ISA INTEGER VALUE 58)
 (FIFTY-NINE ISA INTEGER VALUE 59) (SIXTY ISA INTEGER VALUE 60)
 (SIXTY-ONE ISA INTEGER VALUE 61) (SIXTY-TWO ISA INTEGER VALUE 62)
 (SIXTY-THREE ISA INTEGER VALUE 63) (SIXTY-FOUR ISA INTEGER VALUE 64)
 (SIXTY-FIVE ISA INTEGER VALUE 65) (SIXTY-SIX ISA INTEGER VALUE 66)
 (SIXTY-SEVEN ISA INTEGER VALUE 67) (SIXTY-EIGHT ISA INTEGER VALUE 68)
 (SIXTY-NINE ISA INTEGER VALUE 69) (SEVENTY ISA INTEGER VALUE 70)
 (SEVENTY-ONE ISA INTEGER VALUE 71) (SEVENTY-TWO ISA INTEGER VALUE 72)
 (SEVENTY-THREE ISA INTEGER VALUE 73) (SEVENTY-FOUR ISA INTEGER VALUE 74)
 (SEVENTY-FIVE ISA INTEGER VALUE 75) (SEVENTY-SIX ISA INTEGER VALUE 76)
 (SEVENTY-SEVEN ISA INTEGER VALUE 77) (SEVENTY-EIGHT ISA INTEGER VALUE 78)
 (SEVENTY-NINE ISA INTEGER VALUE 79) (EIGHTY ISA INTEGER VALUE 80)
 (EIGHTY-ONE ISA INTEGER VALUE 81)
 (ZERO+ZERO ISA ADDITION-FACT ARG1 ZERO ARG2 ZERO SUM ZERO)
 (ZERO+ONE ISA ADDITION-FACT ARG1 ZERO ARG2 ONE SUM ONE)
 (ZERO+TWO ISA ADDITION-FACT ARG1 ZERO ARG2 TWO SUM TWO)
 (ZERO+THREE ISA ADDITION-FACT ARG1 ZERO ARG2 THREE SUM THREE)
 (ZERO+FOUR ISA ADDITION-FACT ARG1 ZERO ARG2 FOUR SUM FOUR)
 (ZERO+FIVE ISA ADDITION-FACT ARG1 ZERO ARG2 FIVE SUM FIVE)
 (ZERO+SIX ISA ADDITION-FACT ARG1 ZERO ARG2 SIX SUM SIX)
 (ZERO+SEVEN ISA ADDITION-FACT ARG1 ZERO ARG2 SEVEN SUM SEVEN)
 (ZERO+EIGHT ISA ADDITION-FACT ARG1 ZERO ARG2 EIGHT SUM EIGHT)
 (ZERO+NINE ISA ADDITION-FACT ARG1 ZERO ARG2 NINE SUM NINE)
 (ONE+ZERO ISA ADDITION-FACT ARG1 ONE ARG2 ZERO SUM ONE)
 (ONE+ONE ISA ADDITION-FACT ARG1 ONE ARG2 ONE SUM TWO)
 (ONE+TWO ISA ADDITION-FACT ARG1 ONE ARG2 TWO SUM THREE)
 (ONE+THREE ISA ADDITION-FACT ARG1 ONE ARG2 THREE SUM FOUR)
 (ONE+FOUR ISA ADDITION-FACT ARG1 ONE ARG2 FOUR SUM FIVE)
 (ONE+FIVE ISA ADDITION-FACT ARG1 ONE ARG2 FIVE SUM SIX)
 (ONE+SIX ISA ADDITION-FACT ARG1 ONE ARG2 SIX SUM SEVEN)
 (ONE+SEVEN ISA ADDITION-FACT ARG1 ONE ARG2 SEVEN SUM EIGHT)
 (ONE+EIGHT ISA ADDITION-FACT ARG1 ONE ARG2 EIGHT SUM NINE)
 (ONE+NINE ISA ADDITION-FACT ARG1 ONE ARG2 NINE SUM TEN)
 (TWO+ZERO ISA ADDITION-FACT ARG1 TWO ARG2 ZERO SUM TWO)
 (TWO+ONE ISA ADDITION-FACT ARG1 TWO ARG2 ONE SUM THREE)
 (TWO+TWO ISA ADDITION-FACT ARG1 TWO ARG2 TWO SUM FOUR)
 (TWO+THREE ISA ADDITION-FACT ARG1 TWO ARG2 THREE SUM FIVE)
 (TWO+FOUR ISA ADDITION-FACT ARG1 TWO ARG2 FOUR SUM SIX)
 (TWO+FIVE ISA ADDITION-FACT ARG1 TWO ARG2 FIVE SUM SEVEN)
 (TWO+SIX ISA ADDITION-FACT ARG1 TWO ARG2 SIX SUM EIGHT)
 (TWO+SEVEN ISA ADDITION-FACT ARG1 TWO ARG2 SEVEN SUM NINE)
 (TWO+EIGHT ISA ADDITION-FACT ARG1 TWO ARG2 EIGHT SUM TEN)
 (TWO+NINE ISA ADDITION-FACT ARG1 TWO ARG2 NINE SUM ELEVEN)
 (THREE+ZERO ISA ADDITION-FACT ARG1 THREE ARG2 ZERO SUM THREE)
 (THREE+ONE ISA ADDITION-FACT ARG1 THREE ARG2 ONE SUM FOUR)
 (THREE+TWO ISA ADDITION-FACT ARG1 THREE ARG2 TWO SUM FIVE)
 (THREE+THREE ISA ADDITION-FACT ARG1 THREE ARG2 THREE SUM SIX)
 (THREE+FOUR ISA ADDITION-FACT ARG1 THREE ARG2 FOUR SUM SEVEN)
 (THREE+FIVE ISA ADDITION-FACT ARG1 THREE ARG2 FIVE SUM EIGHT)
 (THREE+SIX ISA ADDITION-FACT ARG1 THREE ARG2 SIX SUM NINE)
 (THREE+SEVEN ISA ADDITION-FACT ARG1 THREE ARG2 SEVEN SUM TEN)
 (THREE+EIGHT ISA ADDITION-FACT ARG1 THREE ARG2 EIGHT SUM ELEVEN)
 (THREE+NINE ISA ADDITION-FACT ARG1 THREE ARG2 NINE SUM TWELVE)
 (FOUR+ZERO ISA ADDITION-FACT ARG1 FOUR ARG2 ZERO SUM FOUR)
 (FOUR+ONE ISA ADDITION-FACT ARG1 FOUR ARG2 ONE SUM FIVE)
 (FOUR+TWO ISA ADDITION-FACT ARG1 FOUR ARG2 TWO SUM SIX)
 (FOUR+THREE ISA ADDITION-FACT ARG1 FOUR ARG2 THREE SUM SEVEN)
 (FOUR+FOUR ISA ADDITION-FACT ARG1 FOUR ARG2 FOUR SUM EIGHT)
 (FOUR+FIVE ISA ADDITION-FACT ARG1 FOUR ARG2 FIVE SUM NINE)
 (FOUR+SIX ISA ADDITION-FACT ARG1 FOUR ARG2 SIX SUM TEN)
 (FOUR+SEVEN ISA ADDITION-FACT ARG1 FOUR ARG2 SEVEN SUM ELEVEN)
 (FOUR+EIGHT ISA ADDITION-FACT ARG1 FOUR ARG2 EIGHT SUM TWELVE)
 (FOUR+NINE ISA ADDITION-FACT ARG1 FOUR ARG2 NINE SUM THIRTEEN)
 (FIVE+ZERO ISA ADDITION-FACT ARG1 FIVE ARG2 ZERO SUM FIVE)
 (FIVE+ONE ISA ADDITION-FACT ARG1 FIVE ARG2 ONE SUM SIX)
 (FIVE+TWO ISA ADDITION-FACT ARG1 FIVE ARG2 TWO SUM SEVEN)
 (FIVE+THREE ISA ADDITION-FACT ARG1 FIVE ARG2 THREE SUM EIGHT)
 (FIVE+FOUR ISA ADDITION-FACT ARG1 FIVE ARG2 FOUR SUM NINE)
 (FIVE+FIVE ISA ADDITION-FACT ARG1 FIVE ARG2 FIVE SUM TEN)
 (FIVE+SIX ISA ADDITION-FACT ARG1 FIVE ARG2 SIX SUM ELEVEN)
 (FIVE+SEVEN ISA ADDITION-FACT ARG1 FIVE ARG2 SEVEN SUM TWELVE)
 (FIVE+EIGHT ISA ADDITION-FACT ARG1 FIVE ARG2 EIGHT SUM THIRTEEN)
 (FIVE+NINE ISA ADDITION-FACT ARG1 FIVE ARG2 NINE SUM FOURTEEN)
 (SIX+ZERO ISA ADDITION-FACT ARG1 SIX ARG2 ZERO SUM SIX)
 (SIX+ONE ISA ADDITION-FACT ARG1 SIX ARG2 ONE SUM SEVEN)
 (SIX+TWO ISA ADDITION-FACT ARG1 SIX ARG2 TWO SUM EIGHT)
 (SIX+THREE ISA ADDITION-FACT ARG1 SIX ARG2 THREE SUM NINE)
 (SIX+FOUR ISA ADDITION-FACT ARG1 SIX ARG2 FOUR SUM TEN)
 (SIX+FIVE ISA ADDITION-FACT ARG1 SIX ARG2 FIVE SUM ELEVEN)
 (SIX+SIX ISA ADDITION-FACT ARG1 SIX ARG2 SIX SUM TWELVE)
 (SIX+SEVEN ISA ADDITION-FACT ARG1 SIX ARG2 SEVEN SUM THIRTEEN)
 (SIX+EIGHT ISA ADDITION-FACT ARG1 SIX ARG2 EIGHT SUM FOURTEEN)
 (SIX+NINE ISA ADDITION-FACT ARG1 SIX ARG2 NINE SUM FIFTEEN)
 (SEVEN+ZERO ISA ADDITION-FACT ARG1 SEVEN ARG2 ZERO SUM SEVEN)
 (SEVEN+ONE ISA ADDITION-FACT ARG1 SEVEN ARG2 ONE SUM EIGHT)
 (SEVEN+TWO ISA ADDITION-FACT ARG1 SEVEN ARG2 TWO SUM NINE)
 (SEVEN+THREE ISA ADDITION-FACT ARG1 SEVEN ARG2 THREE SUM TEN)
 (SEVEN+FOUR ISA ADDITION-FACT ARG1 SEVEN ARG2 FOUR SUM ELEVEN)
 (SEVEN+FIVE ISA ADDITION-FACT ARG1 SEVEN ARG2 FIVE SUM TWELVE)
 (SEVEN+SIX ISA ADDITION-FACT ARG1 SEVEN ARG2 SIX SUM THIRTEEN)
 (SEVEN+SEVEN ISA ADDITION-FACT ARG1 SEVEN ARG2 SEVEN SUM FOURTEEN)
 (SEVEN+EIGHT ISA ADDITION-FACT ARG1 SEVEN ARG2 EIGHT SUM FIFTEEN)
 (SEVEN+NINE ISA ADDITION-FACT ARG1 SEVEN ARG2 NINE SUM SIXTEEN)
 (EIGHT+ZERO ISA ADDITION-FACT ARG1 EIGHT ARG2 ZERO SUM EIGHT)
 (EIGHT+ONE ISA ADDITION-FACT ARG1 EIGHT ARG2 ONE SUM NINE)
 (EIGHT+TWO ISA ADDITION-FACT ARG1 EIGHT ARG2 TWO SUM TEN)
 (EIGHT+THREE ISA ADDITION-FACT ARG1 EIGHT ARG2 THREE SUM ELEVEN)
 (EIGHT+FOUR ISA ADDITION-FACT ARG1 EIGHT ARG2 FOUR SUM TWELVE)
 (EIGHT+FIVE ISA ADDITION-FACT ARG1 EIGHT ARG2 FIVE SUM THIRTEEN)
 (EIGHT+SIX ISA ADDITION-FACT ARG1 EIGHT ARG2 SIX SUM FOURTEEN)
 (EIGHT+SEVEN ISA ADDITION-FACT ARG1 EIGHT ARG2 SEVEN SUM FIFTEEN)
 (EIGHT+EIGHT ISA ADDITION-FACT ARG1 EIGHT ARG2 EIGHT SUM SIXTEEN)
 (EIGHT+NINE ISA ADDITION-FACT ARG1 EIGHT ARG2 NINE SUM SEVENTEEN)
 (NINE+ZERO ISA ADDITION-FACT ARG1 NINE ARG2 ZERO SUM NINE)
 (NINE+ONE ISA ADDITION-FACT ARG1 NINE ARG2 ONE SUM TEN)
 (NINE+TWO ISA ADDITION-FACT ARG1 NINE ARG2 TWO SUM ELEVEN)
 (NINE+THREE ISA ADDITION-FACT ARG1 NINE ARG2 THREE SUM TWELVE)
 (NINE+FOUR ISA ADDITION-FACT ARG1 NINE ARG2 FOUR SUM THIRTEEN)
 (NINE+FIVE ISA ADDITION-FACT ARG1 NINE ARG2 FIVE SUM FOURTEEN)
 (NINE+SIX ISA ADDITION-FACT ARG1 NINE ARG2 SIX SUM FIFTEEN)
 (NINE+SEVEN ISA ADDITION-FACT ARG1 NINE ARG2 SEVEN SUM SIXTEEN)
 (NINE+EIGHT ISA ADDITION-FACT ARG1 NINE ARG2 EIGHT SUM SEVENTEEN)
 (NINE+NINE ISA ADDITION-FACT ARG1 NINE ARG2 NINE SUM EIGHTEEN)
 (ZERO*ZERO ISA MULTIPLICATION-FACT ARG1 ZERO ARG2 ZERO PRODUCT ZERO)
 (ZERO*ONE ISA MULTIPLICATION-FACT ARG1 ZERO ARG2 ONE PRODUCT ZERO)
 (ZERO*TWO ISA MULTIPLICATION-FACT ARG1 ZERO ARG2 TWO PRODUCT ZERO)
 (ZERO*THREE ISA MULTIPLICATION-FACT ARG1 ZERO ARG2 THREE PRODUCT ZERO)
 (ZERO*FOUR ISA MULTIPLICATION-FACT ARG1 ZERO ARG2 FOUR PRODUCT ZERO)
 (ZERO*FIVE ISA MULTIPLICATION-FACT ARG1 ZERO ARG2 FIVE PRODUCT ZERO)
 (ZERO*SIX ISA MULTIPLICATION-FACT ARG1 ZERO ARG2 SIX PRODUCT ZERO)
 (ZERO*SEVEN ISA MULTIPLICATION-FACT ARG1 ZERO ARG2 SEVEN PRODUCT ZERO)
 (ZERO*EIGHT ISA MULTIPLICATION-FACT ARG1 ZERO ARG2 EIGHT PRODUCT ZERO)
 (ZERO*NINE ISA MULTIPLICATION-FACT ARG1 ZERO ARG2 NINE PRODUCT ZERO)
 (ONE*ZERO ISA MULTIPLICATION-FACT ARG1 ONE ARG2 ZERO PRODUCT ZERO)
 (ONE*ONE ISA MULTIPLICATION-FACT ARG1 ONE ARG2 ONE PRODUCT ONE)
 (ONE*TWO ISA MULTIPLICATION-FACT ARG1 ONE ARG2 TWO PRODUCT TWO)
 (ONE*THREE ISA MULTIPLICATION-FACT ARG1 ONE ARG2 THREE PRODUCT THREE)
 (ONE*FOUR ISA MULTIPLICATION-FACT ARG1 ONE ARG2 FOUR PRODUCT FOUR)
 (ONE*FIVE ISA MULTIPLICATION-FACT ARG1 ONE ARG2 FIVE PRODUCT FIVE)
 (ONE*SIX ISA MULTIPLICATION-FACT ARG1 ONE ARG2 SIX PRODUCT SIX)
 (ONE*SEVEN ISA MULTIPLICATION-FACT ARG1 ONE ARG2 SEVEN PRODUCT SEVEN)
 (ONE*EIGHT ISA MULTIPLICATION-FACT ARG1 ONE ARG2 EIGHT PRODUCT EIGHT)
 (ONE*NINE ISA MULTIPLICATION-FACT ARG1 ONE ARG2 NINE PRODUCT NINE)
 (TWO*ZERO ISA MULTIPLICATION-FACT ARG1 TWO ARG2 ZERO PRODUCT ZERO)
 (TWO*ONE ISA MULTIPLICATION-FACT ARG1 TWO ARG2 ONE PRODUCT TWO)
 (TWO*TWO ISA MULTIPLICATION-FACT ARG1 TWO ARG2 TWO PRODUCT FOUR)
 (TWO*THREE ISA MULTIPLICATION-FACT ARG1 TWO ARG2 THREE PRODUCT SIX)
 (TWO*FOUR ISA MULTIPLICATION-FACT ARG1 TWO ARG2 FOUR PRODUCT EIGHT)
 (TWO*FIVE ISA MULTIPLICATION-FACT ARG1 TWO ARG2 FIVE PRODUCT TEN)
 (TWO*SIX ISA MULTIPLICATION-FACT ARG1 TWO ARG2 SIX PRODUCT TWELVE)
 (TWO*SEVEN ISA MULTIPLICATION-FACT ARG1 TWO ARG2 SEVEN PRODUCT FOURTEEN)
 (TWO*EIGHT ISA MULTIPLICATION-FACT ARG1 TWO ARG2 EIGHT PRODUCT SIXTEEN)
 (TWO*NINE ISA MULTIPLICATION-FACT ARG1 TWO ARG2 NINE PRODUCT EIGHTEEN)
 (THREE*ZERO ISA MULTIPLICATION-FACT ARG1 THREE ARG2 ZERO PRODUCT ZERO)
 (THREE*ONE ISA MULTIPLICATION-FACT ARG1 THREE ARG2 ONE PRODUCT THREE)
 (THREE*TWO ISA MULTIPLICATION-FACT ARG1 THREE ARG2 TWO PRODUCT SIX)
 (THREE*THREE ISA MULTIPLICATION-FACT ARG1 THREE ARG2 THREE PRODUCT NINE)
 (THREE*FOUR ISA MULTIPLICATION-FACT ARG1 THREE ARG2 FOUR PRODUCT TWELVE)
 (THREE*FIVE ISA MULTIPLICATION-FACT ARG1 THREE ARG2 FIVE PRODUCT FIFTEEN)
 (THREE*SIX ISA MULTIPLICATION-FACT ARG1 THREE ARG2 SIX PRODUCT EIGHTEEN)
 (THREE*SEVEN ISA MULTIPLICATION-FACT ARG1 THREE ARG2 SEVEN PRODUCT TWENTY-ONE)
 (THREE*EIGHT ISA MULTIPLICATION-FACT ARG1 THREE ARG2 EIGHT PRODUCT TWENTY-FOUR)
 (THREE*NINE ISA MULTIPLICATION-FACT ARG1 THREE ARG2 NINE PRODUCT TWENTY-SEVEN)
 (FOUR*ZERO ISA MULTIPLICATION-FACT ARG1 FOUR ARG2 ZERO PRODUCT ZERO)
 (FOUR*ONE ISA MULTIPLICATION-FACT ARG1 FOUR ARG2 ONE PRODUCT FOUR)
 (FOUR*TWO ISA MULTIPLICATION-FACT ARG1 FOUR ARG2 TWO PRODUCT EIGHT)
 (FOUR*THREE ISA MULTIPLICATION-FACT ARG1 FOUR ARG2 THREE PRODUCT TWELVE)
 (FOUR*FOUR ISA MULTIPLICATION-FACT ARG1 FOUR ARG2 FOUR PRODUCT SIXTEEN)
 (FOUR*FIVE ISA MULTIPLICATION-FACT ARG1 FOUR ARG2 FIVE PRODUCT TWENTY)
 (FOUR*SIX ISA MULTIPLICATION-FACT ARG1 FOUR ARG2 SIX PRODUCT TWENTY-FOUR)
 (FOUR*SEVEN ISA MULTIPLICATION-FACT ARG1 FOUR ARG2 SEVEN PRODUCT TWENTY-EIGHT)
 (FOUR*EIGHT ISA MULTIPLICATION-FACT ARG1 FOUR ARG2 EIGHT PRODUCT THIRTY-TWO)
 (FOUR*NINE ISA MULTIPLICATION-FACT ARG1 FOUR ARG2 NINE PRODUCT THIRTY-SIX)
 (FIVE*ZERO ISA MULTIPLICATION-FACT ARG1 FIVE ARG2 ZERO PRODUCT ZERO)
 (FIVE*ONE ISA MULTIPLICATION-FACT ARG1 FIVE ARG2 ONE PRODUCT FIVE)
 (FIVE*TWO ISA MULTIPLICATION-FACT ARG1 FIVE ARG2 TWO PRODUCT TEN)
 (FIVE*THREE ISA MULTIPLICATION-FACT ARG1 FIVE ARG2 THREE PRODUCT FIFTEEN)
 (FIVE*FOUR ISA MULTIPLICATION-FACT ARG1 FIVE ARG2 FOUR PRODUCT TWENTY)
 (FIVE*FIVE ISA MULTIPLICATION-FACT ARG1 FIVE ARG2 FIVE PRODUCT TWENTY-FIVE)
 (FIVE*SIX ISA MULTIPLICATION-FACT ARG1 FIVE ARG2 SIX PRODUCT THIRTY)
 (FIVE*SEVEN ISA MULTIPLICATION-FACT ARG1 FIVE ARG2 SEVEN PRODUCT THIRTY-FIVE)
 (FIVE*EIGHT ISA MULTIPLICATION-FACT ARG1 FIVE ARG2 EIGHT PRODUCT FORTY)
 (FIVE*NINE ISA MULTIPLICATION-FACT ARG1 FIVE ARG2 NINE PRODUCT FORTY-FIVE)
 (SIX*ZERO ISA MULTIPLICATION-FACT ARG1 SIX ARG2 ZERO PRODUCT ZERO)
 (SIX*ONE ISA MULTIPLICATION-FACT ARG1 SIX ARG2 ONE PRODUCT SIX)
 (SIX*TWO ISA MULTIPLICATION-FACT ARG1 SIX ARG2 TWO PRODUCT TWELVE)
 (SIX*THREE ISA MULTIPLICATION-FACT ARG1 SIX ARG2 THREE PRODUCT EIGHTEEN)
 (SIX*FOUR ISA MULTIPLICATION-FACT ARG1 SIX ARG2 FOUR PRODUCT TWENTY-FOUR)
 (SIX*FIVE ISA MULTIPLICATION-FACT ARG1 SIX ARG2 FIVE PRODUCT THIRTY)
 (SIX*SIX ISA MULTIPLICATION-FACT ARG1 SIX ARG2 SIX PRODUCT THIRTY-SIX)
 (SIX*SEVEN ISA MULTIPLICATION-FACT ARG1 SIX ARG2 SEVEN PRODUCT FORTY-TWO)
 (SIX*EIGHT ISA MULTIPLICATION-FACT ARG1 SIX ARG2 EIGHT PRODUCT FORTY-EIGHT)
 (SIX*NINE ISA MULTIPLICATION-FACT ARG1 SIX ARG2 NINE PRODUCT FIFTY-FOUR)
 (SEVEN*ZERO ISA MULTIPLICATION-FACT ARG1 SEVEN ARG2 ZERO PRODUCT ZERO)
 (SEVEN*ONE ISA MULTIPLICATION-FACT ARG1 SEVEN ARG2 ONE PRODUCT SEVEN)
 (SEVEN*TWO ISA MULTIPLICATION-FACT ARG1 SEVEN ARG2 TWO PRODUCT FOURTEEN)
 (SEVEN*THREE ISA MULTIPLICATION-FACT ARG1 SEVEN ARG2 THREE PRODUCT TWENTY-ONE)
 (SEVEN*FOUR ISA MULTIPLICATION-FACT ARG1 SEVEN ARG2 FOUR PRODUCT TWENTY-EIGHT)
 (SEVEN*FIVE ISA MULTIPLICATION-FACT ARG1 SEVEN ARG2 FIVE PRODUCT THIRTY-FIVE)
 (SEVEN*SIX ISA MULTIPLICATION-FACT ARG1 SEVEN ARG2 SIX PRODUCT FORTY-TWO)
 (SEVEN*SEVEN ISA MULTIPLICATION-FACT ARG1 SEVEN ARG2 SEVEN PRODUCT FORTY-NINE)
 (SEVEN*EIGHT ISA MULTIPLICATION-FACT ARG1 SEVEN ARG2 EIGHT PRODUCT FIFTY-SIX)
 (SEVEN*NINE ISA MULTIPLICATION-FACT ARG1 SEVEN ARG2 NINE PRODUCT SIXTY-THREE)
 (EIGHT*ZERO ISA MULTIPLICATION-FACT ARG1 EIGHT ARG2 ZERO PRODUCT ZERO)
 (EIGHT*ONE ISA MULTIPLICATION-FACT ARG1 EIGHT ARG2 ONE PRODUCT EIGHT)
 (EIGHT*TWO ISA MULTIPLICATION-FACT ARG1 EIGHT ARG2 TWO PRODUCT SIXTEEN)
 (EIGHT*THREE ISA MULTIPLICATION-FACT ARG1 EIGHT ARG2 THREE PRODUCT TWENTY-FOUR)
 (EIGHT*FOUR ISA MULTIPLICATION-FACT ARG1 EIGHT ARG2 FOUR PRODUCT THIRTY-TWO)
 (EIGHT*FIVE ISA MULTIPLICATION-FACT ARG1 EIGHT ARG2 FIVE PRODUCT FORTY)
 (EIGHT*SIX ISA MULTIPLICATION-FACT ARG1 EIGHT ARG2 SIX PRODUCT FORTY-EIGHT)
 (EIGHT*SEVEN ISA MULTIPLICATION-FACT ARG1 EIGHT ARG2 SEVEN PRODUCT FIFTY-SIX)
 (EIGHT*EIGHT ISA MULTIPLICATION-FACT ARG1 EIGHT ARG2 EIGHT PRODUCT SIXTY-FOUR)
 (EIGHT*NINE ISA MULTIPLICATION-FACT ARG1 EIGHT ARG2 NINE PRODUCT SEVENTY-TWO)
 (NINE*ZERO ISA MULTIPLICATION-FACT ARG1 NINE ARG2 ZERO PRODUCT ZERO)
 (NINE*ONE ISA MULTIPLICATION-FACT ARG1 NINE ARG2 ONE PRODUCT NINE)
 (NINE*TWO ISA MULTIPLICATION-FACT ARG1 NINE ARG2 TWO PRODUCT EIGHTEEN)
 (NINE*THREE ISA MULTIPLICATION-FACT ARG1 NINE ARG2 THREE PRODUCT TWENTY-SEVEN)
 (NINE*FOUR ISA MULTIPLICATION-FACT ARG1 NINE ARG2 FOUR PRODUCT THIRTY-SIX)
 (NINE*FIVE ISA MULTIPLICATION-FACT ARG1 NINE ARG2 FIVE PRODUCT FORTY-FIVE)
 (NINE*SIX ISA MULTIPLICATION-FACT ARG1 NINE ARG2 SIX PRODUCT FIFTY-FOUR)
 (NINE*SEVEN ISA MULTIPLICATION-FACT ARG1 NINE ARG2 SEVEN PRODUCT SIXTY-THREE)
 (NINE*EIGHT ISA MULTIPLICATION-FACT ARG1 NINE ARG2 EIGHT PRODUCT SEVENTY-TWO)
 (NINE*NINE ISA MULTIPLICATION-FACT ARG1 NINE ARG2 NINE PRODUCT EIGHTY-ONE))



;*****************************************************************
;*****************************************************************

;*****************************************************************
;                     Freq Dist - Tutor Chunks
;*****************************************************************

#|
(setf *text-info* '((TEXT1 TEXT2 TEXT3 TEXT4 TEXT5) (TEXT6 TEXT7 TEXT8 TEXT9 TEXT10) 
                    (TEXT11 TEXT12) (TEXT13 TEXT14 TEXT15 TEXT16 TEXT17) (TEXT18 TEXT19)
                    (TEXT18 TEXT19) (TEXT18 TEXT19) (TEXT18 TEXT19) (TEXT18 TEXT19 TEXT20)
                    (TEXT21 TEXT22 TEXT23 TEXT24)))
(setf *current-text* 'TEXT0)
(setf *scenario-info* '(amusement-park burger-place restaurants shopping-mall football))
(setf *current-state* 'scenario-choices)
(setf *cell-count* 0)
(setf *scenario-count* 1)
(setf *instruction-text* 0)
(setf *instruction-pos-fdbk-txt* 0)
(setf *pos-fdbk* 0)
(setf *done-button-count* 0)
|#

(AddWM
    (TEN+ONE isa addition-fact arg1 ten arg2 one sum eleven)
    (ONE+TEN isa addition-fact arg1 one arg2 ten sum eleven)

;Please choose a scenario that you would like to work with.
    (TEXT0
       isa text
       type instruction
       utility directive
       already-read yes
       encoded-as choose-next-scenario
       length 8
       on-screen yes)

;Frequency Distribution for Injury Complaints Data
    (TEXT1
       isa text
       type instruction
       utility descriptive
       encoded-as title
       value frequency-distribution
       length 6)

;(pos.feed.)
    (TEXT2
       isa text
       type posfeed
       length 1)

;Now you need to complete the worksheet to the right.
    (TEXT3
       isa text
       type instruction
       utility descriptive
       encoded-as complete-worksheet
       value complete-worksheet
       length 10)

;Notice that your data have been delivered to a table titled "Your Data."
    (TEXT4
       isa text
       type instruction
       utility descriptive
       encoded-as notice-table
       value data-table
       length 12)

;Step1: Click on the red ? and enter in the correct symbol/formula for the column.
    (TEXT5
       isa text
       type instruction
       utility directive
       encoded-as click-red-?
       prior sort-descending
       value ?
       length 16)

;(pos.feed.) 
    (TEXT6
       isa text
       type posfeed
       length 1)

;(pos.feed.)
    (TEXT7 
       isa text
       type posfeed
       length 2)

;The symbol for that column is X.
    (TEXT8
       isa text
       type instruction-posfeed
       utility descriptive
       encoded-as x-symbol-for-left-column
       value X
       length 7)

;Click on the Fill Column button.
    (TEXT9
       isa text
       type instruction-posfeed
       utility directive
       encoded-as click-fill-for-x
       prior click-done
       length 6)

;Step 2: Click on Fill Column.
    (TEXT10
       isa text
       type instruction
       utility directive
       encoded-as click-fill-for-x
       prior click-done
       length 6)

;Step 1: Click on the red ? and enter in the correct symbol/formula for the column.
    (TEXT11
       isa text
       type instruction
       utility directive
       encoded-as click-red-?
       prior click-fill-for-x
       length 17)

;Click on the next red ? and enter the correct symbol or formula.  (this text
;disappears as soon as subject hits the ?)
    (TEXT12
       isa text
       type instruction-posfeed
       utility directive
       encoded-as click-red-?
       prior click-fill-for-x
       length 13)

;(pos.feed.)
    (TEXT13
       isa text
       type posfeed
       length 3)

;(pos.feed.)
    (TEXT14
       isa text
       type posfeed
       length 3)

;f is the correct symbol for the frequency column.
    (TEXT15
       isa text
       type instruction-posfeed
       utility descriptive
       encoded-as f-symbol-for-frequency-column
       value f
       length 9)

;Fill the table in by clicking on each cell and entering the answer.
    (TEXT16
       isa text
       type instruction-posfeed
       utility directive
       encoded-as enter-frequencies
       prior click-done-2
       length 13)

;Step 2: Click on each empty cell and enter your answer.
    (TEXT17
       isa text
       type instruction
       utility directive
       encoded-as enter-frequencies
       prior click-done-2
       length 11)

;(pos.feed.) 
    (TEXT18
       isa text
       type posfeed
       length 3)

;The answer is ...x. - after each number is entered.
    (TEXT19
       isa text
       type instruction-posfeed
       utility descriptive
       encoded-as correct-answer
       value answer
       length 4)

;Click on Fill Column to fill in the f column.
    (TEXT20
       isa text
       type instruction-posfeed
       utility directive
       encoded-as fill-column
       length 10)

;(pos.feed.) 
    (TEXT21
       isa text
       type posfeed
       length 1)

;You have completed the table.
    (TEXT22
       isa text
       type instruction-posfeed
       utility descriptive
       encoded-as table-complete
       value done
       length 5)

;Now click on Done to continue.
    (TEXT23
       isa text
       type instruction-posfeed
       utility directive
       encoded-as click-on-done
       length 6)
   
;Step 3: Click on "Done."
    (TEXT24
       isa text
       type instruction
       utility directive
       encoded-as click-on-done
       length 5)

    (first isa nth)
    (second isa nth)
    (third isa nth)
    (fourth isa nth)
    (fifth isa nth)
    (sixth isa nth)
    (seventh isa nth)
    (eighth isa nth)
    (ninth isa nth)
    (tenth isa nth)
    (eleventh isa nth)
    (twelfth isa nth)
    (thirteenth isa nth)
    (fourteenth isa nth)
    (fifteenth isa nth)
    (sixteenth isa nth)
    (seventeenth isa nth)
    (eighteenth isa nth)
    (below-top isa nth)
    (nineteenth isa nth)
)

;*****************************************************************
;*****************************************************************


(goal-focus goal)


(p FIGURE-OUT-WHAT-TO-DO-NEXT
    =goal>
       isa complete-tutor
       previous =previous
       current nil
==>
    =newgoal>
       isa get-next
       previous =previous
       current =current
    =goal>
       current =current
!push! =newgoal)

; This is necessary in case the previous attempt resulted in a failure.
(p FIGURE-OUT-WHAT-TO-DO-NEXT-2
   =goal>
      isa complete-tutor
      previous =previous
      current failure
==>
   =newgoal>
      isa get-next
      previous =previous
      current =current
   =goal>
      current =current
!push! =newgoal)


(p RETRIEVE-NEXT-ACTION
   =goal>
      isa get-next
      previous =previous
      current nil
      scan nil
   =previous-action>
      isa action
      previous =previous
      current =current
==>
   =goal>
      current =current
!pop!)

(p SCAN-INSTRUCTION-WINDOW
   =goal>
      isa get-next
      previous =previous
      current nil
      scan nil
==>
   =newgoal>
      isa get-next
      previous =previous
      current =current
      scan instruction-window
   =goal>
      current =current
!push! =newgoal)


(p SCAN-FEEDBACK-WINDOW
   =goal>
      isa get-next
      previous =previous
      current nil
      scan nil
==>
   =newgoal>
      isa get-next
      previous =previous
      current =current
      scan feedback-window
   =goal>
      current =current
!push! =newgoal)


; This is necessary in order to pass the current action down the goal hierarchy
(p GOT-CURRENT-ACTION
   =goal>
      isa get-next
      previous =previous
      current =current
    - current Failure
      scan nil
==>
!pop!)


;;;This production should fire when the model is going to read some text
;;;on the screen and that text is descriptive instruction text. 
(p READ-INSTRUCTION-DESCRIPTIVE
    =goal>
       isa get-next
       previous =previous
       current nil
       scan instruction-window
    =text>
       isa text
       on-screen yes
       type instruction
       utility descriptive
       already-read nil
       encoded-as =instruction
       value =value
       length =length
==>
    =text>
       already-read yes
    =newgoal>
       isa rehearsal
       chunk =value
!output! ("This is chunk ~S. ~%" =text)
!eval! (statgirl-fd-model 'instruction)
!push! =newgoal
)


;;;This production is similar to the previous, except that it fires when the instr. text is
;;;directive, then pops the next action back to the lowest level goal.
(p READ-INSTRUCTION-DIRECTIVE
    =goal>
       isa get-next
       previous =previous
       current nil
       scan instruction-window
    =text>
       isa text
       on-screen yes
       type instruction
       utility directive
       already-read nil
       encoded-as =direction
       length =length
==>
    =text>
       already-read yes
    =goal>
       current =direction
!output! ("I'm reading text that says to ~S. ~%" =direction)
!output! ("This is chunk ~S. ~%" =text)
!eval! (statgirl-fd-model 'instruction)
!pop!)


(p READ-INSTRUCTIONS-IN-POSFEED-DESCRIPTIVE
    =goal>
       isa get-next
       previous =previous
       current nil
       scan feedback-window
    =text>
       isa text
       on-screen yes
       type instruction-posfeed
       utility descriptive
       already-read nil
       encoded-as =instruction
       value =value
       length =length
==>
    =text>
       already-read yes
    =newgoal>
       isa rehearsal
       chunk =value
!output! ("This is chunk ~S. ~%" =text)
!eval! (statgirl-fd-model 'inst-posfeed)
!push! =newgoal
)


(p READ-INSTRUCTIONS-IN-POSFEED-DIRECTIVE
    =goal>
       isa get-next
       previous =previous
       current nil
       scan feedback-window
    =text>
       isa text
       on-screen yes
       type instruction-posfeed
       utility directive
       already-read nil
       encoded-as =direction
       length =length
==>
    =text>
       already-read yes
    =goal>
       current =direction
!output! ("I'm reading text that says to ~S. ~%" =direction)
!output! ("This is chunk ~S. ~%" =text)
!eval! (statgirl-fd-model 'inst-posfeed)
!pop!)


(p READ-POSITIVE-FEEDBACK
    =goal>
       isa get-next
       previous =previous
       current nil
       scan feedback-window
    =text>
       isa text
       on-screen yes
       type posfeed
       already-read nil
       length =length
==>
    =text>
       already-read yes
    =goal>
       current nil
!output! ("This is chunk ~S. ~%" =text)
!eval! (statgirl-fd-model 'posfeed)
!pop!
!pop!)


;;This production retrieves the chunk relevant to the semantic content 
;;of the descriptive text - to represent cognitive processing of that content
(p RETRIEVE-CHUNK
   =goal>
      isa rehearsal
      chunk =chunk
   =chunk>
      isa descriptive-chunk
==>
!pop!
!pop!
!pop!)


(p DO-NEXT-ACTION
    =goal>
       isa complete-tutor
       previous =previous
       current =current
     - current Failure
==>
    =newgoal>
       isa action
       previous =previous
       current =current
       update =update
    =goal>
       previous =current
       current =update
!push! =newgoal)


(p SELECT-A-SCENARIO
    =goal>
       isa action
       previous instruction-section
       current choose-next-scenario
==>
!pop!
!eval! (statgirl-fd-model 'next-scenario))

;(pbreak SELECT-A-SCENARIO)

(p CLICK-RED-?
      =goal>
         isa action
         previous =previous
         current click-red-?
      =question-mark>
         isa cell
         row =row
         column =column
         value red-question-mark
==>
      =goal>
         update =column
!pop!
!eval! (statgirl-fd-model 'click-red-? =column))


(p ENTER-SYMBOL
   =goal>
      isa action
      previous click-red-?
      current =current
   =question-mark>
      isa cell
      column =column
      value red-question-mark
   =symbol>
      isa symbol
      active yes
      meaning =column
==>
   =newgoal>
      isa action
      previous use-symbol-pad
      current done-symbol-pad
!focus-on! =newgoal)


(p DONE-BUTTON
   =goal>
      isa action
      previous use-symbol-pad
      current done-symbol-pad
   =done-button>
      isa button
      name done
      active yes
==>
!output! ("I'm hitting the Done button.~%")
!eval! (statgirl-fd-model 'done-button)
!pop!)


(p CLICK-FILL-COLUMN-BUTTON
   =goal>
      isa action
      previous =previous
      current click-fill-for-x
   =button>
      isa button
      name fill
      active yes
==>
   =goal>
      update nil
!pop!
!eval! (statgirl-fd-model 'new-directions 'add-qm2))


(p FILL-FREQUENCY-COLUMN
   =goal>
      isa action
      previous =previous
      current enter-frequencies
   =cell>
      isa cell
      in-table frequency-table
      row =row
      column frequency
      value =special
   !eval! (< *cell-count* 5)
==>
!output! ("I'm clicking on a cell in the frequency column, on row ~S.~%" =row)
!eval! (statgirl-fd-model 'reset-scenario))

;(pbreak fill-frequency-column)

;; The additional 300ms for each reading production includes time to notice the text is there,
;; shift attention to it, and decide to read it.  345ms is the average reading rate (per word)
;; computed from the verbal protocol subjects.  It was computed by dividing the time spent 
;; reading context by the number of context words read, and averaging that number across
;; all 4 subjects in all the scenarios.

(spp 
    (scan-instruction-window
     :effort .5
     :creation-time -400
     :references 24
     :successes 24
     :eventual-successes 22
     :eventual-failures 2
     )

    (scan-feedback-window
     :effort .5
     :creation-time -400
     :references 24
     :successes 24
     :eventual-successes 22
     :eventual-failures 2
     )

    (retrieve-next-action
     :creation-time -400
     :references 1000
     :successes 1000
     :eventual-successes 90
     :eventual-failures 10
     )

    (read-instruction-descriptive 
     :failure t 
     :effort (+ (* .345 =length) .300)
     :creation-time -400
     :references 50
     :successes 100
     :eventual-successes 80
     :eventual-failures 20
    )

     (read-instruction-directive 
      :success t 
      :effort (+ (* .345 =length) .300)
      :creation-time -400
      :references 50
      :successes 100
      :eventual-successes 80
      :eventual-failures 20
    )

     (read-instructions-in-posfeed-descriptive 
      :failure t 
      :effort (+ (* .345 =length) .300)
      :creation-time -400
      :references 50
      :successes 100
      :eventual-successes 80
      :eventual-failures 20
     )

     (read-instructions-in-posfeed-directive 
      :success t 
      :effort (+ (* .345 =length) .300)
      :creation-time -400
      :references 50
      :successes 100
      :eventual-successes 80
      :eventual-failures 20
     )

     (read-positive-feedback 
      :failure t 
      :effort (+ (* .345 =length) .300)
      :creation-time -400
      :references 50
      :successes 100
      :eventual-successes 80
      :eventual-failures 20
      )

;; We had originally estimated effort for "moving the mouse to click something" at 400ms
;; for a short movement and 1s for a long movement.  Review of the videotape, however,
;; leads to the conclusion that subjects are not arriving at the desired location for
;; a mouse click that quickly.  It appears that there is an initial very fast movement
;; to an area close to the desired location, followed by one or more corrective movements
;; which hone in on the spot to be clicked.  To account for this honing in, I have added
;; an additional 1s to the effort estimates.

     (click-red-? 
      :success t 
      :effort 2
      :creation-time -400
      :references 50
      :successes 100
      :eventual-successes 80
      :eventual-failures 20
     )
     (enter-symbol 
      :success t 
      :effort 2
      :creation-time -400
      :references 50
      :successes 100
      :eventual-successes 80
      :eventual-failures 20
     )
     (click-fill-column-button
      :success t 
      :effort 2
      :creation-time -400
      :references 50
      :successes 100
      :eventual-successes 80
      :eventual-failures 20
     )

;; The additional 3.28s of effort for done-button is time listening to auditory feedback.
;; That's the mean length of the auditory feedback messages heard by the VP subjects at this point.

     (done-button 
      :success t 
      :effort (+ 1.4 3.28)
      :creation-time -400
      :references 50
      :successes 100
      :eventual-successes 80
      :eventual-failures 20
     )

;; The additional 4s allocated to effort for hitting the first cell in the frequency column
;; is a way of finessing the fact that subjects seem to pause for a couple of moments while
;; they digest the instructions to do this.  There is most likely quite a lot of active visual
;; scanning of the interface happening at this point, while the subjects figure out how to 
;; carry out the instructions to fill in the f column, but since this isn't a model of visual
;; scanning, I'm simply accounting for that time in the effort parameter.

     (fill-frequency-column 
      :success t 
      :effort 4)
)