proj3b - CS 61A A6a. Project 3 solutions (Part II) First...

Info iconThis preview shows pages 1–3. Sign up to view the full content.

View Full Document Right Arrow Icon
CS 61A Project 3 solutions (Part II) A6a. First the easy parts: ;;; make a jail-house. Since we give it no neighbors, there will be no ;;; entrances or exits (define jail (instantiate place 'sing-sing)) ;;; make a GO-DIRECTLY-TO method ;;; insert this into the definition of the PERSON class (method (go-directly-to new-place) (announce-move name place new-place) (for-each (lambda (p) (ask place 'gone p) (ask new-place 'appear p)) possessions) (ask place 'exit self) (set! place new-place) (ask new-place 'enter self)) ;; Notes on the above: The part about possessions isn't really ;; relevant for the thief who's been arrested, but we might use ;; this method for other people in other circumstances. Since the ;; existing GO method does all of this plus more, you might choose ;; to rewrite that method so that it says ;; (ask self 'go-directly-to new-place) ;; instead of the stuff I've duplicated here. (That is, have the ;; old method invoke the new method.) A6b. We just explicitly check for no exits before the thief tries to choose one: (define-class (thief name initial-place) ... (method (notice person) (if (eq? behavior 'run) (LET ((EXITS (ASK (USUAL 'PLACE) 'EXITS))) (IF (NOT (NULL? EXITS)) (ASK SELF 'GO (PICK-RANDOM EXITS)))) (let ((food-things (filter (lambda (thing) (and (edible? thing) (not (eq? (ask thing 'possessor) self)))) (ask (usual 'place) 'things)))) (if (not (null? food-things)) (begin (ask self 'take (car food-things)) (set! behavior 'run) (ask self 'notice person)) )))) ) A7a. Give people money.
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
(define-class (person name place) (instance-vars
Background image of page 2
Image of page 3
This is the end of the preview. Sign up to access the rest of the document.

This note was uploaded on 01/15/2011 for the course CS 61A taught by Professor Harvey during the Spring '08 term at University of California, Berkeley.

Page1 / 5

proj3b - CS 61A A6a. Project 3 solutions (Part II) First...

This preview shows document pages 1 - 3. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online