;;; MASSACHUSETTS INSTITUTE OF TECHNOLOGY ;;; Department of Electrical Engineering and Computer Science ;;; 6.001---Structure and Interpretation of Computer Programs ;;; Fall Semester, 1997 ;;; Problem Set 6 ;;; ;;; Code file WORLD.SCM ;;;============================================================================ ;;; You can extend this file to make more stuff part of your world. ;;;============================================================================ ;;;============================================================================ ;;; *CAVEAT* To keep your world consistent, whenever you change a procedure or ;;; redefine a person/place/etc you should reload this entire file ;;; into Scheme. This prevents you from having old-moldy folks running ;;; around who have not evolved to adhere to your modifications. To ;;; make this work out well, you should create little scripts at the ;;; end of this file to make the game evolve as you work through it. ;;; [See the bottom of this file for an example.] ;;;============================================================================ (define *ALL-BUILDINGS* '()) (Define (clear-buildings!) (set! *ALL-BUILDINGS* '())) (define (add-building! location) (set! *ALL-BUILDINGS* (cons location *ALL-BUILDINGS*))) (initialize-clock-list) (clear-buildings!) ;; Here we define the places in our world... ;;------------------------------------------ (define (make&install-building name) ; Buildings are places we can drive to! (let ((dest (make&install-place name))) (add-building! dest) dest)) (define EGG-Atrium (make&install-building 'EGG-Atrium)) (define Building-36 (make&install-building 'Building-36)) (define Tech-Square (make&install-building 'Tech-Square)) (define dormitory (make&install-building 'dormitory)) (define dungeon (make&install-place 'dungeon)) (define computer-lab (make&install-place 'computer-lab)) (define eric-office (make&install-place 'eric-office)) (define jim-office (make&install-place 'jim-office)) ;; - WORLD - 1 - ;; The following isolated place is defined in GAME.SCM too but redefined ;; here so you can just "zap" altered definitions there then re-evaluate this ;; file w/o worrying about forgetting to update any places. ;; ;; Consequently, to be consistent, if you find it appropriate to define any new ;; places in GAME.SCM, you should likewise duplicate their definitions here. (define heaven (make&install-place 'heaven)) ; The point of no return ;; One-way paths connect individual places in the world. ;;------------------------------------------------------ (define (can-go from direction to) (ask from 'add-neighbor direction to)) (define (can-go-both-ways from direction reverse-direction to) (can-go from direction to) (can-go to reverse-direction from)) (can-go-both-ways Building-36 'up 'down computer-lab) (can-go-both-ways Building-36 'north 'south Tech-Square) (can-go-both-ways Building-36 'west 'east EGG-Atrium) (can-go-both-ways Tech-Square 'up 'down jim-office) (can-go-both-ways jim-office 'up 'down eric-office) (can-go-both-ways dormitory 'west 'east Building-36) (can-go dungeon 'up EGG-Atrium) ;; The important critters in our world... ;;--------------------------------------- (define eric (make&install-person 'eric eric-office 3)) (define jim (make&install-person 'jim jim-office 2)) (define grendel (make&install-troll 'grendel dungeon 4)) ;; The beginning of an ever-expanding game script ;;------------------------------------------------ (define (play-game) (ask jim 'go 'up) ; Jim meets Eric ) ;; ...now whenever you re-load this file, you can bring things up to ;; date by invoking PLAY-GAME. ;; - WORLD - 2 -