2. 1. Your program should only process this plain text file with the data and format: The first line of the file contains two integers representing the number of rows and the number of columns (in that order) of the maze. Read these two numbers and save them in two variables: Row and Column, respectively. 3. The next Row lines (where Row is the number of rows) will contain Column integer values (where Column is the number of columns) containing 1 and 0 separated by a space. 4. A 1 represent a wall and a 0 represents a space (can be moved to and from) in the maze. 5. The single "2" represents the location of the end point. 6. When you print this map in the code, 1 should be replaced by 'l' and 0 should be replaced by ''(space). The current location of the robot should print 'C', and the target should print 'E'. moses > Downloads > C maze.c>main() This is an example of the Maze project framework, it is not a working project. You need to complete this code. please finish the function printMap and updateMap to make the maze project work. include include The global variables. mt rows, columns; nt charx, chary;

EBK JAVA PROGRAMMING
9th Edition
ISBN:9781337671385
Author:FARRELL
Publisher:FARRELL
Chapter8: Arrays
Section: Chapter Questions
Problem 9PE
icon
Related questions
Question

Complete and fix this code C program ONLY.
 Please finish the function printMap and updateMap to make the maze project work.Your code should move the cursor to the starting point located at the first 0 from the topand left border, and then use w, a, s, or d keys to control it to move to E. When E isreached, your code will print a message on the screen “Maze solved!!!”Please notice that part of the code is already provided, and you need to understand the code and finish it by sending screenshots

