$30
CS 402
Third Programming Assignment
This should be implemented in Racket
This program makes use of a “database” contained in a separate file called “Program-3-data.rkt”
which is posted under Files of the Canvas site for this course. This file should be input as an
external file into your program.
Write a function SET-ROBBIE-LOCATION which situates Robbie in some room in database by
updating a global variable LOC to that location.
Write a function CHOICES that takes the name of a room as input and returns the table of
permissib1e directions Robbie may take from that room. For exarrp1e, (CHOICES 'PANTRY)
should return the
list ((NORTH KITCHEN) (WEST DINING-ROOM)). Test your function to make sure it returns
the correct result.
Write a function LOOK that takes two inputs, a direction and a room, and tells where Robbie
would end up if he moved in that direction from that room. For example, (LOOK 'NOR1H
'PANTRY) should return KITCHEN. (LOOK 'WEST 'PANTRY) should return DININGROOM. (LOOK 'SOU1H 'PANTRY) should return NIL. Hint: The CHOICES function will be a
useful building block.
Write a function of no inputs called WHERE that tells where Robbie is. If he is in the library,
(WHERE) should say (ROBBIE IS UPSTAIRS IN THE LIBRARY). If he is in the kitchen, it
should say (ROBBIE IS DOWNSTAIRS IN THE KITCHEN). If he is on the front stairs, it
should say (ROBBIE IS ON THE FRONT-STAIRS).
Write a function MOVE that takes one input, a direction, and moves Robbie in that direction.
MOVE should make use of the LOOK function you wrote previously, and should call SETROBBIE LOCATION to move him. If Robbie can't move in the specified direction an
appropriate message should be returned. For example, if Robbie is in the pantry, (MOVE
'SOUTH) should return something like (OUCH! ROBBIE HIT A WALL). (MOVE 'NORTH)
should change Robbie's location and return (ROBBIE IS DOWNSTAIRS IN THE KITCHEN).
I will test your program in several ways. For example, starting from the pantry, take Robbie to
the library via the back stairs. Then take him to the kitchen, but do not lead him through the
downstairs bedroom on the way.
Finally, write a function called TRAVERSE that takes as input a current location and a
destination for Robbie and prints out the sequence of locations and directions needed for him to
traverse from the input location to the input destination. For example, a call to
(Traverse ‘pantry ‘living-room) might return ((GO NORTH TO KITCHEN) (GO WEST TO
DINING-ROOM) .. ) until a full path from the pantry to the living-room was specified.