Changeset 12135
- Timestamp:
- Dec 4, 2018, 1:56:55 PM (6 years ago)
- Location:
- code/branches/wagnis_HS18/src/modules/wagnis
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
code/branches/wagnis_HS18/src/modules/wagnis/WagnisPlayer.cc
r12134 r12135 5 5 #include <vector> 6 6 #include <string> 7 #include <cstdlib> 8 #include <ctime> 7 9 8 10 namespace orxonox … … 60 62 { 61 63 if (checkMove(SET_TROOPS_INITIAL)){ 62 this->target_province-> owner_ID = this->Player_ID;64 this->target_province->setOwner_ID(this->Player_ID); 63 65 this->target_province->setTroops(this->target_province->getTroops()+1); 64 orxout()<<"Province "<<this->target_province-> ID<<" owned by Player "<<this->target_province->owner_ID<<" troops: "<<this->target_province->getTroops()<<endl;66 orxout()<<"Province "<<this->target_province->getID()<<" owned by Player "<<this->target_province->getOwner_ID()<<" troops: "<<this->target_province->getTroops()<<endl; 65 67 master->playerFinishedStageCallback(this); 66 68 }else{ 67 69 orxout()<<"Sorry, someone already owns this provice"<<endl; 68 70 } 71 //TODO: Set more troops to provinces before game begins 69 72 70 73 break; … … 73 76 case REINFORCEMENT_STAGE: 74 77 { 75 if (checkMove(SET_TROOPS)){ 76 this->target_province->setTroops(this->target_province->getTroops()+1); 77 orxout()<<"Province "<<this->target_province->ID<<" owned by Player "<<this->target_province->owner_ID<<" troops: "<<this->target_province->getTroops()<<endl; 78 int i = reinforcementCounter(); //i tells how many troops player gets 79 while (i > 0) 80 { 81 if (checkMove(SET_TROOPS)) 82 { 83 this->target_province->setTroops(this->target_province->getTroops()+1); 84 orxout()<<"Province "<<this->target_province->getID()<<" owned by Player "<<this->target_province->getOwner_ID()<<" troops: "<<this->target_province->getTroops()<<endl; 85 --i; 86 } 78 87 } 79 88 89 master->playerFinishedStageCallback(this); 90 80 91 break; 81 92 } … … 89 100 { 90 101 //normal fight, 3 attackers, 2 defenders 102 int att1 = dice(); 103 int att2 = dice(); 104 int att3 = dice(); 105 int def1 = dice(); 106 int def2 = dice(); 107 int attBest = best3(att1, att2, att3); 108 int attSecond = second3(att1, att2, att3); 109 int defBest = best2(def1, def2); 110 int defSecond = second2(def1, def2); 111 112 if(defBest >= attBest) 113 this->origin_province->setTroops(this->origin_province->getTroops()-1); 114 if (attBest > defBest) 115 this->target_province->setTroops(this->target_province->getTroops()-1); 116 if(defSecond >= attSecond) 117 this->origin_province->setTroops(this->origin_province->getTroops()-1); 118 if (attSecond > defSecond) 119 this->target_province->setTroops(this->target_province->getTroops()-1); 91 120 } 92 121 … … 94 123 { 95 124 //2 attackers, 2 defenders 125 int att1 = dice(); 126 int att2 = dice(); 127 int def1 = dice(); 128 int def2 = dice(); 129 int attBest = best2(att1, att2); 130 int attSecond = second2(att1, att2); 131 int defBest = best2(def1, def2); 132 int defSecond = second2(def1, def2); 133 134 if(defBest >= attBest) 135 this->origin_province->setTroops(this->origin_province->getTroops()-1); 136 if (attBest > defBest) 137 this->target_province->setTroops(this->target_province->getTroops()-1); 138 if(defSecond >= attSecond) 139 this->origin_province->setTroops(this->origin_province->getTroops()-1); 140 if (attSecond > defSecond) 141 this->target_province->setTroops(this->target_province->getTroops()-1); 96 142 } 97 143 … … 99 145 { 100 146 //1 attacker, 2 defenders 101 } 102 103 //TODO: implement other cases 147 int attBest = dice(); 148 int def1 = dice(); 149 int def2 = dice(); 150 int defBest = best2(def1, def2); 151 152 if(defBest >= attBest) 153 this->origin_province->setTroops(this->origin_province->getTroops()-1); 154 if (attBest > defBest) 155 this->target_province->setTroops(this->target_province->getTroops()-1); 156 } 157 158 if((this->origin_province->getTroops() >= 4) && (this->target_province->getTroops() == 1)) 159 { 160 //3 attackers, 1 defender 161 int att1 = dice(); 162 int att2 = dice(); 163 int att3 = dice(); 164 int defBest = dice(); 165 int attBest = best3(att1, att2, att3); 166 167 if(defBest >= attBest) 168 this->origin_province->setTroops(this->origin_province->getTroops()-1); 169 if (attBest > defBest) 170 this->target_province->setTroops(this->target_province->getTroops()-1); 171 } 172 173 if((this->origin_province->getTroops() == 3) && (this->target_province->getTroops() == 1)) 174 { 175 //2 attackers, 1 defender 176 int att1 = dice(); 177 int att2 = dice(); 178 int defBest = dice(); 179 int attBest = best2(att1, att2); 180 181 if(defBest >= attBest) 182 this->origin_province->setTroops(this->origin_province->getTroops()-1); 183 if (attBest > defBest) 184 this->target_province->setTroops(this->target_province->getTroops()-1); 185 } 186 187 if((this->origin_province->getTroops() == 2) && (this->target_province->getTroops() == 1)) 188 { 189 //1 attacker, 1 defender 190 int attBest = dice(); 191 int defBest = dice(); 192 193 if(defBest >= attBest) 194 this->origin_province->setTroops(this->origin_province->getTroops()-1); 195 if (attBest > defBest) 196 this->target_province->setTroops(this->target_province->getTroops()-1); 197 } 104 198 } 105 199 106 200 if (this->target_province->getTroops() == 0) //attacker won 107 201 { 108 this->target_province-> owner_ID = this->Player_ID;202 this->target_province->setOwner_ID(this->Player_ID); 109 203 this->target_province->setTroops(this->origin_province->getTroops() - 1); 110 204 this->origin_province->setTroops(1); … … 120 214 this->target_province->setTroops(this->origin_province->getTroops()-1); 121 215 this->origin_province->setTroops(1); 216 master->playerFinishedStageCallback(this); 122 217 } 123 218 break; … … 221 316 return false; 222 317 } 318 319 int WagnisPlayer::dice() //returns random integer in range [1, 2, 3, 4, 5, 6] 320 { 321 srand(time(NULL)); 322 return (rand()%6+1); 323 } 324 325 int WagnisPlayer::best3(int a, int b, int c) 326 { 327 if(a >= b && a>= c) 328 return a; 329 if(b >= a && b>= c) 330 return b; 331 else 332 return c; 333 } 334 335 int WagnisPlayer::best2(int a, int b) 336 { 337 if(a >= b) 338 return a; 339 else 340 return b; 341 } 342 343 int WagnisPlayer::second3(int a, int b, int c) 344 { 345 if((a >= b && a <= c)||(a <= b && a >= c)) 346 return a; 347 if((b >= a && b <= c)||(b <= a && b >= c)) 348 return b; 349 else 350 return c; 351 } 352 353 int WagnisPlayer::second2(int a, int b) 354 { 355 if(a <= b) 356 return a; 357 else 358 return b; 359 } 360 361 int WagnisPlayer::reinforcementCounter() //calculates how many troops a player gets at beginning of his turn 362 { 363 364 return 10; 365 /* 366 int counter = 0; 367 368 for (int i = 0; i <= 100; ++i) 369 { 370 if 371 } 372 */ 373 374 } 223 375 } -
code/branches/wagnis_HS18/src/modules/wagnis/WagnisPlayer.h
r12134 r12135 49 49 bool isNeighbour(WagnisProvince*, WagnisProvince*); 50 50 bool existPath(WagnisProvince*, WagnisProvince*); 51 int dice(); 52 int best3(int, int, int); 53 int best2(int, int); 54 int second3(int, int, int); 55 int second2(int, int); 56 int reinforcementCounter(); 51 57 }; 52 58 }
Note: See TracChangeset
for help on using the changeset viewer.