-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.cpp
366 lines (326 loc) · 15 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
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
355
356
357
358
359
360
361
362
#include <time.h>
#include <string>
#include<unordered_set>
#include <cmath>
//for graph
#include "Bridges.h"
#include "GraphAdjList.h"
//for data
#include "DataSource.h"
#include "data_src/Game.h"
//our created Datastrucutres
#include "HashTable.h"
#include "MaxHeap.h"
using namespace std;
using namespace bridges;
string tostring (float value) {
int result = (value * 10);
string ans = to_string(result);
if (result == 100) {
ans = "10.0";
}
else {
ans.insert(1,".");
}
return ans;
} //to round to the first decimal place
void displayMenu(){
std::cout << R"(
__________________________________________________________________________________
_______ _ _ _ ______ _
/\ | ____| (_) (_) | ____| |
/ \ | |__ __ _ _ __ ___ _| |_ __ _ _ __ | |__ | | __ ___ _____ _ __
/ /\ \ | __/ _` | '_ ` _ \| | | |/ _` | '__| | __| | |/ _` \ \ / / _ \| '__|
/ ____ \ | | | (_| | | | | | | | | | (_| | | | | | | (_| |\ V / (_) | |
/_/ \_\ |_| \__,_|_| |_| |_|_|_|_|\__,_|_| |_| |_|\__,_| \_/ \___/|_|
__________________________________________________________________________________
)" << '\n';
cout << "Color Rating System" << endl;
cout << "purple:1 pink:2 limegreen:3 cyan:4 white:5 red:6 blue:7 green:8 yellow:9 orange:10" << endl << endl;
cout << "0: Exit program." << endl;
cout << "1: Load all games, coorelate between rating and genre." << endl;
cout << "2: Load all games, coorelate between rating and platform." << endl;
cout << "3: Load a specific genre." << endl;
cout << "4: Load a specific platform." << endl;
cout << "5: Load a specific game" << endl;
cout << "6: Cluster by ratings." << endl;
cout << "7: Load top N highest rated games" << endl;
}
int main(int argc, char **argv) {
const double MAX_VERTEX_SIZE = 50.0;
const double VERTEX_SIZE_CONST = 4.5;
bool isPlaying = true;
int userInput;
int lowestRanking;
unordered_set<string> titles;
vector<string> platforms = {"Game.Com", "Lynx", "Nintendo 64", "DVD / HD Video Game", "WonderSwan", "Dreamcast", "Game Boy Advance", "GameCube", "Vectrex", "Game Boy", "NeoGeo Pocket Color", "Sega CD", "Atari 2600", "N-Gage", "NeoGeo", "Windows Phone", "Nintendo 3DS", "WonderSwan Color", "iPad", "iPod", "Xbox 360", "TurboGrafx-16", "Macintosh", "Wii U", "PlayStation 4", "TurboGrafx-CD", "PlayStation Vita", "Sega 32X", "PC", "iPhone", "Xbox One", "Wireless", "PlayStation", "Linux", "PlayStation Portable", "Android", "Commodore 64/128", "PlayStation 2", "Game Boy Color", "Super NES", "Wii", "Nintendo 64DD", "Pocket PC", "Windows Surface", "Nintendo DS", "PlayStation 3", "Nintendo DSi", "Dreamcast VMU", "Atari 5200", "Web Games", "Saturn", "Arcade", "NES", "Xbox", "Master System", "Genesis"};
vector<string> genres = {"Compilation", "Action", "Board", "Sports", "Party", "Adventure", "Simulation", "Fighting", "Pinball", "Hunting", "RPG", "Racing", "Strategy", "Card", "Trivia", "Platformer", "Wrestling", "Virtual Pet", "Baseball", "None", "Battle", "Casino", "Flight", "Puzzle", "Educational", "Shooter", "Adult", "Music", "Productivity", "Other"};
vector<string> ratings = {"1", "2", "3", "4", "5", "6", "7", "8", "9", "10"};
vector<string> colors = {"purple", "pink", "limegreen", "cyan", "white", "red", "blue", "green", "yellow", "orange"};
//introductory statement
cout << "Welcome to A Familiar Flavor, where we aim to help you tackle the broad and confusing world of gaming." << endl << "Please insert the lowest ranking of game you would like to view:";
cin >> lowestRanking;
cout << endl;
while(isPlaying){
//load bridges graph and data source
Bridges bridges (1, "DeclanGazil", "1387522173459");
GraphAdjList<string> graph;
bridges.setTitle("IGN Game Data");
DataSource ds (&bridges);
vector<Game> game_list = ds.getGameData();
//create hashtable and time
cout << "Time for Hash Table insertion of games: ";
clock_t t;
t = clock();
HashTable hashList(game_list);
t = clock() - t;
cout << t << " ticks or " << float(t)/CLOCKS_PER_SEC << " seconds." << endl;
//create max heap and time
MaxHeap maxHeap;
cout << "Time for Max Heap insertion of games: ";
t = clock();
for(int i = 0; i < game_list.size(); i++){
maxHeap.insertGame(game_list[i]);
}
cout << t << " ticks or " << float(t)/CLOCKS_PER_SEC << " seconds." << endl;
//for switch statement
string tempGenre;
string displayInfo;
string userGenre;
string userPlatform;
string userTitle;
string ratingValue;
string vertex;
string colorTemp;
int userNum;
int colorValue;
bool genreFound;
bool platformFound;
Game userGame;
Game tempGame;
displayMenu();
cin >> userInput;
switch(userInput){
case 0:
cout << "Exit program." << endl;
isPlaying = !isPlaying;
break;
case 1://generate different colors and spread out
bridges.setDescription("Load all games, coorelate between rating and genre.");
//add all genres as base vertices
for(int i = 0; i < genres.size(); i++){
graph.addVertex(genres[i]);
graph.getVertex(genres[i])->setSize(MAX_VERTEX_SIZE);
graph.getVertex(genres[i])->setColor("black");
}
//add all games to respective genre, size changing based off rating
for(int i = 0; i < game_list.size(); i++){
if(game_list[i].getRating() >= lowestRanking){
tempGenre = game_list[i].getGameGenre()[0];
displayInfo = game_list[i].getTitle() + ": " + tostring(game_list[i].getRating()) + " " + game_list[i].getPlatformType() +
" " + tempGenre;
graph.addVertex(displayInfo);
graph.addEdge(displayInfo,tempGenre);
graph.getVertex(displayInfo)->setSize(game_list[i].getRating() * VERTEX_SIZE_CONST);
//set color based on rating
colorValue = int(ceil(game_list[i].getRating())) - 1;
graph.getVertex(displayInfo)->setColor(colors[colorValue]);
}
}
bridges.setDataStructure(&graph);
bridges.visualize();
break;
case 2:
bridges.setDescription("Load all games, coorelate between rating and platform.");
//add all platforms as base vertices
for(int i = 0; i < platforms.size(); i++){
graph.addVertex(platforms[i]);
graph.getVertex(platforms[i])->setSize(MAX_VERTEX_SIZE);
graph.getVertex(platforms[i])->setColor("black");
}
//add all games to respective platform, size changing based off rating
for(int i = 0; i < game_list.size(); i++){
if(game_list[i].getRating() >= lowestRanking){
tempGenre = game_list[i].getGameGenre()[0];
displayInfo = game_list[i].getTitle() + ": " + tostring(game_list[i].getRating()) + " " + game_list[i].getPlatformType() +
" " + tempGenre;
graph.addVertex(displayInfo);
graph.addEdge(displayInfo,game_list[i].getPlatformType());
graph.getVertex(displayInfo)->setSize(game_list[i].getRating() * VERTEX_SIZE_CONST);
//set color based on rating
colorValue = int(ceil(game_list[i].getRating())) - 1;
graph.getVertex(displayInfo)->setColor(colors[colorValue]);
}
}
bridges.setDataStructure(&graph);
bridges.visualize();
break;
case 3:
cout << "Please input a genre." << endl;
bridges.setDescription("Load a specific genre.");
cin.get();
getline(cin, userGenre);
genreFound = false;
//search to see if that genre exists
for(int i = 0; i < genres.size(); i++){
if(genres[i] == userGenre)
genreFound = true;
}
if(!genreFound){
cout << "Genre not found." << endl;
}
else{
//add that genre as a base vertex
graph.addVertex(userGenre);
graph.getVertex(userGenre)->setSize(MAX_VERTEX_SIZE);
graph.getVertex(userGenre)->setColor("black");
//go through the list of games and all games with user genre
for(int i = 0; i < game_list.size(); i++){
if(game_list[i].getGameGenre()[0] == userGenre && game_list[i].getRating() >= lowestRanking){
tempGenre = game_list[i].getGameGenre()[0];
displayInfo = game_list[i].getTitle() + ": " + tostring(game_list[i].getRating()) + " " + game_list[i].getPlatformType() +
" " + tempGenre;
graph.addVertex(displayInfo);
graph.getVertex(displayInfo)->setSize(game_list[i].getRating() * VERTEX_SIZE_CONST);
//set color based on rating
colorValue = int(ceil(game_list[i].getRating())) - 1;
graph.getVertex(displayInfo)->setColor(colors[colorValue]);
graph.addEdge(displayInfo,userGenre);
}
}
bridges.setDataStructure(&graph);
bridges.visualize();
}
break;
case 4:
bridges.setDescription("Load a specific platform.");
cout << "Please input a platform." << endl;
//get userInput
cin.get();
getline(cin, userPlatform);
platformFound = false;
//search to see if input platform is valid
for(int i = 0; i < platforms.size(); i++){
if(platforms[i] == userPlatform)
platformFound = true;
}
if(!platformFound){
cout << "Platform not found." << endl;
}
else{
//add base vertex
graph.addVertex(userPlatform);
graph.getVertex(userPlatform)->setSize(MAX_VERTEX_SIZE);
graph.getVertex(userPlatform)->setColor("black");
//add all games with that platform
for(int i = 0; i < game_list.size(); i++){
if(game_list[i].getPlatformType() == userPlatform && game_list[i].getRating() >= lowestRanking){
tempGenre = game_list[i].getGameGenre()[0];
displayInfo = game_list[i].getTitle() + ": " + tostring(game_list[i].getRating()) + " " + game_list[i].getPlatformType() +
" " + tempGenre;
graph.addVertex(displayInfo);
graph.getVertex(displayInfo)->setSize(game_list[i].getRating() * VERTEX_SIZE_CONST);
//set color based on rating
colorValue = int(ceil(game_list[i].getRating())) - 1;
graph.getVertex(displayInfo)->setColor(colors[colorValue]);
graph.addEdge(displayInfo,userPlatform);
}
}
bridges.setDataStructure(&graph);
bridges.visualize();
}
break;
case 5:
bridges.setDescription("Load a specific game.");
cout << "Please input a title." << endl;
cin.get();
getline(cin, userTitle);
//hashList search
cout << "Time for Hash Table search of specific title: ";
t = clock();
userGame = hashList.Find(userTitle);
t = clock() - t;
cout << t << " ticks or " << float(t)/CLOCKS_PER_SEC << " seconds." << endl;
//goes through max heap till found
cout << "Time for Max Heap search of specific title: ";
t = clock();
while (true) {
if (maxHeap.getSize() == 0) {
break;
}
if (maxHeap.removeTop().getTitle() == userTitle) {
break;
}
}
cout << t << " ticks or " << float(t)/CLOCKS_PER_SEC << " seconds." << endl;
if(userGame.getTitle() == userTitle){ //see if title exists
tempGenre = userGame.getGameGenre()[0];
displayInfo = userGame.getTitle() + ": " + tostring(userGame.getRating()) + " " + userGame.getPlatformType() + " " + tempGenre;
graph.addVertex(displayInfo);
graph.getVertex(displayInfo)->setSize(MAX_VERTEX_SIZE);
colorValue = int(ceil(userGame.getRating())) - 1;
graph.getVertex(displayInfo)->setColor(colors[colorValue]);
bridges.setDataStructure(&graph);
bridges.visualize();
}
else //if the title does not exist in the data set
cout << "Game not found." << endl;
break;
case 6:
bridges.setDescription("Cluster by ratings.");
//make vertices for all game ratings
for(int i = 0; i < ratings.size(); i++){
ratingValue = ratings[i];
ratingValue.append(" and below");
graph.addVertex(ratingValue);
colorTemp = colors[i];
graph.getVertex(ratingValue)->setSize(MAX_VERTEX_SIZE);
graph.getVertex(ratingValue)->setColor("black");
}
//add all games to the respective ratings
for(int i = 0; i < game_list.size(); i++){
if(game_list[i].getRating() >= lowestRanking){
tempGenre = game_list[i].getGameGenre()[0];
displayInfo = game_list[i].getTitle() + ": " + tostring(game_list[i].getRating()) + " " + game_list[i].getPlatformType() +
" " + tempGenre;
graph.addVertex(displayInfo);
graph.getVertex(displayInfo)->setSize(game_list[i].getRating() * VERTEX_SIZE_CONST);
//set color based on rating
vertex = ratings[ceil(game_list[i].getRating()) - 1] + " and below";
colorValue = int(ceil(game_list[i].getRating())) - 1;
graph.getVertex(displayInfo)->setColor(colors[colorValue]);
graph.addEdge(displayInfo, vertex);
}
}
bridges.setDataStructure(&graph);
bridges.visualize();
break;
case 7:
cout << "Insert number of games to retrieve up to 17,534" << endl;
cin >> userNum;
bridges.setDescription("Load top " + to_string(userNum) + " games.");
vertex = "Top " + to_string(userNum) + " games";
graph.addVertex(vertex);
graph.getVertex(vertex)->setSize(MAX_VERTEX_SIZE);
graph.getVertex(vertex)->setColor("black");
for(int i = 0; i < userNum; i++){ //need to change on whether we are retirieving game object or title
tempGame = maxHeap.removeTop();
tempGenre = tempGame.getGameGenre()[0];
displayInfo = tempGame.getTitle() + ": " + tostring(tempGame.getRating()) + " " + tempGame.getPlatformType() + " " + tempGenre;
graph.addVertex(displayInfo);
graph.getVertex(displayInfo)->setSize(tempGame.getRating() * VERTEX_SIZE_CONST);
colorValue = int(ceil(tempGame.getRating())) - 1;
graph.getVertex(displayInfo)->setColor(colors[colorValue]);
graph.addEdge(displayInfo,vertex);
}
bridges.setDataStructure(&graph);
bridges.visualize();
break;
default:
cout << "Unrecognized input." << endl;
break;
}//end of switch
}//end of while
cout << "Thank you for participating!" << endl;
return 0;
}//end of main