25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
1. Your program should only process this plain text file with the data and format:
2. The first line of the file contains two integers representing the number of rows
and the number of columns (in that order) of the maze. Read these two numbers
and save them in two variables: Row and Column, respectively.
3.
The next Row lines (where Row is the number of rows) will contain Column
integer values (where Column is the number of columns) containing 1 and 0
separated by a space.
4.
A 1 represent a wall and a 0 represents a space (can be moved to and from) in
the maze.
C: > Users > moses > Downloads > C maze.c> main()
1
// This is an example of the Maze project framework, it is not a working project.
2
// You need to complete this code.
3
// please finish the function printMap and updateMap to make the maze project work.
#include<stdio.h>
4
5 #include<stdlib.h>
6 // The global variables.
7
int rows, columns;
8
int charx, chary;
9
48
49
5.
6.
10
// This function is to udpate the array map after each cursor movement.
11 updateMap (int map[][], const char choice) {
12
}
13
14
15
16
17
18
19
20
21
22
23
24
50
51
52
53
54
55
56
57
58
The single "2" represents the location of the end point.
When you print this map in the code, 1 should be replaced by 'l' and 0 should
be replaced by " (space). The current location of the robot should print 'C',
and the target should print 'E'.
// This function is to print/draw the map.
void printMap (const int map[rows][columns], const int charx, const int chary){
}
// This function is to find the initial Location of the car and update the global variables
// charx and chary
findInitialPosition (const int map[rows] [columns]) {
}
int main(){
FILE* in = fopen("mapData.txt","r");
int x,y,done=0;
char choice;
// load the map
// Step 1: Read the maze rows and columns from the mapData.txt file, you need to read the file.
// The map will be stored in a 2-dimensional array.
int map[rows] [columns];
// Step 2: Find the initial location of the car.
findInitialPosition (map);
//printf ("The Maze has %d rows %d columns \n", rows, columns); // Test Code
//printf ("The car starts at row %d and column %d\n", charx, charY); // Test Code
// Step 3: Read the nput to the two-dimensional array map, using fscanf and loops
// load map finished
// Step 4: use function printMap to print the Map on the screen.
printMap (map, charx, charY); // charx, chary is the new location.
while (done==0) {
printf ("This code is designed by _your_names_ \n"); // Display your name on the screen.
printf("Press w,a,s,d to move the car up, left down and right...");
choice=getch(); // Get the keyboard input
done=updateMap (map, choice);
// in this function, it should update the map array for the current cursor positions
// when the input is valid (w,a,s,d).
// also, should make done = 1 if the cursor is moved to the end point E.
system("cls"); // this is a windwos-only function to clean the screen.
// For Mac, please check some reference to clean the screen.
printMap (map, charx, charY); // print the map after each valid movement.
printf ("\n Maze Solved!!! \n"); // problem solved if done is not 0.
fclose(in); // close the file.
system("pause");
return 0;
Sample format (mapData.txt):
10 8
1 1 1 1 1 1 1 1
1 0 1 0 0 0 0 1
1 0 1 1 1 1 0 1
1 0 0 0 0 0 0 1
1 1 0 1 1 1 1 1
1 0 0 0 1 0 0 1
1 0 1 0 0 0 0 1
1 0 1 0 1 1 1 1
1 0 1 0 0 0 2 1
1 1 1 1 1 1 1 1
Your code should move the cursor to the starting point located at the first 0 from the top
and left border, and then use w, a, s, or d keys to control it to move to E. When E is
reached, your code will print a message on the screen "Maze solved!!!"
Please notice that part of the code is already provided, and you need to understand the
code and finish it.
Transcribed Image Text:25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 1. Your program should only process this plain text file with the data and format: 2. The first line of the file contains two integers representing the number of rows and the number of columns (in that order) of the maze. Read these two numbers and save them in two variables: Row and Column, respectively. 3. The next Row lines (where Row is the number of rows) will contain Column integer values (where Column is the number of columns) containing 1 and 0 separated by a space. 4. A 1 represent a wall and a 0 represents a space (can be moved to and from) in the maze. C: > Users > moses > Downloads > C maze.c> main() 1 // This is an example of the Maze project framework, it is not a working project. 2 // You need to complete this code. 3 // please finish the function printMap and updateMap to make the maze project work. #include<stdio.h> 4 5 #include<stdlib.h> 6 // The global variables. 7 int rows, columns; 8 int charx, chary; 9 48 49 5. 6. 10 // This function is to udpate the array map after each cursor movement. 11 updateMap (int map[][], const char choice) { 12 } 13 14 15 16 17 18 19 20 21 22 23 24 50 51 52 53 54 55 56 57 58 The single "2" represents the location of the end point. When you print this map in the code, 1 should be replaced by 'l' and 0 should be replaced by " (space). The current location of the robot should print 'C', and the target should print 'E'. // This function is to print/draw the map. void printMap (const int map[rows][columns], const int charx, const int chary){ } // This function is to find the initial Location of the car and update the global variables // charx and chary findInitialPosition (const int map[rows] [columns]) { } int main(){ FILE* in = fopen("mapData.txt","r"); int x,y,done=0; char choice; // load the map // Step 1: Read the maze rows and columns from the mapData.txt file, you need to read the file. // The map will be stored in a 2-dimensional array. int map[rows] [columns]; // Step 2: Find the initial location of the car. findInitialPosition (map); //printf ("The Maze has %d rows %d columns \n", rows, columns); // Test Code //printf ("The car starts at row %d and column %d\n", charx, charY); // Test Code // Step 3: Read the nput to the two-dimensional array map, using fscanf and loops // load map finished // Step 4: use function printMap to print the Map on the screen. printMap (map, charx, charY); // charx, chary is the new location. while (done==0) { printf ("This code is designed by _your_names_ \n"); // Display your name on the screen. printf("Press w,a,s,d to move the car up, left down and right..."); choice=getch(); // Get the keyboard input done=updateMap (map, choice); // in this function, it should update the map array for the current cursor positions // when the input is valid (w,a,s,d). // also, should make done = 1 if the cursor is moved to the end point E. system("cls"); // this is a windwos-only function to clean the screen. // For Mac, please check some reference to clean the screen. printMap (map, charx, charY); // print the map after each valid movement. printf ("\n Maze Solved!!! \n"); // problem solved if done is not 0. fclose(in); // close the file. system("pause"); return 0; Sample format (mapData.txt): 10 8 1 1 1 1 1 1 1 1 1 0 1 0 0 0 0 1 1 0 1 1 1 1 0 1 1 0 0 0 0 0 0 1 1 1 0 1 1 1 1 1 1 0 0 0 1 0 0 1 1 0 1 0 0 0 0 1 1 0 1 0 1 1 1 1 1 0 1 0 0 0 2 1 1 1 1 1 1 1 1 1 Your code should move the cursor to the starting point located at the first 0 from the top and left border, and then use w, a, s, or d keys to control it to move to E. When E is reached, your code will print a message on the screen "Maze solved!!!" Please notice that part of the code is already provided, and you need to understand the code and finish it.
Expert Solution
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 3 steps

Blurred answer
Knowledge Booster
Constants and Variables
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
  • SEE MORE QUESTIONS
Recommended textbooks for you
EBK JAVA PROGRAMMING
EBK JAVA PROGRAMMING
Computer Science
ISBN:
9781337671385
Author:
FARRELL
Publisher:
CENGAGE LEARNING - CONSIGNMENT
Programming Logic & Design Comprehensive
Programming Logic & Design Comprehensive
Computer Science
ISBN:
9781337669405
Author:
FARRELL
Publisher:
Cengage