-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSolitaireCode.cpp
More file actions
827 lines (792 loc) · 20.7 KB
/
Copy pathSolitaireCode.cpp
File metadata and controls
827 lines (792 loc) · 20.7 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
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
#include <iostream>
#include <ctime>
#include <string>
using namespace std;
class card {
public:
string rank;
string suit;
bool faceup;
card(string r="", string s="", bool f = false)
{
rank = r;
suit = s;
faceup = f;
}
void SetRankandSuit(string r, string s) {
rank = r;
suit = s;
}
void ChangeFace() {
faceup = !faceup;
}
bool operator>(card& w) {
if ((rank == "K") && (w.rank == "Q")) return true;
else if ((rank == "Q") && (w.rank == "J")) return true;
else if ((rank == "J") && (w.rank == "10")) return true;
else if ((rank == "10") && (w.rank == "9")) return true;
else if ((rank == "9") && (w.rank == "8")) return true;
else if ((rank == "8") && (w.rank == "7")) return true;
else if ((rank == "7") && (w.rank == "6")) return true;
else if ((rank == "6") && (w.rank == "5")) return true;
else if ((rank == "5") && (w.rank == "4")) return true;
else if ((rank == "4") && (w.rank == "3")) return true;
else if ((rank == "3") && (w.rank == "2")) return true;
else if ((rank == "2") && (w.rank == "A")) return true;
return false;
}
bool checkalternativecolor(card& rhs) {
if (((suit == "\4") || (suit == "\3")) && ((rhs.suit == "\5") || (rhs.suit == "\6"))) return true;
else if (((suit == "\5") || (suit == "\6")) && ((rhs.suit == "\4") || (rhs.suit == "\3"))) return true;
return false;
}
bool checksamesuit(card& rhs) {
return (suit == rhs.suit);
}
void print() {
if (faceup) {
if ((suit == "\4") || (suit == "\3")) {
cout << "\033[91m";
cout << rank << suit;
cout << "\033[0m";
}
else cout << rank << suit;
}
else {
cout << "[ ]";
}
}
};
template <class T>
class list {
class node {
public:
T Data;
node* prev;
node* next;
node(T& d, node* p, node* n)
{
Data = d;
prev = p;
next = n;
}
node()
{
prev = next = nullptr;
}
};
node* head;
node* tail;
int size;
public:
class iterator {
friend class list;
node* current;
iterator(node* c)
{
current = c;
}
public:
iterator()
{
current = nullptr;
}
node* getcurrent() {
return current;
}
T& operator*() const //deference opr
{
return current->Data;
}
iterator& operator++()
{ //pre increment
current = current->next;
return *this;
}
iterator operator++(int)
{ // post increment
iterator old = *this;
current = current->next;
return old;
}
iterator& operator--()
{ //pre decrement
current = current->prev;
return *this;
}
iterator operator--(int)
{ // post decrement
iterator old = *this;
current = current->prev;
return old;
}
bool operator==(iterator rhs) {
return current == rhs.current;
}
bool operator!=(iterator rhs) {
return current != rhs.current;
}
};
list()
{
head = new node();
tail = new node();
head->next = tail;
tail->prev = head;
size = 0;
}
list(list&& rhs) {
head = rhs.head;
tail = rhs.tail;
rhs.head = nullptr;
rhs.tail = nullptr;
}
bool empty() {
return (head->next == tail);
}
T& gethead() {
return (head->next->Data);
}
T& gettail() {
return (tail->prev->Data);
}
iterator getlastnode() {
iterator it(tail->prev);
return it;
}
int getsize() { return size; }
iterator begin() {
iterator it(head->next);
return it;
}
iterator end() {
iterator it(tail);
return it;
}
void faceuplastnode() {
tail->prev->Data.faceup = true;
}
void facedownlastnode() {
tail->prev->Data.faceup = false;
}
bool Isanyfacedown() {
iterator it;
for (it = begin(); it != end(); it++) {
if (!(*it).faceup)
return true;
}
return false;
}
void insertatend(T d) {
node* t = new node(d, tail->prev, tail);
tail->prev->next = t;
tail->prev = t;
size++;
}
void addnodeslist(iterator it1,iterator it2,int k=1) {
node* t = it1.getcurrent();
t->prev = tail->prev;
tail->prev->next = t;
t = it2.getcurrent();
t->next = tail;
tail->prev = t;
size = size + k;
}
void addnode(iterator it) {
node* t = it.getcurrent();
t->prev = tail->prev;
t->next = tail;
tail->prev->next = t;
tail->prev = t;
size++;
}
void removeattail() {
if (tail->prev != head) {
node* temp = tail->prev;
tail->prev = temp->prev;
temp->prev->next = tail;
delete temp;
size--;
}
}
iterator movefromtail(int k=1) {
node* temp = tail;
for (int i = 0; i < k; i++) {
temp = temp->prev;
}
iterator it(temp);
size=size - k;
temp->prev->next = tail;
tail->prev = temp->prev;
return it;
}
int countfaceupcards() {
iterator it;
int count = 0;
for (it = begin(); it != end(); it++)
{
if ((*it).faceup)
count++;
}
return count;
}
T& getnodefromtail(int k=1) {
node* temp = nullptr;
node* c = tail;
for (int i = 0; i < k; i++)
{
temp = c->prev;
c = temp;
}
return (temp->Data);
}
void PrintAllListsAdjacently(list<card>& l1, list<card>& l2, list<card>& l3, list<card>& l4, list<card>& l5, list<card>& l6) {
list<card>::iterator it1 = l1.begin();
list<card>::iterator it2 = l2.begin();
list<card>::iterator it3 = l3.begin();
list<card>::iterator it4 = l4.begin();
list<card>::iterator it5 = l5.begin();
list<card>::iterator it6 = l6.begin();
iterator it = begin();
cout << "\t(" << size <<" cards)\t(" << l1.size << " cards)\t(" << l2.size << " cards)\t(" << l3.size << " cards)\t(" << l4.size <<" cards)\t(" << l5.size << " cards)\t(" << l6.size << " cards)" << endl;
while ((it!=end())||(it1 != l1.end())||(it2 != l2.end())||(it3 != l3.end())||(it4 != l4.end())|| (it5 != l5.end())|| (it6 != l6.end())) {
cout << "\t ";
if (it != end()) {
(*it).print();
++it;
}
cout << "\t\t ";
if (it1 != l1.end()) {
(*it1).print();
++it1;
}
cout << "\t\t ";
if (it2 != l2.end()) {
(*it2).print();
++it2;
}
cout << "\t\t ";
if (it3 != l3.end()) {
(*it3).print();
++it3;
}
cout << "\t\t ";
if (it4 != l4.end()) {
(*it4).print();
++it4;
}
cout << "\t\t ";
if (it5 != l5.end()) {
(*it5).print();
++it5;
}
cout << "\t\t ";
if (it6 != l6.end()) {
(*it6).print();
++it6;
}
cout << endl;
}
}
~list()
{
while (head->next != tail)
{
node* temp = head->next;
head->next = temp->next; temp->next->prev = head;
delete temp;
}
delete head;
delete tail;
}
};
class Command {
public:
string commandType;
string source;
string destination;
int numCards;
Command(string type="", string src = "", string dest = "", int num = 1)
: numCards(num) {
commandType = type;
source = src;
destination = dest;
}
};
template <class T>
class stack {
list <T> s;
public:
void push(T d) {
s.insertatend(d);
}
int Size() {
return s.getsize();
}
bool pop(T& d) {
if (!s.empty())
{
d = s.gettail();
s.removeattail();
return true;
}
else return false;
}
bool Isempty() {
return s.empty();
}
bool peekTop(T& d) {
if (!s.empty())
{
d = s.gettail();
return true;
}
else return false;
}
list<card>::iterator moveTop() {
return s.movefromtail();
}
void addAttop(list<card>::iterator it) {
s.addnode(it);
}
};
class Game {
list <card> tableau[7];
stack <card> foundation[4];
stack <card> stockpile;
stack <card> wastepile;
stack <Command> AllCommands;
int moves;
public:
Game() { moves = 85; }
void InitializeDeck(card deck[52]) {
string suits[] = { "\3", "\6", "\5", "\4"};
string ranks[] = { "A", "2", "3", "4", "5", "6", "7", "8", "9", "10", "J", "Q", "K" };
int index = 0;
for (int i = 0; i < 4; ++i) {
for (int j = 0; j < 13; ++j) {
deck[index].SetRankandSuit(ranks[j], suits[i]);
index++;
}
}
while (index < 52) {
stockpile.push(deck[index++]);
}
}
void shuffleDeck(card deck[52]) {
srand(time(0));
for (int i = 0; i < 52; ++i) {
int randIndex = rand() % 52;
card temp = deck[i];
deck[i] = deck[randIndex];
deck[randIndex] = temp;
}
}
void GameSetUp(){
card deck[52];
InitializeDeck(deck);
shuffleDeck(deck);
int index = 0;
for (int i = 0; i < 7; ++i) {
for (int j = 0; j <= i; ++j) {
if (j == i) {
deck[index].ChangeFace();
}
tableau[i].insertatend(deck[index++]);
}
}
while (index < 52) {
stockpile.push(deck[index]);
index++;
}
}
bool movefromcol(string src, string des,int& numofcards) {
int colsrc = src[1] - '1';
if ((colsrc < 0) || (colsrc > 6)) return false;
if (tableau[colsrc].empty())
return false;
if ((des[0] == 'c') || (des[0] == 'C')) {
cout << "Enter number of cards: ";
cin >> numofcards;
if ((numofcards > (tableau[colsrc].countfaceupcards())) || (numofcards < 0)) return false;
if (numofcards == 0) return true;
card c1;
c1 = tableau[colsrc].getnodefromtail(numofcards);
int coldes = des[1] - '1';
if ((coldes < 0) || (coldes > 6)) return false;
if (tableau[coldes].empty()) {
if ((c1.rank == "K")) {
list<card>::iterator it2 = tableau[colsrc].getlastnode();
list<card>::iterator it = tableau[colsrc].movefromtail(numofcards);
tableau[colsrc].faceuplastnode();
tableau[coldes].addnodeslist(it, it2, numofcards);
moves--;
return true;
}
else return false;
}
card c2 = tableau[coldes].gettail();
if ((c1.checkalternativecolor(c2)) && (c2 > c1)) {
list<card>::iterator it2 = tableau[colsrc].getlastnode();
list<card>::iterator it = tableau[colsrc].movefromtail(numofcards);
tableau[colsrc].faceuplastnode();
tableau[coldes].addnodeslist(it, it2, numofcards);
moves--;
return true;
}
else return false;
}
else if ((des[0] == 'f') || (des[0] == 'F')) {
card c1;
c1 = tableau[colsrc].getnodefromtail();
int foundIndex = des[1] - '1';
if ((foundIndex < 0) || (foundIndex > 6)) return false;
if (foundation[foundIndex].Isempty()) {
if ((c1.rank == "A")) {
list<card>::iterator it = tableau[colsrc].movefromtail();
tableau[colsrc].faceuplastnode();
foundation[foundIndex].addAttop(it);
return true;
}
else return false;
}
card f;
foundation[foundIndex].peekTop(f);
if ((f.checksamesuit(c1)) && (c1 > f)) {
list<card>::iterator it = tableau[colsrc].movefromtail();
tableau[colsrc].faceuplastnode();
foundation[foundIndex].addAttop(it);
return true;
}
else return false;
}
else return false;
}
bool movefromwaste(string des) {
if (wastepile.Isempty())
return false;
card w;
wastepile.peekTop(w);
if ((des[0] == 'c') || (des[0] == 'C')) {
int colIndex = des[1] - '1';
if ((colIndex < 0) || (colIndex > 6)) return false;
if (tableau[colIndex].empty()) {
if ((w.rank == "K")) {
list<card>::iterator it = wastepile.moveTop();
tableau[colIndex].addnode(it);
moves--;
return true;
}
else return false;
}
card c = tableau[colIndex].gettail();
if ((c.checkalternativecolor(w)) && (c > w)) {
list<card>::iterator it = wastepile.moveTop();
tableau[colIndex].addnode(it);
moves--;
return true;
}
else return false;
}
else if ((des[0] == 'f') || (des[0] == 'F')) {
int foundIndex = des[1] - '1';
if ((foundIndex < 0) || (foundIndex > 6)) return false;
if (foundation[foundIndex].Isempty()) {
if ((w.rank == "A")) {
list<card>::iterator it = wastepile.moveTop();
foundation[foundIndex].addAttop(it);
return true;
}
else return false;
}
card f;
foundation[foundIndex].peekTop(f);
if ((f.checksamesuit(w)) && (w > f)) {
list<card>::iterator it = wastepile.moveTop();
foundation[foundIndex].addAttop(it);
return true;
}
else return false;
}
else return false;
}
bool movefromfound(string src, string des) {
int foundIndex = src[1] - '1';
if ((foundIndex < 0) || (foundIndex > 6)) return false;
if (foundation[foundIndex].Isempty())
return false;
card f;
foundation[foundIndex].peekTop(f);
if ((des[0] == 'c') || (des[0] == 'C')) {
int colIndex = des[1] - '1';
if ((colIndex < 0) || (colIndex > 6)) return false;
if (tableau[colIndex].empty()) {
if ((f.rank == "K")) {
list<card>::iterator it = foundation[foundIndex].moveTop();
tableau[colIndex].addnode(it);
return true;
}
else return false;
}
card c = tableau[colIndex].gettail();
if ((c.checkalternativecolor(f)) && (c > f)) {
list<card>::iterator it = foundation[foundIndex].moveTop();
tableau[colIndex].addnode(it);
return true;
}
else return false;
}
else if ((des[0] == 'f') || (des[0] == 'F')) {
int founddesIndex = des[1] - '1';
if ((founddesIndex < 0) || (founddesIndex > 6)) return false;
if (foundIndex == founddesIndex) {
return true;
}
else if (foundation[founddesIndex].Isempty()) {
if (f.rank == "A") {
list<card>::iterator it = foundation[foundIndex].moveTop();
foundation[founddesIndex].addAttop(it);
return true;
}
else return false;
}
}
else return false;
}
void draw() {
if (!stockpile.Isempty()) {
list<card>::iterator it = stockpile.moveTop();;
(*it).ChangeFace();
wastepile.addAttop(it);
}
else {
while (!wastepile.Isempty()) {
list<card>::iterator it = wastepile.moveTop();
(*it).ChangeFace();
stockpile.addAttop(it);
}
}
}
bool undo() {
Command lastcommand;
if (AllCommands.pop(lastcommand)) {
string input = lastcommand.commandType;
if ((input == "s") || (input == "S"))
{
if (wastepile.Isempty()) {
while (!stockpile.Isempty()) {
list<card>::iterator it = stockpile.moveTop();
(*it).ChangeFace();
wastepile.addAttop(it);
}
}
else {
list<card>::iterator it = wastepile.moveTop();
(*it).ChangeFace();
stockpile.addAttop(it);
}
}
else if ((input == "m") || (input == "M"))
{
string src = lastcommand.source;
string des = lastcommand.destination;
int numofcards = lastcommand.numCards;
if ((src[0] == 'c') || (src[0] == 'C')) {
int colsrc = src[1] - '1';
if (tableau[colsrc].empty()) return true;
if ((des == "w") || (des == "W")) {
list<card>::iterator it = tableau[colsrc].movefromtail();
wastepile.addAttop(it);
}
else if ((des[0] == 'f') || (des[0] == 'F')) {
int foundindex = des[1] - '1';
list<card>::iterator it = tableau[colsrc].movefromtail();
foundation[foundindex].addAttop(it);
}
else if ((des[0] == 'c') || (des[0] == 'C')) {
int coldes = des[1] - '1';
tableau[coldes].facedownlastnode();
list<card>::iterator it2 = tableau[colsrc].getlastnode();
list<card>::iterator it = tableau[colsrc].movefromtail(numofcards);
tableau[coldes].addnodeslist(it, it2, numofcards);
}
}
else if ((src[0] == 'f') || (src[0] == 'F')) {
int foundsrc = src[1] - '1';
if (foundation[foundsrc].Isempty()) return true;
if ((des == "w") || (des == "W")) {
list<card>::iterator it = foundation[foundsrc].moveTop();
wastepile.addAttop(it);
}
else if ((des[0] == 'f') || (des[0] == 'F')) {
int founddes = des[1] - '1';
list<card>::iterator it = foundation[foundsrc].moveTop();
foundation[founddes].addAttop(it);
}
else if ((des[0] == 'c') || (des[0] == 'C')) {
int coldes = des[1] - '1';
list<card>::iterator it = foundation[foundsrc].moveTop();
tableau[coldes].facedownlastnode();
tableau[coldes].addnode(it);
}
}
}
return true;
}
else return false;
}
bool RunCommand(string input) {
string src, des;
cout << "Enter Source: ";
cin >> src;
cout << "Enter Destination: ";
cin >> des;
int numofcards = 1;
if ((src[0] == 'c')|| (src[0] == 'C')) {
if (!movefromcol(src,des,numofcards)) return false;
}
else if ((src == "w")|| (src == "W")) {
if (!movefromwaste(des)) return false;
}
else if ((src[0] == 'f')|| (src[0] == 'F')) {
if (!movefromfound(src,des)) return false;
}
else {
return false;
}
Command currentCommand(input, des,src, numofcards);
AllCommands.push(currentCommand);
return true;
}
bool CheckWinCondition() {
for (int i = 0; i < 4; ++i) {
card d;
if (foundation[i].peekTop(d)) {
if (d.rank != "K")
return false;
}
else return false;
}
for (int i = 0; i < 7; i++) {
if (tableau[i].Isanyfacedown())
return false;
}
return true;
}
void PrintGameState() {
system("cls");
cout << "\033[1;6;3;33m";
cout << "\n\n\t\t\t\t\t\t \5 SOLITAIRE \5" << endl;
cout << "\033[0;91m";
cout << "Moves left : " << moves << endl;
cout << "\033[1;6;94m";
cout << "________________________________________________________________________________________________________________________\n" << endl;
cout << "\033[0m";
cout << "Stockpile\t\tWastepile\t\t\tFoundation 1\tFoundation 2\tFoundation 3\tFoundation 4" << endl;
card c;
if (stockpile.peekTop(c)) { c.print(); }
else cout << "[ ]";
cout << "\t\t\t";
if(wastepile.peekTop(c)) { c.print(); }
else cout << "[ ]";
cout << "\t\t\t\t";
for (int i = 0; i < 4; i++)
{
if(foundation[i].peekTop(c)) { c.print(); }
else cout << "[ ]";
cout << "\t\t";
}
cout << "\n(" << stockpile.Size() << " cards)\t\t(" << wastepile.Size() << " cards)\t\t\t";
for (int i = 0; i < 4; i++) cout <<"(" << foundation[i].Size() << " cards)\t";
cout << "\033[1;93m";
cout << "\n\n\n______________________________________________________Tableau_________________________________________________________" << endl;
cout << "\033[0m";
cout << "\tColumn1 \t Column2 \t Column3 \t Column4 \t Column5 \t Column6 \t Column7" << endl;
tableau[0].PrintAllListsAdjacently(tableau[1], tableau[2], tableau[3], tableau[4], tableau[5], tableau[6]);
cout << "\033[1;6;94m";
cout << "________________________________________________________________________________________________________________________\n" << endl;
cout << "\033[0m";
}
void GameInstructionsAndDisplay() {
cout << "\033[1;6;3;93m";
cout << "\n\n\t\t\t\t\t\t \5 SOLITAIRE \5" << endl;
cout << "\033[0m";
cout << "\033[6;91m";
cout << "\n\n\n\4 \3 \5 \6 \4 \3 \5 \6 \4 \3 \5 \6 \4 \3 \5 \6 \4 \3 \5 \6 \4 \3 \5 \6 \4 \3 \5 \6 \4 \3 \5 \6 \4 \3 \5 \6 \4 \3 \5 \6 \4 \3 \5 \6 \4 \3 \5 \6 \4 \3 \5 \6 \4 \3 \5 \6 \4 \3 \5 \6" << endl;
cout << "\033[1;6;94m";
cout << "________________________________________________________________________________________________________________________\n" << endl;
cout << "\033[0;93m";
cout << "\nGame Commands And Instructions: " << endl;
cout << "\033[0m";
cout << "\n\n~ Command s to draw a card from the stack\n~ Command q to quit the game \n~ Command z to undo recent command\n~ Command m to move cards\n~ Sources can be columns (c1,c2,c3,c4,c5,c6,c7) or foundations (f1,f2,f3,f4) or wastepile (w)\n~ Destination can be columns (c1,c2,c3,c4,c5,c6,c7) or foundations (f1,f2,f3,f4)\n~ Cards should be placed in ascending rank order and alternative color" << endl;
cout << "\033[1;6;94m";
cout << "\n________________________________________________________________________________________________________________________" << endl;
cout << "\033[6;91m";
cout << "\n\4 \3 \5 \6 \4 \3 \5 \6 \4 \3 \5 \6 \4 \3 \5 \6 \4 \3 \5 \6 \4 \3 \5 \6 \4 \3 \5 \6 \4 \3 \5 \6 \4 \3 \5 \6 \4 \3 \5 \6 \4 \3 \5 \6 \4 \3 \5 \6 \4 \3 \5 \6 \4 \3 \5 \6 \4 \3 \5 \6" << endl;
cout << "\033[1;6;34m";
cout << "\n\n \t\t\t\t\tPress enter to Start the Game...." << endl;
cout << "\033[0m";
cin.get();
system("cls");
PrintGameState();
}
void RunGame() {
GameSetUp();
GameInstructionsAndDisplay();
string input;
while (true) {
cout << "Enter your command: ";
cin >> ws;
getline(cin,input);
if ((input == "q") || (input == "Q")){
break;
}
else if ((input == "z") || (input == "Z")) {
if (!undo()) {
cout << "\033[1;6;3;31m";
cout << "\tYou are at the start of the game... \t" << endl;
cout << "\033[0m";
continue;
}
}
else if ((input == "s") || (input == "S")) {
draw();
Command currentCommand(input);
AllCommands.push(currentCommand);
}
else if ((input == "m") || (input == "M")) {
if (!RunCommand(input)) {
cout << "\033[1;6;3;31m";
cout << "\tI N V A L I D M O V E \t" << endl;
cout << "\033[0m";
continue;
}
}
else {
cout << "\033[1;6;3;31m";
cout << "\tI N V A L I D M O V E \t" << endl;
cout << "\033[0m";
continue;
}
PrintGameState();
if (CheckWinCondition()) {
cout << "\033[1;6;3;32m";
cout << "\n\t\t\t\t\t < G A M E W O N > \t\n\t\t\t\t\tC O N G R A T U L A T I O N S :)" << endl;
cout << "\033[0m";
break;
}
if (moves==0) {
cout << "\033[1;6;3;91m";
cout << "\n\t\t\t\t\t You lost the Game :(" << endl;
cout << "\033[0m";
break;
}
}
}
};
int main() {
Game solitaire;
solitaire.RunGame();
system("pause");
return 0;
}