Skip to content

Instantly share code, notes, and snippets.

@yesidays
Created January 15, 2012 04:00
Show Gist options
  • Save yesidays/1614240 to your computer and use it in GitHub Desktop.
Save yesidays/1614240 to your computer and use it in GitHub Desktop.
code.jobs - Wumpus - Lisp
;;;; Agents for the wumpus world
(defstructure (wumpus-agent (:include agent (body (make-wumpus-agent-body))))
"The default wumpus agent gets an arrow.")
(defstructure (random-wumpus-agent
(:include wumpus-agent
(program
#'(lambda (percept)
(declare (ignore percept))
(random-element '(forward (turn right) (turn left) shoot grab
release climb)))))))
(defstruct (aimless-wumpus-agent
(:include wumpus-agent
(program
(let ((plan nil)
(wumpus-alive? t))
#'(lambda (percept)
(destructuring-bind (stench breeze glitter bump sound) percept
(when sound
(setf wumpus-alive? nil))
(cond (glitter 'grab)
(bump (setf plan '((turn right) (turn right) forward))
(pop plan))
(plan (pop plan))
((or breeze (and wumpus-alive? stench))
(setf plan (list (random-element '((turn left) (turn right)))
'forward))
(pop plan))
(t (random-element '(forward forward (turn right)
(turn left)))))))))))
"This agent does the obvious reactive things: grab when there's a glitter,
and turn and move when there's a bump. If the wumpus is alive and
there's a stench, it turns and moves. Otherwise it wanders aimlessly.")
@matiussmith12
Copy link

How do you start this game?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment