Implement a simple maze generator and solver

Assignment Help Basic Computer Science
Reference no: EM132924355

Overview - Maze generator and solver

In this assignment, you are going to implement a simple maze generator and solver. Your program has two usages:

Generate maze usage: ./hw2 <maze file> <width> <height> [threshold = 0.5] [seed = 0] Solve maze usage: ./hw2 <maze file>

The first one will generate a maze with size <width> x <height> saved as a text file in <maze file> . [threshold] and [seed] are optional parameters for maze generation, which will be described in the program specification section. The second usage will solve the maze provided by <maze file> . Here are some sample runs to illustrate the idea.

Program Specification

Starter codes and Makefile
The main goal of this assignment is for you to practice breaking a program down into functions and modularizing your code. In the starter code, you will find the following files:

1. hw2.c is the main driver function; it checks and parses the command line arguments, and calls functions to complete the main logic.
2. print_functions.[c|h] is a module for all print-related functions.
3. maze.[c|h] is the maze module which provides all maze-related functionalities.

We also provide you with some maze files for testing your program. To start the project, you must provide the Makefile that compiles each source file into an object file and then links them together into a target called hw2 . [Note, your output program must be called hw2 . Otherwise, it may fail all the testing.]

Read the comments in the codes carefully to get a sense of what each function is supposed to do. Details are provided in the *.h files, but not the *.c files. Your task is to implement all the functions. You are free to create your own helper functions if necessary.

Maze generator

Generate maze usage: ./hw2 <maze file> <width> <height> [threshold = 0.5] [seed = 0]

To generate a maze, your program accepts at least 3 arguments: the output maze filename <maze file> , the maze width <width> , and the maze height <height> . It can accept two more optional arguments [threshold] and [seed] . When they are not provided, [threshold] and [seed] should have default values of 0.5 and 0 respectively. Your program should check that
<width> and <height> are positive integers. If they are invalid input, your program should terminate and return an error code -3 . You don't need to perform any input validation for [threshold] and [seed] . Finish the command line argument parsing logic in hw2.c for that.

Maze generation - genMaze

Your program should generate a maze of size <width> x <height> as follows [Note: you must follow this order to generate the expected results]:

1. Initialize a random seed with the argument [seed] . You can do this by calling
srand(seed) .
2. Use rand() to generate a start position (first generate at which column, then generate at which row) inside the interior of the maze. (i.e. the start position should not be at the
boundary walls.)
3. Do the same to generate a target ending position (first generate at which column, then generate at which row) inside the interior of the maze. (You don't need to check if start and target are the same.)
4. For each row of the maze

For each column of the maze
If it is on the boundary, set it to # Else if it is the start position, set it to @ Else if it is the end position, set it to <
Else generate a random number between 0 and 1, and check if it is greater than or equal to [threshold] . If so, set it to # ; otherwise, set it to (a space)

Your program is looking for a solution path connecting the start position @ to the target position
< without hitting or going through any wall # . In this homework, a path can only move in four directions: left, right, up, and down (not diagonally). Our functions are organized with a second maze representation ( char* sol ) to keep track of the solution path. This array mirrors the original maze array in many ways. The solution path can be found and established in the sol array using the below recursive search algorithm:

1. For each position in the solution maze ( sol ), mark them all as unvisited.

2. Given a position and a current path ( sol ), do the following:
If the position is the end target (in maze ), the current path is a solution path. Return true.
Else if it is a wall (in maze ), or it is already visited (in sol ), the current path is not a solution path. Return false.
Mark the current position as visited in sol .

Try to extend the path in each direction (in the order of left, right, up, down) and for each one, recursively perform Step 2 to check if a solution path can be found by moving to the neighbor in that direction. If a solution path is found from one of the neighbors, mark the position as a part of the solution path (in sol ), and immediately return true.
Otherwise, no solution path can be found. Return false.

Attachment:- Coding Homework.rar

Reference no: EM132924355

Questions Cloud

Calculate the net death benefit to be paid : The company paid a death benefit to the former employee's spouse in the amount of $50,000.00. Calculate the net death benefit to be paid
What is the minimum selling price on the special order : Fixed costs for the period were cost of goods sold $960,000, and selling and administrative expenses $244,000. What is the minimum selling price on the order
What is leadership aesthetics : What is leadership aesthetics and what is the concepts of leadership aesthetics?
Marketing campaign for local cheese : In order to protect the dairy farmers, the Canadian government has assured the provinces it will pay compensation to cheese producers, and that it will set up a
Implement a simple maze generator and solver : Maze generator and solver - Implement a simple maze generator and solver - generate a maze, your program accepts at least 3 arguments
Design for investigating the market for introducing : Curate a market research design for investigating the market for introducing healthier and plant-based ice cream alternatives.
Evaluating company vision and mission statement : 1. Find the mission statements of three different organizations, which can be business or not-for-profit.
Determine the appropriate bonus per hour for the workers : A production operation is making 150 units of a product by engaging five workers for 300 hours. However, 40 percent of the units appear to have various quality
Relationship between gender and leadership : Explain how goals and needs motivate people and what kinds of goals are likely to result in high performance.

Reviews

len2924355

6/23/2021 1:27:50 AM

I need help with a coding homework. The language is c. It is not long. I have some code for this assignment, but I just need help with a few parts.

Write a Review

Basic Computer Science Questions & Answers

  Identifies the cost of computer

identifies the cost of computer components to configure a computer system (including all peripheral devices where needed) for use in one of the following four situations:

  Input devices

Compare how the gestures data is generated and represented for interpretation in each of the following input devices. In your comparison, consider the data formats (radio waves, electrical signal, sound, etc.), device drivers, operating systems suppo..

  Cores on computer systems

Assignment : Cores on Computer Systems:  Differentiate between multiprocessor systems and many-core systems in terms of power efficiency, cost benefit analysis, instructions processing efficiency, and packaging form factors.

  Prepare an annual budget in an excel spreadsheet

Prepare working solutions in Excel that will manage the annual budget

  Write a research paper in relation to a software design

Research paper in relation to a Software Design related topic

  Describe the forest, domain, ou, and trust configuration

Describe the forest, domain, OU, and trust configuration for Bluesky. Include a chart or diagram of the current configuration. Currently Bluesky has a single domain and default OU structure.

  Construct a truth table for the boolean expression

Construct a truth table for the Boolean expressions ABC + A'B'C' ABC + AB'C' + A'B'C' A(BC' + B'C)

  Evaluate the cost of materials

Evaluate the cost of materials

  The marie simulator

Depending on how comfortable you are with using the MARIE simulator after reading

  What is the main advantage of using master pages

What is the main advantage of using master pages. Explain the purpose and advantage of using styles.

  Describe the three fundamental models of distributed systems

Explain the two approaches to packet delivery by the network layer in Distributed Systems. Describe the three fundamental models of Distributed Systems

  Distinguish between caching and buffering

Distinguish between caching and buffering The failure model defines the ways in which failure may occur in order to provide an understanding of the effects of failure. Give one type of failure with a brief description of the failure

Free Assignment Quote

Assured A++ Grade

Get guaranteed satisfaction & time on delivery in every assignment order you paid with us! We ensure premium quality solution document along with free turntin report!

All rights reserved! Copyrights ©2019-2020 ExpertsMind IT Educational Pvt Ltd