Created
January 15, 2012 03:57
-
-
Save yesidays/1614233 to your computer and use it in GitHub Desktop.
code.jobs - Vacuum - Lisp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
;;;; Vacuum world | |
(defstructure (random-vacuum-agent | |
(:include agent | |
(program | |
#'(lambda (percept) | |
(declare (ignore percept)) | |
(random-element | |
'(suck forward (turn right) (turn left) shut-off)))))) | |
"A very stupid agent: ignore percept and choose a random action.") | |
(defstructure (reactive-vacuum-agent | |
(:include agent | |
(program | |
#'(lambda (percept) | |
(destructuring-bind (bump dirt home) percept | |
(cond (dirt 'suck) | |
(home (random-element '(shut-off forward (turn right)))) | |
(bump (random-element '((turn right) (turn left)))) | |
(t (random-element '(forward forward forward | |
(turn right) (turn left)))))))))) | |
"When you bump, turn randomly; otherwise mostly go forward, but | |
occasionally turn. Always suck when there is dirt.") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment