/* Spamventure! */ %% starter file by Ran Libeskind-Hadas %% and modified by Z Dodds /* Comments on your game should go here -- including how to "solve" it -- and anything else the graders should know (extras) */ % some "nice" prolog settings... see assignment 8's % description for the details on what these do % -- but it's not crucial to know the details of these Prolog internals :- set_prolog_flag( prompt_alternatives_on, groundness ). :- set_prolog_flag(toplevel_print_options, [quoted(true), portray(true), attributes(portray), max_depth(999), priority(699)]). %% thing_at(X, Y) will be true iff thing X is at location Y. %% player_at(X) will be true iff player is at location X. %% The use of dynamic should be at the beginning of the file when %% we plan to mix static and dynamic facts with the same names. :- dynamic thing_at/2, player_at/1. %% The player is initially at Jacobs player_at(jacobs). %% thing_at(X, Y) is true iff thing X is at location Y. %% note that the key is not described at jacobs and %% the spam is described along with west_dorm %% both of these are problems -- you might start by considering %% how you might fix them... (see west_dorm for a similar note) thing_at(key, jacobs). thing_at(spam, west_dorm). %% path(X, Y, Z) is true iff there is a path from X to Z via direction Y. path(jacobs, north, parsons). path(jacobs, east, west_dorm). path(parsons, east, platt). path(parsons, south, jacobs). path(platt, west, parsons). path(platt, south, west_dorm). path(west_dorm, north, platt). path(west_dorm, west, jacobs). %% This is how one can take an object. take(X) :- thing_at(X, in_hand), nl, write('You are already holding that.'), nl. /* new line */ take(X) :- player_at(Place), thing_at(X, Place), retract(thing_at(X, Place)), assert(thing_at(X, in_hand)), nl, write('OK you now have '), write(X), nl. %% This is how we move. north :- go(north). south :- go(south). east :- go(east). west :- go(west). go(Direction) :- player_at(Here), path(Here, Direction, There), retract(player_at(Here)), assert(player_at(There)), nl, write('OK, you are now walking to '), write(There), nl, look. go(Direction) :- player_at(Here), \+path(Here, Direction, _), write('You cannot go that way.'), nl. %% The predicates used to describe a place look :- nl, player_at(Place), describe(Place), nl. describe(jacobs) :- write('You are in Jacobs building in CS 60.'), nl, write('The prof is talking about Prolog.'), nl, write('Prolog is so much fun!'). describe(parsons) :- write('You are in the Parsons building.'), nl, write('There are engineers here.'), nl, write('One of them wants a fourier transform --'), nl, write('and wants it fast!'). describe(platt) :- write('You are in Platt.'), nl, write('Jays Place has good pizza.'). %% notice that there is a problem here... %% the can of spam is described in the description %% of West dorm - but this means that it will %% still be present in the description even %% after being picked up! %% %% this may be a good thing to fix to get you started! %% describe(west_dorm) :- write('You are at West Dorm.'), nl, write('It is probably best not to describe this place.'), nl, write('There is a can of Spam at your feet!'). %% The predicates used to start the game %% You should customize these instructions to reveal %% the object of your adventure along with any special %% commands the user might need to know. start :- instructions, look. instructions :- nl, write('Welcome to Spamventure!'), nl, write('Type east, west, north, or south to move.'), nl, write('Type take(item) to take item.'), nl.