Created
January 15, 2012 04:00
-
-
Save yesidays/1614240 to your computer and use it in GitHub Desktop.
code.jobs - Wumpus - 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
;;;; 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.") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
How do you start this game?