Solving a Maze Programming Assignment, Assignments of Computer Science

A programming assignment where students are required to write a program to solve a maze represented as a two-dimensional array of characters. An example data structure, input format, and sub-procedures for loading, displaying, and solving the maze. The assignment includes instructions for displaying the maze array and finding a path through the maze.

Typology: Assignments

Pre 2010

Uploaded on 08/18/2009

koofers-user-08c
koofers-user-08c 🇺🇸

10 documents

1 / 2

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
CSC 145 - Programming Assignment 7: Solving a Maze
In this programming exercise you are to write a program to solve a maze represented as a rectangular two-
dimensional array of characters. Your program should display the maze array in its original form and then
with the solution path included.
Data Structure - You should create global variables to hold a maze array of up to 50 rows by 50 columns,
the start position, finish position and current position in the maze. An example data structure is shown
below:
TYPE Mazetype IS ARRAY(1..50,1..50) OF Character;
TYPE Position IS RECORD -- a structured data type to hold the row
Row : Integer; -- and column of a position in the maze
Col : Integer;
END RECORD;
Maze : Mazetype; -- rectangular array of size 50 x 50
Nrow,Ncol : Integer; -- actual size of maze array currently loaded
Start : Position; -- start position in maze
Finish : Position; -- finish or goal position in maze
This data structure is provided as an example only. You may use any appropriate structure in your program.
For example you might choose to represent positions start and finish as integer pairs rather than record
types.
Input - Your program should ask the user for the name of the file containing the maze description and then
load the maze array and other variables using the data in the specified text file. The format of the maze text
file is shown in the example below:
10 10 2 1 9 10 # of rows, # of columns, Start.Row, Start.Col, Finish.Row, Finish.Col
**********
* '*'= wall
**** *** * ' '=passage
* * *
* ** *** *
* * * *
**** * * *
* ** * ***
* *
**********
The first row of the maze text file contains numbers giving the size of the maze array, the starting position
and the finish position. Write a sub-procedure that reads the maze text file and loads the data into main
memory.
Display - Write a sub-procedure that displays the maze array on the monitor. Your display will be more
appealing if you include an extra blank after each maze character in the display. This is because the spacing
between characters is less than the spacing between rows.
********** * * * * * * * * * *
* *
**** *** * * * * * * * * *
* * * * * *
* ** *** * * * * * * * *
* * * * * * * *
pf2

Partial preview of the text

Download Solving a Maze Programming Assignment and more Assignments Computer Science in PDF only on Docsity!

CSC 145 - Programming Assignment 7: Solving a Maze

In this programming exercise you are to write a program to solve a maze represented as a rectangular two-

dimensional array of characters. Your program should display the maze array in its original form and then

with the solution path included.

Data Structure - You should create global variables to hold a maze array of up to 50 rows by 50 columns,

the start position, finish position and current position in the maze. An example data structure is shown

below:

TYPE Mazetype IS ARRAY(1..50,1..50) OF Character; TYPE Position IS RECORD -- a structured data type to hold the row Row : Integer; -- and column of a position in the maze Col : Integer; END RECORD; Maze : Mazetype; -- rectangular array of size 50 x 50 Nrow,Ncol : Integer; -- actual size of maze array currently loaded Start : Position; -- start position in maze Finish : Position; -- finish or goal position in maze

This data structure is provided as an example only. You may use any appropriate structure in your program.

For example you might choose to represent positions start and finish as integer pairs rather than record

types.

Input - Your program should ask the user for the name of the file containing the maze description and then

load the maze array and other variables using the data in the specified text file. The format of the maze text

file is shown in the example below:

10 10 2 1 9 10 # of rows, # of columns, Start.Row, Start.Col, Finish.Row, Finish.Col

  • '*'= wall **** *** * ' '=passage






The first row of the maze text file contains numbers giving the size of the maze array, the starting position

and the finish position. Write a sub-procedure that reads the maze text file and loads the data into main

memory.

Display - Write a sub-procedure that displays the maze array on the monitor. Your display will be more

appealing if you include an extra blank after each maze character in the display. This is because the spacing

between characters is less than the spacing between rows.

Processing - In order to find a path through the maze you need to set the current position Curpos to the

start location and move along passages until the goal or finish position is reached. Using the data structure

defined above your maze solving sub-procedure should be similar to the following example:

PROCEDURE Solve_Maze IS BEGIN Curpos:=Start; LOOP Record_Current_Position(Curpos); EXIT WHEN Curpos=Finish; Choose_Direction_To_Move(Dir); Move(Dir,Curpos); END LOOP; END Solve_Maze;

The main procedure for this program should contain only calls to subprograms.

BEGIN --main program Load_Maze; Show_Maze; Solve_Maze; Show_Path; END Amaze;

Output - You are free to use graphical or text output in your program. You may make the program display

the solution as it is being constructed or wait until a solution is found. Your solution may be in the form of a

display of the maze with the path shown or you may output the sequence of moves as a string of characters.

For example, the solution to the sample maze is path = "RRRRDDDDRRDDDRRR", where R = right, L =

left, U = up and D = down. You can also display the solution as special symbols in the maze itself.

Due Dates :

April 23 A listing of your program with the load_maze and show_maze sub-procedures only.

A copy of the output of your program for "maze1.dat"

April 30 A listing of the completed program.

An example output using the test file "maze2.dat"