魔兽3:开战

  1 #include <iostream>
  2 #include <string>
  3 #include <cmath>
  4 #include <vector>
  5 #include <list>
  6 #include <algorithm>
  7 #include <deque>
  8 
  9 using namespace std;
 10 int dragon_l=0,ninja_l=0,iceman_l=0,lion_l=0,wolf_l=0;
 11 int dragon_a=0,ninja_a=0,iceman_a=0,lion_a=0,wolf_a=0;
 12 int caseN;
 13 int life;
 14 int cityN;
 15 int ArrowAttack;
 16 int loyd;
 17 int time_limit;
 18 int minute;
 19 int hour;
 20 int red_taken=0;
 21 int blue_taken=0;
 22 class soldier;
 23 class city{
 24 public:
 25     soldier* red_in_city=NULL;
 26     soldier* blue_in_city=NULL;
 27     int red_exist=0;
 28     int blue_exist=0;
 29     int flag=0;                                 //旗子状态:0是没升旗,1是蓝旗,2是红旗
 30     int taken=0;
 31 };
 32 class time_line{
 33 public:
 34     static void time_telling(int h, int m){
 35         printf("%03d:%02d ",h,m);
 36     }
 37 };
 38 
 39 class weapon{
 40 private:
 41     int tp;
 42 public:
 43     int arrows=2;
 44     weapon(){}
 45     weapon(const int n):tp(n){}
 46     weapon(const weapon& b):tp(b.tp),arrows(b.arrows){}
 47     weapon(int x,int y):tp(x),arrows(y){}
 48     int tpp(){return tp;}
 49 };
 50 bool weaponsort(weapon &a,weapon &b){
 51     if(a.tpp()==2&&b.tpp()==2)
 52         return a.arrows<=b.arrows;
 53     return a.tpp()<b.tpp();
 54 }
 55 
 56 
 57 class soldier:public time_line{
 58 public:
 59     int dead=0;
 60     double loyalty;
 61     string name;
 62     string color;
 63     int blood;
 64     int attack;
 65     int sub_num=0;
 66     int place;
 67     int reach_hq=0;
 68     int bomb_n=0;
 69     int sword_n=0;
 70     int arrow_n=0;
 71     deque<weapon> equipment;
 72     inline void weapon_n_increase(int n){
 73         if(n==0) ++sword_n;                          //武器数量相应增加
 74         if(n==1) ++bomb_n;
 75         if(n==2) ++arrow_n;
 76     }
 77     soldier(){}
 78     soldier(int b,int a,const char*p,const char*n,int s):blood(b),attack(a),color(p),name(n),sub_num(s),equipment(10){
 79         if(color=="red")
 80             place=0;
 81         else
 82             place=cityN+1;
 83         if(name=="dragon"){
 84             equipment.clear();
 85             equipment.push_front(weapon(sub_num%3));
 86             weapon_n_increase(sub_num%3);
 87         }
 88         else if(name=="lion"){
 89             equipment.clear();
 90             equipment.push_front(weapon(sub_num%3));
 91             weapon_n_increase(sub_num%3);
 92         }
 93         else if(name=="ninja"){
 94             equipment.clear();
 95             equipment.push_front(weapon((sub_num+1)%3));
 96             equipment.push_front(weapon(sub_num%3));
 97             weapon_n_increase(sub_num%3);
 98             weapon_n_increase((sub_num+1)%3);
 99         }
100         else if(name=="wolf"){
101             equipment.clear();
102         }
103         else if(name=="iceman"){
104             equipment.clear();
105             equipment.push_front(weapon(sub_num%3));
106             weapon_n_increase(sub_num%3);
107         }
108     }
109     int attack_it(soldier *p);
110     void march(class city*p);
111     void hurted(int n);
112     void yelling();
113     void aquire_weapon(soldier *p);
114     void steal_weapon(soldier *p);
115     bool operator==(soldier &p){
116         if(this->color==p.color&&this->sub_num==p.sub_num)
117             return true;
118         else
119             return false;
120     }
121 };
122 void soldier::yelling(){
123     if(name=="dragon"&&!dead){
124         time_telling(hour,minute);
125         cout<<color<<" dragon "<<sub_num<<" yelled in city "<<place<<endl;
126     }
127 };
128 
129 void soldier::aquire_weapon(soldier *p){
130     if(p->sword_n+p->arrow_n+p->bomb_n==0)
131         return;
132     for(int i=1;i<=p->equipment.size();i++){
133         equipment.push_front(p->equipment[i-1]);
134         p->equipment.pop_front();
135     }
136     sword_n+=p->sword_n;
137     bomb_n+=p->bomb_n;
138     arrow_n+=p->arrow_n;
139 }
140 
141 void soldier::steal_weapon(soldier *p){
142         sort(p->equipment.begin(), p->equipment.end(), weaponsort);  //非常关键!!若不先SORT,会偷错武器,出事,GG。
143     if(arrow_n+bomb_n+sword_n==0)
144         equipment.clear();
145     if(p->name=="wolf")
146         return;                         //盗亦有道,狼和狼不互相偷
147     if(p->sword_n+p->arrow_n+p->bomb_n>0){
148     if(p->sword_n>0){
149         for(int i=1;i<=p->sword_n;i++)
150             equipment.push_front(*(p->equipment.begin()+i-1));
151         sword_n+=p->sword_n;
152         for(int i=1;i<=p->sword_n;i++)
153             p->equipment.pop_front();
154         time_telling(hour,minute);
155         cout<<color<<" wolf "<<sub_num<<" took "<<p->sword_n<<" sword from "<<p->color<<" "<<p->name<<" "<<p->sub_num
156         <<" in city "<<place<<endl;
157         p->sword_n=0;
158     }
159     else if(p->bomb_n>0){
160         for(int i=1;i<=p->bomb_n;i++)
161             equipment.emplace_front(*(p->equipment.begin()+i-1));
162         bomb_n+=p->bomb_n;
163         for(int i=1;i<=p->bomb_n;i++)
164             p->equipment.pop_front();
165         time_telling(hour,minute);
166         cout<<color<<" wolf "<<sub_num<<" took "<<p->bomb_n<<" bomb from "<<p->color<<" "<<p->name<<" "<<p->sub_num
167         <<" in city "<<place<<endl;
168         p->bomb_n=0;
169     }
170     else if(p->arrow_n>0){
171         for(int i=1;i<=p->arrow_n;i++) {
172             weapon tmp(2,(p->equipment.begin() -i + 1)->arrows);
173             equipment.push_front(tmp);
174         }
175         arrow_n+=p->arrow_n;
176         for(int i=1;i<=p->arrow_n;i++)
177           p->equipment.pop_front();
178         time_telling(hour,minute);
179         cout<<color<<" wolf "<<sub_num<<" took "<<p->arrow_n<<" arrow from "<<p->color<<" "<<p->name<<" "<<p->sub_num
180         <<" in city "<<place<<endl;
181         p->arrow_n=0;
182     }
183     }
184 }
185 
186 int soldier::attack_it(soldier *p) {
187     
188     sort(equipment.begin(), equipment.end(), weaponsort);
189     sort(p->equipment.begin(), p->equipment.end(), weaponsort);
190     int life1;
191     int life2;
192     if(equipment.empty()==true&&p->equipment.empty()==true){
193         if(color=="red"){
194             time_telling(hour,minute);
195             cout<<"both "<<color<<" "<<name<<" "<<sub_num<<" and "<<p->color<<" "<<p->name<<" "<<p->sub_num<<
196             " were alive in city "<<place<<endl;
197             yelling();
198             p->yelling();
199             return 0;
200         }
201         else
202         {
203             time_telling(hour,minute);
204             cout<<"both "<<p->color<<" "<<p->name<<" "<<p->sub_num<<" and "<<color<<" "<<name<<" "<<sub_num<<
205             " were alive in city "<<place<<endl;
206             p->yelling();
207             yelling();
208         }
209         return 0;}
210     
211     deque<weapon>::iterator it;
212     deque<weapon>::iterator ip;
213     bool used=false;
214     if(equipment.empty()==false)
215         it=equipment.begin();
216     if(p->equipment.empty()==false)
217         ip=p->equipment.begin();
218     do {
219         life1 = blood;
220         life2 = p->blood;
221         if (!dead && sword_n + bomb_n + arrow_n > 0) {
222             for (int i = 1; i <= equipment.size(); i++) {
223                 used = false;
224                 if (it->tpp() == 0) {
225                     p->hurted(attack * 2 / 10);
226                     //cout << "我砍" <<color<< endl;
227                     it++;
228                     if (it == equipment.end())
229                         it = equipment.begin();
230                     used = true;
231                 }
232                 else if (it->tpp() == 1) {
233                     if (bomb_n > 0) {
234                         p->hurted(attack * 4 / 10);                            //攻击对方
235                         if (name != "ninja")                             //本方若是ninja则不受攻击
236                             hurted(attack * 4 / 20);
237                         //cout << "我炸" <<color<< endl;
238                         --bomb_n;
239                         used = true;
240                         it++;
241                     } else
242                         it++;
243                     if (it == equipment.end())
244                         it = equipment.begin();
245                 }
246                 else if (it->tpp() == 2) {
247                     if (it->arrows > 0) {
248                         //cout << "看箭" << endl;
249                         p->hurted(attack * 3 / 10);
250                         it->arrows-=1;
251                         if (it->arrows == 0)
252                             arrow_n-=1;
253                         used = true;
254                         it++;
255                     } else
256                         it++;
257                     if (equipment.end() == it)
258                         it = equipment.begin();}
260                 if (used){
261                     break;}
262                     
263             }
264         }
265         if (!dead&&!p->dead && p->sword_n + p->bomb_n + p->arrow_n > 0) {
266             for (int i = 1; i <= p->equipment.size()*2; i++) {
267                 used = false;
268                 if (ip->tpp() == 0) {
269                     hurted((p->attack) * 2 / 10);
270                         used = true;
271                     //cout << "我砍" <<p->color<< endl;
272                      if(p->equipment.size()>1)
273                          ip++;
274                     if (ip == p->equipment.end())
275                         ip = p->equipment.begin();
276                 } else if (ip->tpp() == 1) {
277                     if (p->bomb_n >0) {
278                         hurted(p->attack * 4 / 10);                            //攻击对方
279                         if (p->name != "ninja")  {                           //本方若是ninja则不受攻击
280                             p->hurted(p->attack * 4 / 20);
281                         }
282                         //cout << "我炸" <<p->color<< endl;
283                         --p->bomb_n;
284                         used = true;
285                         ip++;
286                     } else if(p->equipment.size()>1)
287                         ip++;
288                     if (p->equipment.size()>1&&ip == p->equipment.end())
289                         ip = p->equipment.begin();
290                 } else if (ip->tpp() == 2) {
291                     if (ip->arrows >0) {
292                         //cout << "看箭" << endl;
293                         hurted(p->attack * 3 / 10);
294                         int &s=ip->arrows;
295                         s--;
296                         if (ip->arrows == 0) {
297                             --p->arrow_n;
298                         }
299                         used = true;
300                         ip++;
301                     } else if(p->equipment.size()>1)
302                         ip++;
303                     if (ip == p->equipment.end())
304                         ip = p->equipment.begin();
305                 }
306                 if (used)
307                     break;
308             }
309         }
310         if(dead||p->dead)
311             break;
312     }while(life1!=blood||life2!=p->blood||bomb_n+arrow_n>0||p->bomb_n+p->arrow_n>0);
313     
314     
315     if (dead && !p->dead) {
316         time_telling(hour, minute);
317         cout << p->color << " " << p->name << " " << p->sub_num << " killed " << color << " " << name << " "
318         << sub_num << " in city "
319         << place << " remaining " << p->blood << " elements" << endl;
320         p->yelling();
321         p->aquire_weapon(this);
322         return -1;
323         
324     } else if (p->dead && !dead) {
325         time_telling(hour, minute);
326         cout << color << " " << name << " " << sub_num << " killed " << p->color << " " << p->name << " "
327         << p->sub_num << " in city "
328         << place << " remaining " << blood << " elements" << endl;
329         yelling();
330         aquire_weapon(p);
331         return 1;
332         
333     } else if (p->dead && dead) {
334         if (color == "red") {
335             time_telling(hour, minute);
336             cout << "both " << color << " " << name << " " << sub_num << " and " << p->color << " " << p->name
337             << " " << p->sub_num <<
338             " died in city " << place << endl;
339         } else {
340             time_telling(hour, minute);
341             cout << "both " << p->color << " " << p->name << " " << p->sub_num << " and " << color << " " << name
342             << " " << sub_num <<
343             " died in city " << place << endl;
344         }
345         return -2;
346         
347     } else if (life1 == blood && life2 == p->blood) {
348         if (color == "red") {
349             time_telling(hour, minute);
350             cout << "both " << color << " " << name << " " << sub_num << " and " << p->color << " " << p->name
351             << " " << p->sub_num <<
352             " were alive in city " << place << endl;
353             yelling();
354             p->yelling();
355         } else {
356             time_telling(hour, minute);
357             cout << "both " << p->color << " " << p->name << " " << p->sub_num << " and " << color << " " << name
358             << " " << sub_num <<
359             " were alive in city " << place << endl;
360             p->yelling();
361             yelling();
362         }
363         return 0;
364         
365     }
366     
367     return 0;
368 }
369 void soldier::hurted(int n){
370     blood-=n;
371     if(blood<=0) dead=1; }
372 
373 void enter_city(class city&from,class city&to,class soldier *p) {
374     if(p==from.blue_in_city) {
375         --from.blue_exist;
376     }
377     else if(p==from.red_in_city){
378         --from.red_exist;
379     }
380     if(p->color=="red"){
381         ++to.red_exist;
382         to.red_in_city=p;}
383     if(p->color=="blue"){
384         ++to.blue_exist;
385         to.blue_in_city=p;
386     }
387 }
388 
389 void soldier::march(class city*p) {
390     if(name=="lion"&&!dead) {
391         loyalty-=loyd;
392     }
393     if(name=="iceman"&&!dead) {
394         int d=floor(blood/10);
395         blood-=d;
396     }
397     if (color == "red") {
398         if (reach_hq) return;
399         else {
400             place++;
401             enter_city(p[place-1],p[place],this);
402             if (place == cityN+1) {
403                 reach_hq = 1;
404                 p->taken=1;
405                 blue_taken=1;
406                 return;
407             }
408             
409         }
410         return;
411     }
412     else {
413         if (reach_hq) return;
414         
415         else {
416             place--;
417             enter_city(p[place+1],p[place],this);
418             if (place == 0) {
419                 reach_hq = 1;
420                 p->taken=1;
421                 red_taken=1;
422                 return;
423             }
424         }
425         return;
426     }
427 }
428 
429 class dragon:public soldier{
430 public:
431     dragon(int b,int a,const char*p,const char*n,int s):soldier(b,a,p,n,s){}
432 };
433 class ninja:public soldier{
434 public:
435     ninja(int b,int a,const char*p,const char*n,int s):soldier(b,a,p,n,s){}
436 };
437 class iceman:public soldier{
438 public:
439     iceman(int b,int a,const char*p,const char*n,int s):soldier(b,a,p,n,s){}
440 };
441 class lion:public soldier{
442 public:
443     lion(int b,int a,const char*p,const char*n,int s,int q):soldier(b,a,p,n,s){
444         loyalty=q;
445         cout<<"Its loyalty is "<<loyalty<<endl;
446     }
447     
448 public:
449     int flee(){
450         if(loyalty>0)
451             return -1;
452         else{
453             time_telling(hour,minute);
454             dead=1;
455             have_weapon=0;
456             cout<<color<<" lion "<<sub_num<<" ran away"<<endl;
457         }
458         return place;
459     };
460 };
461 class wolf:public soldier{
462 public:
463     wolf(int b,int a,const char*p,const char*n,int s):soldier(b,a,p,n,s){}
464 };
465 
466 class HQ:public time_line ,public city{
467 public:
468     char *color;
469     int working;
470     int life;
471     int cp = 0;                                               //目前造到哪一个小兵,SEQUENCE中的下标
472     int sub = 1;                                                // 小兵的下标
473     int taken_over=0;
474     
475     string na[5] = {"dragon", "ninja", "iceman", "lion", "wolf"};  //小兵名字
476     string we[3] = {"sword", "bomb", "arrow"};
477     int sequence[5];                                        //造兵顺序
478     int con[5];                                             //造每个兵的消耗
479     int num[5] = {0, 0, 0, 0, 0};                                 //每种小兵的数量
480     soldier *warriors[100];
481     
482     HQ(int a[5], char *c) {
483         memcpy(sequence, a, 5 * sizeof(int));
484         color = new char[10];
485         working = 1;
486         strcpy(color, c);
487     }
488     
489     void init(int a, int b, int c, int d, int e) {
490         con[0] = a;con[1] = b;
491         con[2] = c;con[3] = d;
492         con[4] = e; memset(warriors,0,sizeof(warriors)) ;
493     }
494     
495     void reset() {
496         working = 1;
497         for (int i = 0; i < 5; i++)
498             num[i] = 0;
499         cp = 0; sub = 1;
500     }
501     
502     void weapon() {
503         if (sequence[cp] == 4)
504             return;
505         else if (sequence[cp] == 3) {
506             cout << "It's loyalty is " << life << endl;
507             return;
508         } else if (sequence[cp] == 0) {
509             cout << "It has a " << we[sub % 3] << ",and it's morale is ";
510             printf("%.2f
", (float) life / con[sequence[cp]]);
511             return;
512         } else if (sequence[cp] == 1) {
513             cout << "It has a " << we[sub % 3] << " and a " << we[(sub + 1) % 3] << endl;
514             return;
515         } else if (sequence[cp] == 2) {
516             cout << "It has a " << we[sub % 3] << endl;
517         }
518     }
519     
520     void making() {
521         if (life >= con[sequence[cp]]) {
522             //sub=1;
523             num[sequence[cp]]++;
524             time_telling(hour,minute);
525             cout << color << " " << na[sequence[cp]] << " " << sub << " " << "born"<<endl;
526             life -= con[sequence[cp]];
527             if (sequence[cp] == 0) {
528                 dragon *q1 = new dragon(dragon_l, dragon_a, color, "dragon", sub);
529                 warriors[sub] = q1;
530             } else if (sequence[cp] == 1) {
531                 ninja *q2 = new ninja(ninja_l, ninja_a, color, "ninja", sub);
532                 warriors[sub] = q2;
533             } else if (sequence[cp] == 2) {
534                 iceman *q3 = new iceman(iceman_l, iceman_a, color, "iceman", sub);
535                 warriors[sub] = q3;
536                 
537             } else if (sequence[cp] == 3) {
538                 lion *q4 = new lion(lion_l, lion_a, color, "lion", sub, this->life);
539                 warriors[sub] = q4;
540             } else if (sequence[cp] == 4) {
541                 wolf *q5 = new wolf(wolf_l, wolf_a, color, "wolf", sub);
542                 warriors[sub] = q5;
543             }
544             sub++; cp = (cp + 1) % 5;
545         }
546     }
547     
548     void tell_elements(){
549         time_telling(hour,minute);
550         cout<<life<<" elements in "<<color<<" headquarter"<<endl;
551     }
552     
553     void tell_weapon(city *cities){
554         for(int i=1;i<=cityN;i++){
555             if(cities[i].red_exist>0&&cities[i].red_in_city!=NULL){
556                 
557                 soldier *tmp=cities[i].red_in_city;
558                 if(!tmp->dead){
559                     
560                     time_telling(hour, minute);
561                     cout<<tmp->color<<" "<<tmp->name<<" "<<tmp->sub_num<<" has "<<tmp->sword_n<<
562                     " sword "<<tmp->bomb_n<<" bomb "<<tmp->arrow_n<<" arrow and "<<
563                     tmp->blood<<" elements"<<endl;}
564             }
565             if(cities[i].blue_exist>0&&cities[i].blue_in_city!=NULL){
566                 
567                 soldier *tmp=cities[i].blue_in_city;
568                 if(!tmp->dead){
569                     
570                     
571                     time_telling(hour, minute);
572                     cout<<tmp->color<<" "<<tmp->name<<" "<<tmp->sub_num<<" has "<<tmp->sword_n<<
573                     " sword "<<tmp->bomb_n<<" bomb "<<tmp->arrow_n<<" arrow and "<<
574                     tmp->blood<<" elements"<<endl;}
575             }
576         }
577     }
578 };
579 void tell_position(city* cities){
580     for(int i=1;i<=cityN;i++){
581         if(cities[i].red_exist>0&&cities[i].red_in_city!=NULL&&cities[i].red_in_city->dead==0){
582             
583             soldier *tmp=cities[i].red_in_city;
584             if (tmp->color=="red") {
585                 if (tmp->reach_hq == 1) {
586                     
587                 } else {
588                     time_line::time_telling(hour, minute);
589                     cout << tmp->color << " " << tmp->name << " " << tmp->sub_num << " marched to city "
590                     << tmp->place << " with " << tmp->blood
591                     << " elements and force " << tmp->attack << endl;
592                 }
593             }
594         }
595         
596         if(cities[i].blue_exist>0&&cities[i].blue_in_city!=NULL&&cities[i].blue_in_city->dead==0){
597             
598             if (cities[i].blue_in_city->color=="blue") {
599                 soldier* tm=cities[i].blue_in_city;
600                 if (cities[i].blue_in_city->reach_hq==1) {
601                     
602                 }
603                 else{
604                     time_line::time_telling(hour, minute);
605                     cout << tm->color << " " << tm->name << " " << tm->sub_num << " marched to city " << tm->place
606                     << " with " << tm->blood << " elements and force " << tm->attack << endl;
607                 }
608             }
609         }
610     }
611 }
612 
613 void HQ_check(int a,int b,city* cities,int seq){
614     if(a&&seq==1){
615         soldier* tm=cities[0].blue_in_city;
616         time_line::time_telling(hour, minute);
617         cout << tm->color << " " << tm->name << " " << tm->sub_num << " reached red headquarter"
618         << " with "<< tm->blood
619         << " elements and force " << tm->attack << endl;
620         time_line::time_telling(hour, minute);
621         cout << "red" << " " << "headquarter was taken" << endl;
622     }
623     if(b&&seq==2){
624         soldier*tmp=cities[cityN+1].red_in_city;
625         time_line::time_telling(hour, minute);
626         cout << tmp->color << " " << tmp->name << " " << tmp->sub_num << " reached blue headquarter"
627         << " with "
628         << tmp->blood
629         << " elements and force " << tmp->attack << endl;
630         time_line::time_telling(hour, minute);
631         cout << "blue" << " " << "headquarter was taken" << endl;
632     }
633 }
634 
635 
636 int main() {
637     int a[5] = {2, 3, 4, 1, 0};
638     int b[5] = {3, 0, 1, 2, 4};
639     HQ red(a, "red"), blue(b, "blue");
640     
641     cin >> caseN;
642     for (int ip = 1; ip <= caseN; ip++) {
643         red.reset();
644         blue.reset();
645         cin >> life;
646         cin >> cityN;
647         cin >> loyd;
648         cin >> time_limit;
649         cin >> dragon_l >> ninja_l >> iceman_l >> lion_l >> wolf_l;
650         red.init(dragon_l, ninja_l, iceman_l, lion_l, wolf_l);
651         blue.init(dragon_l, ninja_l, iceman_l, lion_l, wolf_l);
652         cin >> dragon_a >> ninja_a >> iceman_a >> lion_a >> wolf_a;
653         red.life = life;
654         blue.life = life;
655         city* cities=new city[20];
656         
657         cout << "Case " << ip << ":" << endl;
658         for(hour=0;hour<time_limit/60+1;hour++) {
659             minute = 0;       //1) 武士降生
660             red.making();
661             blue.making();
662             
663             minute = 5;       //2) lion逃跑
664             for (int xu = 1; xu <= red.sub; xu++) {
665                 if (red.warriors[xu] != NULL && red.warriors[xu]->sub_num !=0&&red.warriors[xu]->name=="lion"&&
666                     !red.warriors[xu]->dead) {
667                     //cout<<red.warriors[xu]->loyalty;
668                     if (red.warriors[xu]->loyalty < 0) {
669                         lion *pq = (class lion *) red.warriors[xu];
670                         int t=pq->flee();
671                         if(t!=-1){
672                             cities[t].red_exist--;
673                             cities[t].red_in_city=NULL;}
674                     }
675                 }
676             }
677             for (int xu = 1; xu <= blue.sub; xu++) {
678                 if (blue.warriors[xu] != NULL && blue.warriors[xu]->name == "lion" && !blue.warriors[xu]->dead) {
679                     
680                     if (blue.warriors[xu]->loyalty <= 0) {
681                         lion *pq = (class lion *) blue.warriors[xu];
682                         int t=pq->flee();
683                         if(t!=-1){
684                             cities[t].blue_exist--;
685                             cities[t].blue_in_city=NULL;}
686                     }
687                 }
688             }
689             
690             minute = 10;      //3) 武士前进到某一城市
691             //3)*或进入某个总部
692             for (int xu = 1; xu <= red.sub; xu++) {
693                 if (red.warriors[xu]!=NULL&&!red.warriors[xu]->dead)
694                     red.warriors[xu]->march(cities);
695             }
696             for (int xu = 1; xu <= blue.sub; xu++) {
697                 if (blue.warriors[xu]!=NULL&&!blue.warriors[xu]->dead)
698                     blue.warriors[xu]->march(cities);
699             }
700             HQ_check(red_taken, blue_taken,cities,1);
701             tell_position(cities);
702             HQ_check(red_taken, blue_taken,cities,2);
703             if (red_taken||blue_taken){
704                 break;}
705             minute = 35;      //4)武士放箭     wolf抢武器
706             for (int xu = 1; xu <= cityN; xu++) {
707                 if (cities[xu].red_exist > 0 && cities[xu].blue_exist > 0) {
708                     if (cities[xu].red_in_city!=NULL &&cities[xu].red_in_city->name == "wolf")
709                         cities[xu].red_in_city->steal_weapon(cities[xu].blue_in_city);
710                     if (cities[xu].blue_in_city!=NULL &&cities[xu].blue_in_city->name == "wolf")
711                         cities[xu].blue_in_city->steal_weapon(cities[xu].red_in_city);
712                 }
713             }
714             
715             //minute = 38;      //5)武士使用bomb
716             minute = 40;      //6) 武士主动进攻
717             for (int xu = 1; xu <= cityN; xu++) {
718                 if (cities[xu].red_exist > 0 && cities[xu].blue_exist > 0) {
719                     if (xu % 2 == 1) {
720                         int stat = cities[xu].red_in_city->attack_it(cities[xu].blue_in_city);
721                         if (stat == 1) {
722                             cities[xu].blue_in_city=NULL;
723                             cities[xu].blue_exist = 0;
724                         } else if (stat == -1) {
725                             cities[xu].red_in_city=NULL;
726                             cities[xu].red_exist = 0;
727                         } else if (stat == -2) {
728                             cities[xu].blue_in_city=NULL;
729                             cities[xu].red_in_city=NULL;
730                             cities[xu].blue_exist = 0;
731                             cities[xu].red_exist = 0;
732                         }
733                     }
734                     else if (xu % 2 == 0) {
735                         int sta =cities[xu].blue_in_city->attack_it(cities[xu].red_in_city);
736                         if (sta == -1) {
737                             cities[xu].blue_in_city=NULL;
738                             cities[xu].blue_exist = 0;
739                         } else if (sta == 1) {
740                             cities[xu].red_in_city=NULL;
741                             cities[xu].red_exist = 0;
742                         } else if (sta == -2) {
743                             cities[xu].blue_in_city=NULL;
744                             cities[xu].red_in_city=NULL;
745                             cities[xu].blue_exist = 0;
746                             cities[xu].red_exist = 0;}
747                     }
748                 }
749             }
750             if(hour*60+minute>=time_limit){
751                 break;}
752             //minute = 40;      //7)武士反击
753             minute = 40;      //8)武士欢呼
754             //minute = 40;      //9)旗帜升起
755             minute = 50;      //10)生命元状况
756             
757             red.tell_elements();
758             blue.tell_elements();
759             minute = 55;      //11)武器状况
760             red.tell_weapon(cities);
761         }
762         red_taken=0;
763         blue_taken=0;
764     }
765 }

emmmmm......周六debug一整天,偷取武器、获取武器、武器失效的部分写的极其烂(能过,但是问题太多了,,,实在懒得优化了emmmmm)

沿用了魔兽1,魔兽2的框架,添加了一些新的要素

适用性太差,好多废话基本只是为了能过

如果要修改的话:

1、把武器函数统统改了。。

2、每个case结束后重置的部分也有问题,应该单独写个reset()统一处理

3、想办法去掉color=="red"、color=="blue"这样的智障语句

4、我为什么不他妈的用printf???写一长串cout真的好玩吗

原文地址:https://www.cnblogs.com/maskoff/p/8747415.html