-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathStrategyPattern.cpp
2059 lines (1780 loc) · 60 KB
/
StrategyPattern.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
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
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
#include "StrategyPattern.h"
#include <ctime>
/**
* Returns the number of armies (as an int) that a player gets after exchanging cards.
* \param player A pointer to the current player
* \param map A pointer to the map
*/
int Strategy::determineExchangedArmies(Player* player, Map* map, Deck& deck)
{
int my_card;
int exchangedArmies = 0;
my_card = player->getHandSize();
cout << player->getName() << " currently has " << my_card << " cards in their hand. " << endl;
player->displayHand();
if (player->exchangeableHand() == true)
{
if (my_card > 5)
{
cout << endl;
cout << player->getName() << " has more than 5 cards and must exchange. " << endl;
exchangedArmies = player->exchangeCardsAI(deck); // Uses the method to exchange cards for AI
}
}
else
{
cout << endl;
cout << player->getName() << " cannot exchange cards at this time. " << endl;
}
player->m_StatusInfo.phaseView = false;
player->m_StatusInfo.currentPhase = REINFORCEMENT;
player->m_StatusInfo.cardsView = true;
player->notify();
player->m_StatusInfo.cardsView = false;
player->m_StatusInfo.phaseView = true;
return exchangedArmies;
}
/**
* Places armies to place.
* \param assign_to ID of territory being applied.
* \param place_num Number of territories to place.
* \param map The map.
*/
void Strategy::placeArmiesDuringReinforcement(int assign_to, int place_num, Player* player, Map* map)
{
for (int i = 0; i < place_num; i++)
{
map->assignArmies(player, map->getTerritoryName(assign_to));
}
}
/**
* Moves armies around.
* \param move_from ID where the troops are moving from.
* \param move_to ID where the troops are moving to.
* \param move_num Number of people moving.
* \param map The map where this is all taking place.
*/
void Strategy::moveArmiesDuringFortification(int move_from, int move_to, int move_num, Player* player, Map * map)
{
for (int i = 0; i < move_num; i++)
{
map->removeArmies(player, map->getTerritoryName(move_from));
map->assignArmies(player, map->getTerritoryName(move_to));
}
}
/**
* Method that triggers an automatic dice battle for AI.
* \param from ID of territory we're attacking from.
* \param to ID of territory being attacked.
* \param player Pointer to the player
* \param map The map where the battle is taking place.
*/
void Strategy::engageInBattle(int from, int to, Player* player, Map* map)
{
vector<int> myRolledList, enemyRolledList;
Player * enemy = map->getOwnerOfTheTerritory(to);
cout << "The Attaker, Player " << player->getPlayerID() << ": " << player->getName() << " is about to shake the dice cup. " << endl;
myRolledList = shakeDiceCup(map->getArmyNumOfTheTerritory(from), ATTACK, player);
cout << "The Defender, Player " << enemy->getPlayerID() << ": "
<< enemy->getName() << " is about to shake the dice cup. " << endl;
enemyRolledList = shakeDiceCup(map->getArmyNumOfTheTerritory(to), DEFENSE, player);
for (int i = 0; i < myRolledList.size(); i++) {
if (i == 0)
{
cout << "The Attaker, Player " << player->getPlayerID() << ": " << player->getName() << " rolled: ";
cout << myRolledList[i];
}
else
{
cout << " | " << myRolledList[i];
}
}
cout << endl;
for (int i = 0; i < enemyRolledList.size(); i++) {
if (i == 0)
{
cout << "The Defender, Player " << enemy->getPlayerID() << ": "
<< enemy->getName() << " rolled: ";
cout << enemyRolledList[i];
}
else
{
cout << " | " << enemyRolledList[i];
}
}
cout << endl;
int armiesInBattle = myRolledList.size() < enemyRolledList.size() ? myRolledList.size() : enemyRolledList.size();
cout << "Rolled Dice Pairs: " << armiesInBattle << endl;
for (int i = 0; i < armiesInBattle; i++)
{
cout << myRolledList[i] << " VS " << enemyRolledList[i] << " : ";
if (myRolledList[i] > enemyRolledList[i])
{
cout << myRolledList[i] << " > " << enemyRolledList[i] << " --> ";
cout << "Player " << enemy->getPlayerID() << ", "
<< enemy->getName() << ", lost one army. " << endl;
map->removeArmies(enemy, map->getTerritoryName(to));
}
else
{
cout << myRolledList[i] << " <= " << enemyRolledList[i] << " --> ";
cout << "Player " << player->getPlayerID() << ", "
<< map->getOwnerOfTheTerritory(from)->getName() << ", lost one army. " << endl;
map->removeArmies(player, map->getTerritoryName(from));
}
}
}
/**
* Automatically rolls the largest possible number of dice for the aggressive AI.
* \param armiesOfATerri Number of armies of the territory passed
* \param phase The phase during which this method is called
* \param player A pointer to the player
*/
vector<int> Strategy::shakeDiceCup(int armiesOfATerri, PlayerPhase phase, Player* player)
{
int numOfDice;
if (phase == ATTACK)
{
numOfDice = armiesOfATerri - 1;
if (numOfDice > 3)
{
numOfDice = 3;
return (player->shakeDiceCup(numOfDice));
}
else if (numOfDice == 2 || numOfDice == 3)// logic error missing case numOfDice == 3
{
return (player->shakeDiceCup(numOfDice));
}
else // if numOfDice == 1
{
cout << player->getName() << " is only allowed to roll 1 dice for the current battle. " << endl;
return (player->shakeDiceCup(numOfDice));
}
}
else // if player is defending
{
numOfDice = armiesOfATerri;
if (numOfDice > 2)
{
numOfDice = 2;
return (player->shakeDiceCup(numOfDice));
}
else // if numOfDice = 1
{
return (player->shakeDiceCup(numOfDice));
}
}
}
/**
* The method for the reinforcement phase during the human player's turn.
* \param player A pointer to the current player
* \param map A pointer to the map
*/
void HumanPlayer::reinforce(Player* player, Map* map, Deck& deck)
{
//Reinforce, notify PLAYER STATUS
player->m_StatusInfo.phaseView = true;
player->m_StatusInfo.currentPhase = REINFORCEMENT;
player->m_StatusInfo.statusType = myTerritories;
player->m_StatusInfo.globalView = true;
player->m_StatusInfo.cardsView = true;
player->m_StatusInfo.contiView = true;
player->notify();
player->m_StatusInfo.contiView = false;
player->m_StatusInfo.cardsView = false;
player->m_StatusInfo.globalView = false;
int assign_terri_ID = -1, assign_num = 0;
int exchangedArmies = determineExchangedArmies(player, map, deck);
int valid_assigned_armies = player->assignedAvailableArmies(exchangedArmies);
do {
cout << "You have " << valid_assigned_armies << " troop(s) left to deploy." << endl;
//choose territory attack from
cout << "Please select ID of the territory where you want to assign your armies: " << endl;
cin >> assign_terri_ID;
if (assign_terri_ID >= 0)
{
if ((map->getOwnerOfTheTerritory(assign_terri_ID)) != player)
{
cout << "INVALID INPUT: the territory that you select is not your territory. " << endl;
continue;
}
}
else
{
cout << "INVALID INPUT: invalid territory ID. " << endl;
continue;
}
do {
cout << "Please enter the number of armies that you want to place on this territory: " << endl;
cin >> assign_num;
if (assign_num >= 0 && assign_num <= valid_assigned_armies)
{
placeArmiesDuringReinforcement(assign_terri_ID, assign_num, player, map);
valid_assigned_armies -= assign_num;
//Reinforce selected terri notify update
player->m_StatusInfo.currentSelectedTerriID = assign_terri_ID;
player->m_StatusInfo.statusType = mySpecificTerritory;
player->notify();
break;
}
else
{
cout << "INVALID INPUT " << endl;
}
} while (true);
cout << endl;
} while (valid_assigned_armies > 0);
//Reinforce all terri notify
player->m_StatusInfo.statusType = myTerritories;
player->notify();
//Reinforce, notify counting -1, end of this phase
player->m_StatusInfo.statusType = myPhaseEnded;
player->notify();
}
/**
* Returns the number of armies (as an int) that a player gets after exchanging cards.
* Overrides the Strategy method to allow user input.
* \param player A pointer to the current player
* \param map A pointer to the map
*/
int HumanPlayer::determineExchangedArmies(Player* player, Map* map, Deck& deck)
{
int my_card;
int exchangedArmies = 0;
my_card = player->getHandSize();
//**??Notify cards in hand?
cout << "Currently, you have " << my_card << " cards in your hand. " << endl;
player->displayHand();
if (player->exchangeableHand() == true)
{
cout << "Your have exchangeable cards. " << endl;
if (my_card > 5)
{
cout << "Since you have more than 5 cards you must exchange. " << endl;
while (exchangedArmies == 0)
exchangedArmies = player->exchangeCards(deck);
//hand update
player->m_StatusInfo.phaseView = false;
player->m_StatusInfo.currentPhase = REINFORCEMENT;
player->m_StatusInfo.cardsView = true;
player->notify();
player->m_StatusInfo.cardsView = false;
player->m_StatusInfo.phaseView = true;
}
else
{
string exchange = "";
do {
cout << "Do you want to exchange your cards? [Y/N] " << endl;
cin >> exchange;
if (exchange == "Y" || exchange == "y")
{
exchangedArmies = player->exchangeCards(deck);
//hand update
if (exchangedArmies != 0)
{
player->m_StatusInfo.phaseView = false;
player->m_StatusInfo.currentPhase = REINFORCEMENT;
player->m_StatusInfo.cardsView = true;
player->notify();
player->m_StatusInfo.cardsView = false;
player->m_StatusInfo.phaseView = true;
break;
}
}
else if (exchange == "N" || exchange == "n")
{
exchangedArmies = 0;
break;
}
else
{
cout << "INVALID INPUT " << endl;
}
} while (true);
}
}
else
{
cout << "You cannot exchange cards at this time. " << endl;
}
return exchangedArmies;
}
/**
* The method for the attack phase during the human player's turn.
* \param player A pointer to the current player
* \param map A pointer to the map
*/
bool HumanPlayer::attack(Player* player, Map* map)
{
//Attack, notify PLAYER STATUS
player->m_StatusInfo.phaseView = true;
player->m_StatusInfo.currentPhase = ATTACK;
player->m_StatusInfo.statusType = myTerritories;
player->m_StatusInfo.globalView = true;
player->m_StatusInfo.contiView = true;
player->notify();
player->m_StatusInfo.contiView = false;
player->m_StatusInfo.globalView = false;
bool attack_state;
string atk = "";
do {
cout << "Do you want to attack? <Y/N> " << endl;
cin >> atk;
if (atk == "Y" || atk == "y")
{
attack_state = true;
break;
}
else
{
if (atk == "N" || atk == "n")
{
attack_state = false;
break;
}
else
{
cout << "INVALID INPUT " << endl;
}
}
} while (true);
if (attack_state == true)
{
int attack_from = -1, attack_to = -1;
do {
//choose territory attack from
cout << "Please select the territory ID (integer) that you want to attack from: " << endl;
cout << "** -1 for ending attack phase" << endl;
cin >> attack_from;
if (attack_from == -1)
{
//Notify: end of this phase
player->m_StatusInfo.statusType = myPhaseEnded;
player->notify();
return false;
}
else
if (attack_from >= 0)
{
if ((map->getOwnerOfTheTerritory(attack_from)) == player)
{
if (map->getArmyNumOfTheTerritory(attack_from) > 1)
{
if (!map->enemyNeighbourExists(attack_from))
{
cout << "INVALID INPUT: you must choose one of your territories having at least one enemy neighbour. " << endl;
continue;
}
}
else
{
cout << "INVALID INPUT: you must choose one of your territories assigned more than one armies. " << endl;
continue;
}
}
else
{
cout << "INVALID INPUT: the territory that you select is not your territory. " << endl;
continue;
}
}
else
{
cout << "INVALID INPUT: invalid territory ID. " << endl;
continue;
}
//Attack, notify enemylist
player->m_StatusInfo.currentSelectedTerriID = attack_from;
player->m_StatusInfo.statusType = myEnemyList;
player->notify();
//choose territory attack to
cout << "Please select the adjacent territory ID (integer) that you want to attack to: " << endl;
cout << "** -1 for ending attack phase" << endl;
cin >> attack_to;
if (attack_to == -1)
{
//Attack, notify counting -1, phase ending
player->m_StatusInfo.statusType = myPhaseEnded;
player->notify();
return false;
}
else
if (attack_to >= 0)
{
if (map->isAdjacent(attack_from, attack_to))
{
if ((map->getOwnerOfTheTerritory(attack_to)) != player)
{
break;
}
else
{
cout << "INVALID INPUT: the territory that you select is your territory. " << endl;
//continue;
}
}
else
{
cout << "INVALID INPUT: you can only attack your neighbour territory. " << endl;
//continue;
}
}
else
{
cout << "INVALID INPUT: invalid territory ID. " << endl;
//continue;
}
} while (true);
while (true)
{
cout << "--------------------------------" << endl;
if (map->getArmyNumOfTheTerritory(attack_from) > 1)
{
if (map->getArmyNumOfTheTerritory(attack_to) > 0)
{
engageInBattle(attack_from, attack_to, player, map);
//Attack, notify, selected terri -> attack from
player->m_StatusInfo.currentSelectedTerriID = attack_from;
player->m_StatusInfo.statusType = mySpecificTerritory;
player->notify();
//Attack, notify, selected terri -> attack to
player->m_StatusInfo.currentSelectedTerriID = attack_to;
player->notify();
if (map->getArmyNumOfTheTerritory(attack_from) > 1 && map->getArmyNumOfTheTerritory(attack_to) > 0)
{
bool change_terri;
do
{
cout << "Do you want to keep attacking this territory? [Y/N] " << endl;
cin >> atk;
if (atk == "Y" || atk == "y")
{
change_terri = false;
break;
}
else
{
if (atk == "N" || atk == "n")
{
change_terri = true;
break;
}
else
{
cout << "INVALID INPUT " << endl;
}
}
} while (true);
if (change_terri)
break;
}
}
else
{
int assign_num_of_armies;
cout << "Congradulations! You win the battle." << endl;
if (map->getArmyNumOfTheTerritory(attack_from) == 2)
{
cout << "You can only assign one army to capture the territory." << endl;;
assign_num_of_armies = 1;
}
else
{
while (true)
{
cout << "Please assign a number of armies to caputre the territory (1-"
<< map->getArmyNumOfTheTerritory(attack_from) - 1
<< "): " << endl;
cin >> assign_num_of_armies;
if (assign_num_of_armies > 0 && assign_num_of_armies < map->getArmyNumOfTheTerritory(attack_from))
{
break;
}
else
{
cout << "INVALID INPUT: out of range. " << endl;
}
}
}
for (int i = 0; i < assign_num_of_armies; i++)
{
map->removeArmies(player, map->getTerritoryName(attack_from));
map->assignArmies(player, map->getTerritoryName(attack_to));
}
cout << "Territory captured. " << endl;
//Attack, notify player status
//player->m_StatusInfo.statusType = myTerritories;
//player->m_StatusInfo.globalView = true;
//player->notify();
//player->m_StatusInfo.globalView = false;
break;
}
}
else
{
cout << "You do not have enough armies in your current territory, " << map->getTerritoryName(attack_from) << ". " << endl;
cout << "You failed the battle. " << endl;
////Attack, notify player status
//player->m_StatusInfo[1] = 0;
//player->notify();
break;
}
}
cout << endl;
//Attack, notify player status
player->m_StatusInfo.statusType = myTerritories;
player->m_StatusInfo.globalView = true;
player->m_StatusInfo.contiView = true;
player->notify();
player->m_StatusInfo.contiView = false;
player->m_StatusInfo.globalView = false;
return true;
}
else
{
//Attack, notify counting -1, phase ending
player->m_StatusInfo.statusType = myPhaseEnded;
player->notify();
return false;
}
return false;
}
/**
* Method that actually triggers a dice battle.
* \param from ID of territory we're attacking from.
* \param to ID of territory being attacked.
* \param player Pointer to the player // no need since the from ID has already been checked
* \param map The map where the battle is taking place.
*/
void HumanPlayer::engageInBattle(int from, int to, Player* player, Map* map)
{
vector<int> myRolledList, enemyRolledList;
Player * enemy = map->getOwnerOfTheTerritory(to);
cout << "The Attaker, Player " << player->getPlayerID() << ": " << player->getName() << " is about to shake the dice cup. " << endl;
myRolledList = shakeDiceCup(map->getArmyNumOfTheTerritory(from), ATTACK, player);
cout << "The Defender, Player " << enemy->getPlayerID() << ": "
<< enemy->getName() << " is about to shake the dice cup. " << endl;
enemyRolledList = shakeDiceCup(map->getArmyNumOfTheTerritory(to), DEFENSE, player);//here is the current player or enemy?? & why need player param??
for (int i = 0; i < myRolledList.size(); i++) {
if (i == 0)
{
cout << "The Attaker, Player " << player->getPlayerID() << ": " << player->getName() << " rolled: ";
cout << myRolledList[i];
}
else
{
cout << " | " << myRolledList[i];
}
}
cout << endl;
for (int i = 0; i < enemyRolledList.size(); i++) {
if (i == 0)
{
cout << "The Defender, Player " << enemy->getPlayerID() << ": "
<< enemy->getName() << " rolled: ";
cout << enemyRolledList[i];
}
else
{
cout << " | " << enemyRolledList[i];
}
}
cout << endl;
int armiesInBattle = myRolledList.size() < enemyRolledList.size() ? myRolledList.size() : enemyRolledList.size();
cout << "Rolled Dice Pairs: " << armiesInBattle << endl;
for (int i = 0; i < armiesInBattle; i++)
{
cout << myRolledList[i] << " VS " << enemyRolledList[i] << " : ";
if (myRolledList[i] > enemyRolledList[i])
{
cout << myRolledList[i] << " > " << enemyRolledList[i] << " --> ";
cout << "Player " << enemy->getPlayerID() << ", "
<< enemy->getName() << ", lost one army. " << endl;
map->removeArmies(enemy, map->getTerritoryName(to));
}
else
{
cout << myRolledList[i] << " <= " << enemyRolledList[i] << " --> ";
cout << "Player " << player->getPlayerID() << ", "
<< map->getOwnerOfTheTerritory(from)->getName() << ", lost one army. " << endl;
map->removeArmies(player, map->getTerritoryName(from));
}
}
}
/**
* Prompts user to select the number of dice they wish to roll.
* \param armiesOfATerri Number of armies of the territory passed
* \param phase The phase during which this method is called
* \param player A pointer to the player
*/
vector<int> HumanPlayer::shakeDiceCup(int armiesOfATerri, PlayerPhase phase, Player* player)
{
int numOfDice;
int maxDiceLimit;
if (phase == ATTACK)
{
maxDiceLimit = armiesOfATerri - 1;
if (maxDiceLimit > 3)
{
maxDiceLimit = 3;
}
}
else
{
maxDiceLimit = armiesOfATerri;
if (maxDiceLimit > 2)
{
maxDiceLimit = 2;
}
}
if (maxDiceLimit == 1)
{
cout << "You are only allowed to roll 1 dice for the current battle. " << endl;
cout << endl;
numOfDice = 1;
return (player->shakeDiceCup(numOfDice));
}
else
{
do {
cout << "Please choose the number of dice that you want to roll (1-" << maxDiceLimit << "):" << endl;
cin >> numOfDice;
cout << endl;
if (numOfDice > 0 && numOfDice <= maxDiceLimit)
{
break;
}
else
{
cout << "INVALID INPUT: invalid dice number. " << endl;
cout << endl;
}
} while (true);
return (player->shakeDiceCup(numOfDice));
}
}
/**
* The method for the fortification phase during the human player's turn.
* \param player A pointer to the current player
* \param map A pointer to the map
*/
bool HumanPlayer::fortify(Player* player, Map* map)
{
//Fortify, notify PLAYER STATUS
player->m_StatusInfo.phaseView = true;
player->m_StatusInfo.currentPhase = FORTIFICATION;
player->m_StatusInfo.statusType = myTerritories;
player->m_StatusInfo.globalView = true;
player->notify();
player->m_StatusInfo.globalView = false;
bool fortify_state, verified_input = false ;
string ftf = "";
do {
cout << "Do you want to fortify? <Y/N> " << endl;
cin >> ftf;
if (ftf == "Y" || ftf == "y")
{
fortify_state = true;
break;
}
else
{
if (ftf == "N" || ftf == "n")
{
return false;
}
else
{
cout << "INVALID INPUT " << endl;
}
}
} while (true);
if (fortify_state == true)
{
int move_from = -1, move_to = -1, move_num = 0;
vector<string> fortifyPath;
do
{
cout << "Please select the source territory ID (integer) that you want to move your armies from: " << endl;
cout << "** -1 for ending fortification phase" << endl;
cin >> move_from;
if (move_from == -1)
{
//Fortify, notify PLAYER STATUS
player->m_StatusInfo.statusType = myTerritories;
player->notify();
//Fortify, notify end of phase
player->m_StatusInfo.statusType = myPhaseEnded;
player->notify();
return false;
}
else
if (move_from >= 0)
{
if ((map->getOwnerOfTheTerritory(move_from)) == player)
{
if (map->getArmyNumOfTheTerritory(move_from) > 1)
{
if (!map->friendNeighbourExists(move_from))
{
cout << "INVALID INPUT: you must choose one of your territories having at least one friend neighbour. " << endl;
continue;
}// notify the selected terri? & valid terri list of move to?
else
{
//Fortify, notify the selected terri
player->m_StatusInfo.currentSelectedTerriID = move_from;
player->m_StatusInfo.statusType = myPathList;
player->notify();
}
}
else
{
cout << "INVALID INPUT: you must choose one of your territories assigned more than one armies. " << endl;
continue;
}
}
else
{
cout << "INVALID INPUT: the territory that you select is not your territory. " << endl;
continue;
}
}
else
{
cout << "INVALID INPUT: invalid territory ID. " << endl;
continue;
}
do {
//choose territory move to
cout << "Please select the target territory ID (integer) that you want to move your armies to: " << endl;
cout << "** -1 for ending fortification phase" << endl;
cout << "** -2 for re-select source territory" << endl;
cin >> move_to;
if (move_to == -1 || move_to == -2)
{
if (move_to == -1)
{
//Fortify, notify PLAYER STATUS
player->m_StatusInfo.statusType = myTerritories;
player->notify();
//Fortify, notify end of phase
player->m_StatusInfo.statusType = myPhaseEnded;
player->notify();
return false;
}
if (move_to == -2)
{
break;
}
}
else
if (move_to >= 0)
{
fortifyPath.clear();
if (map->seekPath(player, map->getTerritoryName(move_from), map->getTerritoryName(move_to), fortifyPath))
{
do {
cout << "Please enter the number of armies that you want to fortify (0-"
<< map->getArmyNumOfTheTerritory(move_from) - 1 << "): " << endl;
cin >> move_num;
if (move_num >= 0 && move_num <= map->getArmyNumOfTheTerritory(move_from) - 1)
{
verified_input = true;
break;
}
else
{
cout << "INVALID INPUT " << endl;
}
} while (true);
break;
}
else
{
cout << "INVALID INPUT: invalid territory ID. " << endl;
}
}
} while (true);
if (verified_input == true)
break;
} while (true);
moveArmiesDuringFortification(move_from, move_to, move_num, player, map);
//Fortify, notify the selected terri : source terri
player->m_StatusInfo.currentSelectedTerriID = move_from;
player->m_StatusInfo.statusType = mySpecificTerritory;
player->notify();
//Fortify, notify the selected terri : target terri
player->m_StatusInfo.currentSelectedTerriID = move_to;
player->notify();
return true;
}
else
{
//Fortify, notify PLAYER STATUS
player->m_StatusInfo.statusType = myTerritories;
player->notify();
//Fortify, notify end of phase
player->m_StatusInfo.statusType = myPhaseEnded;
player->notify();
return false;
}
}
/**
* This method has no current implementation for the human player.
* \param player A pointer to the current player
* \param map A pointer to the map
* \param move_to The territory ID of the territory we move armies to
*/
int HumanPlayer::territoryToMoveArmyFrom(Player* player, Map* map, int move_to)
{
// No implementation
return -1;
}
/**
* Calls the methods for the different phases of the human player's turn.
* \param player A pointer to the current player
* \param map A pointer to the map
*/
void HumanPlayer::play(Player* player, Map* map, Deck& deck)
{
reinforce(player, map, deck);
while(attack(player, map));
while(fortify(player, map));
}
/**
* The method for the reinforcement phase during the aggressive player's turn.
* \param player A pointer to the current player
* \param map A pointer to the map
*/
void AggressiveAI::reinforce(Player* player, Map* map, Deck& deck)
{
//Reinforce, notify PLAYER STATUS
player->m_StatusInfo.phaseView = true;
player->m_StatusInfo.currentPhase = REINFORCEMENT;
player->m_StatusInfo.statusType = myTerritories;
player->m_StatusInfo.globalView = true;
player->m_StatusInfo.cardsView = true;
player->m_StatusInfo.contiView = true;
player->notify();
player->m_StatusInfo.contiView = false;
player->m_StatusInfo.cardsView = false;
player->m_StatusInfo.globalView = false;
int exchangedArmies = determineExchangedArmies(player, map, deck);
int valid_assigned_armies = player->assignedAvailableArmies(exchangedArmies);
cout << player->getName() << " (aggressive AI) has " << valid_assigned_armies << " troop(s) left to deploy." << endl;
cout << player->getName() << " wants to assign their armies to : ";
int assign_terri_ID = getStrongestTerritory(player, map, REINFORCEMENT);
cout << map->getTerritoryName(assign_terri_ID) << endl;
// Aggressive AI will place all its available armies on its strongest country
cout << player->getName() << " is going to place " << valid_assigned_armies << " armies on " << map->getTerritoryName(assign_terri_ID) << endl;
placeArmiesDuringReinforcement(assign_terri_ID, valid_assigned_armies, player, map);
player->m_StatusInfo.phaseView = false;
player->m_StatusInfo.currentPhase = REINFORCEMENT;
player->m_StatusInfo.cardsView = true;
player->notify();
player->m_StatusInfo.cardsView = false;
player->m_StatusInfo.phaseView = true;
cout << endl;
//Reinforce all terri notify
player->m_StatusInfo.statusType = myTerritories;
player->notify();
//Reinforce, notify counting -1, end of this phase
player->m_StatusInfo.statusType = myPhaseEnded;
player->notify();
}
/**
* Returns the aggressive player's strongest territory (under different conditions according to the phase).
* \param player A pointer to the current player