                   (cond ((and (>= dir 2) (<= dir 4)) 1)
                         ((or (= dir 1) (= dir 5)) 0)
                         (t -1))
-                  *width*)
-               *width*))
+                  evolution-width)
+               evolution-width))
 
     (setf (animal-y animal)
           (mod (+ y
                   (cond ((and (>= dir 1) (<= dir 2)) -1)
                         ((or (= dir 3) (= dir 7)) 0)
                         (t 1))
-                  *height*)
-               *height*))
+                  evolution-height)
+               evolution-height))
 
     (decf (animal-energy animal))))
 

;; evolution.el -- the evolution demo, ported to EmacsLisp

(defun evolution ()
  (interactive)
  (switch-to-buffer "*evolution*")


(defun eat (animal)
  (let ((pos (cons (animal-x animal) (animal-y animal))))
    (when (gethash pos evolution-plants)
      (incf (animal-energy animal) evolution-plant-energy)
      (remhash pos evolution-plants))))

(defun reproduce (animal)
  (let ((e (animal-energy animal)))
    (when (>= e evolution-reproduction-energy)
      (setf (animal-energy animal) (ash e -1))
      (let ((animal-nu (copy-animal animal))
            (genes     (copy-list (animal-genes animal)))
            (mutation (random 8)))
        (setf (nth mutation genes) (max 1 (+ (nth mutation genes) (random 3) -1)))
        (setf (animal-genes animal) genes)
        (push animal-nu evolution-animals)))))

(defun update-world ()
  (setf evolution-animals (remove-if (lambda (animal)
                               (<= (animal-energy animal) 0))
                             evolution-animals))
  (mapc (lambda (animal)
          (turn animal)
          (move animal)
          (eat animal)
          (reproduce animal))
        evolution-animals)
  (add-plants))

(defun draw-world ()
  (erase-buffer)
  (loop for y
        below evolution-height
        do (progn (newline)
                  (insertc "|" "green" nil)
                  (loop for x
                        below evolution-width
                        do (insert (cond ((some (lambda (animal)
                                                  (and (= (animal-x animal) x)
                                                       (= (animal-y animal) y)))
                                                evolution-animals)
                                          ?M )
                                         ((gethash (cons x y) evolution-plants) ?\* )
                                         (t ?\s ))))
                  (insertc "|" "green" nil)))
  (redisplay t))

(defun evolution ()
  (interactive)
