-
Notifications
You must be signed in to change notification settings - Fork 0
/
main_roomba.cpp
143 lines (104 loc) · 2.9 KB
/
main_roomba.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
136
137
138
139
140
141
142
143
/*
Program: main_roomba.cpp
Author: Jaydeep Rotithor
Date:5/25/2015
Description:contains the main roomba function.
Input:None
Output:None
*/
#include "Roomba.h"
#include "Room.hpp"
#include "RandomRoomba.h"
#include "smarter_roomba.h"
#include "smartest_roomba.h"
#include <iostream>
#include <cstdlib>
#include <fstream>
#include <stdexcept>
using namespace std;
/*
Function:maim
Description: executes the cleaning of the room by the roomba
Parameters: the number of command line arguments and the actual arguments
Pre-conditions:none
Post-conditions: the roomba cleans the room with the specified floorplan
*/
int main(int argc, char*argv[]){
bool x;
if(argc != 11){
cout << "Too few arguments. You need 11" << endl;
exit(0);
}
ifstream input;
try{
input.open(argv[2], ios::in);
}
catch(exception e){
cout << "failed to open input" << endl;
}
int roomba_input;
if(argv[1][1] != 'f' || argv[3][1] != 'b' || argv[5][1] != 'r' || argv[7][1] != 'c' || argv[9][1] != 'v'){
cout << "Please enter -f for the 2nd argument, -b for the 4th argument, -r for the 6th argument, -c for the 8th argument, and -v for the 10th argument." << endl;
exit(0);
}
cout << "which roomba?(1- random, 2- more efficient, 3- most efficient)" << endl;
cin >> roomba_input;
while(roomba_input < 1 || roomba_input > 3){
cout << "The input is invalid. Please try again: " << endl;
cin.clear();
cin.ignore();
cin >> roomba_input;
}
Roomba *r;
Room <char>room1;
//RandomRoomba r1;
//smarter_roomba r2;
//smartest_roomba r3;
floor f(atoi(argv[6]), atoi(argv[8]));
vector <vector<char> >a;
vector <char>temp;
int i = 0;
for(int i = 0; i < 4; i++){
//while(!input.eof()){
//input.read(c,256);
temp.clear();
for(int j = 0; j < 4; j++){
temp.push_back('f');
}
a.push_back(temp);
}
//a[atoi(argv[6])] [atoi(argv[8])] = 'r';
f.set_v(a);
//atoi(argv[6]), atoi(argv[8])
f.place_roomba();
//room1.set_floor(f);
//room1.view_room();
if(roomba_input == 1)
r = new RandomRoomba;
else if(roomba_input == 2)
r = new smarter_roomba;
else if(roomba_input == 3)
r = new smartest_roomba;
r->set_battery(atoi(argv[4]));
int y = 0;
while((y < a.size()*a[0].size())|| r->get_battery() > 0){
if(roomba_input == 2 || roomba_input == 3){
if(room1.get_f().get_row() == a.size()-1 && (room1.get_f().get_col() == a[0].size() -1 || room1.get_f().get_col() == 0))
exit(0);
}
//room1.get_f().place_roomba();
//room1.get_f().get_row(), room1.get_f().get_col()
r->move_roomba(atoi(argv[6]), atoi(argv[8]), f);
//f.place_roomba(room1.get_f().get_row(), room1.get_f().get_col());
cout << "Move: " << r->get_total_moves() + 1 << endl;
r->change_battery();
r->change_total_moves();
cout << endl;
room1.set_floor(f);
room1.view_room();
cout << endl;
y++;
}
delete r;
return 0;
}