On this page:
An A-Maze-ing Game
Challenges and Updates
6.6

Lab 9 Finding Your Way

lab!

Purpose: The purpose of this lab is to practice working with tree-structured data as well as mutually recursive data.

Textbook references: Chapter 19.1: Trees, Chapter 19.4 Designing with Intertwined Data, Chapter 20: Incremental Refinement

An A-Maze-ing Game

In this lab we will create a simple maze game. In this game you can see one room of the maze with up to four doors (up, down, left, and right). You can choose a door to go through by pressing any of the four arrow keys. If there is a door in that direction, you will then see the room that is in that direction. You cannot go back unfortunately, so be careful what you choose. Eventually you will end up in either a room where you win (hooray!) or a room where you lose (noooooo). Your TAs will helpfully demonstrate how this works.

Consider the following data definitions:
; A Maze is one of:
; - "you win"
; - "you lose"
; - Room
 
(define-struct room [up right down left])
; A Room is a (make-room MaybeDoor MaybeDoor MaybeDoor MaybeDoor)
; representing a room with four possible doors (in the up, right, down, and left directions)
 
; A MaybeDoor is one of:
; - #false (representing the fact that there is no door here)
; - Maze (representing a door to more of the maze)

Exercise 1 Complete the steps of the data design recipe for the given data definitions. When designing with intertwined data, following the template is essential so that you don’t get lost.

Exercise 2 Define some constants to represent the things that are not changing in the game.

Exercise 3 Design the game! What handlers might you need? How can you draw the rooms such that it is clear where the doors are? How will you know when to stop the game?

Exercise 4 Design a function which generates a random maze of a certain maximum depth. You can use this to play the game without knowing which ways will let you win or lose! WARNING: This function may generate mazes with "dead ends" (rooms with no doors). How can you update your program to account for this?

Challenges and Updates

Exercise 5 Design a function which generates a random maze that has at least one winning room, so you can feel good about yourself. The maze should still be able to have losing rooms as well, to provide you with a bit of a challenge.

Exercise 6 Update your maze game so that rooms can have a treasure inside. The treasure contains some number of coins and at the end of the maze you show the user how much treasure they collected. Update your random maze generator to work for your new data definitions.

Exercise 7 Update your maze game so that doors can be locked. You can only unlock a door if you have a key. Rooms may randomly contain a key in addition to, or in place of, treasure. All the locks on the doors are the same, but the key is very old so it breaks after one use. Therefore, if you encounter another locked door, you will need another key.

Exercise 8 Update your maze game so that the user can go backwards as well as forwards. That way if they come to a dead end they can just reverse and go a different way.