As the player walks through the maze, she can collect two items. When the player enters a cave, she may pick up the item, if one of the pockets is empty or exchange one of the two items for the item in the cave. Once the player is happy with the state of the items, she moves on by choosing one of the exits out of the cave. The game is over when the player exits the maze.
Task 2 Define the function create-player, which accepts a cave and creates a player who is in that cave and with nothing (empty) in their pockets. You will also need the functions player-left-pocket, player-right-pocket, and player-current-cave. Then define the function swap-items, which accepts a player, a cave (if you like), and one of the symbols'left
, 'right
.
It swaps the item (or empty
) in the indicated
pocket with the item in the cave.
Swap-items has no (useful) return value.
The walk is simulated with a simple generative recursive program. It prints a question and reads a typed response from the keyboard. The response is one of a pre-determined number of symbols: 'show-pockets, 'show-exits, 'swap-left, 'swap-right and 'leave. In the latter case, the program asks one more question which must be answered with a number. It then selects the exit from the current cave with this number and moves the player to this next cave.
Task 3 Implement the dialogue. You may use the following functions:
Here is a sample dialogue:
You entered the cave LovettHall. It contains water. What would you like to do next? swap-left You just put down shoes and picked up water. What would you like to do next? swap-right You just put down bread and picked up shoes. What would you like to do next? show-pockets You own water in the left and shoes in the right pocket. What would you like to do next? leave There are 5 exits. Which one would you like to take? 3 ...(A better dialogue might list the names of the five exits.)
(printf "You entered the cave ~s. It contains ~s.~n" 'LovettHall 'water)
End of Problem
This problem is open-ended and
flexible. The design of the dialogue is up to you. You are in
control of how you output descriptions of items, caves, or
connections, if you choose to do so.
It may be a simple text-based dialogue as above.
It is acceptable to implement the minimum
described above, but don't feel constrained by this standard;
if you implement more, tell us.
Be creative!
The Royal Jailer has a curious habit: Every evening, she turns the key in every door---numbers 1 through 150. Then, she goes back and turns the key in every other door---numbers 2, 4, 6, ..., 150. Then, she goes back and turns the key in every third door---numbers 3, 6, 9, ..., 150. Then, she turns the key in every fourth door---numbers 4, 8, 12, ..., 148. And so on, until she finishes by turning the key in every 150th door (just number 150). After that, she falls asleep, and anybody in an unlocked cell can escape during the night. (At the start of the evening, all cells are locked.)
You and your friends have been framed, and falsely convicted of Meandering with Intent to Jay-walk, and are scheduled to be executed at dawn. Fortunately, each of you can name which cell to be locked away in. Which cell numbers do you-all ask for?
Hints: