Content
4.lispzzi 1 5 (ql:quickload "croatoan" ) (in-package :croatoan) it Example from "Land of Lisp", Copyright by Conrad Barski. ; Source: http: landoflisp.comevolution. lisp ;; Unknown licence. 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 (defparameter width 100) (defparameter height 30) (defparameter jungle ‘ (45 10 10 10)) (defparameter plant-energy 80) (defparameter plants (make-hash-table :test ‘equal)) (defparameter reproduction-energy 200) (defstruct animal x y energy dir genes) (defun random-plant (left top width height) (let ((pos (cons ( left (random width)) ( top (random height))))) (setf (gethash pos plants) t))) (defun add-plants () First one in the jungle. (apply ‘random-plant jungle) it Then one in the rest of the world. (random-plant 0 0 width height)) ;; Define one starting animal. (defparameter animals (list (make-animal : (ash width -1) :y (ash height -1) :energy 1000 :dir B genes (loop repeat 8 collect (1 (random 10)))))) (defun move- (animal) (let ((dir (animal-dir animal)) ( (animal x animal)) (y (animal-y animal))) it If xwidth, wrap around the world border with the mod function. (set (animal-x animal) (mod ( (cond ( (and ( dir 2) ( dir 5)) 1) ((or ( dir 1) ( dir 5)) 0) (t -1)) width) width)) 84.lisp 1:0 Top LE UTF-8 Lisp