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

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;
;;;         ACT-R 5.0 Model of a spatial orientation task
;;;                         Version WEB
;;;               Wednesday, February, 6, 2002, 1:00 PM
;;;
;;;(c) 2002, Glenn Gunzelmann
;;;
;;;     Requirements:
;;;
;;; 1. Lisp that will run ACT-R 5.0 (except ACL with the IDE due to
;;;    a minor conflict)
;;; 2. ACT-R 5.0 (version 5.0.6 or newer)
;;;    -Available at http://act-r.psy.cmu.edu/software
;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;
;;;                    Running the Model:
;;;
;;; 1. Start your Lisp
;;; 2. Load ACT-R 5.0 
;;; 3. Load this file
;;; 4. Call (run-block n condition)
;;;    -Where n is the number of participants
;;;    -And condition is either 'count or 'angle (i.e. the strategy)
;;; 5. If you are using MCL or the ACT-R Environment you can add 
;;;     :visible t to the run-block call:
;;;     (run-block n condition :visible t)
;;;     to see the model's version of the task screen and it's focus of
;;;     visual attention (the red circle) as it performs the experiment
;;; 6. Also, if using a system as described in 5 you can run yourself
;;;    through the experiment.
;;;    -First, call (setf *actr-enabled-p* nil) to disable the model
;;;    -Then call run-block as in 5  
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;
;; Global variables used in the simulation
;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(defparameter *imaginal* nil
  "The global variable for holding buffer content has to be defined separately.")

(defvar *doty* 0)
(defvar *key-pressed-was*)
(defvar *response-time*)

(defparameter *experiment-window* nil)

(defparameter *start-trial-time* 0)

(defparameter *model-data* nil)

(defparameter *trialnum* 0)

(defparameter *tgt* 0)

(defparameter *pln* 0)

(defparameter *participant* 0)

(defparameter *angles* '(0 45 90 135 180 225 270 315))

(defparameter *x1* 0)

(defparameter *y1* 0)

(defparameter *x2* 0)

(defparameter *y2* 0)

(defparameter *correct-answers* '(s sw w nw n ne e se
                                  sw w nw n ne e se s
                                  w nw n ne e se s sw
                                  nw n ne e se s sw w
                                  n ne e se s sw w nw
                                  ne e se s sw w nw n
                                  e se s sw w nw n ne
                                  se s sw w nw n ne e))


(defparameter *cur-region* nil)

(defparameter *in-region* nil)

(defparameter *region-data* (make-hash-table))

(defparameter *regions* '(ccen c180 c225 c270 c315 c000 c045 c090 c135
                  m_c m_n mne m_e mse m_s msw m_w mnw))

(defparameter *region-data-array* nil)


(defparameter *targets* 
  '((:x 227 :y 507 :text "O") 
    (:x 107 :y 459 :text "O")
    (:x  56 :y 337 :text "O")
    (:x 105 :y 217 :text "O")
    (:x 228 :y 166 :text "O")
    (:x 347 :y 217 :text "O")
    (:x 397 :y 337 :text "O")
    (:x 346 :y 458 :text "O")
    ))
(defparameter *directions*
  '((:x 719 :y 407 :text "S")
    (:x 552 :y 406 :text "SW")
    (:x 551 :y 244 :text "W")
    (:x 552 :y 82  :text "NW")
    (:x 719 :y 82  :text "N")
    (:x 885 :y 83  :text "NE")
    (:x 882 :y 242 :text "E")
    (:x 856 :y 405 :text "SE")))

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; Participant data
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

