; Define a Lisp structure, which is much like an object, called ; silly-vacuum agent. ; Programmed by Dave Musicant (defstruct (silly-vacuum-agent ; Inherit all properties from a pre-existing structure called 'agent' (:include agent ; Override a variable named 'program' from the 'agent' ; structure so that it will point to the new function we'll create (program ; Define an 'instance variable' called non-moves, ; that will persist over multiple function calls (let ((num-moves 0)) ; Define a function that takes a list of percepts as a parameter #'(lambda (percept) ; --- DON'T CHANGE ANY OF THE ABOVE CODE, WITH THE EXCEPTION ; --- OF THE 'LET' STATEMENT AND THE NAME AT THE TOP. ; --- CHANGE CODE BELOW AS YOU PLEASE. ; Pause for keyboard input so the program doesn't scoll like mad. (read-line) ; Separate the percepts for easier processing. (setf bump (first percept)) (setf dirt (second percept)) (setf home (third percept)) ; Proceed around the board, stopping when reach home, assuming ; you actually went somewhere. (if (and home (> num-moves 2)) 'shut-off (progn (setf num-moves (+ 1 num-moves)) (cond (dirt 'suck) (bump '(turn right)) (t 'forward))))))))))