-
Notifications
You must be signed in to change notification settings - Fork 0
/
PlayerStrategies.cpp
785 lines (629 loc) · 21.7 KB
/
PlayerStrategies.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
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
#include "PlayerStrategies.h"
#include "Player.h"
#include "Orders.h"
#include "GameEngine.h"
#include "Map.h"
PlayerStrategy::PlayerStrategy(): PlayerStrategy(nullptr)
{
//Player not set yet. Will set with setPlayer();
}
PlayerStrategy::~PlayerStrategy()
{
p = nullptr; //Do NOT delete p! p is an actual Player so do not delete it!
}
void PlayerStrategy::setPlayer(Player* newPlayer)
{
p = newPlayer;
}
Player* PlayerStrategy::getPlayer()
{
return p;
}
PlayerStrategy::PlayerStrategy(Player* p): p(p)
{
}
PlayerStrategy::PlayerStrategy(const PlayerStrategy& other): p(other.p)
{
}
PlayerStrategy& PlayerStrategy::operator=(const PlayerStrategy& rhs)
{
this->p = rhs.p;
return *this;
}
std::ostream& operator<<(std::ostream& out, const PlayerStrategy& playerStrategy)
{
out << "PlayerStrategy class pointing to player with the following info:" << std::endl;
out << *playerStrategy.p;
return out;
}
std::ostream& operator<<(std::ostream& out, const NeutralPlayerStrategy& neutral)
{ //If the neutral player was attacked, the player is now aggressive!
if(*neutral._wasAttacked) {
out << *neutral._agressiveStrategy;
}
else {
out << "Neutral strategy: Computer player that never issues any order. If a Neutral player is attacked, it becomes an Aggressive player." << std::endl;
out << "Player info:" << std::endl;
out << *neutral.p;
}
return out;
}
std::ostream& operator<<(std::ostream& out, const AggressivePlayerStrategy& aggressive)
{
out << "Aggressive player: computer player that focuses on attack (deploys or advances armies on its strongest country, then always advances to enemy territories until it cannot do so anymore)." << std::endl;
out << "Player info:" << std::endl;
out << *aggressive.p;
return out;
}
std::ostream& operator<<(std::ostream& out, const BenevolentPlayerStrategy& benevolent)
{
out << "Benevolent player: computer player that focuses on protecting its weak countries (deploys or advances armies on its weakest countries, never advances to enemy territories)." << std::endl;
out << "Player info:" << std::endl;
out << *benevolent.p;
return out;
}
std::ostream& operator<<(std::ostream& out, const CheaterPlayerStrategy& cheater)
{
out << "Cheater player: computer player that automatically conquers all territories that are adjacent to its own territories(only once per turn)." << std::endl;
out << "Player info:" << std::endl;
out << *cheater.p;
return out;
}
std::ostream& operator<<(std::ostream& out, const HumanPlayerStrategy& human)
{
out << " Human player: requires user interactions to make decisions." << std::endl;
out << "Player info:" << std::endl;
out << *human.p;
return out;
}
//----------------------------------------------------------------------------------------
//----------------------------------------------------------------------------------------
//-----------------------------------Neutral Player Stategy-------------------------------
//----------------------------------------------------------------------------------------
//----------------------------------------------------------------------------------------
NeutralPlayerStrategy::NeutralPlayerStrategy() : PlayerStrategy()
{
_wasAttacked = new bool(false);
_agressiveStrategy = new AggressivePlayerStrategy();
}
NeutralPlayerStrategy::~NeutralPlayerStrategy()
{
delete _wasAttacked;
delete _agressiveStrategy;
}
void NeutralPlayerStrategy::issueOrder(GameEngine* gameEngine, string orderType)
{
//If player was attacked, permanently turn _wasAttacked to true
if (p->wasAttacked() && *_wasAttacked == false) {
*_wasAttacked = true;
std::cout << "!!! Neutral player \"" << *p->getName() << "\" was attacked! This player will now become aggressive !!!" << std::endl;
}
//No orders to issue UNLESS attacked
if (*_wasAttacked) {
if (_agressiveStrategy->getPlayer() == nullptr)
_agressiveStrategy->setPlayer(p);
else
_agressiveStrategy->issueOrder(gameEngine, orderType); //We will now let the aggressive strategy issue orders
}
}
vector<Territory*> NeutralPlayerStrategy::toAttack(Territory* t)
{
//If player was attacked, permanently turn _wasAttacked to true
if (p->wasAttacked() && *_wasAttacked == false) {
*_wasAttacked = true;
std::cout << "!!! Neutral player \"" << *p->getName() << "\" was attacked! This player will now become aggressive !!!" << std::endl;
}
//Don't attack UNLESS we were attacked at some point in which case we delegate to _agressiveStrategy
if (*_wasAttacked) {
return _agressiveStrategy->toAttack(t);
} else
//No territories to attack
return vector<Territory*>();
}
vector<Territory*> NeutralPlayerStrategy::toDefend(Territory* t)
{
//If player was attacked, permanently turn _wasAttacked to true
if (p->wasAttacked() && *_wasAttacked == false) {
*_wasAttacked = true;
std::cout << "!!! Neutral player \"" << *p->getName() << "\" was attacked! This player will now become aggressive !!!" << std::endl;
}
//Don't defend UNLESS we were attacked at some point in which case we delegate to _agressiveStrategy
if (*_wasAttacked) {
return _agressiveStrategy->toDefend(t);
}
else
//No territories to defend
return vector<Territory*>();
}
NeutralPlayerStrategy::NeutralPlayerStrategy(Player* p) : NeutralPlayerStrategy()
{
setPlayer(p);
_agressiveStrategy->setPlayer(p);
}
NeutralPlayerStrategy::NeutralPlayerStrategy(const NeutralPlayerStrategy& other) : PlayerStrategy(other)
{
this->_wasAttacked = new bool(*other._wasAttacked);
this->_agressiveStrategy = new AggressivePlayerStrategy(*other._agressiveStrategy);
}
NeutralPlayerStrategy& NeutralPlayerStrategy::operator=(const NeutralPlayerStrategy& rhs)
{
setPlayer(rhs.p);
this->_wasAttacked = new bool(*rhs._wasAttacked);
this->_agressiveStrategy = new AggressivePlayerStrategy(*rhs._agressiveStrategy);
return *this;
}
NeutralPlayerStrategy* NeutralPlayerStrategy::clone()
{
return new NeutralPlayerStrategy(*this);
}
//----------------------------------------------------------------------------------------
//----------------------------------------------------------------------------------------
//-----------------------------------Aggressive Player Stategy-------------------------------
//----------------------------------------------------------------------------------------
//----------------------------------------------------------------------------------------
AggressivePlayerStrategy::AggressivePlayerStrategy() : PlayerStrategy()
{
}
AggressivePlayerStrategy::~AggressivePlayerStrategy()
{
//Nothing to destroy
}
void AggressivePlayerStrategy::issueOrder(GameEngine* gameEngine, string orderType)
{
//Strongest territory
Territory* strongest = strongestTerritory();
//Neighbours of strongest
vector<Territory*> neighboursOfStrongest = strongest->get_neighbors();
//If we are at the deploy phase, deploy on the strongest territory all armies in your army pool.
if (orderType == "deploy")
{
int armiesToDeploy = *(gameEngine->get_ArmyPoolAt(p->getIndex()));
Deploy* deployOrder = new Deploy(p, strongest, *(gameEngine->get_ArmyPoolAt(p->getIndex())));
deployOrder->attach(p->getOrdersList()->getObservers().at(0));
p->getOrdersList()->addOrder(deployOrder);
*(gameEngine->get_ArmyPoolAt(p->getIndex())) -= armiesToDeploy;
}
//Advance all your armies to the strongest territory (if you can)
for (Territory* neighbour : neighboursOfStrongest) {
//If we are a neighbour of the strongest territory and we have at least 1 army unit, advance it to our strongest territory
if (neighbour->get_claimant() == p && neighbour->get_stationed_army() > 0) {
Advance* advanceOrder = new Advance(&(*p), neighbour, strongest);
advanceOrder->attach(p->getOrdersList()->getObservers().at(0));
p->getOrdersList()->addOrder(advanceOrder);
}
}
//Then advance all your armies into enemy territories until you cannot.
for (Territory* myTerritory : p->get_territories()) {
//continue to next if we have no armies to advance.
if (myTerritory->get_stationed_army() == 0)
continue;
//If the neighbour is an enemy, attack it
for (Territory* neighbour : myTerritory->get_neighbors()) {
if (neighbour->get_claimant() != p) {
Advance* advanceOrder = new Advance(&(*p), myTerritory, neighbour);
advanceOrder->attach(p->getOrdersList()->getObservers().at(0));
p->getOrdersList()->addOrder(advanceOrder);
break; //We advanced all armies to that enemy, so break this loop and move onto next territory of ours.
}
}
}
}
vector<Territory*> AggressivePlayerStrategy::toAttack(Territory* t)
{
vector<Territory*> neighbors;
for (Territory* terr : t->get_neighbors()) {
if (terr->get_claimant() != p) {
neighbors.push_back(terr);
}
}
return neighbors;
}
vector<Territory*> AggressivePlayerStrategy::toDefend(Territory* t)
{
vector<Territory*> neighbors;
for (Territory* terr : t->get_neighbors()) {
if (terr->get_claimant() == p) {
neighbors.push_back(terr);
}
}
return neighbors;
}
AggressivePlayerStrategy::AggressivePlayerStrategy(Player* p) : PlayerStrategy(p)
{
}
AggressivePlayerStrategy::AggressivePlayerStrategy(const AggressivePlayerStrategy& other) : PlayerStrategy(other)
{
this->p = other.p;
}
AggressivePlayerStrategy& AggressivePlayerStrategy::operator=(const AggressivePlayerStrategy& rhs)
{
this->p = rhs.p;
return *this;
}
AggressivePlayerStrategy* AggressivePlayerStrategy::clone()
{
return new AggressivePlayerStrategy(*this);
}
Territory* AggressivePlayerStrategy::strongestTerritory()
{
//Set strongest initially to the first territory
Territory* strongest = p->get_territories().at(0);
//Return first territory with the highest army count
for (auto ter : p->get_territories()) {
if (ter->get_stationed_army() > strongest->get_stationed_army()) {
strongest = ter;
}
}
return strongest;
}
//----------------------------------------------------------------------------------------
//----------------------------------------------------------------------------------------
//-----------------------------------Benevolent Player Stategy----------------------------
//----------------------------------------------------------------------------------------
//----------------------------------------------------------------------------------------
BenevolentPlayerStrategy::BenevolentPlayerStrategy(): PlayerStrategy()
{
_weakest = nullptr; //Do not make a new territory!
}
void BenevolentPlayerStrategy::issueOrder(GameEngine* gameEngine, string orderType)
{
int armyCount = *(gameEngine->get_ArmyPoolAt(p->getIndex()));
if (armyCount != 0) {
findWeakest();
Deploy* deployOrder = new Deploy(p, _weakest, armyCount);
deployOrder->attach(p->getOrdersList()->getObservers().at(0));
p->getOrdersList()->addOrder(deployOrder);
*(gameEngine->get_ArmyPoolAt(p->getIndex())) -= armyCount;
}
if (armyCount == 0) {
Territory* old;
old = _weakest;
findWeakest();
Advance* advanceOrder = new Advance(p, old, _weakest);
//Attach the first observer to the order.
advanceOrder->attach(p->getOrdersList()->getObservers().at(0));
p->getOrdersList()->addOrder(advanceOrder);
}
//if armyCount > 0, deploy on armyCount on weakest
//
//then advance half of the army to newest weakeast once from old weakest
}
vector<Territory*> BenevolentPlayerStrategy::toAttack(Territory* t)
{
return vector<Territory*>();
}
vector<Territory*> BenevolentPlayerStrategy::toDefend(Territory* t)
{
vector<Territory*> owned;
for (Territory* terr : t->get_neighbors()) {
if (terr->get_claimant() == p) {
owned.push_back(terr);
}
}
return owned;
}
BenevolentPlayerStrategy::BenevolentPlayerStrategy(Player* p) : PlayerStrategy(p)
{
_weakest = nullptr;
if (this->p) //Don't find the weakest if the player pointer hasn't been set!
findWeakest();
}
BenevolentPlayerStrategy::~BenevolentPlayerStrategy() {
//Do NOT delete the weakest since it points to a real territory
}
BenevolentPlayerStrategy::BenevolentPlayerStrategy(const BenevolentPlayerStrategy& other) : PlayerStrategy(other)
{
this->setPlayer(other.p);
this->p = other.p;
this->_weakest = other._weakest;
}
BenevolentPlayerStrategy& BenevolentPlayerStrategy::operator=(const BenevolentPlayerStrategy& rhs)
{
this->p = rhs.p;
this->_weakest = rhs._weakest;
return *this;
}
BenevolentPlayerStrategy* BenevolentPlayerStrategy::clone()
{
return new BenevolentPlayerStrategy(*this);
}
Territory* BenevolentPlayerStrategy::getWeakest()
{
return _weakest;
}
void BenevolentPlayerStrategy::findWeakest()
{
this->_weakest = p->get_territories().at(0);
int lowest = p->get_territories().at(0)->get_stationed_army();
for (auto ter : p->get_territories()) {
if (ter->get_stationed_army() < _weakest->get_stationed_army()) {
_weakest = ter;
}
}
}
//----------------------------------------------------------------------------------------
//----------------------------------------------------------------------------------------
//-----------------------------------Cheater Player Stategy-------------------------------
//----------------------------------------------------------------------------------------
//----------------------------------------------------------------------------------------
CheaterPlayerStrategy::CheaterPlayerStrategy(): PlayerStrategy()
{
}
CheaterPlayerStrategy::~CheaterPlayerStrategy()
{
//Nothing to delete here
}
void CheaterPlayerStrategy::issueOrder(GameEngine* gameEngine, string orderType)
{ //toAttack returns a list of all neighbouring territories in main. replace get_territories() with toAttack
vector<Territory*> territories = p->get_territories();
int territoryCount = territories.size();
for (int i = 0; i < territoryCount; i++) {
Territory* terr = territories.at(i);
for (auto neighbour : toAttack(terr)) {
neighbour->claim(p, true);
}
}
//automatically switches ownership of neigbouring countries to their own
}
vector<Territory*> CheaterPlayerStrategy::toAttack(Territory* t)
{
vector<Territory*> neighbors;
for (Territory* terr : t->get_neighbors()) {
if (terr->get_claimant() != p) {
neighbors.push_back(terr);
}
}
return neighbors;
}
vector<Territory*> CheaterPlayerStrategy::toDefend(Territory* t)
{
//TEMPORARY
return vector<Territory*>();
}
CheaterPlayerStrategy::CheaterPlayerStrategy(Player* p) : PlayerStrategy(p)
{
}
CheaterPlayerStrategy::CheaterPlayerStrategy(const CheaterPlayerStrategy& other) : PlayerStrategy(other)
{
}
CheaterPlayerStrategy& CheaterPlayerStrategy::operator=(const CheaterPlayerStrategy& rhs)
{
this->p = rhs.p;
return *this;
}
CheaterPlayerStrategy* CheaterPlayerStrategy::clone()
{
return new CheaterPlayerStrategy(*this);
}
//----------------------------------------------------------------------------------------
//----------------------------------------------------------------------------------------
//-----------------------------------Human Player Stategy-------------------------------
//----------------------------------------------------------------------------------------
//----------------------------------------------------------------------------------------
HumanPlayerStrategy::HumanPlayerStrategy() : PlayerStrategy()
{
}
HumanPlayerStrategy::~HumanPlayerStrategy()
{
//Nothing to delete here!
}
void HumanPlayerStrategy::issueOrder(GameEngine* gameEngine, string orderType)
{
if (orderType == "deploy")
gameEngine->deploy_phase(*p);
else if (orderType == "diplomacy")
diplomacyHelper(gameEngine);
else if (orderType == "airlift")
airliftHelper();
else if (orderType == "blockade")
blockadeHelper();
else if (orderType == "bomb")
bombHelper();
else if (orderType == "advance")
advanceHelper();
else
std::cout << "~~Invalid order issued in HumanPlayerStrategy~~" << std::endl;
}
vector<Territory*> HumanPlayerStrategy::toAttack(Territory* t)
{
vector<Territory*> neighbors;
for (Territory* terr : t->get_neighbors()) {
if (terr->get_claimant() != p) {
neighbors.push_back(terr);
}
}
return neighbors;
}
vector<Territory*> HumanPlayerStrategy::toDefend(Territory* t)
{
vector<Territory*> neighbors;
for (Territory* terr : t->get_neighbors()) {
if (terr->get_claimant() == p) {
neighbors.push_back(terr);
}
}
return neighbors;
}
HumanPlayerStrategy::HumanPlayerStrategy(Player* p) : PlayerStrategy(p)
{
}
HumanPlayerStrategy::HumanPlayerStrategy(const HumanPlayerStrategy& other) : PlayerStrategy(other)
{
}
HumanPlayerStrategy& HumanPlayerStrategy::operator=(const HumanPlayerStrategy& rhs)
{
this->p = rhs.p;
return *this;
}
HumanPlayerStrategy* HumanPlayerStrategy::clone()
{
return new HumanPlayerStrategy(*this);
}
void HumanPlayerStrategy::log(string str)
{
std::cout << "\n>> " << str << std::endl;
}
void HumanPlayerStrategy::input()
{
std::cout << "> " << std::endl;
}
void HumanPlayerStrategy::advanceHelper()
{
// Pick a territory from all the territories
int count = 0;
cout << *p->getName() << endl;
cout << "Pick territory of choice: " << endl;
for (Territory* t : p->get_territories()) {
cout << "\n" << to_string(count) << ": " << t->get_name() << " [" << t->get_stationed_army() << "]";
count++;
}
int option;
do {
input();
std::cin >> option;
if (std::cin.fail()) {
std::cin.clear();
std::cin.ignore(1000, '\n');
option = -1;
}
if (option > count - 1 || option < 0)
cout << "Please enter a number between 0 and " << count - 1 << endl;
} while (option > count - 1 || option < 0);
count = 0;
cout << "Please choose a territory to advance to: " << endl;
for (Territory* t : p->get_territories()[option]->get_neighbors()) {
cout << "\n" + to_string(count) + ": " + t->get_name();
count++;
}
int option2;
do {
input();
std::cin >> option2;
if (std::cin.fail()) {
std::cin.clear();
std::cin.ignore(1000, '\n');
option = -1;
}
if (option2 > count - 1 || option2 < 0)
cout << "Please enter a number between 0 and " << count - 1 << endl;
} while (option2 > count - 1 || option2 < 0);
Advance* advanceOrder = new Advance(&(*p), p->get_territories()[option], p->get_territories()[option]->get_neighbors()[option2]);
//Attach the first observer to the order.
advanceOrder->attach(p->getOrdersList()->getObservers().at(0));
p->getOrdersList()->addOrder(advanceOrder);
}
void HumanPlayerStrategy::airliftHelper()
{
log("Airlift");
// Pick a territories from all the territories
int count = 0;
int option[2]; //option 0 is souce and 1 is destination
cout << *p->getName() << endl;
for (size_t i = 0; i < 2; i++) {
cout << "Select territory " << ((i == 0) ? "SOURCE" : "DESTINATION") << " for airlift : " << endl;
for (Territory* t : p->get_territories()) {
cout << "\n" << to_string(count) << ": " << t->get_name() << " [" << t->get_stationed_army() << "]";
count++;
}
do {
input();
std::cin >> option[i];
if (std::cin.fail()) {
std::cin.clear();
std::cin.ignore(1000, '\n');
option[i] = -1;
}
if (option[i] > count - 1 || option[i] < 0)
cout << "Please enter a number between 0 and " << count - 1 << endl;
} while (option[i] > count - 1 || option[i] < 0);
count = 0;
}
Airlift* airliftOrder = new Airlift(p->get_territories()[option[0]], p->get_territories()[option[1]]);
airliftOrder->attach(p->getOrdersList()->getObservers().at(0));
p->getOrdersList()->addOrder(airliftOrder);
}
void HumanPlayerStrategy::bombHelper()
{
log("Bomb");
// Pick a territories from all the territories
int count = 0;
int option;// destination
cout << *p->getName() << endl;
cout << "Select territory DESTINATION to Bomb : " << endl;
for (Territory* t : Map::get_instance()->get_territories()) {
cout << "\n" << to_string(count) << ": " << t->get_name() << " [" << t->get_stationed_army() << "]";
count++;
}
do {
input();
std::cin >> option;
if (std::cin.fail()) {
std::cin.clear();
std::cin.ignore(1000, '\n');
option = -1;
}
if (option > count - 1 || option < 0)
cout << "Please enter a number between 0 and " << count - 1 << endl;
else if (Map::get_instance()->get_territories()[option]->get_claimant() == &(*p)) {
cout << "You can't bomb yourself" << endl;
option = -1;
}
} while (option > count - 1 || option < 0);
Bomb* bombOrder = new Bomb(Map::get_instance()->get_territories()[option]);
bombOrder->attach(p->getOrdersList()->getObservers().at(0));
p->getOrdersList()->addOrder(bombOrder);
}
void HumanPlayerStrategy::blockadeHelper()
{
log("Blockade");
// Pick a territories from all the territories
int count = 0;
int option;// destination
cout << *p->getName() << endl;
cout << "Select territory DESTINATION to Bomb : " << endl;
for (Territory* t : p->get_territories()) {
cout << "\n" << to_string(count) << ": " << t->get_name() << " [" << t->get_stationed_army() << "]";
count++;
}
do {
input();
std::cin >> option;
if (std::cin.fail()) {
std::cin.clear();
std::cin.ignore(1000, '\n');
option = -1;
}
if (option > count - 1 || option < 0)
cout << "Please enter a number between 0 and " << count - 1 << endl;
} while (option > count - 1 || option < 0);
Blockade* blockadeOrder = new Blockade(p->get_territories()[option]);
blockadeOrder->attach(p->getOrdersList()->getObservers().at(0));
p->getOrdersList()->addOrder(blockadeOrder);
}
void HumanPlayerStrategy::diplomacyHelper(GameEngine* gameEngine)
{
log("Diplomacy");
// Pick a territories from all the territories
int count = 0;
int option;// destination
cout << *p->getName() << endl;
cout << "Select Player to Negotiate : " << endl;
for (Player* p : gameEngine->get_players()) {
cout << "\n" << to_string(count) << ": " << *p->getName();
count++;
}
do {
input();
std::cin >> option;
if (std::cin.fail()) {
std::cin.clear();
std::cin.ignore(1000, '\n');
option = -1;
}
if (option > count - 1 || option < 0)
cout << "Please enter a number between 0 and " << count - 1 << endl;
} while (option > count - 1 || option < 0);
Negotiate* negotiateOrder = new Negotiate(&(*p), gameEngine->get_players()[option]);
negotiateOrder->attach(p->getOrdersList()->getObservers().at(0));
p->getOrdersList()->addOrder(negotiateOrder);
}