;; First Training Study
(defparameter *Data-Count-Camera-T* '(2.205 2.341 2.518 2.693 2.703 2.581 2.382 2.323))
(defparameter *Data-Count-Target-T* '(1.675 2.262 2.768 3.129 1.772 3.166 2.655 2.319))
(defparameter *Data-Angle-Camera-T* '(2.133 2.461 2.511 2.969 3.082 2.903 2.360 2.378))
(defparameter *Data-Angle-Target-T* '(2.043 2.680 2.694 3.130 1.866 3.191 2.580 2.614))
        
;; Eye Tracking Study
(defparameter *Data-Count-Camera-E* '(2.148 2.115 2.185 2.263 2.517 2.314 2.155 2.068))
(defparameter *Data-Count-Target-E* '(1.505 2.086 2.246 2.640 1.774 2.968 2.397 2.149))
(defparameter *Data-Angle-Camera-E* '(2.707 3.254 3.360 3.646 3.860 3.751 3.371 3.045))
(defparameter *Data-Angle-Target-E* '(2.279 3.451 3.706 4.054 1.963 4.353 3.713 3.475))
        
;; Combined
(defparameter *Data-Count-Camera* '(2.183 2.254 2.390 2.527 2.631 2.478 2.295 2.225))
(defparameter *Data-Count-Target* '(1.610 2.195 2.567 2.941 1.772 3.090 2.556 2.254))
(defparameter *Data-Angle-Camera* '(2.354 2.766 2.838 3.229 3.381 3.229 2.749 2.635))
(defparameter *Data-Angle-Target* '(2.134 2.977 3.083 3.486 1.903 3.638 3.016 2.945))

;; Eye Data
(defparameter *eye-chance* '(0.06 0.07 0.02 0.06 0.30 0.06 0.06 0.02 0.07 0.30))
(defparameter *eye-angle* '(0.15 0.09 0.04 0.05 0.18 0.18 0.13 0.07 0.06 0.10))
(defparameter *eye-count* '(0.13 0.10 0.03 0.08 0.18 0.15 0.13 0.03 0.09 0.13))


;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;
;;   Code for presenting the experiment through the ACT-R web interface
;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

(defvar *WWW-interface*)

(defvar *lf* .11)
(defvar *v* nil)
(defvar *n* 1)
(defvar *graphic* nil)
(defvar *combine* nil)

(setf  *WWW-interface* 
      '((:heading "Orientation Model" 2)
        (:heading "Parameters" 3)
        (:table)
        (:table)
        "Retrieval time in seconds:"      (:string :sy *lf*  .11)  (:new-row)
        "number of runs (1-10):"          (:string :sy *n* 1)         
        
        (:table-end)
        
        (:table)
        (:checkbox "Trace" :sy *v*  nil)                (:new-row)
        (:checkbox "Graphic output" :sy *graphic*  t) (:new-row)
        (:table-end)
        (:table-end)
        
        (:new-para)
        (:button "Run Angle model" "(if (and (numberp *lf*) (numberp *n*))
                                      (run-block (min 10 (max *n* 1)) 'angle)
                                  (format *standard-output* \"~%~%All parameters must be numbers.~%\"))")
        (:button "Run Count model" "(if (and (numberp *lf*) (numberp *n*))
                                      (run-block (min 10 (max *n* 1)) 'count)
                                  (format *standard-output* \"~%~%All parameters must be numbers.~%\"))")
        (:button "Run Both models" "(if (and (numberp *lf*) (numberp *n*))
                                     (progn
                                    (let* ((*combine* t)
                                           (a (run-block (min 10 (max *n* 1)) 'angle))
                                           (b (run-block (min 10 (max *n* 1)) 'count))
                                           ) 
                                            (draw-combined-graphs a b))
                                       
                                  (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 less than 1 minute for 1 run of one model"
        (:new-line)
        "- The trace of 1 run is approximatly k ( pages) in size"
        (:use-actr51)))

(defun draw-graphs (angle-d angle-m target-d target-m)

   (format *standard-output* " 
        <applet 
        code = \"DansGraphs.class\" 
        width = 500 
        height = 400> 
        <PARAM name=\"title\" value=\"RT by target location\">
        <PARAM name=\"xmin\" value=\"0\">
        <PARAM name=\"xmax\" value=\"9\">
        <PARAM name=\"ymax\" value=\"4.0\">
        <PARAM name=\"ymin\" value=\"0.0\">
        <PARAM name=\"longestline\" value=\"9\">
        <PARAM name=\"numlines\" value=\"4\">
        <PARAM name=\"numxlabels\" value=\"10\">
        <PARAM name=\"xlabels\" value=\" ;Near;Near-Left;Mid-Left;Far-Left;Far;Far-Right;Mid-Right;Near-Right;Near;\">
        <PARAM name=\"widestxlabel\" value=\"WWWWWWWWW\">
        <PARAM name=\"ydiv\" value=\"0.25\">
        <PARAM name=\"yspacing\" value=\"0.5\">
        <PARAM name=\"xname\" value=\"Target Location\">
        <PARAM name=\"yname\" value=\"RT (seconds)\">
        <PARAM name=\"name0\" value=\"Model\">
        <PARAM name=\"lcolor0\" value=\"0\">
        <PARAM name=\"lstyle0\" value=\"2\">
        <PARAM name=\"xval0\" value=\"1;2;3;4;5;6;7;8;9;\">
        <PARAM name=\"yval0\" value=\"~4,3f;~4,3f;~4,3f;~4,3f;~4,3f;~4,3f;~4,3f;~4,3f;~4,3f;\">
        <PARAM name=\"name1\" value=\"Data\">
        <PARAM name=\"lcolor1\" value=\"1\">
        <PARAM name=\"lstyle1\" value=\"6553\">
        <PARAM name=\"xval1\" value=\"1;2;3;4;5;6;7;8;9;\">
        <PARAM name=\"yval1\" value=\"~4,3f;~4,3f;~4,3f;~4,3f;~4,3f;~4,3f;~4,3f;~4,3f;~4,3f;\">
        <HR> Either your browser does not support JAVA or this graph has scrolled off the top of the display.~%</HR></applet>"
        
         (nth 0 target-m)(nth 1 target-m)(nth 2 target-m)(nth 3 target-m)(nth 4 target-m)(nth 5 target-m)(nth 6 target-m)(nth 7 target-m)(nth 0 target-m)
         (nth 0 target-d)(nth 1 target-d)(nth 2 target-d)(nth 3 target-d)(nth 4 target-d)(nth 5 target-d)(nth 6 target-d)(nth 7 target-d)(nth 0 target-d)
         )
           (format *standard-output* " 
        <applet 
        code = \"DansGraphs.class\" 
        width = 500 
        height = 400> 
        <PARAM name=\"title\" value=\"RT by orientation (plane location)\">
        <PARAM name=\"xmin\" value=\"0\">
        <PARAM name=\"xmax\" value=\"9\">
        <PARAM name=\"ymax\" value=\"4.0\">
        <PARAM name=\"ymin\" value=\"0.0\">
        <PARAM name=\"longestline\" value=\"9\">
        <PARAM name=\"numlines\" value=\"4\">
        <PARAM name=\"numxlabels\" value=\"10\">
        <PARAM name=\"xlabels\" value=\" ;S;SW;W;NW;N;NE;E;SE;S;\">
        <PARAM name=\"widestxlabel\" value=\"WW\">
        <PARAM name=\"ydiv\" value=\"0.25\">
        <PARAM name=\"yspacing\" value=\"0.5\">
        <PARAM name=\"xname\" value=\"Plane Location\">
        <PARAM name=\"yname\" value=\"RT (seconds)\">
        <PARAM name=\"name0\" value=\"Model\">
        <PARAM name=\"lcolor0\" value=\"0\">
        <PARAM name=\"lstyle0\" value=\"2\">
        <PARAM name=\"xval0\" value=\"1;2;3;4;5;6;7;8;9;\">
        <PARAM name=\"yval0\" value=\"~4,3f;~4,3f;~4,3f;~4,3f;~4,3f;~4,3f;~4,3f;~4,3f;~4,3f;\">
        <PARAM name=\"name1\" value=\"Data\">
        <PARAM name=\"lcolor1\" value=\"1\">
        <PARAM name=\"lstyle1\" value=\"6553\">
        <PARAM name=\"xval1\" value=\"1;2;3;4;5;6;7;8;9;\">
        <PARAM name=\"yval1\" value=\"~4,3f;~4,3f;~4,3f;~4,3f;~4,3f;~4,3f;~4,3f;~4,3f;~4,3f;\">
        <HR> Either your browser does not support JAVA or this graph has scrolled off the top of the display.~%</HR></applet>"
        
         (nth 0 angle-m)(nth 1 angle-m)(nth 2 angle-m)(nth 3 angle-m)(nth 4 angle-m)(nth 5 angle-m)(nth 6 angle-m)(nth 7 angle-m)(nth 0 angle-m)
         (nth 0 angle-d)(nth 1 angle-d)(nth 2 angle-d)(nth 3 angle-d)(nth 4 angle-d)(nth 5 angle-d)(nth 6 angle-d)(nth 7 angle-d)(nth 0 angle-d)
         )
         
)
      

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;
;;   Code for the experiment delivery, etc.
;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;



(defmethod rpm-window-key-event-handler ((win rpm-window) key)
  (setf *key-pressed-was* 
        (cond ((equal key #\2) 'S)
              ((equal key #\1) 'SW)
              ((equal key #\4) 'W)
              ((equal key #\7) 'NW)
              ((equal key #\8) 'N)
              ((equal key #\9) 'NE)
              ((equal key #\6) 'E)
              ((equal key #\3) 'SE)
              (t 'ERROR)))
  (setf *response-time* (- (pm-get-time) *start-trial-time*)))



;;Adds the rest of the non-essential elements to display
(defun add-eye-candy ()
  (add-line-to-exp-window '(500 0) '(500 700))
  (add-text-to-exp-window :x 210 :y 650 :text "Plane")
  (add-text-to-exp-window :x 145 :y 50 :width 300 :text "View from camera mounted on plane")
  (add-text-to-exp-window :x 550 :y 600 :width 400 :text "In which direction is the RED object?")
  (add-text-to-exp-window :x 240 :y 358 :text ".")
  (add-text-to-exp-window :x 731 :y 264 :text "."))

;;makes a list of the possible trials
(defun make-trials ()
  (let ((res nil))
    (dotimes (plane 8 res)
      (dotimes (target 8)
        (push (list (* plane 45) (* target 45)) res)))))
  
(defparameter *trial-set* (make-trials))


;;Places targets and cardinal directions on screen.
(defun place-items (tgt pln)
  (dotimes (i 8)
    (apply #'add-text-to-exp-window (append (nth i *targets*) (if (= i tgt) (list :color 'red) (list :color 'black))))
    (apply #'add-text-to-exp-window (append (nth i *directions*) (if (= i pln) (list :color 'red) (list :color 'black))))
    ))


(defun run-trial (x cond &key (visible nil) (make-data t))
  (let ((trial nil)
        (window (open-exp-window
          "glenns-window"
          :width 980 
          :height 700
          :x 0 :y 0
          :visible visible)))
 
   (pm-install-device window)
   
   (when make-data
     (setf *model-data* (make-array (list 1 8 8 5)))
     (setf *region-data-array* (make-array (list 1 8 8 18))))
   
    (setf trial (nth x *trial-set*))
    (setf *pln* (/ (car trial) 45))
    (setf *tgt* (/ (cadr trial) 45))

    (clear-exp-window)

    (pm-proc-display)

    (add-eye-candy)

    (place-items *tgt* *pln*)

    (setf *start-trial-time* (pm-get-time))
    (setf *key-pressed-was* nil)
                    
    (if *actr-enabled-p* 
      (progn (pm-proc-display :clear t)

         (dolist (i (visicon (vis-m *mp*)))
           (when (equal (kind i) 'text)
             (cond ((string-equal (val i) "s") (mod-chunk-fct 'south (list 'loc-x (screen-x i) 'loc-y (screen-y i))))
                    ((string-equal (val i) "sw") (mod-chunk-fct 'southwest (list 'loc-x (screen-x i) 'loc-y (screen-y i))))
                    ((string-equal (val i) "se") (mod-chunk-fct 'southeast (list 'loc-x (screen-x i) 'loc-y (screen-y i))))
                    ((string-equal (val i) "n") (mod-chunk-fct 'north (list 'loc-x (screen-x i) 'loc-y (screen-y i))))
                    ((string-equal (val i) "nw") (mod-chunk-fct 'northwest (list 'loc-x (screen-x i) 'loc-y (screen-y i))))
                    ((string-equal (val i) "ne") (mod-chunk-fct 'northeast (list 'loc-x (screen-x i) 'loc-y (screen-y i))))
                    ((string-equal (val i) "e") (mod-chunk-fct 'east (list 'loc-x (screen-x i) 'loc-y (screen-y i))))
                    ((string-equal (val i) "w") (mod-chunk-fct 'west (list 'loc-x (screen-x i) 'loc-y (screen-y i))))
                    ((and (string-equal (val i) ".") (< (screen-x i) 500)) (mod-chunk-fct 'centercam (list 'loc-x (screen-x i) 'loc-y (screen-y i))))
                    ((string-equal (val i) ".") (mod-chunk-fct 'centermap (list 'loc-x (screen-x i) 'loc-y (screen-y i)))
                     (setf *doty* (screen-y i)))
                    ((string-equal (val i) "o") (let ((region (find-region (screen-x i) (screen-y i))))
                                                  (case region
                                                    (c135 (mod-chunk-fct 't135 (list 'loc-x (screen-x i) 'loc-y (screen-y i))))
                                                    (c090 (mod-chunk-fct 't090 (list 'loc-x (screen-x i) 'loc-y (screen-y i))))
                                                    (c045 (mod-chunk-fct 't045 (list 'loc-x (screen-x i) 'loc-y (screen-y i))))
                                                    (c180 (mod-chunk-fct 't180 (list 'loc-x (screen-x i) 'loc-y (screen-y i))))
                                                    (c000 (mod-chunk-fct 't000 (list 'loc-x (screen-x i) 'loc-y (screen-y i))))
                                                    (c225 (mod-chunk-fct 't225 (list 'loc-x (screen-x i) 'loc-y (screen-y i))))
                                                    (c270 (mod-chunk-fct 't270 (list 'loc-x (screen-x i) 'loc-y (screen-y i))))
                                                    (c315 (mod-chunk-fct 't315 (list 'loc-x (screen-x i) 'loc-y (screen-y i))))))))))

                   

              (setf *in-region* (pm-get-time))
             (setf *cur-region* (nth (random (length *regions*)) *regions*))
             (mod-chunk trial side nil height nil t-cur nil p-cur nil count nil step nil answer nil)
             (eval (list 'mod-chunk 'trial 'strategy cond))
             (pm-run 100)
             (get-new-region 0 0)
             (update-region-array)
             )
      (if visible
        (while (null *key-pressed-was*)
          (allow-event-manager window))
        (format t "You must use a visible window to run with a person"))))
    (list *key-pressed-was* *response-time* (equal *key-pressed-was* (nth x (reverse *correct-answers*)))))



;;Runs model n times on one block of trials
;;Trials are presented in random order
(defun run-block (n condition &key (visible nil))

  (setf *model-data* (make-array (list n 8 8 5)))
  (setf *region-data-array* (make-array (list n 8 8 18)))
  
  (dotimes (i n)
    (setf *trialnum* 0)
    (dolist (x (permute-list *trial-set*))
      (let ((res (run-trial (position x *trial-set*) condition :visible visible :make-data nil)))
        (setf (aref *model-data* i *tgt* *pln* 0) (incf *trialnum*))
        (setf (aref *model-data* i *tgt* *pln* 1) (* *tgt* 45))
        (setf (aref *model-data* i *tgt* *pln* 2) (* *pln* 45))
        (setf (aref *model-data* i *tgt* *pln* 3) (first res))
        (setf (aref *model-data* i *tgt* *pln* 4) (second res)))))
  
  (close-exp-window)
  
  (format t "Data for ~S Model~%" condition)
  
  (let ((data (if (equal condition 'angle)
                 (dostats n *Data-Angle-Camera* *Data-Angle-Target*)
                 (dostats n *Data-Count-Camera* *Data-Count-Target*))))
  
  (let* ((raw-data (print-region-data-long n))
         (averaged (mapcar #'(lambda (x) (/ x (length raw-data))) (apply #'mapcar #'+ raw-data)))
         (corrected (mapcar #'(lambda (x) (/ x 2.0)) (mapcar #'+ averaged *eye-chance*))))
    
    (format t "~%Correlation to eye data: ")
    (correlation corrected (if (equal condition 'count) *eye-count* *eye-angle*)))
    data))

;;Calculates statistics for model run
;;and prints out data to screen
(defun dostats (n cam tar)
  (let ((temp nil)
        (pln-time 0)
        (tgt-time 0)
        (plns nil)
        (tgts nil)
        (model-answers nil))
    (dotimes (x 8)
      (dotimes (y 8)
        (dotimes (z n)
          (setf pln-time (+ (aref *model-data* z y x 4) pln-time))
          (setf tgt-time (+ (aref *model-data* z x y 4) tgt-time))))
      (setf plns (cons (/ (/ pln-time 8000.0) n) plns))
      (setf tgts (cons (/ (/ tgt-time 8000.0) n) tgts))
      (setf pln-time 0)
      (setf tgt-time 0))
    (setf plns (reverse plns))
    (setf tgts (reverse tgts))
    (dotimes (z n)
      (dotimes (x 8)
        (dotimes (y 8)
          (setf temp (cons (aref *model-data* z x y 3) temp))))
      (setf model-answers (cons temp model-answers))
      (setf temp nil)
      )
    (format t "~%~%~c~cRESPONSE TIMES" #\tab #\tab)
    (format t "~%~%Target Angle~%~%~cAngle~cData~cModel~%"  #\tab #\tab #\tab)
    (dotimes (i 8)
      (format t "~c~d~c~d~c~d~%" #\tab
              (nth i *angles*) #\tab
              (nth i tar) #\tab
              (nth i tgts)))
    (format t "~%~%Camera Angle~%~%~cAngle~cData~cModel~%"  #\tab #\tab #\tab)
    (dotimes (i 8)
      (format t "~c~d~c~d~c~d~%" #\tab
              (nth i *angles*) #\tab
              (nth i cam) #\tab
              (nth i plns)))
    (format t "~%")
    (mean-deviation (append tgts plns) (append tar cam))
    (correlation (append tgts plns) (append tar cam))
    (format t "~%")
    
    (when (and *graphic* (not *combine*)) (draw-graphs cam plns tar tgts)) 
    (list cam plns tar tgts)))

(defun constraint (axis value direction pixels)
  (let ((lower (- pixels 25))
        (upper (+ pixels 25)))
    (if (equal axis 'x)
        (if (equal direction 'left)
            (cond ((equal value "s") 'less-than-current)
                 ((equal value "n") 'less-than-current)
                  ((equal value "ne") 'less-than-current)
                   ((equal value "se") 'less-than-current)
                  (t (list 'within lower upper)))
            (cond ((equal value "s") 'greater-than-current)
                  ((equal value "sw") 'greater-than-current)
                  ((equal value "nw") 'greater-than-current)
                  ((equal value "n") 'greater-than-current)
                  (t (list 'within lower upper))))
        (if (equal direction 'left)
            (cond ((equal value "sw") 'less-than-current)
                  ((equal value "w") 'less-than-current)
                  ((equal value "nw") 'greater-than-current)
                  ((equal value "e") 'greater-than-current)
                  (t (list 'within lower upper)))
            (cond ((equal value "w") 'greater-than-current)
                  ((equal value "ne") 'greater-than-current)
                  ((equal value "e") 'less-than-current)
                  ((equal value "se") 'less-than-current)
                  (t (list 'within lower upper)))))))

(defun get-new-region (x y)
  (multiple-value-bind (val found?)
                       (gethash *cur-region* *region-data*)
    (declare (ignore val))
    (if found?
        (setf (gethash *cur-region* *region-data*) (+ (gethash *cur-region* *region-data*) (- (pm-get-time) *in-region*)))
        (setf (gethash *cur-region* *region-data*) (- (pm-get-time) *in-region*))))
  (setf *in-region* (pm-get-time))
  (setf *cur-region* (find-region x y)))

(defun find-region (x y)
  (cond ((equal x 0) (nth (random (length *regions*)) *regions*))
        ((< x 150) (cond ((< y 300) 'c135)
                         ((< y 400) 'c090)
                         ((< y 600) 'c045)
                         (t (format t "crap - ~d~c~d" x #\tab y))))
        ((< x 300) (cond ((< y 300) 'c180)
                         ((< y 400) 'ccen)
                         ((< y 600) 'c000)
                         (t (format t "crap - ~d~c~d" x #\tab y))))
        ((< x 500) (cond ((< y 300) 'c225)
                         ((< y 400) 'c270)
                         ((< y 600) 'c315)
                         (t (format t "crap - ~d~c~d" x #\tab y))))
        ((< x 600) (cond ((< y 100) 'mnw)
                         ((< y 300) 'm_w)
                         ((< y 430) 'msw)
                         (t (format t "crap - ~d~c~d" x #\tab y))))
        ((< x 800) (cond ((< y 100) 'm_n)
                         ((< y 300) 'm_c)
                         ((< y 430) 'm_s)
                         (t (format t "crap - ~d~c~d" x #\tab y))))
        ((< x 900) (cond ((< y 100) 'mne)
                         ((< y 300) 'm_e)
                         ((< y 430) 'mse)
                         (t (format t "crap - ~d~c~d" x #\tab y))))
        (t '(format t "crap - ~d~c~d" x #\tab y))))

(defun update-region-array ()
  (dotimes (regions 18)
    (setf (aref *region-data-array* *participant* *tgt* *pln* regions)
          (if (gethash (nth regions *regions*) *region-data*)
              (gethash (nth regions *regions*) *region-data*)
              0)))
    (setf *region-data* (make-hash-table)))

(defun print-region-data (n)
  (let ((sum 0))
    (format t "~%~%Region~cTime~%" #\tab)
    (dotimes (regions 18)
      (setf sum 0)
      (dotimes (target 8)
        (dotimes (plane 8)
          (dotimes (participants n)
            (setf sum (+ (aref *region-data-array* (1- n) target plane regions) sum)))))
          (format t "~d~c~d~%" (nth regions *regions*) #\tab (/ sum n)))
          ))

(defun print-region-data-long (n)
  (let ((sum 0)
        (totalsum 0)
        (templist nil)
        (datalist  nil))
;    (format t "Cam-Target~cCam-Plane~cCam-center~cCam-between~cCam-other~c~cMap-Ans~cMap-Plane~cMap-center~cMap-between~cMap-other~%~%"
;            #\tab #\tab #\tab #\tab #\tab #\tab #\tab #\tab #\tab #\tab)
    (dotimes (target 8)
      (dotimes (plane 8)
        (setf totalsum 0)
        (setf templist nil)
        (dotimes (regions 18)
          (setf sum 0)
          (dotimes (participants n)
            (setf sum (+ (aref *region-data-array* participants target plane regions) sum))
            (setf totalsum (+ (aref *region-data-array* participants target plane regions) totalsum)))
          (setf templist (cons sum templist))
          )
        (setf templist (reverse templist))
        (let ((cam-cen 0)
              (cam-tgt 0)
              (cam-pln 0)
              (cam-bet 0)
              (cam-otr 0)
              (map-cen 0)
              (map-tgt 0)
              (map-pln 0)
              (map-bet 0)
              (map-otr 0))
          (setf cam-cen (nth 0 templist))
          (setf cam-tgt (nth (1+ (mod (+ target 4) 8)) templist))
          (setf cam-pln (nth 5 templist))
          (if (> target 1) (setf cam-bet (find-between target 0 'c templist)))
          (setf cam-otr (- (+ (nth 0 templist) (nth 1 templist) (nth 2 templist) (nth 3 templist) (nth 4 templist)
                           (nth 5 templist) (nth 6 templist) (nth 7 templist) (nth 8 templist))
                           (+ cam-cen cam-tgt cam-pln cam-bet)))
          (if (equal target 0)
              (setf cam-otr (+ cam-otr cam-tgt)))

          (setf map-cen (nth 9 templist))
          (setf map-tgt (nth (+ 10 (mod (+ 4 plane target) 8)) templist))
          (setf map-pln (nth (+ 10 (mod (+ 4 plane) 8)) templist))
          (if (> target 1) (setf map-bet (find-between target plane 'm templist)))
          (setf map-otr (- (+ (nth 9 templist) (nth 10 templist) (nth 11 templist) (nth 12 templist) (nth 13 templist)
                           (nth 14 templist) (nth 15 templist) (nth 16 templist) (nth 17 templist))
                           (+ map-cen map-tgt map-pln map-bet)))
          (if (equal target 0)
              (setf map-otr (+ map-otr map-tgt)))
          (setf templist (list (* 1.0 (/ cam-tgt totalsum))
                               (* 1.0 (/ cam-pln totalsum))
                               (* 1.0 (/ cam-cen totalsum))
                               (* 1.0 (/ cam-bet totalsum))
                               (* 1.0 (/ cam-otr totalsum))
                               (* 1.0 (/ map-tgt totalsum))
                               (* 1.0 (/ map-pln totalsum))
                               (* 1.0 (/ map-cen totalsum))
                               (* 1.0 (/ map-bet totalsum))
                               (* 1.0 (/ map-otr totalsum))))
          (setf datalist (cons templist datalist))
;          (format t "~s~c~s~c~s~c~s~c~s~c~c~s~c~s~c~s~c~s~c~s~%"
;                  (* 1.0 (/ cam-tgt totalsum)) #\tab
;                  (* 1.0 (/ cam-pln totalsum)) #\tab
;                  (* 1.0 (/ cam-cen totalsum)) #\tab
;                  (* 1.0 (/ cam-bet totalsum)) #\tab
;                  (* 1.0 (/ cam-otr totalsum)) #\tab #\tab 
;                  (* 1.0 (/ map-tgt totalsum)) #\tab
;                  (* 1.0 (/ map-pln totalsum)) #\tab
;                  (* 1.0 (/ map-cen totalsum)) #\tab
;                  (* 1.0 (/ map-bet totalsum)) #\tab
;                  (* 1.0 (/ map-otr totalsum)) #\tab)
          )))
     datalist))

(defun find-between (target plane view templist)
  (cond ((equal view 'c)
         (cond ((equal target 2) (nth 6 templist))
               ((equal target 3) (+ (nth 6 templist) (nth 7 templist)))
               ((equal target 4) (+ (nth 6 templist) (nth 7 templist) (nth 8 templist)))
               ((equal target 5) (+ (nth 3 templist) (nth 4 templist)))
               ((equal target 6) (+ (nth 4 templist)))
               (t 0)))
         (t (cond ((equal target 2) (+ (nth (+ 10 (mod (+ plane 5) 8)) templist)))
                  ((equal target 3) (+ (nth (+ 10 (mod (+ plane 5) 8)) templist)
                                       (nth (+ 10 (mod (+ plane 6) 8)) templist)))
                  ((equal target 4) (+ (nth (+ 10 (mod (+ plane 5) 8)) templist)
                                       (nth (+ 10 (mod (+ plane 6) 8)) templist)
                                       (nth (+ 10 (mod (+ plane 7) 8)) templist)))
                  ((equal target 5) (+ (nth (+ 10 (mod (+ plane 3) 8)) templist)
                                       (nth (+ 10 (mod (+ plane 2) 8)) templist)))
                  ((equal target 6) (+ (nth (+ 10 (mod (+ plane 3) 8)) templist)))
                  (t 0)))))
    
(defun searchdir (original cardinal)
  (cond ((or (equal original 'left) (equal original 'mid))
         (cond ((or (equal cardinal "nw")
                    (equal cardinal "ne")
                    (equal cardinal "n"))
                'right)
                (t 'left)))
        ((equal original 'right)
         (cond ((or (equal cardinal "nw")
                    (equal cardinal "ne")
                    (equal cardinal "n"))
                'left)
                (t 'right)))
        (t 'ack)))


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

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;
;;;  Model Code
;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;
;;; Initialization
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

(clear-all)
(pm-reset)

(define-buffer imaginal *imaginal*
  :equal-lhs get-buffer-content
  :plus-rhs create-buffer-chunk
  :equal-rhs modify-buffer-chunk
  :minus-rhs clear-buffer)

(setf *actr-enabled-p* t)

(sgp-fct (list :er t :esc t :ga 0 :lf *lf* :v *v*))

(pm-set-params :real-time nil :show-focus nil)

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;
;; The following are set to nil above.
;;
;; (pm-set-params :real-time t)
;;   -Causes model to run in real-time
;;
 (pm-set-params :show-focus t)
;;   -Will show the current location of the eye's fixation
;;
;; (sgp :v t)
;;   -Will print the model trace to the active listener
;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;
;;;  Chunk-types and declarative memory
;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
 
(chunk-type trial side height t-cur p-cur count strategy step answer)
(chunk-type cardinal name loc-x loc-y next-l next-r opposite)
(chunk-type target loc-x loc-y side height aligned)
(chunk-type number value next)
(chunk-type side value opposite)
(chunk-type key number direction)
(chunk-type pnt side loc-x loc-y)
(chunk-type angle plane vertex target)

(add-dm (trial isa trial side nil height nil t-cur nil p-cur nil count nil strategy nil step nil answer nil)
        (camangle isa angle plane nil vertex centercam target nil)
        (mapangle isa angle plane nil vertex centermap target nil)
        (centercam isa pnt side map loc-x 242 loc-y 361)
        (centermap isa pnt side camera loc-x 733 loc-y 266)
        (south     isa cardinal name "s"  loc-x 732 loc-y 431 next-l "sw" next-r "se" opposite "n" )
        (southwest isa cardinal name "sw" loc-x 582 loc-y 430 next-l "w"  next-r "s"  opposite "ne")
        (west      isa cardinal name "w"  loc-x 569 loc-y 268 next-l "nw" next-r "sw" opposite "e" )
        (northwest isa cardinal name "nw" loc-x 583 loc-y 106 next-l "w"  next-r "n"  opposite "se")
        (north     isa cardinal name "n"  loc-x 733 loc-y 106 next-l "nw" next-r "ne" opposite "s" )
        (northeast isa cardinal name "ne" loc-x 881 loc-y 107 next-l "n"  next-r "e"  opposite "sw")
        (east      isa cardinal name "e"  loc-x 895 loc-y 266 next-l "se" next-r "ne" opposite "w" )
        (southeast isa cardinal name "se" loc-x 881 loc-y 429 next-l "s"  next-r "e"  opposite "nw")
        (r1 isa key number 2 direction "s" )
        (r2 isa key number 1 direction "sw")
        (r3 isa key number 4 direction "w" )
        (r4 isa key number 7 direction "nw")
        (r5 isa key number 8 direction "n" )
        (r6 isa key number 9 direction "ne")
        (r7 isa key number 6 direction "e" )
        (r8 isa key number 3 direction "se")
        (T000 isa target loc-x 242 loc-y 531 side mid   height 0 aligned "s" )
        (T045 isa target loc-x 122 loc-y 483 side left  height 1 aligned "sw")
        (T090 isa target loc-x  71 loc-y 361 side left  height 2 aligned "w" )
        (T135 isa target loc-x 120 loc-y 241 side left  height 3 aligned "nw")
        (T180 isa target loc-x 243 loc-y 190 side mid   height 4 aligned "n" )
        (T225 isa target loc-x 362 loc-y 241 side right height 3 aligned "ne")
        (T270 isa target loc-x 412 loc-y 361 side right height 2 aligned "e" )
        (T315 isa target loc-x 361 loc-y 482 side right height 1 aligned "se")
        (left  isa side value  left opposite right)
        (right isa side value right opposite  left)
        (mid   isa side value   mid opposite right)
        (up    isa side value    up opposite  down)
        (down  isa side value  down opposite    up)
        (zero  isa number value 0)
        (one   isa number value 1 next 0)
        (two   isa number value 2 next 1)
        (three isa number value 3 next 2)
        (four  isa number value 4 next 3)
        )

(goal-focus trial)

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;
;;  Productions for processing the information in the camera view
;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;


;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; Moves attention to the location currently in the visual-location
;;    buffer
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(p generic-attend-location
   =goal>
      isa trial
      step attend
   =visual-location>
      isa visual-location
      screen-x =x
      screen-y =y
==>
   +visual>
      isa visual-object
      screen-pos =visual-location
   =goal>
      step attended
   !eval! (get-new-region =x =y)
)

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; Locates the plane's position on the camera view to begin counting.
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(p find-bottom-target
   =goal>
      isa trial
      side nil
      height nil
      t-cur nil
      p-cur nil
      count nil
      step nil
      answer nil
      strategy count
==>
   =goal>
      step attend
   +visual-location>
      isa visual-location
       screen-y (within 514 518)
)

(p find-target-direction
   =goal>
      isa trial
      side nil
      height nil
      t-cur nil
      p-cur nil
      count nil
      step attended
      answer nil
      strategy count
   =visual-location>
      isa visual-location
;      screen-x 242
;      screen-y 531
==>
   +visual-location>
      isa visual-location
      color red
    < screen-x 500
   =goal>
      step next
)

(p retrieve-target-info
   =goal>
      isa trial
      side nil
      height nil
      t-cur nil
      p-cur nil
      count nil
      step next
      answer nil
      strategy count
   =visual-location>
      isa visual-location
      color red
    < screen-x 500
      screen-x =x
      screen-y =y
   =visual>
      isa visual-object
      value "o"
==>
   +retrieval>
      isa target
      loc-x =x
      loc-y =y
   =goal>
      step encode
      p-cur initial
)

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; Encodes the target information for 0 and 180 positions
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(p encode-special-cases
   =goal>
      isa trial
      side nil
      height nil
      t-cur nil
      p-cur =tag
      count nil
      step encode
      answer nil
      strategy count
   =visual-location>
      isa visual-location
      screen-x =x
      screen-y =y
   =visual>
      isa visual-object
      value "o"
   =retrieval>
      isa target
      loc-x =x2
      loc-y =y2
      aligned =aligned
      height =height
      side mid
==>
   =goal>
      side mid
      height =height
      step attend
   +visual-location>
      isa visual-location
    < screen-x 500
      color red
)


;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; Encodes the information used in the count strategy from the target
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(p encode-as-left-or-right
   =goal>
      isa trial
      side nil
      height nil
      t-cur nil
      p-cur =tag
      count nil
      step encode
      answer nil
      strategy count
   =visual-location>
      isa visual-location
      screen-x =x
      screen-y =y
      color red
   =visual>
      isa visual-object
      value "o"
   =retrieval>
      isa target
      loc-x =x
      loc-y =y
      aligned =aligned
      height =height
      side =side
    - side mid
==>
   +visual-location>
      isa visual-location
       screen-y (within 514 518)
   =goal>
      side =side
      height 0
      step attended
)

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; Finds the next target and increments the count.
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(p find-next-target-left
   =goal>
      isa trial
      side left
      height =height
      t-cur nil
      p-cur =tag
      count nil
      step attended
      answer nil
      strategy count
   =visual-location>
      isa visual-location
      screen-x =x
    < screen-x 500
      screen-y =y
    - color red
   =visual>
      isa visual-object
      screen-pos =visual-location
==>
   +visual-location>
      isa visual-location
    < screen-x 240
      screen-y less-than-current
      nearest current
   =goal>
      step attend
      height (!eval! (1+ =height))
)

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; Finds the next target and increments the count.
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(p find-next-target-right
   =goal>
      isa trial
      side right
      height =height
      t-cur nil
      p-cur =tag
      count nil
      step attended
      answer nil
      strategy count
   =visual-location>
      isa visual-location
      screen-x =x
    < screen-x 500
      screen-y =y
    - color red
   =visual>
      isa visual-object
      screen-pos =visual-location
==>
   +visual-location>
      isa visual-location
      nearest current
    > screen-x 245
      screen-y less-than-current
      nearest current
   =goal>
      step attend
      height (!eval! (1+ =height))
)

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; Fires when the target has been reached through the counting process.
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(p target-found-red
   =goal>
      isa trial
      side =side
      height =height
      t-cur nil
      p-cur =tag
      count nil
      step attended
      answer nil
      strategy count
   =visual-location>
      isa visual-location
      screen-x =x
    < screen-x 500
      screen-y =y
      color red
   =visual>
      isa visual-object
      screen-pos =visual-location
==>
   +retrieval>
      isa target
      loc-x =x
      loc-y =y
   =goal>
      step initial
)

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; Encodes the rest of the target information.
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(p encode-aligned
   =goal>
      isa trial
      side =side
      height =height
      t-cur nil
      p-cur =tag
      count nil
      step initial
      answer nil
      strategy count
   =visual-location>
      isa visual-location
      screen-x =x
    < screen-x 500
      screen-y =y
      color red
   =visual>
      isa visual-object
      screen-pos =visual-location
   =retrieval>
      isa target
      loc-x =x
      loc-y =y
      aligned =aligned
==>
   =goal>
      t-cur =aligned
)
   

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;
;;  Productions for finding the plane on the map view
;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; Locates the plane in the map view
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(p find-plane
   =goal>
      isa trial
      t-cur =aligned
      p-cur =tag
      count nil
      step initial
      answer nil
      strategy count
   =visual-location>
      isa visual-location
    < screen-x 500
==>
   +visual-location>
      isa visual-location
    > screen-x 500
      color red
   =goal>
      step attend
)

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; Retrieves the cardinal direction chunk for the plane's location
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(p retrieve-plane-info-count
   =goal>
      isa trial
      height =height
      side =side
      t-cur =aligned
      p-cur =tag
      count nil
      step attended
      answer nil
      strategy count
   =visual-location>
      isa visual-location
    > screen-x 500
      color red
   =visual>
      isa visual-object
      value =direction
      screen-pos =visual-location
==>
   +retrieval>
      isa cardinal
      name =direction
   =goal>
      step solve
      p-cur =direction
)

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;
;;  Target at top or bottom
;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; If the target's location was at the bottom of the camera view
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(p Target-at-bottom-count
   =goal>
      isa trial
      height 0
      side =side
      t-cur "s"
      p-cur =direction
      count nil
      step solve
      answer nil
      strategy count
   =visual-location>
      isa visual-location
    > screen-x 500
      color red
   =visual>
      isa visual-object
      value =direction
      screen-pos =visual-location
   =retrieval>
      isa cardinal
      name =direction
==>
   =goal>
      step respond
   +retrieval>
      isa key
      direction =direction
)

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; If the target's location was at the top of the camera view
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(p Target-at-top-count
   =goal>
      isa trial
      height 4
      side =side
      t-cur "n"
      p-cur =direction
      count nil
      step solve
      answer nil
      strategy count
   =visual-location>
      isa visual-location
    > screen-x 500
      color red
   =visual>
      isa visual-object
      value =direction
      screen-pos =visual-location
   =retrieval>
      isa cardinal
      name =direction
      opposite =answer
==>
   +retrieval>
      isa cardinal
      opposite =direction
      name =answer
)

(p target-at-top-count-2
   =goal>
      isa trial
      height 4
      side =side
      t-cur "n"
      p-cur =direction
      count nil
      step solve
      answer nil
      strategy count
   =visual-location>
      isa visual-location
    > screen-x 500
      color red
   =visual>
      isa visual-object
      value =direction
      screen-pos =visual-location
   =retrieval>
      isa cardinal
      name =answer
      opposite =direction
      loc-x =x
      loc-y =y
==>
   +visual-location>
      isa visual-location
      screen-x =x
      screen-y =y
   =goal>
      step attend
      height 0
   +retrieval>
      isa key
      direction =answer
)

#|
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; If the plane's location is at the bottom of the map view
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(p plane-at-bottom-1
   =goal>
      isa trial
      side =side
      height =height
      t-cur =aligned
      p-cur "s"
      count nil
      step solve
      answer nil
      strategy count
   =visual-location>
      isa visual-location
    > screen-x 500
      color red
   =visual>
      isa visual-object
      value "s"
      screen-pos =visual-location
   =retrieval>
      isa cardinal
      name "s"
==>
   +retrieval>
      isa cardinal
      name =aligned
   =goal>
      step finish
)

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; If the plane's location is at the bottom of the map view
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(p plane-at-bottom-2
   =goal>
      isa trial
      side =side
      height =height
      t-cur =aligned
      p-cur "s"
      count nil
      step finish
      answer nil
      strategy count
   =visual-location>
      isa visual-location
    > screen-x 500
      color red
   =visual>
      isa visual-object
      value "s"
      screen-pos =visual-location
   =retrieval>
      isa cardinal
      name =aligned
      loc-x =x
      loc-y =y
==>
   +visual-location>
      isa visual-location
      screen-x =x
      screen-y =y
   =goal>
      step attend
      height 0
   +retrieval>
      isa key
      direction =aligned
)
|#
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;
;;  Productions for implementing the search in the map view
;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; If the plane is not past horizontal, do not switch the search
;;   direction
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(p Start-no-switch
   =goal>
      isa trial
      side =side
      height =height
    - height 0
    - height 4
      t-cur =aligned
      p-cur =current
      count nil
      step solve
      answer nil
      strategy count
   =visual-location>
      isa visual-location
    > screen-x 500
    > screen-y 200
   =visual>
      ISA   visual-object
      value =current
      screen-pos =visual-location
   =retrieval>
      isa cardinal
      name =current
==>
   =goal>
      count no
   )

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; If the plane is at NW, N, or NE, change the direction of search
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(p start-change-direction
   =goal>
      isa trial
      side =side
      height =height
    - height 0
    - height 4
      t-cur =aligned
      p-cur =current
      count nil
      step solve
      answer nil
      strategy count
   =visual-location>
      isa visual-location
    > screen-x 500
    < screen-y 200
      attended t
   =visual>
      ISA   visual-object
      value =current
      screen-pos =visual-location
   =retrieval>
      isa cardinal
      name =current
==>
   =goal>
      count yes
   +retrieval>
      isa side
      value =side
   )

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; Changes the search direction
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(p change-search-direction
   =goal>
      isa trial
      side =side
      height =height
    - height 0
      t-cur =aligned
      p-cur =current
      count yes
      step solve
      answer nil
      strategy count
   =visual-location>
      isa visual-location
    > screen-x 500
    < screen-y 200
      screen-x =x
      screen-y =y
      attended t
   =retrieval>
      isa side
      value =side
      opposite =new
==>
   =goal>
      count =side
      side =new
   +retrieval>
      isa cardinal
      loc-x =x
      loc-y =y
   )

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; Locates the next cardinal location in the proper search direction.
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(p find-new-direction
   =goal>
      isa trial
      side =side
      height =height
    - height 0
      t-cur =aligned
      p-cur =current
      count =count
    - count yes
      step solve
      answer nil
      strategy count
   =visual-location>
      isa visual-location
    > screen-x 500
      screen-x =x
      screen-y =y
      attended t
   =visual>
      isa visual-object
      value =current
      screen-pos =visual-location
   =retrieval>
      isa cardinal
      loc-x =x
      loc-y =y
      name =current
==>
   !bind! =newx (constraint 'x =current =side =x)
   !bind! =newy (constraint 'y =current =side =y)
   +visual-location>
      isa visual-location
      screen-x =newx
      screen-y =newy
      nearest current
      color black
   =goal>
      step attend
   )

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; Encodes the new Cardinal direction.
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(p encode-new-direction
   =goal>
      isa trial
      side =side
      height =height
    > height 1
      t-cur =aligned
      p-cur =current
      count =something
      step attended
      answer nil
      strategy count
   =visual-location>
      isa visual-location
    > screen-x 500
      screen-x =x
      screen-y =y
      attended t
   =visual>
      isa visual-object
      value =next
    - value =current
      screen-pos =visual-location
    - color red
==>
   !bind! =doty *doty*
   +visual-location>
      isa visual-location
      nearest current
    > screen-x 550
    - screen-y =doty
      attended nil
   =goal>
      p-cur =next
      step attend
      height (!eval! (1- =height))
   )

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; Retrieves chunk corresponding to the currently attended location
;;  which just happens to be the answer.
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(p done-counting
   =goal>
      isa trial
      side =side
      height 1
      t-cur =aligned
      p-cur =current
      count =something
      step attended
      answer nil
      strategy count
   =visual-location>
      isa visual-location
    > screen-x 500
      screen-x =x
      screen-y =y
      attended t
   =visual>
      isa visual-object
      value =next
    - value =current
      screen-pos =visual-location
==>
   +retrieval>
      isa cardinal
      loc-x =x
      loc-y =y
      name =next
   =goal>
      p-cur =next
      step solve
      count nil
      height 0
)

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;
;;  Response Productions
;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; When the count decrements to 0, the cardinal direction of the
;; currently encoded direction is stored as the response
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(p encode-response-direction
   =goal>
      isa trial
      side =side
      height 0
      t-cur =aligned
      p-cur =current
      count nil
      step solve
      answer nil
      strategy count
   =visual-location>
      isa visual-location
    > screen-x 500
      attended t
   =visual>
      isa visual-object
      value =current
      screen-pos =visual-location
   =retrieval>
      isa cardinal
      loc-x =x
      loc-y =y
      name =current
==>
   =goal>
      step respond
   +retrieval>
      isa key
      direction =current
   )

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; Maps the cardinal direction to the correct response
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(p map-response
   =goal>
      isa trial
      step =step
    - step done
    - step attend
      answer nil
      strategy =strategy
   =retrieval>
      ISA                  key
      number =ans
      direction =direction
   =visual-location>
      isa visual-location
    > screen-x 500
==>
   =goal>
      side nil
      height nil
      t-cur nil
      p-cur nil
      count nil
      step respond
      answer =ans
   )

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; Issues the motor command to press the response key
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; *Currently, responses are made by the model using the
;; number row at the top of the keyboard.
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(p make-response
   =goal>
      isa trial
      side nil
      height nil
      t-cur nil
      p-cur nil
      count nil
      step respond
      answer =ans
      strategy =strategy
   =manual-state>
      isa module-state
      modality free
   =visual-state>
      ISA         module-state
      modality    free
==>
   =goal>
      answer nil
      step done
   +manual>
      isa press-key
      key =ans
 -visual>   )

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;
;;;  Angle Strategy
;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; Begins the trial for the angle strategy by retrieving the bottom
;;   target information (location of the plane in the camera view)
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(p start-angle
   =goal>
      isa trial
      side nil
      height nil
      t-cur nil
      p-cur nil
      count nil
      step nil
      answer nil
      strategy angle
==>
   =goal>
      step attend
   +retrieval>
      isa target
      height 0
   +imaginal>
      isa angle
   +visual-location>
      isa visual-location
    < screen-x 500
      screen-y (within 500 600)
)

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; Finds the target on the camera view - angle strategy
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(p tag-plane-angle
   =goal>
      isa trial
      side nil
      height nil
      t-cur nil
      p-cur nil
      count nil
      step attended
      answer nil
      strategy angle
   =retrieval>
      isa target
      height 0
      loc-x =x
      loc-y =y
   =visual-location>
      isa visual-location
      screen-x =x
      screen-y =y
   =visual>
      isa visual-object
      screen-pos =visual-location
   =imaginal>
      isa angle
      vertex nil
      plane nil
      target nil
==>
   =goal>
      p-cur =visual
      step attend
   =imaginal>
      isa angle
      plane =visual-location
   +visual-location>
      isa visual-location
      screen-x (within 230 260)
      screen-y (within 350 380)
)

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; Encodes the vertex of the angle as the center of the camera view.
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(p encode-angle-center
    =goal>
      isa trial
      side nil
      height nil
      t-cur nil
      p-cur =plane
      count nil
      step attended
      answer nil
      strategy angle
   =retrieval>
      isa target
      height 0
      loc-x =x
      loc-y =y
   =visual-location>
      isa visual-location
    < screen-x 260
    > screen-x 230
    < screen-y 380
    > screen-y 350
   =visual>
      isa visual-object
      screen-pos =visual-location
      value "."
   =imaginal>
      isa angle
      vertex nil
      plane =plane-cam
      target nil
==>
   =imaginal>
      vertex =visual-location
   +visual-location>
      isa visual-location
    < screen-x 500
      color red
   =goal>
      step attend
)


;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; Retrieves the chunk with the target information
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(p retrieve-target-information
   =goal>
      isa trial
      side nil
      height nil
      t-cur nil
      p-cur =plane
      count nil
      step attended
      answer nil
      strategy angle
   =visual-location>
      isa visual-location
      screen-x =x
    < screen-x 500
      screen-y =y
      color red
   =visual>
      isa visual-object
      screen-pos =visual-location
   =imaginal>
      isa angle
      vertex =center-cam
      plane =plane-cam
      target nil
==>
   +retrieval>
      isa target
      loc-x =x
      loc-y =y
   =goal>
      p-cur =visual
      step encode
)

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; Encodes the information used in the angle strategy from the target
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(p encode-target-angle
   =goal>
      isa trial
      side nil
      height nil
      t-cur nil
      p-cur =tag
      count nil
      step encode
      answer nil
      strategy angle
   =visual-location>
      isa visual-location
      screen-x =x
    < screen-x 500
      screen-y =y
      color red
   =visual>
      isa visual-object
      screen-pos =visual-location
   =retrieval>
      isa target
      loc-x =x
      loc-y =y
      aligned =aligned
      height =height
      side =side
   =imaginal>
      isa angle
      vertex =center-cam
      plane =plane-cam
      target nil
==>
   =goal>
      t-cur =aligned
      side =side
      height =height
      step move
   =imaginal>
      target =visual-location
   +retrieval>
      isa cardinal
      name =aligned
)

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;
;;  Productions for "moving" the angle image to the map view
;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; Retrieves "South" so that it's visual location can be encoded
;;  as the plane's initial location on the map
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(p move-angle-to-map-1
   =goal>
      isa trial
      height =height
    - height 0
    - height 4
      side =side
      t-cur =aligned
      p-cur =plane
      count nil
      step move
      answer nil
      strategy angle
   =visual-location>
      isa visual-location
    < screen-x 500
      color red
   =imaginal>
      isa angle
      vertex =center-cam
      plane =plane-cam
      target =target-cam
   =visual>
      isa visual-object
      value =target
   =retrieval>
      isa cardinal
      name =aligned
      loc-x =x
      loc-y =y
==>
   +visual-location>
      isa visual-location
      screen-x =x
      screen-y =y
   +retrieval>
      isa pnt
      side map
      loc-x =px
      loc-y =py
)

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; Encodes the plane's location as "s" in the angle. Retrieve's the
;;  map center chunk to update the vertex's location
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(p move-angle-to-map-2
   =goal>
      isa trial  
      height =height
    - height 0
    - height 4
      t-cur =aligned
      p-cur =plane
      count nil
      step move
      answer nil
      strategy angle
   =visual-location>
      isa visual-location
      screen-x =x
      screen-y =y
   =imaginal>
      isa angle
      vertex =center-cam
      plane =plane-cam
      target =target-cam
   =visual>
      isa visual-object
      value =target
   =retrieval>
      isa pnt
      side map
      loc-x =px
      loc-y =py
==>
   =imaginal>
      target =visual-location
   +visual-location>
      isa visual-location
      screen-x (within 720 750)
      screen-y (within 260 290)
   +retrieval>
      isa cardinal
      name "s"
)

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; Updates the vertex and retrieves the target's relative position on
;;  the map to update that.
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(p move-angle-to-map-3
   =goal>
      isa trial  
      height =height
    - height 0
    - height 4
      t-cur =aligned
      p-cur =plane
      count nil
      step move
      answer nil
      strategy angle
   =visual-location>
      isa visual-location
    < screen-x 750
    > screen-x 720
    < screen-y 290
    > screen-y 260
   =imaginal>
      isa angle
      vertex =center-cam
      plane =plane-cam
      target =target-map
   =visual>
      isa visual-object
      value =target
   =retrieval>
      isa cardinal
      name "s"
      loc-x =x
      loc-y =y
==>
   =imaginal>
      vertex =visual-location
   +visual-location>
      isa visual-location
      screen-x =x
      screen-y =y
   +retrieval>
      isa cardinal
      name =aligned
   =goal>
      step moved
)

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; Updates the last piece of the angle, and retrieves the information
;;  for setting the search parameters on the map view.
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(p finish-move-angle
   =goal>
      isa trial  
      t-cur =aligned
      p-cur =plane
      count nil
      step moved
      answer nil
      strategy angle
   =visual-location>
      isa visual-location
      screen-x =x
      screen-y =y
   =imaginal>
      isa angle
      vertex =center-cam
      plane =plane-map
      target =target-map
   =visual>
      isa visual-object
      value "o"
   =retrieval>
      isa cardinal
      name =aligned
==>
   =goal>
      step attend
   =imaginal>
      plane =visual-location
   +visual-location>
      isa visual-location
    > screen-x 500
      color red
)

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;
;;  Productions for finding the plane on the map view
;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; Retrieves the corresponding target information for the plane's
;;   location - angle strategy
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(p retrieve-plane-info-angle
   =goal>
      isa trial
      height =height
    - height 4
    - height 0
      side =side
      t-cur =aligned
      p-cur =plane
      count nil
      step attended
      answer nil
      strategy angle
   =visual-location>
      isa visual-location
    > screen-x 500
      color red
   =visual>
      isa visual-object
      value =direction
      screen-pos =visual-location
   =imaginal>
      isa angle
==>
   +retrieval>
      isa target
      aligned =direction
   =goal>
      step encode
      p-cur =direction
   =imaginal>
      plane =visual-location
   +visual-location>
      isa visual-location
      screen-x (within 720 750)
      screen-y (within 260 290)
)

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;
;;  Productions for processing the information in the map view
;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; Encodes the plane's location on the map
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(p encode-plane-search-info
   =goal>
      isa trial
      height =theight
    - height 0
    - height 4
      side =tside
      t-cur =aligned
      p-cur =plane
      count nil
      step encode
      answer nil
      strategy angle
   =visual-location>
      isa visual-location
    < screen-x 750
    > screen-x 720
    < screen-y 290
    > screen-y 260
   =imaginal>
      isa angle
      vertex =center-map
      plane =plane-map
      target =target-map
   =visual>
      isa visual-object
      value =plane
   =retrieval>
      isa target
      aligned =plane
      height =count
      side =side
==>
   =goal>
      height =count
      side =side
      step attend
   +retrieval>
      isa cardinal
      name =aligned
)

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; Finds the aligned target location on the map.
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(p locate-aligned
   =goal>
      isa trial
      height =height
      side =side
      t-cur =aligned
      p-cur =plane
      count nil
      step attended
      answer nil
      strategy angle
   =visual-location>
      isa visual-location
    < screen-x 750
    > screen-x 720
    < screen-y 290
    > screen-y 260
   =imaginal>
      isa angle
      vertex =center-map
      plane =plane-map
      target =target-map
   =visual>
      isa visual-object
      value "."
   =retrieval>
      isa cardinal
      name =aligned
      loc-x =x
      loc-y =y
==>
   +visual-location>
      isa visual-location
      screen-x =x
      screen-y =y
   =goal>
      step solve
)

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; Start search without adjusting search direction
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(p no-direction-change
   =goal>
      isa trial
      height =height
    > height 0
      side =side
      t-cur =aligned
      p-cur =plane
      count nil
      step solve
      answer nil
      strategy angle
   =visual-location>
      isa visual-location
      screen-x =x
      screen-y =y
   =imaginal>
      isa angle
      vertex =center-map
      plane =plane-map
      target =target-map
   =visual>
      isa visual-object
      value "."
   =retrieval>
      isa cardinal
      name =aligned
    > loc-y 200
      loc-x =x
      loc-y =y
      next-r =right
      next-l =left
==>
   =goal>
      count =side
      step search
)

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; Search direction must be changed (aligned location is NW, N, or NE).
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(p reverse-search-direction
   =goal>
      isa trial
      height =height
    > height 0
      side =side
      t-cur =aligned
      p-cur =plane
      count nil
      step solve
      answer nil
      strategy angle
   =visual-location>
      isa visual-location
      screen-x =x
      screen-y =y
   =imaginal>
      isa angle
      vertex =center-map
      plane =plane-map
      target =target-map
   =visual>
      isa visual-object
      value "."
   =retrieval>
      isa cardinal
      name =aligned
    < loc-y 200
      loc-x =x
      loc-y =y
      next-r =right
      next-l =left
==>
   +retrieval>
      isa side
      value =side
)

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; Completes reversal of search direction
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(p reverse-search-direction-2
   =goal>
      isa trial
      height =height
      side =side
      t-cur =aligned
      p-cur =plane
      count nil
      step solve
      answer nil
      strategy angle
   =visual-location>
      isa visual-location
      screen-x =x
      screen-y =y
   =imaginal>
      isa angle
      vertex =center-map
      plane =plane-map
      target =target-map
   =visual>
      isa visual-object
      value "."
   =retrieval>
      isa side
      value =side
      opposite =newside
==>
   =goal>
      side =newside
      count =side
      step search
   +retrieval>
      isa cardinal
      name =aligned
)

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; Identifies the next cardinal direction to the left.
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(p locate-next-left
   =goal>
      isa trial
    > height 0
    - side right
      t-cur =aligned
      p-cur =plane
      count =something
      step search
      answer nil
      strategy angle
   =visual-location>
      isa visual-location
      screen-x =x
      screen-y =y
   =imaginal>
      isa angle
      vertex =center-map
      plane =plane-map
      target =target-map
   =visual>
      isa visual-object
      value "."
   =retrieval>
      isa cardinal
      name =aligned
      next-l =next
      loc-x =x
      loc-y =y
==>
   +retrieval>
      isa cardinal
      name =next
   =goal>
      step update
)

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; Identifies the next cardinal direction to the right.
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(p locate-next-right
   =goal>
      isa trial
    > height 0
      side right
      t-cur =aligned
      p-cur =plane
      count =something
      step search
      answer nil
      strategy angle
   =visual-location>
      isa visual-location
      screen-x =x
      screen-y =y
   =imaginal>
      isa angle
      vertex =center-map
      plane =plane-map
      target =target-map
   =visual>
      isa visual-object
      value "."
   =retrieval>
      isa cardinal
      name =aligned
      next-r =next
      loc-x =x
      loc-y =y
==>
   +retrieval>
      isa cardinal
      name =next
   =goal>
      step update
)

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; Finds that direction's visual-location.
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(p find-new-location
   =goal>
      isa trial
    > height 0
      height =height
      side =side
      t-cur =aligned
      p-cur =plane
      count =something
      step update
      answer nil
      strategy angle
   =visual-location>
      isa visual-location
      screen-x =x
      screen-y =y
   =imaginal>
      isa angle
      vertex =center-map
      plane =plane-map
      target =target-map
   =visual>
      isa visual-object
      value "."
   =retrieval>
      isa cardinal
      name =next
    - name =aligned
    - loc-x =x
      loc-x =newx
      loc-y =newy
==>
   +visual-location>
      isa visual-location
      screen-x =newx
      screen-y =newy
)

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; Encodes that new location in the imagery buffer and increments
;;  the count.
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(p encode-new-location
   =goal>
      isa trial
    > height 0
      height =height
      side =side
      t-cur =aligned
      p-cur =plane
      count =something
      step update
      answer nil
      strategy angle
   =visual-location>
      isa visual-location
      screen-x =x
      screen-y =y
   =imaginal>
      isa angle
      vertex =center-map
      plane =plane-map
      target =target-map
   =visual>
      isa visual-object
      value "."
   =retrieval>
      isa cardinal
      name =new
    - name =aligned
      loc-x =x
      loc-y =y
==>
   !bind! =newdir (searchdir =something =new)
   =goal>
      height (!eval! (1- =height))
      count (!eval! (if (> (1- =height) 0) =something nil))
      t-cur =new
      side =newdir
      step search
   =imaginal>
      target =visual-location
   )

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; Shifts visual attention to the cardinal direction identified as
;;  the correct answer.
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(p attend-answer
   =goal>
      isa trial
      height 0
      height =height
      side =side
      t-cur =aligned
      p-cur =plane
      count nil
      step =step
    - step attend
      answer nil
      strategy angle
   =visual-location>
      isa visual-location
      screen-x =x
      screen-y =y
   =imaginal>
      isa angle
      vertex =center-map
      plane =plane-map
      target =target-map
   =visual>
      isa visual-object
      value "."
   =retrieval>
      isa cardinal
      name =aligned
      loc-x =x
      loc-y =y
==>
   =goal>
      step attend
   )

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; Retrieves the information about the correct response.
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(p encode-response-info
   =goal>
      isa trial
      height 0
      height =height
      side =side
      t-cur =aligned
      p-cur =plane
      count nil
      step attended
      answer nil
      strategy angle
   =visual-location>
      isa visual-location
      screen-x =x
      screen-y =y
   =imaginal>
      isa angle
      vertex =center-map
      plane =plane-map
      target =target-map
   =visual>
      isa visual-object
      value =aligned
   =retrieval>
      isa cardinal
      name =aligned
      loc-x =x
      loc-y =y
==>
   =goal>
      step respond
   +retrieval>
      isa key
      direction =aligned
)

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;
;;  Target at top or bottom
;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

(p target-top-or-bottom-1
   =goal>
      isa trial
      height =height
    - height 1
    - height 2
    - height 3
      side =side
      t-cur =aligned
      p-cur =plane
      count nil
      step move
      answer nil
      strategy angle
   =visual-location>
      isa visual-location
    < screen-x 500
      color red
   =imaginal>
      isa angle
      vertex =center-cam
      plane =plane-cam
      target =target-cam
   =visual>
      isa visual-object
      value =target
   =retrieval>
      isa cardinal
      name =aligned
      loc-x =x
      loc-y =y
==>
   +visual-location>
      isa visual-location
    > screen-x 500
      color red
   =goal>
      step attend
)

(p target-top-or-bottom-2
   =goal>
      isa trial
      height =height
    - height 1
    - height 2
    - height 3
      side =side
      t-cur =aligned
      p-cur =plane
      count nil
      step attended
      answer nil
      strategy angle
   =visual-location>
      isa visual-location
    > screen-x 500
      color red
   =imaginal>
      isa angle
      vertex =center-cam
      plane =plane-cam
      target =target-cam
   =visual>
      isa visual-object
      value =direction
   =retrieval>
      isa cardinal
      name =aligned
      loc-x =x
      loc-y =y
==>
   +retrieval>
      isa cardinal
      name =direction
   =goal>
      step move
)

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; If the target's location was at the bottom of the camera view
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(p target-at-bottom-angle
   =goal>
      isa trial
      t-cur "s"
      p-cur =tag
      count nil
      step move
      answer nil
      strategy angle
   =visual-location>
      isa visual-location
    > screen-x 500
      color red
   =visual>
      isa visual-object
      value =direction
      screen-pos =visual-location
   =retrieval>
      isa cardinal
      name =direction
   ==>
   =goal>
      step respond
   +retrieval>
      isa key
      direction =direction
)

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; If the target's location was at the top of the camera view (1)
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(p target-at-top-angle-1
   =goal>
      isa trial
      t-cur "n"
      p-cur =tag
      count nil
      step move
      answer nil
      strategy angle
   =visual-location>
      isa visual-location
    > screen-x 500
      color red
   =visual>
      isa visual-object
      value =direction
      screen-pos =visual-location
   =retrieval>
      isa cardinal
      name =aligned
==>
   =goal>
      step encode
   +retrieval>
      isa cardinal
      opposite =direction
)

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; If the target's location was at the top of the camera view (2)
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(p target-at-top-angle-2
   =goal>
      isa trial
      t-cur "n"
      p-cur =tag
      count nil
      step encode
      answer nil
      strategy angle
   =visual-location>
      isa visual-location
    > screen-x 500
      color red
   =visual>
      isa visual-object
      value =direction
      screen-pos =visual-location
   =retrieval>
      isa cardinal
      name =answer
      opposite ==direction
      loc-x =x
      loc-y =y
==>
   =goal>
      step attend
   +retrieval>
      isa key
      direction =answer
   +visual-location>
      isa visual-location
      screen-x =x
      screen-y =y
)




;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;
;;  Production Parameters
;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;
;;
      (spp change-search-direction :effort .2)     ;counting
      (spp reverse-search-direction-2 :effort .2)  ;rotation
;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;