Skip to content

Instantly share code, notes, and snippets.

@yesidays
Created January 15, 2012 03:57
Show Gist options
  • Save yesidays/1614233 to your computer and use it in GitHub Desktop.
Save yesidays/1614233 to your computer and use it in GitHub Desktop.
code.jobs - Vacuum - Lisp
;;;; 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