Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Could you help me to clear the screen in the main function? I tried system(cls) / system(CLS) / system(clear) / clscr? but those are not

Could you help me to clear the screen in the main function?

I tried system("cls") / system("CLS") / system("clear") / clscr? but those are not working and error said that "sh : cls: command not found" or TERM environment variable not set.

#include  #include  #include  #include  #include  #include  // system("cls"); but it is not working as well. using namespace std; void create_maze(int &row_robot, int &column_robot ); void show_maze(int row_robot, int column_robot); bool robot_move(int &row_robot, int &column_robot); const int SIZE = 10; enum Values {space, wall, e, robot}; Values maze[SIZE][SIZE]; int main() { srand((unsigned int)time(0)); int row_robot, column_robot, moving; row_robot = 4, column_robot = 4; moving = -1; create_maze(row_robot, column_robot); show_maze(row_robot, column_robot); while (1) { ++moving; if (system("clear")) system("clear"); bool escaped = robot_move(row_robot, column_robot); show_maze(row_robot, column_robot); usleep(1000); cout << "How many moves: " << moving << endl; if (escaped) { break; } } cout << "Robot is survived" << endl; } void create_maze(int &row_robot, int &column_robot) { int i, j; for (i = 0; i < SIZE; i++) for (j = 0; j < SIZE; j++) maze[i][j] = wall; for (i = 1; i < SIZE; i += 3) for (j = 0; j < SIZE; j++) maze[i][j] = space; maze[1][0] = e; maze[7][9] = e; maze[1][9] = wall; maze[4][0] = wall; maze[4][8] = wall; maze[4][9] = wall; maze[7][0] = wall; maze[2][2] = space; maze[2][6] = space; maze[2][8] = space; maze[3][2] = space; maze[5][7] = space; maze[6][3] = space; maze[6][7] = space; maze[row_robot][column_robot] = robot; // Robot describe as 'X' } void show_maze(int , int); bool robot_move(int &row_robot, int &column_robot) { while (1) { unsigned int num; //srand(time(0)); num = rand() % 4 + 1; cout << "RANDOM NUMBER: " << num << endl; if (num == 1) //Move to North { if (maze[row_robot+1][column_robot] != wall) { if (maze[row_robot+1][column_robot] == e) { return true; } maze[row_robot][column_robot] = space; row_robot++; maze[row_robot][column_robot] = robot; break; } } else if (num == 2) //Move to South { if (maze[row_robot-1][column_robot] != wall) { if (maze[row_robot-1][column_robot] == e) { return true; } maze[row_robot][column_robot] = space; row_robot--; maze[row_robot][column_robot] = robot; break; } } else if (num == 3) //Move to East { if (maze[row_robot][column_robot+1] != wall) { if (maze[row_robot][column_robot+1] == e) { return true; } maze[row_robot][column_robot] = space; column_robot++; maze[row_robot][column_robot] = robot; break; } } else //Move to west { if (maze[row_robot][column_robot-1] != wall) { if (maze[row_robot][column_robot-1] == e) { return true; } maze[row_robot][column_robot] = space; column_robot--; maze[row_robot][column_robot] = robot; break; } } return false; } } void show_maze(int, int) { int i, j; for(i = 0; i < SIZE; i++) { for (j = 0; j < SIZE; j++) { if (maze[i][j] == space) cout << " "; else if (maze[i][j] == wall) cout << "+"; else if (maze[i][j] == e) cout << "e"; else  cout << "X"; } cout <                        

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

Guide To Client Server Databases

Authors: Joe Salemi

2nd Edition

1562763105, 978-1562763107

More Books

Students also viewed these Databases questions

Question

=+2 Is the decision sustainable in the long run?

Answered: 1 week ago