-
Notifications
You must be signed in to change notification settings - Fork 2
/
Orders.cpp
1312 lines (971 loc) · 37.6 KB
/
Orders.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 "Orders.h"
#include "PlayerStrategies.h"
#include <cstdlib>
#include <ctime>
Order::Order() {
bool valid;
vector<string> vec_type2 = {"Deploy", "Advance", "Bombs", "Blockadess", "Airliftss", "negotiate"};
int type_id;
this->valid = true;
this->type_id = 1;
this->vec_type1 = vec_type2;
}
Order::Order(Player* player, Map * map) {
}
void Order::SetPlayer(Player *player) {
this->p = player;
}
void Order::SetMap(Map *map) {
this->m= map;
}
void Order:: set_type_id(int num){
this->type_id = num;
}
void Order:: set_valid(bool valid){
this->valid = valid;
}
void Order:: set_vec_type1(vector<string> vec_type1 ){
this->vec_type1 = vec_type1;
}
OrderList::OrderList() {
}
Airlifts ::Airlifts(bool valids, vector<string> vec_types1 ,int type_ids ) {
this->set_valid(valids);
this->set_vec_type1(vec_types1);
this->set_type_id(type_ids);
}
Bombs ::Bombs(bool valids, vector<string> vec_types1 ,int type_ids ) {
this->set_valid(valids);
this->set_vec_type1(vec_types1);
this->set_type_id(type_ids);
}
Deploy ::Deploy(bool valids, vector<string> vec_types1 ,int type_ids ) {
this->set_valid(valids);
this->set_vec_type1(vec_types1);
this->set_type_id(type_ids);
}
Advance ::Advance(bool valids, vector<string> vec_types1 ,int type_ids ) {
this->set_valid(valids);
this->set_vec_type1(vec_types1);
this->set_type_id(type_ids);
}
Negotiate ::Negotiate(bool valids, vector<string> vec_types1 ,int type_ids ) {
this->set_valid(valids);
this->set_vec_type1(vec_types1);
this->set_type_id(type_ids);
}
Blockades ::Blockades(bool valids, vector<string> vec_types1 ,int type_ids ) {
this->set_valid(valids);
this->set_vec_type1(vec_types1);
this->set_type_id(type_ids);
}
OrderList::OrderList(vector<Order *> e){
int size= e.size();
for(Order * element :e ){
bool valids = element->get_valid();
vector<string> vec_types1 = element->get_List();
int type_ids= element->get_ID();
}
}
/**
* assignment operator of OrderList
*/
OrderList& OrderList::operator=(const OrderList& e){
for(Order * element : (e.vec_order_list )){
bool valid = element->get_valid();
vector<string> vec_type1 = element->get_List();
int type_id= element->get_ID();
string type = element->type;
//STOP1
if(type == "Airlifts") {
Order * T1 = new Airlifts (valid,vec_type1,type_id);
this->vec_order_list.push_back(T1);
}
if(type == "Deploy") {
Order * T1 = new Deploy (valid,vec_type1,type_id);
this->vec_order_list.push_back(T1);
}
if(type == "Bombs") {
Order * T1 = new Bombs (valid,vec_type1,type_id);
this->vec_order_list.push_back(T1);
}
if(type == "Negotiate") {
Order * T1 = new Negotiate (valid,vec_type1,type_id);
this->vec_order_list.push_back(T1);
}
if(type == "Blockades") {
Order * T1 = new Blockades (valid,vec_type1,type_id);
this->vec_order_list.push_back(T1);
}
}
return *this;
}
void Order::PrintAllOrder() {
int index = 1;
for (auto element: this->vec_type1) {
cout << "This is order number " << index << " with type" << element << endl;
index++;
}
cout << "The type ID is " << this->type_id << endl;
cout << "Now we will print the Player of this Order" << endl;
cout <<"---------------------------------"<<endl;
cout <<endl;
cout <<endl;
cout << *(this->p);
cout <<endl;
cout <<endl;
cout <<"---------------------------------"<<endl;
cout << "Now we will print the Map Used in the Game" << endl;
cout <<"---------------------------------"<<endl;
cout <<endl;
cout <<endl;
cout << *(this->m);
cout <<endl;
cout <<endl;
cout <<"---------------------------------"<<endl;
// e.m->printMap();
}
std::ostream &operator<<(std::ostream &stream, const Order &e) {
int index = 1;
for (auto element: e.vec_type1) {
stream << "This is order number " << index << " with type" << element << endl;
index++;
}
stream << "The type ID is " << e.type_id << endl;
return stream;
}
Order::~Order() {
deck= nullptr;
p= nullptr;
//Add GameEngine Player
m= nullptr;
for(int i=0;i<ListOfPlayers.size();i++){
ListOfPlayers[i]= nullptr;
}
}
//Copy Constructor
Order::Order(const Order& O)
{
this->valid = O.valid;
this->vec_type1 = O.vec_type1;
this->type_id = O.type_id;
}
string Order::get_type() {
return vec_type1.at(type_id);
}
bool Order::get_valid() {
return this->valid;
}
vector<string> Order::get_List() {
return this->vec_type1;
}
int Order::get_ID() {
return this->type_id;
}
Order::Order(bool b, vector<string> vector1, int i) {
this->valid = b;
this->vec_type1 = vector1;
this->type_id = i;
}
void OrderList::set_order_list(Order *i) {
bool valid = i->get_valid();
vector<string> vec_type1 = i->get_List();
int type_id= i->get_ID();
string type = i->type;
//STOP2
if(type == "Airlifts") {
Order * T1 = new Airlifts (valid,vec_type1,type_id);
this->vec_order_list.push_back(T1);
}
if(type == "Deploy") {
Order * T1 = new Deploy (valid,vec_type1,type_id);
this->vec_order_list.push_back(T1);
}
if(type == "Bombs") {
Order * T1 = new Bombs (valid,vec_type1,type_id);
this->vec_order_list.push_back(T1);
}
if(type == "Negotiate") {
Order * T1 = new Negotiate (valid,vec_type1,type_id);
this->vec_order_list.push_back(T1);
}
if(type == "Blockades") {
Order * T1 = new Blockades (valid,vec_type1,type_id);
this->vec_order_list.push_back(T1);
}
}
vector<Order *> *OrderList::get_order_list() {
return &vec_order_list;
}
void OrderList::remove(Order *oneOrder) {
for (int i = 0; i < vec_order_list.size(); i++) {
if (oneOrder->get_type() == vec_order_list.at(i)->get_type()) {
vec_order_list.erase(vec_order_list.begin() + i);
return;
}
}
}
void OrderList::move(int position, int new_position) {
if (position >= 0 && position < vec_order_list.size() && new_position >= 0 &&
new_position < vec_order_list.size()) {
vec_order_list.insert(vec_order_list.begin() + new_position, vec_order_list.at(position));
vec_order_list.erase(vec_order_list.begin() + position);
} else if (new_position == vec_order_list.size()) {
vec_order_list.push_back(vec_order_list.at(position));
vec_order_list.erase(vec_order_list.begin() + position);
} else {
cout << "\n not valid position" << endl;
}
}
Deploy::Deploy() {
set_type_id(0);
}
Deploy::Deploy(const Deploy &e) {
};
Deploy &Deploy::operator=(const Deploy &e) {
return *this;
}
Deploy::~Deploy() {
};
Advance::Advance() {
set_type_id(1);
}
Advance::Advance(const Advance &e) {
};
Advance &Advance::operator=(const Advance &e) {
return *this;
}
Advance::~Advance() {
}
Bombs::Bombs() {
set_type_id(2);
}
Bombs::Bombs(const Bombs &e) {
};
Bombs &Bombs::operator=(const Bombs &e) {
return *this;
}
Bombs::~Bombs() {
}
Blockades::Blockades() {
set_type_id(3);
}
Blockades::Blockades(const Blockades &e) {
};
Blockades &Blockades::operator=(const Blockades &e) {
return *this;
}
std::ostream& operator<<(std::ostream& stream, const OrderList& e){
int index = 1;
for (Order * element: e.vec_order_list) {
stream << "This is card number: " << index << " ,the type of this card is " << element << " " << endl;
index++;
}
return stream;
}
Blockades::~Blockades() {
}
Airlifts::Airlifts() {
set_type_id(4);
}
Airlifts::Airlifts(const Airlifts &e) {
};
Airlifts &Airlifts::operator=(const Airlifts &e) {
return *this;
}
bool Airlifts ::validate() {
if(this->p->toDefend().size()==0){
return false;
}
// The player thas is calling this order, has a hand of cards
vector<Card*> _collection = this->p->getHand()->GetCollection();
for(Card* c : _collection){
// Compare two strings to verify
if(c->GetType()=="Airlift")
return true;
}
return false;
};
void Airlifts ::execute() {
bool verif = this->validate();
// Verify if the player can choose between all the teritories first
// Check in Validate
if(verif) {
vector<Territory *> Territories = this->p->territoriesList;
int size = Territories.size();
int index = rand() % (size);
int index2 = rand() % (size);
if(index == index2){
bool equal = true;
while(equal){
index2 = rand() % (size);
if(index != index2)
equal = false;
}
}
vector<Territory *> Territories2;
for (int i = 0; i < Territories.size(); i++) {
//target and source
if (i == index || i == index2 )
{
cout <<endl;
cout <<endl;
Territories2.push_back(Territories[i]);
}
}
//source
int Army1 = Territories2[0]->numberOfArmies;
if (Army1 >= 0) {
int temp = Army1 * 1/2;
//target
int Army2 = Territories2[1]->numberOfArmies;
// Adding
Army2 = Army2 + temp;
Territories2[1]->SetNumberOfArmies(Army2);
// removing from source territory
Army1 = Army1 - temp;
Territories2[0]->SetNumberOfArmies(Army1);
p->getOrdersList()->remove(this);
}
}
else{
p->getOrdersList()->remove(this);
}
this->LogMessage="Player: "+this->p->GetName()+" has called Airlift order";
Notify(*this);
};
Airlifts::~Airlifts() {
}
bool Deploy::validate(){
if(this->p->toDefend().size()==0){
return false;
}
// checks if there are some armies to add to the reinforcement_pool
if(!(this->p->reinforcement_pool == 0))
return true;
};
void Deploy::execute(){
// places some armies from reinforcement pool -> target territory owned by player ONLY IF validate is true
if (validate()) {
vector<Territory *> PlayerTerritories = this->p->toDefend();
int size = PlayerTerritories.size();
//Trying to pick the First Index always
//int index = rand() % (size);
int index = 0;
vector<Territory *> Target;
for (int i = 0; i < size; i++) {
if (i == index)
Target.push_back(PlayerTerritories[i]);
}
// Add the number of armies to the reinforcement pool
int NumberOfReceivedArmies;
if (this->p->reinforcement_pool > 0) {
if (this->p->reinforcement_pool >= 10) {
NumberOfReceivedArmies = 10;
Target[0]->numberOfArmies += 10; //deploys 10 armies
this->p->reinforcement_pool -= 10;
} else {
Target[0]->numberOfArmies += this->p->reinforcement_pool;
this->p->reinforcement_pool -= this->p->reinforcement_pool;
}
}
p->getOrdersList()->remove(this);
this->LogMessage="Player: "+this->p->GetName()+" has called deploy order";
Notify(*this);
} else{
p->getOrdersList()->remove(this);
}
};
string Deploy::stringToLog() {
return "DEPLOY ORDER LOG:"+LogMessage+"\n";
}
string Advance::stringToLog() {
return "ADVANCE ORDER LOG:"+LogMessage+"\n";
}
string Bombs::stringToLog() {
return "BOMB ORDER LOG:"+LogMessage+"\n";
}
string Blockades::stringToLog() {
return "BLOCKADE ORDER LOG:"+LogMessage+"\n";
}
string Airlifts::stringToLog() {
return "AIRLIFT ORDER LOG:"+LogMessage+"\n";
}
string Negotiate::stringToLog() {
return "NEGOTIATE ORDER LOG:"+LogMessage+"\n";
}
void Order::setDeck(Deck * deck) {
this->deck = deck;
}
void Advance::execute() {
bool validate = this->validate();
if(validate) {
// Getting Source from one country
vector<Territory *> PlayerTerritories = this->p->toDefend();
// Getting Enemy Territory that is Adjacent
vector<Territory *> PlayerTerritoriesAttack = this->p->toAttack();
if(this->p->toAttack().size()==0){
p->getOrdersList()->remove(this);
return;
}
PlayerTerritories.size();
// Check if the territories are adjacent
int size = PlayerTerritories.size();
int size2 = PlayerTerritoriesAttack.size();
//Forcing the Territorie to be the strongest Territory
vector<Territory *> Source;
int index = 0;
bool checkers= false;
// Getting the source Territory
for (int i = 0; i < size&&!checkers; i++) {
// Adding Source Territory
if ( (PlayerTerritories[i]->numberOfArmies != 0)){
for(int j=0;j<this->p->territoriesList.size()&&!checkers;j++){
bool inside=false;
for(int z=0;z<PlayerTerritories[i]->edges.size();z++){
if(PlayerTerritories[i]->edges[z]->number==this->p->territoriesList[j]->number){
inside=true;
}
}
if(!inside){
checkers=true;
Source.push_back(PlayerTerritories[i]);
break;
}
}
}
}
if(Source.size() == 0)
{
cout << "All territories have 0 armies, this player cannot attack" << endl;
this->p->orders->remove(this);
return;
}
int index2 = rand() % (size2);
// Source Territory
PlayerTerritories[0];
// Now get the Adjacent territories We need to make sure that it is also an enemy territory
vector<Territory *> Neighboors ;
int z=0;
for(int i=0;i<Source.size();i++) {
Neighboors = Source[i]->edges;
for (Territory *t:this->p->territoriesList) {
for (Territory *t2:Neighboors) {
if (t2->number == t->number) {
Neighboors.erase(Neighboors.begin() + z);
} else {
z++;
}
}
z = 0;
}
if(Neighboors.size()!=0){
break;
}
}
int index3=0;
if(Neighboors.size()!=0) {
int size3 = Neighboors.size();
index3 = rand() % (size3);
}else{
p->getOrdersList()->remove(this);
return;
}
// Now get the Target Territory from the List of Neighboors
// We also check if it is also an ennemy territory
int count = 0;
for (Territory *t: Neighboors) {
if (count == index3){
Source.push_back(t);
break;
}
count++;
}
// how to verify if they both belong to the same player ?
bool Adjacent = true;
bool BothBelongToPlayer = false;
bool DiplomacyOrder = false;
// Verifying if a Diplomacy order has been made between the two players
if(this->p->negotiate == true){
Player * enemy = this->p->enemynottoattack;
//Check if attack Source Territory belongs to Player and target territory to enemy
vector<Territory*> OwnTerritories = this->p->territoriesList;
vector<Territory*> EnemyTerritories = enemy->territoriesList;
bool SourceT = false;
bool Target = false;
for(Territory * t : OwnTerritories){
if(t->number == Source[0]->number)
SourceT = true;
}
for(Territory * t : EnemyTerritories){
if(t->number == Source[1]->number)
Target = true;
}
if(SourceT && Target)
cout<<"There is a negotiate order between the two players involved "
"in this advance manoeuver , there will be no attack between "
<< Source[0]->name << " and " << Source[1] ->name;
this->p->negotiate = false;
enemy->negotiate = false;
}
// Now to Verify if the Target territory belongs to the player as well
for (int i = 0; i < size; i++) {
if (PlayerTerritories[i]->number == Source[1]->number)
BothBelongToPlayer = true;
}
//Because the Aggressive Player does not need to move armies from The Strongest territory
/*
* We need to verify here if the Attacked Player is the neutral Player
* Then we turn it into an Aggressive Player
*
*/
int PlayerIndex = 0;
for (Player *p: this->ListOfPlayers) {
for (Territory *t: p->territoriesList) {
if (t->number == Source[1]->number){
// Checking if the Player is a Neutral Player then we shift its type to Aggressive
if(p->NeutralPlayer){
// Using the Assignment Operator It will return a deep copy as an aggressive Player;
/*
*/
p->SetStrategy(new AggressivePlayer(p));
// Specifying that this it is no longer a Neutral Player
}
}
}
PlayerIndex++;
}
if (Adjacent && BothBelongToPlayer == false ) {
// Source Territory army Supply
int AttackerArmy = Source[0]->numberOfArmies;
// Target Territory army supply
int DefenseArmy = Source[1]->numberOfArmies;
bool defeatedTarget = true;
cout << "During attack, attacker armies are " << AttackerArmy << " and Defender armies " << DefenseArmy
<< endl;
if(AttackerArmy==0){
p->getOrdersList()->remove(this);
return;
}
if(DefenseArmy==0){
cout << "The Target territory has lost all its territories the source player will take over"
<< endl;
// Source Territory
Source[0];
// Loop through the list of players and locate the player that has this territory
//Then loop through the territory of each player and locate the specific player
for (Player *p: this->ListOfPlayers) {
for (Territory *t: p->territoriesList) {
if (t->number == Source[1]->number)
//Removing the Territories
p->RemoveTerritory(t);
}
}
// Now we add this new Conquered Territory to the source Player
this->p->territoriesList.push_back(Source[1]);
cout << "This player has advanced and conquered a new territory " << endl;
cout << "--------------------------------------------------- " << endl;
cout << "--------------------------------------------------- " << endl;
cout << endl;
cout << (this->p->GetName()) << endl;
cout << "--------------------------------------------------- " << endl;
cout << "--------------------------------------------------- " << endl;
cout << endl;
cout << "The Source territory is" << endl;
cout << *Source[0] << endl;
cout << "The added territory is" << endl;
cout << *Source[1] << endl;
//Attacker armies leaving the source territory
if (Source[0]->numberOfArmies > 0) {
if (Source[0]->numberOfArmies >= AttackerArmy)
Source[0]->numberOfArmies -= AttackerArmy;
else
Source[0]->numberOfArmies = 0;
} else if (Source[0]->numberOfArmies <= 0)
Source[0]->numberOfArmies = 0;
// We need to remove this target Territory from the Target Player list
// and add it to the source Player list
// Target Territory
//Attacking Armies occupying the new Territories
Source[1]->numberOfArmies += AttackerArmy;
//Then player needs to Pick one Card From the Deck
// Player that issues this order picks a new Card from the DECK
this->p->hand->Add((this->deck->draw()));
this->p->orders->remove(this);
return;
}
for (int i = 1; i <= AttackerArmy; i++) {
int value1 = rand() % 10 + 1; // value1 in the range 1 to 10
int value2 = rand() % 10 + 1; // value2 in the range 1 to 10
if (DefenseArmy <= 0) {
cout << "The Target territory has lost all its territories the source player will take over"
<< endl;
// Source Territory
Source[0];
// Loop through the list of players and locate the player that has this territory
//Then loop through the territory of each player and locate the specific player
for (Player *p: this->ListOfPlayers) {
for (Territory *t: p->territoriesList) {
if (t->number == Source[1]->number)
//Removing the Territories
p->RemoveTerritory(t);
}
}
// Now we add this new Conquered Territory to the source Player
this->p->territoriesList.push_back(Source[1]);
cout << "This player has advanced and conquered a new territory " << endl;
cout << "--------------------------------------------------- " << endl;
cout << "--------------------------------------------------- " << endl;
cout << endl;
cout << (this->p->GetName()) << endl;
cout << "--------------------------------------------------- " << endl;
cout << "--------------------------------------------------- " << endl;
cout << endl;
cout << "The Source territory is" << endl;
cout << *Source[0] << endl;
cout << "The added territory is" << endl;
cout << *Source[1] << endl;
//Attacker armies leaving the source territory
if (Source[0]->numberOfArmies > 0) {
if (Source[0]->numberOfArmies >= AttackerArmy)
Source[0]->numberOfArmies -= AttackerArmy;
else
Source[0]->numberOfArmies = 0;
} else if (Source[0]->numberOfArmies <= 0)
Source[0]->numberOfArmies = 0;
// We need to remove this target Territory from the Target Player list
// and add it to the source Player list
// Target Territory
//Attacking Armies occupying the new Territories
Source[1]->numberOfArmies += AttackerArmy;
//Then player needs to Pick one Card From the Deck
// Player that issues this order picks a new Card from the DECK
this->p->hand->Add((this->deck->draw()));
break;
}else if (AttackerArmy <= 0) {
cout << "The attacker has lost all its territories and the defender will keep its territory" << endl;
break;
}
// 60% chance that value 1 is from 1 to 6
//70% chance that value 2 is from 1 to 7
else if (value1 <= 6 && value2 <= 7) {
// This means there is attack and Defense happening
// To determine who wins we compare the two values
AttackerArmy--;
}
else if (value1 > 6 && value2 <= 7) {
AttackerArmy--;
//Dense wins
}
else if (value1 <= 6 && value2 > 7) {
DefenseArmy--;
//Attacks wins
}
}
if(DefenseArmy>0){
if(AttackerArmy>=0)
Source[0]->numberOfArmies=AttackerArmy;
Source[1]->numberOfArmies=DefenseArmy;
}
cout << "The defender armies are not 0 " << endl;
cout << "The source territory" << endl;
cout << *Source[0] << endl;
cout << "The Target territory" << endl;
cout << *Source[1] << endl;
//Updating the attacking and defending Armies
Source[0]->numberOfArmies = AttackerArmy;
// We need to remove this target Territory from the Target Player list
// and add it to the source Player list
// Target Territory
//Attacking Armies occupying the new Territories
Source[1]->numberOfArmies = DefenseArmy;
}
// Botth Territories Belong to the same Player
if (Adjacent && BothBelongToPlayer && this->p->AgressivePlayer == false) {
cout << "The two territories belong to the same player the armies will move" << endl;
cout << "This is before moving " << endl;
cout << "-------------------------------------" << endl;
cout << "-------------------------------------" << endl;
cout << endl;
cout << endl;
cout << *Source[0] << endl;
cout << *Source[1] << endl;
cout << "-------------------------------------" << endl;
cout << "-------------------------------------" << endl;
cout << endl;
cout << endl;
cout << "This is before moving " << endl;
// Moving 50% of the army units
int MovingArmies = Source[0]->numberOfArmies * 0.5;
if (MovingArmies > 0) {
if (Source[0]->numberOfArmies >= MovingArmies){
Source[0]->numberOfArmies -= MovingArmies;
Source[1]->numberOfArmies += MovingArmies;
}else{
int temp= Source[0]->numberOfArmies ;
Source[0]->numberOfArmies = 0;
Source[1]->numberOfArmies+=temp;
}
}
// Call Deploy Order on those two, or implement logic from moving to territory A to territory B
cout << "This is after moving " << endl;
cout << "-------------------------------------" << endl;
cout << "-------------------------------------" << endl;
cout << endl;
cout << endl;
cout << *Source[0] << endl;
cout << *Source[1] << endl;
cout << "-------------------------------------" << endl;
cout << "-------------------------------------" << endl;
cout << endl;
cout << endl;
cout << "This is after moving " << endl;
}
// Check if target territory is not adjacent
p->getOrdersList()->remove(this);
} else{
cout<<"There is no Advance Card for the Player who executed this order";
p->getOrdersList()->remove(this);
}
this->LogMessage="Player: "+this->p->GetName()+" has called Adavnce order";
Notify(*this);
};
bool Advance::validate(){