Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Program needs to be created in C please. Type out answer aswell to avoid iledgiable writing. Thank you. Basic requirements Create a C program that

Program needs to be created in C please. Type out answer aswell to avoid iledgiable writing. Thank you.

Basic requirements

Create a C program that will show a maze in the terminal window and will show a mouse walking through the maze attempting to locate the exit door (the cheese).

The maze is a rectangle. There is a wall of X's that mark the enclosing four walls of the maze. On the left vertical wall there is an opening which is the entrance. On the right vertical wall there is an opening that is the exit. There are no openings in the walls except these two. The interior of the maze is filled with X's and blanks. The mouse walks on the blanks and is not allowed to step on X's.

The mouse can move in any of the four directions (North, East, South, West) one step at a time provided the destination cell is not blocked. The mouse cannot move in a diagonal direction. Each time the mouse takes one step he turns back and places a mark on the cell where he was. That means he is marking his trail. A marked cell is not blocked, and so, the mouse may re-travel over marked cells in the future if necessary.

The inputs to this game (maybe we should call it a simulation) are these.

== Density (what percent of the interior is filled with X's)

== Delay (what is the time interval between each step taken by the mouse)

This is a slow mouse. He pauses between step. The user will set how much time the mouse spends thinking between each step.

A maze can have a density of 0%. In that case the interior of the rectangle has no walls. If a maze has a density of 90% then 90% of the interior of the maze is blocked. The user has to input the amount of density of the maze as a whole number. An input of 23 means the maze has a density of 23%.

The outputs of the game are these:

== Total number of steps taken by the mouse at present time.

== Conclusion: Success if the game ends with the mouse in the exit, or Failed otherwise.

Filling the interior of the maze

Obviously, the four walls are straight lines of X's with an entrance on the left and an exit on the right. The interior is populated with random X's. Here is a suggested algorithm for the interior of the maze.

At each interior cell create a new random number between 0 and 99 inclusively. If the random number is strictly less than the inputted density, then place an X in that cell, otherwise the cell receives a blank. This will create an interior for the maze where the percent of X's relative to all the cells is very close to the density number. Yes, the percent of X's may not be exactly the density number, but the percent will be close enough for our purposes.

The unfair maze

There exists the possibility that a random X may appear in the cell to the right of the entrance. In such a case the mouse is completely blocked before he even has a chance to take a single step. Similarly, at the exit a random X may appear in the cell to the left of the exit. In this case the mouse has no chance of success because that single X is blocking the exit. In order to eliminate these two cases of unfair mazes the following rule is added.

After the interior of the maze has been populated with X's force three contiguous cells near the entrance to be open cells. Also, force three contiguous cells near the exit to be open cells.

~~~~~~Sample screen shots~~~~~~~

Welcome to the Mickey Mouse Maze by Bill Jackson

Enter percent of density: 29

Enter the mouse delay in milliseconds: 225

Thank you. Here is the maze. Mickey will begin his travel in 10 seconds.

{Now the screen is cleared and you see the next page.}

XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX

X X X X

X XX X X X X X X

X X X X XX X X X X

X X X X X X XX X X X X

X X X X X X X X

X X X X X X X X

X X X X X X X X

X X XX X XX X X X

XX XX X XX X X X X

M XX XX XXXX X X X

XX XX XX X XXX X X X

XXX X XX X X X X

X X XX X X X X X

X X XXX XXX X

X X X X XX X X X X

X X X X X X XXXX X

X X X X X X XXXXX XX X

X X X X X X X X X X XXXXXXXXX X X

X X X X X XXX XX XXXXXX XX X

XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX

Total steps: 0 Conclusion:

Description

Before you start programming set the configuration of your terminal in the preferences. Set the font to Deja Vu Sans Mono Book with size 9 point font.

Set the terminal to show black text on a white background.

Set the default size to 160 characters of width and 48 lines of height. This will be the minimum size of your maze in every run: 160 by 48. You are free to set larger width or height if you wish.

After initial screen is cleared the maze shows immediately and the mickey mouse is seen in the starting position. After a few seconds, say 6 seconds, the mouse begins travelling through the maze. At the bottom of the maze you can see a counter showing how many steps the mouse has made. For example: after travelling in the maze the counter may look like this:

Total steps: 384

The mouse is red color. When the mouse takes a step he turns around and paints the cell where he was before with another color. This leaves a trail showing where the mouse has traveled. You pick a nice color for the trail. Green is always pretty.

If the mouse travels all the way to the cheeze exit on the right then the software stops and there is a declaration at the bottom of the showing success. It will look like this:

Total steps: 892 Conclusion: Success

If after a long time the mouse cannot find the cheeze then the software stops and the information at the bottom of the screen looks like this:

Total steps: 1297 Conclusion: Failure

Partitioning the solution

In previous assignments of this course there were rules about which functions you had to make and how those functions had to be in their separate files. On the way to building a solution you partition the problem into smaller problems, and you solve those smaller problems with functions. All of that is good programming style.

In this last assignment of the semester the professor has not set the rules for which functions you should make. You decide which functions to make. Make your own functions as needed.

What would happen if you made no functions? Then you would have one horrible main function that would be highly unmanageable. Dont do that. You are an experienced programmer; so you make functions

Testing the Mouse and Maze

Test your program with different densities and different delay times. For example:

Density Delay (millisec)

0 750

5 485

12 400

21 305

29 280

33 210

38 170

40 100

60 50

90 10

30 10

31 0

You will discover that for a percent number greater than about 38 the mouse will never find the cheeze. If the percent is less than 20 the mouse always finds the cheeze. Therefore, the interesting percents are generally in the range from 20 to 38.

What happens if the delay time is 10ms? Well, the mouse is travelling very very fast in search of the cheeze. But, if the delay time is 0 ms then the mouse travels at CPU speed and will complete the maze travel faster than you can watch it.

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

More Books

Students also viewed these Databases questions