Repository navigation
Expand file tree
/
Copy pathGameRec.cpp
More file actions
576 lines (558 loc) · 20.2 KB
/
Copy pathGameRec.cpp
File metadata and controls
576 lines (558 loc) · 20.2 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
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
/*
* File: Game.cpp
* Author: Shawn Garello
* Created on 11/30/2025,
* Purpose: Game Class Implementation
*/
#include "GameRec.h"
#include "Board.h"
#include <cstring> // for strcpy
#include <iomanip>
#include <iostream>
#include <fstream> // files
#include <list>
#include <map>
#include <algorithm>
#include <utility>
#include <set>
#include <queue>
#include <stack>
#include <thread>
#include <chrono>
#include "AVL.h"
#include <unordered_map>
int* GameRec::turn = new int(1);
GameRec::GameRec(Board *board,char *fromPos,char *toPos){
brd = board;
strcpy(from,fromPos);
strcpy(to,toPos);
}
GameRec::GameRec(Board *board){
brd = board;
}
GameRec::GameRec(const GameRec &gmeRc){
brd = gmeRc.brd;
strcpy(from,gmeRc.from);
strcpy(to,gmeRc.to);
}
GameRec::~GameRec(){}
void GameRec::gamePly(Board *board,fstream &binOut,fstream &txtOut){
list<GameRec *> record1; // record of player 1 moves;
queue<GameRec *> record2; // record of player 2 moves;
stack<GameRec *> prevMve;
map<int,AbsPiece*> tknP1;
map<int,AbsPiece *> tknP2;
unordered_map<unsigned int, int> hshTble;
AVL mveIndx; // stores turn numbers with trees.
map<int, GameRec*> mveLkUp; // maps turn to move
AbsPiece*** brdCopy;
AbsPiece*** brd = board->getBrd();
map<string,int> p1;
map<string,int>p2;
string player;
bool isChck = false;
bool canMove = false;
const int SIZE = 3;
int p1KngRw=7;//row of player 1 king
int p1KngCl=4;//col of player 1 king
int p2KngRw=0;//row of player 2 king
int p2KngCl=4;//col of player 2 king
bool kpPly = true;
do{
int frmRow = 0;int frmCol = 0;
int toRow=0;int toCol = 0;
char from[SIZE];
char to[SIZE];
cout<<endl;
player = *turn%2==0?"Player 2":"Player 1";
do{
isChck = false;
isChck=*turn%2==0?board->isAtck(brd,p2KngRw,p2KngCl):board->isAtck(brd,p1KngRw,p1KngCl);
if(isChck)cout<<setw(18)<<"CHECK! "<<player<<" IS IN CHECK."<<endl;
try{
kpPly=getInpt(from,to);
if(!kpPly)break;
}
catch (const char *msg){
cout<<"Error: "<<msg;
}
cnvrtIn(from,frmRow,frmCol);
cnvrtIn(to,toRow,toCol);
if(brd[frmRow][frmCol]->getOwnr()==player){
if(player=="Player 2"){
canMove=brd[frmRow][frmCol]->cnMvPce(board,frmRow,frmCol,toRow,toCol,isChck,p2KngRw,p2KngCl);
}
else canMove=brd[frmRow][frmCol]->cnMvPce(board,frmRow,frmCol,toRow,toCol,isChck,p1KngRw,p1KngCl);
}
}while(!canMove);
if(!kpPly)break;
if(brd[frmRow][frmCol]->getHsMv()==false)brd[frmRow][frmCol]->setHsMv(true);
AbsPiece* piece = brd[frmRow][frmCol];
board->mvePce(brd,frmRow,frmCol,toRow,toCol,tknP1,tknP2,turn);
if(brd[toRow][toCol]->getName() == "King"){
if(player == "Player 1"){
p1KngRw = toRow;
p1KngCl = toCol;
}
else if(player == "Player 2"){
p2KngRw = toRow;
p2KngCl = toCol;
}
}
/*
debug
for(int i = 0; i < 8; i++) {
for(int j = 0; j < 8; j++) {
AbsPiece* piece = brd[i][j];
cout << "Piece at [" << i << "][" << j << "]: "
<< "pce = " << piece->getPce() << ", "
<< "name = " << piece->getName() << ", "
<< "owner = " << piece->getOwnr() << ", "
<< "hasMove = " << (piece->getHsMv() ? "true" : "false")
<< endl;
}
}
cout<<"King player 1 pos row:"<<p1KngRw<<" col:"<<p1KngCl<<endl;
cout<<"King player 2 pos row:"<<p2KngRw<<" col:"<<p2KngCl<<endl;
*/
GameRec *rec = filObj(board,from,to,turn);
mveIndx.root = mveIndx.insert(mveIndx.root, *turn);
mveLkUp[*turn] = new GameRec(*rec);
string mveStr = string(rec->getFrom()) + "->" + string(rec->getTo());
unsigned int moveHsh = DJBHash(mveStr);
hshTble[moveHsh] = *turn;
GameRec *copy2 = rec;//copies and points to same thing using overlaoded =
GameRec *copy1 = new GameRec(*rec);// copies using copy constructor
if(*turn%2==0){
record2.push(copy1);
}
else{
record1.push_back(copy1);
}
if(*copy1==*rec){
wrtBin(binOut,rec,piece);
wrtTxt(txtOut,rec,piece);
}
prevMve.push(new GameRec(*copy1));
dsplyBd(board,8,8,rec,toRow,toCol);
pair<int,int> points = clcScor(p1,p2,brd);
cout << endl;
shwScor(p1,p2,points);
delete rec;
(*turn)++;
canMove = false;
//testing template function
//shwPlyr<int>(1);
cout<<endl<<" ";
shwPlyr<string>(player);
}while(kpPly);
//delete turn;
cout << endl;
map<string, list<string>> p1Graph;
map<string, list<string>> p2Graph;
bldGrph(board, brd, "Player 1", p1Graph);
shwGrph(p1Graph, "Player 1");
bldGrph(board, brd, "Player 2", p2Graph);
shwGrph(p2Graph, "Player 2");
cout<<endl<<setw(30)<<"END OF GAME"<<endl;
cout<<setw(28)<<"HISTORY"<<endl;
int moveNo = 1;
list<GameRec*>::iterator it = record1.begin(); // iterator for Player 1 (list)
list<GameRec*>::iterator end = record1.end(); // end of list
prntHst(it,end,record2,moveNo);
cout << endl;
shwCptr(tknP1, "Player 2"); // Player 2's captures (took from P1)
cout << endl;
shwCptr(tknP2, "Player 1"); // Player 1's captures (took from P2)
cout << endl;
//cleanup remaining GameRec* in the list
for(GameRec* p : record1){
delete p;
}
record1.clear();
rewind(prevMve,board,tknP1,tknP2);
cout << "\nAVL Tree (Inorder Traversal by Turn): ";
mveIndx.inorder(mveIndx.root);
cout << endl;
string lookupMove = "a2->a4";
unsigned int lookupHash = DJBHash(lookupMove);
if(hshTble.find(lookupHash) != hshTble.end()){
cout << "Move a2->a4 found on turn: " << hshTble[lookupHash] << endl;
} else {
cout << "Move a2-a4 not found." << endl;
}
for(map<int, GameRec*>::iterator it = mveLkUp.begin(); it != mveLkUp.end(); it++){
delete it->second;
}
mveLkUp.clear();
delete turn;
}
void GameRec::rewind(stack<GameRec*> &prev, Board* board,map<int,AbsPiece *> &p1Tkn,map<int, AbsPiece *> &p2Tkn){
AbsPiece*** brd = board->getBrd();
/* // Debug
cout << "Captured Pieces So Far" << endl;
cout << "Player 1:" << endl;
for (auto &p : p1Tkn) {
cout << "Turn " << p.first << ": "
<< p.second->getName() << " owned by "
<< p.second->getOwnr() << endl;
}
cout << "Player 2:" << endl;
for (auto &p : p2Tkn) {
cout << "Turn " << p.first << ": "
<< p.second->getName() << " owned by "
<< p.second->getOwnr() << endl;
}*/
char choice;
int count = 0;
int totalMv = prev.size();
cout <<"Review the game? (y/n): ";
cin >> choice;
if(choice != 'y' && choice != 'Y')return;
else{
dsplyBd(board,8,8);
cout << endl << endl;
this_thread::sleep_for(chrono::seconds(2)); // delay 2 seconds each time displaying previous moves
while(!prev.empty()){
GameRec* mve = prev.top();
int row1,row2,col1,col2;
prev.pop();
char* from = mve->getTo();
char* to = mve->getFrom();
cnvrtIn(from,row1,col1); // convert characters into their positions
cnvrtIn(to,row2,col2);
int rvrsTrn = totalMv - count;
if(p1Tkn.count(rvrsTrn)){ // if a piece is taken restore the taken piece in rewind
brd[row2][col2]->setPce(p1Tkn[rvrsTrn]->getPce());
}
if(p2Tkn.count(rvrsTrn)){
brd[row2][col2]->setPce(p2Tkn[rvrsTrn]->getPce());
}
board->mvePce(brd,row1,col1,row2,col2); // reverse moves from move history
dsplyBd(board,8,8);
cout << endl << endl;
this_thread::sleep_for(chrono::seconds(2));
count++;
delete mve;
}
}
// delete
for(map<int, AbsPiece*>::iterator it = p1Tkn.begin(); it != p1Tkn.end(); it++){
delete it->second;
}
p1Tkn.clear();
for(map<int, AbsPiece*>::iterator it = p2Tkn.begin(); it != p2Tkn.end(); it++){
delete it->second;
}
p2Tkn.clear();
while(!prev.empty()){
delete prev.top();
prev.pop();
}
}
pair<int,int> GameRec::clcScor(map<string,int> &plyr1,map<string,int> &plyr2,AbsPiece*** brd){
int p1Pt = 0;
int p2Pt = 0;
pair<int,int> scores;
map<string, int> pceVal ={{"Pawn",1},{"Rook",5},{"Queen",9}, // map of score value of each piece
{"Bishop",3},{"Knight",3}};
plyr1 ={{"Pawn",0},{"Rook",0},{"Queen",0}, // maps amount of specific pieces
{"Bishop",0},{"Knight",0}}; // taken to help calc players score
plyr2.clear();
copy(plyr1.begin(),plyr1.end(),inserter(plyr2,plyr2.begin())); // copy p1map to p2map
for(int i = 0 ; i < 8; i++){
for(int j = 0; j < 8; j++){
string owner = brd[i][j]->getOwnr();
string pceNme = brd[i][j]->getName();
if(owner == "Player 1") plyr1[pceNme]++;
if(owner == "Player 2") plyr2[pceNme]++;
}
}
for_each(pceVal.begin(),pceVal.end(),[&](const pair<string,int>& pv){
p1Pt += pv.second * plyr1[pv.first];
p2Pt += pv.second * plyr2[pv.first];
});
return scores = {p1Pt,p2Pt};
}
void GameRec::tknPce1(map<string,int> p2Map){ // pieces player 1 took
set<string> allPces = {"Pawn","Knight","Queen","Bishop","Rook"};
map<string,int> pceAmnt = {{"Pawn",8},{"Queen",1},{"Rook",2},
{"Knight",2},{"Bishop",2}};
map<string,string> p2Symbl = {{"Pawn","P"},{"Rook","R"},{"Knight","k"},
{"Bishop","B"},{"Queen","Q"}};
for(string p : allPces){ // print out the pieces player 1 took
int captred = pceAmnt[p] - p2Map[p];
for(int i = 0; i < captred; i++){
cout <<p2Symbl[p];
}
cout << ' ';
}
}
void GameRec::tknPce2(map<string,int> p1Map){ // pieces player 2 took
set<string> allPces = {"Pawn","Knight","Queen","Bishop","Rook"};
map<string,string> p1Symbl = {{"Pawn","!"},{"Rook","/V\\"},{"Knight","?"},
{"Bishop","(-)"},{"Queen","\\|/"}};
map<string,int> pceAmnt = {{"Pawn",8},{"Queen",1},{"Rook",2},
{"Knight",2},{"Bishop",2}};
for(string p : allPces){ // print out the pieces player 2 took
int captred = pceAmnt[p] - p1Map[p];
for(int i = 0; i < captred; i++){
cout <<p1Symbl[p];
}
cout << ' ';
}
}
void GameRec::shwScor(map<string,int> p1Map, map<string,int> p2Map,pair<int,int> plyrPts){
int score = 0;
if(max(plyrPts.first,plyrPts.second) == plyrPts.first && plyrPts.first != plyrPts.second){
score = plyrPts.first - plyrPts.second;
cout << "Player 1: ";tknPce1(p2Map);cout<<"+" << score << endl;
cout << "Player 2: ";tknPce2(p1Map);cout << endl;
}
else if(min(plyrPts.first,plyrPts.second)==plyrPts.first && plyrPts.first != plyrPts.second){
score = plyrPts.second - plyrPts.first;
cout << "Player 1: ";
tknPce1(p2Map);cout<<endl;
cout << "Player 2: ";
tknPce2(p1Map);cout<<" +" << score << endl;
}
else if(plyrPts.first == plyrPts.second){
cout << "Player 1: ";tknPce1(p2Map);cout << endl;
cout << "Player 2: ";tknPce2(p1Map);cout << endl;
}
}
void GameRec::dsplyBd(Board *board,int r,int c,GameRec *p,int toRow,int toCol){
AbsPiece*** brd = board->getBrd();
for(int i = 0;i < r;i++){
cout<<" |-----|-----|-----|-----|-----|-----|-----|-----|\n"<<r-i;
for(int y = 0; y<c;y++){
cout<<"| " << brd[i][y]->getPce() << " ";
if(y==7&&i==4){
cout<<*p; // uses overloaded operator <<
}
else if(y==7)cout<<"|\n";
}
}
cout<<" |-----|-----|-----|-----|-----|-----|-----|-----|"<<endl;
cout<<" a b c d e f g h ";
}
void GameRec::dsplyBd(Board *board,int r,int c){
AbsPiece*** brd = board->getBrd();
for(int i = 0;i < r;i++){
cout<<" |-----|-----|-----|-----|-----|-----|-----|-----|\n"<<r-i;
for(int y = 0; y<c;y++){
cout<<"| " << brd[i][y]->getPce() << " ";
if(y==7)cout<<"|\n";
}
}
cout<<" |-----|-----|-----|-----|-----|-----|-----|-----|"<<endl;
cout<<" a b c d e f g h ";
}
bool GameRec::getInpt(char *from, char *to){
cout <<"Enter position of piece and destination to be moved(ex:e4 e5) or (QIT GME) to stop:";
cin >> from >> to;
if(strcmp(from,"QIT")==0||strcmp(to,"GME")==0)return false;
if(from[0]<'a'||from[0]>'h' ||to[0]<'a'||to[0]>'h'
||from[1]<'1'||from[1]>'8'||to[1]<'1'||to[1]>'8') throw "invalid input";
return true;
}
void GameRec::cnvrtIn(char *plceArr, int &row, int &col){
switch(plceArr[0]){ // letters represent the index values of the enum
case('a'):col=A;break; // 0
case('b'):col=B;break; // 1
case('c'):col=C;break; // 2
case('d'):col=D;break; // 3
case('e'):col=E;break; // 4
case('f'):col=F;break; // 5
case('g'):col=G;break; // 6
case('h'):col=H;break; // 7
}
row = 8 - static_cast<int>(plceArr[1]-'0');//get correct number subtracting based on ascii number
}
void GameRec::wrtTxt(fstream &txtOut, GameRec *rec, AbsPiece *pce){
txtOut<<right;
if(rec->getTurn()%2!=0)txtOut<<endl;
txtOut<<"TURN "<<rec->getTurn()<<setw(20)<<"PIECE"<<setw(22)<<"MOVE\n";
txtOut<<pce->getOwnr()<<':'<<setw(14)<<pce->getName()<<'['<<pce->getPce()<<']'<<
setw(15)<<rec->getFrom()<<" to "<<rec->getTo()<<endl;
txtOut.flush();
}
void GameRec::wrtBin(fstream &binOut, GameRec *rec, AbsPiece *pce){
binOut.write(reinterpret_cast<char *>(pce->getPce()),4*sizeof(char));
int lenNme = pce->getName().length();
binOut.write(reinterpret_cast<char *>(&lenNme),sizeof(lenNme));//write size of string to know
binOut.write(pce->getName().c_str(),lenNme); //where string ends
int lenOwnr = pce->getOwnr().length();
binOut.write(reinterpret_cast<char *>(&lenOwnr),sizeof(lenOwnr));
binOut.write(pce->getOwnr().c_str(),lenOwnr);
bool hsMv = pce->getHsMv();
binOut.write(reinterpret_cast<char *>(&hsMv),sizeof(bool));
int t = rec->getTurn();
binOut.write(reinterpret_cast<char *>(&t),sizeof(int));
char* toPos = rec->getTo();
binOut.write(reinterpret_cast<char *>(toPos),3*sizeof(char));
char* fromPos = rec->getFrom();
binOut.write(reinterpret_cast<char *>(fromPos),3*sizeof(char));
}
void GameRec::setTo(const char toPos[3]){
strcpy(to,toPos);
}
void GameRec::setFrom(const char fromPos[3]){
strcpy(from,fromPos);
}
void GameRec::setTurn(int *t){
*turn = *t;
}
GameRec* GameRec::filObj(Board *board,char *from, char *to,int *turn){
GameRec *rec = new GameRec(board);
rec->setFrom(from);
rec->setTo(to);
rec->setTurn(turn); // return ptr of dynamically allocated structure
return rec;
}
ostream& operator<<(ostream &cout, GameRec &p) {
cout<<"| PREVIOUS - TURN "<<p.getTurn()<<':'<<setw(10)<<' '<<p.getFrom()<<" to "
<<p.getTo()<<"\n";
return cout;
}
bool GameRec::operator==(const GameRec &rec2){
if (brd != rec2.brd) return false;
if (strcmp(from, rec2.from) != 0) return false;
if (strcmp(to, rec2.to) != 0) return false;
if (*turn != *(rec2.turn)) return false;
return true;
}
GameRec& GameRec::operator=(const GameRec &rec2){
brd = rec2.brd;
strcpy(from, rec2.from);
strcpy(to, rec2.to);
return *this;
}
template <class T>
void GameRec::shwPlyr(T data){
cout<< "Previous Turn: "<< data << endl;
}
void GameRec::prntHst(list<GameRec*>::iterator it,list<GameRec*>::iterator end,queue<GameRec*> &p2,int moveNo){
if(it == end && p2.empty()) return; // base case
cout << setw(6) << moveNo;
// Player 1 move (linked list)
if(it != end){
GameRec* g1 = *it;
cout << setw(18)
<< string(g1->getFrom()) + "->" + string(g1->getTo());
++it;
}
else{
cout << setw(18) << " ";
}
cout << " ";
// Player 2 move (queue)
if(!p2.empty()){
GameRec* g2 = p2.front();
p2.pop();
cout << string(g2->getFrom()) + "->" + string(g2->getTo());
delete g2;
}
cout << '\n';
prntHst(it, end, p2, moveNo + 1); // recursive function call
}
unsigned int GameRec::DJBHash(const std::string& str){
unsigned int hash = 5381;
for(std::size_t i = 0; i < str.length(); i++){
hash = ((hash << 5) + hash) + str[i];
}
return hash;
}
void GameRec::shwCptr(map<int, AbsPiece*>& captures, string player){
int size = captures.size();
if(size == 0){
cout << player << " captured no pieces." << endl;
return;
}
// Convert map to array
pair<int, AbsPiece*>* arr = new pair<int, AbsPiece*>[size];
int idx = 0;
for(pair<int, AbsPiece*> p : captures){
arr[idx++] = p;
}
// Recursive Quick Sort
qckSort(arr, 0, size - 1);
// Display sorted captures
cout << player << " captures (sorted by piece value):" << endl;
for(int i = 0; i < size; i++){
cout << " Turn " << arr[i].first << ": "
<< arr[i].second->getName() << " ["
<< arr[i].second->getPce() << "] "
<< "(value: " << getPcVl(arr[i].second->getName()) << ")" << endl;
}
delete[] arr;
}
void GameRec::qckSort(pair<int, AbsPiece*>* arr, int low, int high){
if(low < high){
int pi = prtitn(arr, low, high);
qckSort(arr, low, pi - 1);
qckSort(arr, pi + 1, high);
}
}
int GameRec::prtitn(pair<int, AbsPiece*>* arr, int low, int high){
int pivot = getPcVl(arr[high].second->getName()); // Sort by piece value
int i = low - 1;
for(int j = low; j < high; j++){
if(getPcVl(arr[j].second->getName()) < pivot){
i++;
swap(arr[i], arr[j]);
}
}
swap(arr[i + 1], arr[high]);
return i + 1;
}
int GameRec::getPcVl(string name){
if(name == "Pawn") return 1;
if(name == "Knight" || name == "Bishop") return 3;
if(name == "Rook") return 5;
if(name == "Queen") return 9;
return 0; // Empty space
}
void GameRec::bldGrph(Board* board, AbsPiece*** brd, string player, map<string, list<string>>& graph){
graph.clear();
for(int i = 0; i < 8; i++){
for(int j = 0; j < 8; j++){
if(brd[i][j]->getOwnr() == player){
string from = sqrStr(i, j);
list<string> validMoves;
// Check all possible destinations
for(int r = 0; r < 8; r++){
for(int c = 0; c < 8; c++){
if(i != r || j != c){ // Not same square
bool isCheck = false;
int kingRow = (player == "Player 1") ? 7 : 0;
int kingCol = 4;
// Use cnMvPce to check valid moves
if(brd[i][j]->cnMvPce(board, i, j, r, c, isCheck, kingRow, kingCol)){
validMoves.push_back(sqrStr(r, c));
}
}
}
}
if(!validMoves.empty()){
graph[from] = validMoves;
}
}
}
}
}
string GameRec::sqrStr(int row, int col){
char colChar = 'a' + col;
char rowChar = '1' + (7 - row);
return string(1, colChar) + string(1, rowChar);
}
void GameRec::shwGrph(map<string, list<string>>& graph, string player){
cout << "\n" << player << " Move Graph (Valid Moves):" << endl;
for(pair<string, list<string>> entry : graph){
cout << entry.first << " -> ";
for(string dest : entry.second){
cout << dest << " ";
}
cout << endl;
}
}