-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.cpp
135 lines (122 loc) · 4.61 KB
/
main.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
#include <iostream>
#include <cstring>
#include <fstream>
#include "cleaning_robot.h"
using namespace std;
int main()
{
cout << "Welcome to the cleaning program" << endl;
char map[MAP_HEIGHT][MAP_WIDTH] = {};
char temp_map[MAP_HEIGHT][MAP_WIDTH] = {};
char empty_map[MAP_HEIGHT][MAP_WIDTH] = {};
char result_map[MAP_HEIGHT][MAP_WIDTH] = {};
int robot_full_energy = 10;
int robot_x = 0;
int robot_y = 0;
int robot_energy = robot_full_energy;
int choice = 0;
int int_result = 0;
int dest_x = 0, dest_y = 0;
char result_sequence[MAX_STRING_SIZE] = "";
bool map_loaded = false;
do
{
cout << "Please select from the following options:" << endl;
cout << "0: Load map" << endl;
if (map_loaded)
{
cout << "1. Print original map" << endl;
cout << "2. Print robot details" << endl;
cout << "3. Display the maximum range for the robot in the current place:" << endl;
cout << "4. Find the shortest distance from current position to a designated position" << endl;
cout << "5. Find the shortest distance and the shortest path from current position to a designated position" << endl;
cout << "6. Find the position of the farthest charger and the shortest distance from that charger" << endl;
}
cout << "-1. Exit program" << endl;
cout << "Please enter your choice: ";
cin >> choice;
switch (choice)
{
case 0:
char filename[MAX_STRING_SIZE];
cout << "Please type the file you want to use: ";
cin >> filename;
if (loadMap(filename, map))
{
printMap(map);
map_loaded = true;
setRobot(robot_x, robot_y, robot_full_energy, map);
robot_energy = robot_full_energy;
printMap(map);
}
else
{
cout << "Cannot load map. Please check if the file exists." << endl;
}
break;
case 1:
printMap(map);
break;
case 2:
cout << "Robot position: (" << robot_x << "," << robot_y << ")" << endl;
cout << "Robot energy: " << robot_energy << "/" << robot_full_energy << endl;
break;
case 3:
copyMap(result_map, map);
copyMap(temp_map, empty_map);
int_result = findMaximumPlace(robot_x, robot_y, robot_energy, robot_full_energy, result_map, temp_map);
cout << int_result << endl;
cout << "The result map will be:" << endl;
printMap(result_map);
break;
case 4:
cout << "Please enter the target x and y, separated by space: ";
cin >> dest_x >> dest_y;
copyMap(temp_map, empty_map);
int_result = findShortestDistance(robot_x, robot_y,
dest_x, dest_y, robot_energy, robot_full_energy, map, temp_map);
if (int_result >= PA2_MAX_PATH)
{
cout << "The destination is unreachable." << endl;
}
else
{
cout << int_result;
}
break;
case 5:
cout << "Please enter the target x and y, separated by space: ";
cin >> dest_x >> dest_y;
copyMap(temp_map, empty_map);
int_result = findPathSequence(robot_x, robot_y,
dest_x, dest_y,
robot_energy, robot_full_energy, result_sequence,
map, temp_map);
if (int_result >= PA2_MAX_PATH)
{
cout << "The destination is unreachable." << endl;
}
else
{
cout << int_result << ":" << result_sequence << endl;
}
break;
case 6:
int target_x = -1, target_y = -1;
copyMap(temp_map, empty_map);
int_result = findFarthestPossibleCharger(robot_x, robot_y, robot_x, robot_y, target_x, target_y, robot_energy, robot_full_energy, map, temp_map);
if (int_result > -1)
{
cout << "The farthest position is (" << target_x << ":" << target_y << ")"
<< " and the distance is " << int_result << endl;
}
else
{
cout << "Cannot find" << endl;
}
}
cout << endl;
} while (choice != -1);
cout << "Program ends." << endl;
return 0;
}