-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathUI.cpp
More file actions
354 lines (273 loc) · 9.84 KB
/
UI.cpp
File metadata and controls
354 lines (273 loc) · 9.84 KB
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
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
#include<iostream>
#include<chrono>
#include<fstream>
#include<string>
#include<sstream>
#include "OAHash.cpp"
#include "SCHash.cpp"
#include "BoardGameOBJ/BoardGame.h"
using namespace std;
using namespace std::chrono;
void readData(SCHash& SC, OAHash& OA);
int main() {
int option, filter, contOpt, hashType, year, minPlay, maxPlay, minAge;
string name;
SCHash SC;
OAHash OA;
readData(SC, OA);
auto start = system_clock::now(), stop = system_clock::now();
cout << "Welcome To Board Bot!" << endl;
while (true) {
cout << "\nSelect An Option:" << endl;
cout << "1. Print All Board Games" << endl;
cout << "2. Search By Filter" << endl;
cout << "3. Exit" << endl;
cin >> option;
if (option == 1) { // Print All Board Games
// takes input directly and outputs it
}
else if (option == 2) { // Search by Filter
while (true) {
cout << "\nSelect A Filter:" << endl;
cout << "1. Name" << endl;
cout << "2. Year Published" << endl;
cout << "3. Min Players" << endl;
cout << "4. Max Players" << endl;
cout << "5. Min Age" << endl;
cout << "6. Back To Options" << endl;
cin >> filter;
if (filter > 0 && filter < 7) {
break;
}
cout << "\nInvalid Filter\nPlease Select: 1, 2, 3, 4, 5 or 6" << endl;
}
if (filter == 1) { // Name filter
cout << "\nEnter Board Game Name: " << endl;
cin >> name;
while (true) {
cout << "\nSelect A Collision Resolution Strategy: " << endl;
cout << "1. Open Addressing" << endl;
cout << "2. Separate Chaining" << endl;
cin >> hashType;
if (hashType > 0 && hashType < 3) {
break;
}
cout << "\nInvalid Selection\nPlease Select: 1 or 2" << endl;;
}
if (hashType == 1) {
start = system_clock::now();
// call function for instance of name Open Addressing
OA.find_all(name);
auto duration = duration_cast<microseconds>(system_clock::now() - start);
cout << "\nExecution Time with Open Addressing: " << duration.count() << " microseconds" << endl;
}
if (hashType == 2) {
start = system_clock::now();
// call function for instance of name Separate Chaining
SC.find_all(name);
auto duration = duration_cast<microseconds>(system_clock::now() - start);
cout << "\nExecution Time with Separate Chaining: " << duration.count() << " microseconds" << endl;
}
}
else if (filter == 2) { // Year filter
cout << "\nEnter Year Board Game was Published: " << endl;
cin >> year;
while (true) {
cout << "\nSelect A Collision Resolution Strategy: " << endl;
cout << "1. Open Addressing" << endl;
cout << "2. Separate Chaining" << endl;
cin >> hashType;
if (hashType > 0 && hashType < 3) {
break;
}
cout << "\nInvalid Selection\nPlease Select: 1 or 2" << endl;;
}
if (hashType == 1) {
start = system_clock::now();
// call function to find year Open Addressing
OA.find_all_year(to_string(year));
auto duration = duration_cast<microseconds>(system_clock::now() - start);
cout << "\nExecution Time with Open Addressing: " << duration.count() << " microseconds" << endl;
}
if (hashType == 2) {
start = system_clock::now();
// call function to find year Separate Chaining
SC.find_all_year(to_string(year));
auto duration = duration_cast<microseconds>(system_clock::now() - start);
cout << "\nExecution Time with Separate Chaining: " << duration.count() << " microseconds" << endl;
}
}
else if (filter == 3) { // Min Player filter
while (true) {
cout << "\nInput Minimum Players (1 - 10, 10+ Represented by 10): " << endl;
cin >> minPlay;
if (minPlay > 0 && minPlay < 11) {
break;
}
cout << "\nInvalid Selection\nPlease Select An Integer 1 - 10" << endl;
}
while (true) {
cout << "\nSelect A Collision Resolution Strategy: " << endl;
cout << "1. Open Addressing" << endl;
cout << "2. Separate Chaining" << endl;
cin >> hashType;
if (hashType > 0 && hashType < 3) {
break;
}
cout << "\nInvalid Selection\nPlease Select: 1 or 2" << endl;;
}
if (hashType == 1) {
start = system_clock::now();
// call function to find minPlayers Open Addressing
OA.find_all_minPlayers(to_string(minPlay));
auto duration = duration_cast<microseconds>(system_clock::now() - start);
cout << "\nExecution Time with Open Addressing: " << duration.count() << " microseconds" << endl;
}
if (hashType == 2) {
start = system_clock::now();
SC.find_all_minPlayers(to_string(minPlay));
// call function to find minPlayers Separate Chaining
auto duration = duration_cast<microseconds>(system_clock::now() - start);
cout << "\nExecution Time with Separate Chaining: " << duration.count() << " microseconds" << endl;
}
}
else if (filter == 4) { // Max Player filter
while (true) {
cout << "\nInput Maximum Players (1 - 10, 10+ Represented by 10): " << endl;
cin >> maxPlay;
if (maxPlay > 0 && maxPlay < 11) {
break;
}
cout << "\nInvalid Selection\nPlease Select An Integer 1 - 10" << endl;
}
while (true) {
cout << "\nSelect A Collision Resolution Strategy: " << endl;
cout << "1. Open Addressing" << endl;
cout << "2. Separate Chaining" << endl;
cin >> hashType;
if (hashType > 0 && hashType < 3) {
break;
}
cout << "\nInvalid Selection\nPlease Select: 1 or 2" << endl;;
}
if (hashType == 1) {
start = system_clock::now();
// call function to find maxPlayer Open Addressing
OA.find_all_maxPlayers(to_string(maxPlay));
auto duration = duration_cast<microseconds>(system_clock::now() - start);
cout << "\nExecution Time with Open Addressing: " << duration.count() << " microseconds" << endl;
}
if (hashType == 2) {
start = system_clock::now();
// call function to find maxPlayer Separate Chaining
SC.find_all_maxPlayers(to_string(maxPlay));
auto duration = duration_cast<microseconds>(system_clock::now() - start);
cout << "\nExecution Time with Separate Chaining: " << duration.count() << " microseconds" << endl;
}
}
else if (filter == 5) { // Max Age Filter
while (true) {
cout << "\nInput Minimum Age (1 - 18, 18+ Represented by 18): " << endl;
cin >> minAge;
if (minAge > 0 && minAge < 19) {
break;
}
cout << "\nInvalid Selection\nPlease Select: 1, 2, 3, 4, or 5" << endl;
}
while (true) {
cout << "\nSelect A Collision Resolution Strategy: " << endl;
cout << "1. Open Addressing" << endl;
cout << "2. Separate Chaining" << endl;
cin >> hashType;
if (hashType > 0 && hashType < 3) {
break;
}
cout << "\nInvalid Selection\nPlease Select: 1 or 2" << endl;;
}
if (hashType == 1) {
start = system_clock::now();
// call function to find minAge Open Addressing
OA.find_all_age(to_string(minAge));
auto duration = duration_cast<microseconds>(system_clock::now() - start);
cout << "\nExecution Time with Open Addressing: " << duration.count() << " microseconds" << endl;
}
if (hashType == 2) {
start = system_clock::now();
// call function to find minAge Separate Chaining
SC.find_all_age(to_string(minAge));
auto duration = duration_cast<microseconds>(system_clock::now() - start);
cout << "\nExecution Time with Separate Chaining: " << duration.count() << " microseconds" << endl;
}
}
else if (filter == 6) { // Back to Options
continue;
}
}
else if (option == 3) { // Exit
cout << "\nThanks for Using Board Bot!" << endl;
break;
}
else {
cout << "\nInvalid Option\nPlease Select: 1, 2, or 3" << endl;
continue;
}
while (true) { // Continue Option
cout << "\nDo you want to continue?" << endl;
cout << "1. Yes, bring me to the options menu" << endl;
cout << "2. No, let me exit" << endl;
cin >> contOpt;
if (contOpt > 0 && contOpt < 3) {
break;
}
cout << "\nInvalid Option\nPlease Select: 1 or 2" << endl;
}
if (contOpt == 2) { // Exit
cout << "\nThanks for Using Board Bot!" << endl;
break;
}
}
}
void readData(SCHash& SC, OAHash& OA){
// open file
fstream file;
file.open("bgg_dataset.csv");
// line of data
string line = "";
// read in one line of input
getline(file, line);
// variables to store data
string name;
string yearPublished;
string minPlayers;
string maxPlayers;
string minAge;
string avgRating;
// data order from csv file
// ID;Name;Year Published;Min Players;Max Players;Play Time;Min Age;
// while loop until there's no more lines
while(getline(file, line))
{
stringstream input(line);
// name, skip id
getline(input, name, ';');
getline(input, name, ';');
// year published
getline(input, yearPublished, ';');
// min players
getline(input, minPlayers, ';');
// max players
getline(input, maxPlayers, ';');
// min age, skip play time
getline(input, minAge, ';');
getline(input, minAge, ';');
// avg rating, and changes ',' to '.'
getline(input, avgRating, ';');
getline(input, avgRating, ';');
if(avgRating.find(',') != string::npos){
avgRating.replace(avgRating.find(','), 1, ".");
}
BoardGame test = BoardGame(name, yearPublished, minPlayers, maxPlayers, minAge, avgRating);
SC.insert(name, test);
OA.insert(name, test);
}
}