CS 241 Data Organization using C
Lab 5: Turning arrays into graphs
September 20, 2018
The purpose of lab today is to get you familiar with the data representation for
homework four and to work on arrays in C.
1 Getting Started
Download the https://www.cs.unm.edu/~vasek/cs241/hw/mazegeneration.py
file. We’re going to be making mazes today!
To run the code, use the following command.
python mazegeneration.py SIDELENGTH
In addition, download the maze.c file off the lab directory on the course website.
You’ll need to edit it before it can be compiled.
2 Creating some test cases
Run the python script a number of times using the >> command to append the mazes
to the end of a file. Your file should be called testmaze.in.
Then, edit at least one to be a valid maze, but not have a path from top left to
bottom right.
3 Writing some code
- Think about how big your double array needs to be in order to hold the
first maze you created. Make your array that large.
- Write the readInMaze function to read in one maze from standard in (using
the getchar function).
- Think about how to access the cells in the array. Write some code in your
main method (after you read in the maze) that plays around with once
you’re at a cell, determining if it can go north/east/south/west.
4 More time?
- Write some functions for your cell access. What would you write and how
would you incorporate this into a maze solver?
- Flesh out the printmaze function.
- Think about how your variables/functions change when your maze size
changes. You will want one double array of a static size for everything.
Given that the largest maze you need to handle is 40x40 cells, how large
should your double array be? What character could you use to delimit
what is valid or not in your current working maze?
- Write a function that determines if your maze is valid. What sorts of things
should you be looking for?
5 Turning in your program
It’s ok not to finish this assignment – get through as much as you can.
Zip up your maze.c file along with your testmaze.in file into a zip file entitled
yourCSUsername.zip. Then drop the zip file into the dropbox under the lab-05
folder..