 (defun add-plants ()
   (apply 'random-plant evolution-jungle-rectangle)
   (random-plant 0 0 evolution-width evolution-height))
-
-(defstruct animal x y energy dir genes)
 
 (defun move (animal)
   (let ((dir (animal-dir animal))

        (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 animal-color (a)
  (let ((color (max a 255)))
    (format "#00%X00" color)))

(defun draw-world ()
  (erase-buffer)
  (loop for y
        below evolution-height
        do (progn (newline)
                  (insertc "|" evolution-fence-color nil)
                  (loop for x
                        below evolution-width
                        do (cond ((some (lambda (animal)
                                          (and (= (animal-x animal) x)
                                               (= (animal-y animal) y)))
                                        evolution-animals)
                                  (insertc "m" (animal-color animal) nil))
                                 ((gethash (cons x y) evolution-plants)
                                  (insertc "*" "green" nil))
                                 (t (insertc " " "darkgrey" nil))))
                  (insertc "|" evolution-fence-color nil)))
  (newline)
  (insert (format "Animals: %d -- Plants: %d"
                  (length evolution-animals)
                  (hash-table-count evolution-plants)
                  0))
  (redisplay t))

(defun evolution-start ()
  (interactive)
  (let ((inhibit-read-only t))
    (draw-world)
    (newline)
    (let ((str (read-string "Steps (or 'quit'): ")))
      (cond ((equal str "quit") ())
            (t (let ((x (string-to-int str)))

                     :genes  (loop repeat 8
                                   collecting (1+ (random 10))))))

;; major mode things
(defun evolution ()
  "Starts the evolution game."
  (interactive)
  (switch-to-buffer "*evolution-game*")
  (evolution-mode)
