;;; ************************************* ;;; Here are some world definitions. Each goes as ;;; a the CSPEC argument to the MAKE-GARBAGE-ENVIRONMENT command (defvar *high-density-stuff*) (setf *high-density-stuff* '((at all (p 0.5 garbage)) (at all (p 0.5 paper)) (* 4 recycle-bin) (* 8 garbage-can))) ;;; Careful.... this requires a grid of at least (10x10) (defvar *bins-at-corners*) (setf *bins-at-corners* '((at all (p 0.25 garbage)) (at all (p 0.25 paper)) (at (and (1 1) (8 8) (8 1) (1 8)) recycle-bin) (at (and (1 1) (8 8) (8 1) (1 8)) garbage-can))) ;;;************************************************************* ;;; The first agent can count but can't remember anything else. ;;; It goes for five steps then halts. Before that it moves ;;; kind of randomly. (defstruct (cga (:include garbage-agent (program 'counting-gap))) (count 0)) (defun counting-gap (me percept) (declare (ignore percept)) (cond ((> (cga-count me) 5) '(halt)) (T (incf (cga-count me)) (move-randomly)))) (defun cga-test (&key (cspec *high-density-stuff*)) (setf *env* (make-garbage-environment :size (@ 10 10) :aspec '(cga) :cspec cspec)) (run-environment *env*)) (defun move-randomly () (let ((moves '(forward forward forward (turn right) (turn left)))) (nth (random (length moves)) moves))) ;;;*********************************************************** ;;; Here's an agent that picks up garbage and paper whenever it ;;; can. Also, when it is carrying paper and there's a recycle ;;; bin, or when it is carrying garbage and there's a garbage can, ;;; put it in. It never stops..... (defstruct (hga (:include garbage-agent (program 'holding-gap))) (holdings '())) (defun holding-gap (me percept) (let ((my-location (first percept)) (my-heading (second percept)) (stuff (third percept)) (bump (fourth percept))) (declare (ignore my-location my-heading bump)) (let ((loose-paper (find-if 'paper-p stuff)) (loose-garbage (find-if 'garbage-p stuff)) (held-paper (find-if 'paper-p (hga-holdings me))) (held-garbage (find-if 'garbage-p (hga-holdings me))) (bins (find-if 'recycle-bin-p stuff)) (cans (find-if 'garbage-can-p stuff))) (cond ((and held-paper bins) (setf (hga-holdings me) (delete held-paper (hga-holdings me))) `(put-in ,held-paper ,bins)) ((and held-garbage cans) (setf (hga-holdings me) (delete held-garbage (hga-holdings me))) `(put-in ,held-garbage ,cans)) (loose-paper (push loose-paper (hga-holdings me)) `(grab ,loose-paper)) (loose-garbage (push loose-garbage (hga-holdings me)) `(grab ,loose-garbage)) (T (move-randomly)))))) (defun hga-test (&key (size (@ 5 5)) (cspec *high-density-stuff*)) (setf *env* (make-garbage-environment :size size :aspec '(hga) :cspec cspec)) (run-environment *env*)) (defun hga-test-2 () (hga-test :size (@ 10 10) :cspec *bins-at-corners*))