几个坑:
1.已经走到对方基地但是此时还没有赢的武士,仍需要报告工作
2.dragon的yell条件是自己没有死(对方是被弓射死会yell)
3.在有敌人的城市被射死会影响旗帜更换
4.奖励,获得生命源,插旗子等事情要一起做。

表述不清的地方
两个表述不清的问题:①双方可否知道对方是否有剑?可以②如果双方都判断要用炸弹,怎么输出?红的先判断并使用,如果红的确定要用,蓝的就不输出了

都被射死了不算平局

对方被弓射死dragon士气也变

魔兽3-终极版之间的变化
1.武士降生:需要多输出dragon的士气。如果获得攻击力=0的sword则视为没有武器。函数需要修一修,跟1.2里面规则完全不一样了
2.lion逃走
3.放arrow:发生在放箭城市。死人也可以放箭(表征同时放箭把对方射死)
4.战斗前使用bomb:不算是战斗,双方均不拿走生命源,不影响旗帜。使用bomb后把(双方)死人的指针给置为NULL。

5.战斗:
1)如果只有一个指针:生命值是否>0,如果没血了就给他擦去为NULL
2)如果有两个指针:
先看是否双方都有血
①都没血了,都擦去为NULL。不影响旗子
②只有一方有血,直接进行胜利后的各种操作
③双方都有血:只有一个人主动进攻一次。“被攻击者生命值会减去进攻者的攻击力值和进攻者手中sword的攻击力值。被进攻者若没死,就会发起反击,被反击者的生命值要减去反击者攻击力值的一半(去尾取整)和反击者手中sword的攻击力值。反击可能致敌人于死地。”
Attack_enemy,attack_back和 ninja的Attack_back都得写(写成空)
吸取生命源和战斗胜利在同一时间发生,要写

6.奖励和收取生命源:从远离自己司令部的城市开始奖励杀死敌人的武士。奖励完了再依次从胜利城市拿走生命源
7.插旗子:连续两场战斗都是一方胜利插旗子(中间没有战斗算,平局不算连续)
8.dragon的yell:一场战斗结束之后①士气增加:敌人被杀死,士气+0.2;敌人没被杀死,士气-0.2。
②进行yell:在主动攻击的战斗中没有战死且当前士气>0.8,欢呼。
9.战后需要做的:yell,wolf_rob,loyal_decrease,life_get

1.ninja没有还手。
2.iceman的self_hurt:前进的第二步结束的时候生命值减少9,攻击力增加20.如果将至0以下则置为1.
3.lion的loyal降低:没经过一场没有杀死敌人的战斗,loyal就降低K。如果lion战死,就在40分时的生命值传给对手
4.wolf_rob函数大改:
5.get_weapon函数不需要了
5.占领:同时出现两个敌人
6.武士移动函数里面:移动后检测双方基地对方指针,如果有一个,则将其置为空,并给占领进度+1

City 类:
新增: string 当前旗帜:“red”,“blue”,“none”。
本次战斗情况:+1代表红方胜利;-1代表蓝方胜利,0代表平局
占领进度,init为0。+2代表红方占领,-2代表蓝方占领
生命源数量

Weapon类要大改

--------------2020.07.04更新源代码--------------------
提交地址:http://cxsjsxmooc2.openjudge.cn/warcraft/

提醒:仅供学习交流,抄袭后果自负

【魔兽1】

#include<cstdio>
#include<iostream>
#include<cstring>
using namespace std;string warrior_seq[2][5]={{"iceman","lion","wolf","ninja","dragon"},{"lion","dragon","ninja","iceman","wolf"}};//第一行→红方产生武士顺序;第二行→蓝方
int health_seq[5]={0,0,0,0,0};//全局变量,保存该case下各武士的生命值int return_seq(string type){//返回武士在health_seq中的编号if (type=="dragon")return 0;if (type=="ninja")return 1;if (type=="iceman")return 2;if (type=="lion")return 3;if (type=="wolf")return 4;
}string modify_time(int time){//修正输出的时间格式char ctime[10]={0},return_ctime[10]={0};sprintf(ctime,"%d",time);if (time==0)return "000";if (strlen(ctime)==1){return_ctime[0]='0';return_ctime[1]='0';strcat(return_ctime,ctime);}if (strlen(ctime)==2){return_ctime[0]='0';strcat(return_ctime,ctime);}if(strlen(ctime)==3)return ctime;return return_ctime;
}
/*
@此处整数变字符串不能用itoa,因为这不是标准的c函数,要使用sprintf!!!
@Runtime error 经常的原因是字符串操作的时候数组越界了
@字符串的各种函数都不支持string,都要用char*
@见如上方式给字符串全设为0!!!!!
*/class warrior{private:int tribe;string stribe;//0代表红方,1代表蓝方int number;//武士编号string type;//武士类型int health;//该武士的生命值
/*
@注意,在class的成员变量定义中不可以赋值!不然会出错,
@一切的赋值应该在成员函数中进行!!
*/
public:void init(int itribe,int inumber,int iplus){//初始化武士的各种信息tribe=itribe;number=inumber;stribe=(tribe==0)?"red":"blue";//0代表红方,1代表蓝方type=warrior_seq[tribe][(number+iplus-1)%5];//武士类型health=health_seq[return_seq(type)];//该武士的生命值}void print_born(int time,int*warrior_storge){//输出武士降生cout<<modify_time(time)<<" "<<stribe<<" "<<type<<" "<<number<<" born with strength "<<health_seq[return_seq(type)]<<","<<warrior_storge[return_seq(type)]<<" "<<type<<" in "<<stribe<<" headquarter"<<endl;;}
};bool born_stop(int min_strength,int* stop_done,int ti,int time,int* pstrength,int* number_rb,int*plus_rb,int* health_seq,int* warrior_storge){if (stop_done[ti]==1)//stop_done 看是否已经做过了return false;if(*pstrength<min_strength){//用stop看是否要进行结束动作string stribe_=(ti==0)?"red":"blue";//0代表红方,1代表蓝方cout<<modify_time(time)<<" "<<stribe_<<" headquarter stops making warriors"<<endl;stop_done[ti]=1;return false;}string type=warrior_seq[ti][(number_rb[ti]+plus_rb[ti]-1)%5];int seq=return_seq(type);if (*pstrength>=health_seq[seq]){//如果本次可以直接按顺序创造warrior_storge[seq]+=1;*pstrength-=health_seq[seq];warrior W;W.init(ti,number_rb[ti],plus_rb[ti]);W.print_born(time,warrior_storge);number_rb[ti]+=1;return true;}else{plus_rb[ti]+=1;born_stop(min_strength,stop_done,ti,time,pstrength,number_rb,plus_rb,health_seq,warrior_storge);}
}void onecase(){int strength,min_strength=10001;//生命源总量cin>>strength;for(int i=0;i<5;++i){cin>>health_seq[i];//读入了这个case生产每个武士需要耗费多少生命源if (health_seq[i]<min_strength)min_strength=health_seq[i];}int time=0,strength_rb[2]={strength,strength};//当前时间,红方生命源,蓝方生命源int number_rb[2]={1,1},plus_rb[2]={0,0};//number_rb记录红蓝双方目前的编号;plus用于生产不了的时候同时向后加一个int warrior_storge_rd[2][5]={{0,0,0,0,0},{0,0,0,0,0}};//库存多少武士int stop_done[2]={0,0};while (true){int ti=0;for(ti=0;ti<=1;++ti){//依次执行红蓝部落born_stop(min_strength,stop_done,ti,time,&strength_rb[ti],number_rb,plus_rb,health_seq,warrior_storge_rd[ti]);}++time;if (stop_done[0]&&stop_done[1])break;}
}int main(){int case_n;cin>>case_n;for(int i=0;i<case_n;++i){cout<<"Case:"<<i+1<<endl;onecase();}return 0;
}

【魔兽2】

#include<iostream>
#include<cstring>
#include<cstdio>
using namespace std;string warrior_seq[2][5]={{"iceman","lion","wolf","ninja","dragon"},{"lion","dragon","ninja","iceman","wolf"}};//第一行→红方产生武士顺序;第二行→蓝方
int health_seq[5]={0,0,0,0,0};//全局变量,保存该case下各武士的生命值int return_seq(string type){//返回武士在health_seq中的编号if (type=="dragon")return 0;if (type=="ninja")return 1;if (type=="iceman")return 2;if (type=="lion")return 3;if (type=="wolf")return 4;
}string return_weapon_type(int i){if(i==0)return "sword";if(i==1)return "bomb";if(i==2)return "arrow";
}string modify_time(int time){//修正输出的时间格式char ctime[10]={0},return_ctime[10]={0};sprintf(ctime,"%d",time);if (time==0)return "000";if (strlen(ctime)==1){return_ctime[0]='0';return_ctime[1]='0';strcat(return_ctime,ctime);}if (strlen(ctime)==2){return_ctime[0]='0';strcat(return_ctime,ctime);}if(strlen(ctime)==3)return ctime;return return_ctime;
}class warrior{protected:int tribe;string stribe;//0代表红方,1代表蓝方int number;//武士编号string type;//武士类型int health;//该武士的生命值
public:void init_basicinfo(int itribe,int inumber,int iplus){//初始化武士的基本信息tribe=itribe;number=inumber;stribe=(tribe==0)?"red":"blue";//0代表红方,1代表蓝方type=warrior_seq[tribe][(number+iplus-1)%5];//武士类型health=health_seq[return_seq(type)];//该武士的生命值}virtual void init_otherinfo(int strength,int strength_need){}//虚函数接口,表示能做什么//注意,strength是其降生后剩余的生命源数量↑void print_born(int time,int*warrior_storge){//输出武士降生cout<<modify_time(time)<<" "<<stribe<<" "<<type<<" "<<number<<" born with strength "<<health_seq[return_seq(type)]<<","<<warrior_storge[return_seq(type)]<<" "<<type<<" in "<<stribe<<" headquarter"<<endl;;}virtual void print_specialinfo(){}virtual ~warrior(){}// 析构函数里面不需要写delete,在对象自动销毁的时候会自动调用析构函数,然后delete
};class dragon:public warrior{private :int weapon;string sweapon_type;double morale;
public :virtual void init_otherinfo(int strength,int strength_need){weapon=number%3;morale=double(strength)/double(strength_need);sweapon_type=return_weapon_type(weapon);}virtual void print_specialinfo(){cout<<"It has a "<<sweapon_type<<",and it's morale is ";printf("%.2lf\n",morale);}
};class ninja:public warrior{private:int weapon_l,weapon_r;//左右手武器string sweapon_type_l,sweapon_type_r;
public:virtual void init_otherinfo(int strength,int strength_need){weapon_l=number%3;weapon_r=(number+1)%3;sweapon_type_l=return_weapon_type(weapon_l);sweapon_type_r=return_weapon_type(weapon_r);}virtual void print_specialinfo(){cout<<"It has a "<<sweapon_type_l<<" and a "<<sweapon_type_r<<endl;}
};class iceman:public warrior{private:int weapon;string sweapon_type;
public:virtual void init_otherinfo(int strength,int strength_need){weapon=number%3;sweapon_type=return_weapon_type(weapon);}virtual void print_specialinfo(){cout<<"It has a "<<sweapon_type<<endl;}};class lion:public warrior{private:int loyal;
public:virtual void init_otherinfo(int strength,int strength_need){loyal=strength;}virtual void print_specialinfo(){cout<<"It's loyalty is "<<loyal<<endl;}
};class wolf:public warrior{public:virtual void init_otherinfo(int strength,int strength_need){}virtual void print_specialinfo(){}
};warrior* type_point(int seq){//可以根据seq这个序数返回对映派生武士类的指针,赋值给一个基类的指针if(seq==0){dragon* pd=new dragon;return pd;}if(seq==1){ninja* pn=new ninja;return pn;}if(seq==2){iceman* pi=new iceman;return pi;}if(seq==3){lion* pl=new lion;return pl;}if(seq==4){}wolf* pw=new wolf;return pw;}
/*
注意此处要用指针new一块地址出来,否则每一次调用该函数给的地址可能会重复,发生0xC0000005错误!!!
*/bool born_or_stop(int min_strength,int* stop_done,int ti,int time,int* strength,int* number_rb,int*plus_rb,int* health_seq,int* warrior_storge){//执行出生或停止操作//如果为false则停止,为true则继续if (stop_done[ti]==1)//stop_done 看是否已经停止过了,防止重复打印停止语句return false;if(strength[ti]<min_strength){//用stop看是否要进行结束动作string stribe_=(ti==0)?"red":"blue";//0代表红方,1代表蓝方cout<<modify_time(time)<<" "<<stribe_<<" headquarter stops making warriors"<<endl;stop_done[ti]=1;return false;}string type=warrior_seq[ti][(number_rb[ti]+plus_rb[ti]-1)%5];//找出当前在创建的武士类型int seq=return_seq(type);///从这个地方可以插入返回指针的函数if (strength[ti]>=health_seq[seq]){//如果本次可以直接按顺序创造warrior_storge[seq]+=1;strength[ti]-=health_seq[seq];warrior* pW;pW=type_point(seq);pW->init_basicinfo(ti,number_rb[ti],plus_rb[ti]);pW->init_otherinfo(strength[ti],health_seq[seq]);pW->print_born(time,warrior_storge);pW->print_specialinfo();number_rb[ti]+=1;return true;}else{plus_rb[ti]+=1;born_or_stop(min_strength,stop_done,ti,time,strength,number_rb,plus_rb,health_seq,warrior_storge);}
}void onecase(){int strength,min_strength=10001;//生命源总量,min_strength作用是判断是否停止生产cin>>strength;for(int i=0;i<5;++i){cin>>health_seq[i];//读入了这个case生产每个武士需要耗费多少生命源if (health_seq[i]<min_strength)min_strength=health_seq[i];}int time=0,strength_rb[2]={strength,strength};//当前时间,红方生命源,蓝方生命源int number_rb[2]={1,1},plus_rb[2]={0,0};//number_rb记录红蓝双方目前的编号;plus用于生产不了的时候同时向后加一个int warrior_storge_rd[2][5]={{0,0,0,0,0},{0,0,0,0,0}};//库存多少武士int stop_done[2]={0,0};while (true){int ti=0;for(ti=0;ti<=1;++ti){//依次执行红蓝部落born_or_stop(min_strength,stop_done,ti,time,strength_rb,number_rb,plus_rb,health_seq,warrior_storge_rd[ti]);}++time;if (stop_done[0]&&stop_done[1])break;}
}int main(){int case_n;cin>>case_n;cout.precision(3);for(int i=0;i<case_n;++i){cout<<"Case:"<<i+1<<endl;onecase();}return 0;
}

【魔兽3】

#include<iostream>
#include<cstring>
#include<cstdio>
#include<cstdlib>
using namespace std;string warrior_seq[2][5]={{"iceman","lion","wolf","ninja","dragon"},{"lion","dragon","ninja","iceman","wolf"}};//第一行→红方产生武士顺序;第二行→蓝方
int health_seq[5]={0,0,0,0,0};//全局变量,保存该case下各武士的生命值
int attack_seq[5]={0,0,0,0,0};//全局变量,保存该case下各武士的攻击力
int loyal_decrease=0,city_num=0;int return_seq(string type){//返回武士在health_seq,attack_seq中的编号if (type=="dragon")return 0;if (type=="ninja")return 1;if (type=="iceman")return 2;if (type=="lion")return 3;if (type=="wolf")return 4;
}string return_weapon_type(int i){if(i==0)return "sword";if(i==1)return "bomb";if(i==2)return "arrow";
}string modify_time(int time){//已修正输出的时间格式,oj上只有atoi,没有itoa(用sprintf替代)int hour=time/60,minutes=time%60;char chour[7]="000:",cminutes[3]="00";if(hour>0&&hour<10)sprintf(chour+2,"%d",hour);else if(10<=hour&&hour<100)sprintf(chour+1,"%d",hour);else if(100<=hour)sprintf(chour,"%d",hour);chour[3]=':';//使用sprintf的时候末尾会自动粘贴一个\0过去,覆盖了原本的冒号if(minutes>0&&minutes<10)sprintf(cminutes+1,"%d",minutes);else if(10<=minutes)sprintf(cminutes,"%d",minutes);strcat(chour,cminutes);return chour;
}class weapon{public:int attack;int attack_self;int wnumber;int life;string type;virtual void init(int seq_self){}virtual ~weapon(){}
};class sword:public weapon{public:virtual void init(int seq_self){type="sword";wnumber=0;attack=2*attack_seq[seq_self]/10;life=100000;attack_self=0;}
};class bomb:public weapon{public:virtual void init(int seq_self){type="bomb";wnumber=1;attack=4*attack_seq[seq_self]/10;attack_self=attack/2;life=1;if (seq_self==1) //ninja使用炸弹不会受伤attack_self=0;}
};class arrow:public weapon{public:virtual void init(int seq_self){type="arrow";wnumber=2;attack=3*attack_seq[seq_self]/10;life=2;attack_self=0;}
};template<class T>//记录对方丢失一个武器;使用时此处要写weapon*
void erase_move(T* arr,int pi,int& s){//抹除位置pi的元素,数组的类型为T,抹除前有s个元素if(pi==s-1){arr[pi]=NULL;s--;}else{for(int i=pi;i<s-1;++i){arr[i]=arr[i+1];}arr[s-1]=NULL;s--;}
}weapon* weapon_point(int wnumber){//可以根据seq这个序数返回对映派生武士类的指针,赋值给一个基类的指针if(wnumber==0){sword* sp=new sword;return sp;}if(wnumber==1){bomb* bp=new bomb;return bp;}if(wnumber==2){arrow* ap=new arrow;return ap;}}int desend_compare(const void* s1,const void* s2){//按照序号升序,序号相同按照寿命降序(没用过的排在前面,wolf——rob用)weapon **s_1;weapon **s_2;s_1=(weapon**)(s1);s_2=(weapon**)(s2);if ((*s_1)->wnumber<(*s_2)->wnumber)return -1;else if((*s_1)->wnumber>(*s_2)->wnumber)return 1;else{if ((*s_1)->life>(*s_2)->life)return -1;else if((*s_1)->life<(*s_2)->life)return 1;elsereturn 0;}
}int asend_compare(const void* s1,const void* s2){//按照序号升序,序号相同按照寿命升序(用过的排在前面,战前排武器)weapon **s_1;weapon **s_2;s_1=(weapon**)(s1);s_2=(weapon**)(s2);if ((*s_1)->wnumber<(*s_2)->wnumber)return -1;else if((*s_1)->wnumber>(*s_2)->wnumber)return 1;else{if ((*s_1)->life>(*s_2)->life)return 1;else if((*s_1)->life<(*s_2)->life)return -1;elsereturn 0;}
}class warrior{//做一个武器库这样的weapon 数组
public:int tribe;string stribe;//0代表红方,1代表蓝方int number;//武士编号string type;//武士类型int attack;int health;//该武士的生命值weapon *p_pweapon_storge[10];//每个士兵最多十个武器,数组里存了每个武器的指针int weapon_numbers,now_city,weapon_num_type[3];//weapon_numbers武士现在共有多少武器;now_city武士现在在第几号城市;//weapon_num_type每一个type的武器各有多少(出生+;wolf夺+;战斗损失减;战胜拿对面+)void init_basicinfo(int itribe,int inumber,int iplus){//初始化武士的基本信息tribe=itribe;number=inumber;stribe=(tribe==0)?"red":"blue";//0代表红方,1代表蓝方type=warrior_seq[tribe][(number+iplus-1)%5];//武士类型health=health_seq[return_seq(type)];//该武士的生命值attack=attack_seq[return_seq(type)];weapon_numbers=0;//初始武器数=0memset(p_pweapon_storge,NULL,sizeof(weapon*)*10);//new出一块存放武器指针的内存空间memset(weapon_num_type,0,sizeof(int)*3);if(tribe==0)now_city=0;elsenow_city=city_num+1;}virtual void init_otherinfo(int strength,int strength_need){}//虚函数接口,表示能做什么//注意,strength是其降生后剩余的生命源数量↑void print_born(int time){//输出武士降生cout<<modify_time(time)<<" "<<stribe<<" "<<type<<" "<<number<<" born"<<endl;}virtual void print_specialinfo(){}virtual void yell(int time){}virtual void self_hurt(){}virtual bool run_away_test(int time){return false;}virtual void loyal_decrease_(){}void weapon_get(warrior* penemy){//获胜后拿对方的武器if(penemy->weapon_numbers>0){qsort(penemy->p_pweapon_storge,penemy->weapon_numbers,sizeof(weapon*),desend_compare);while(weapon_numbers<10){if(penemy->p_pweapon_storge[0]==NULL)break;weapon* ptemp=penemy->p_pweapon_storge[0];int life_remain=ptemp->life;erase_move<weapon*>(penemy->p_pweapon_storge,0,penemy->weapon_numbers);//这个函数使得对方的weapon_numbers自动减少ptemp->init(return_seq(type));//改写武器攻击力等ptemp->life=life_remain;p_pweapon_storge[weapon_numbers]=ptemp;weapon_numbers++;weapon_num_type[ptemp->wnumber]+=1;penemy->weapon_num_type[ptemp->wnumber]-=1;}}}virtual void wolf_rob(warrior* penemy,int time){}void arrive_city(int time){//前进一步之后要先给iceman减血再arrive——city!!!!!!cout<<modify_time(time)<<" "<<stribe<<" "<<type<<" "<<number<<" marched to city "<<now_city<<" with "<<health<<" elements and force "<<attack<<endl;}void arrive_enemybase(int time){string enemy_stribe=(tribe==0)?"blue":"red";cout<<modify_time(time)<<" "<<stribe<<" "<<type<<" "<<number<<" reached "<<enemy_stribe<<" headquarter"<<" with "<<health<<" elements and force "<<attack<<endl;}bool death_test(){//true为战死if(health<=0)return true;elsereturn false;}bool no_attack(){//true为该武士目前无法造成伤害了if(attack<=2)//攻击力<=2有什么都不行return true;if(attack<=3&&weapon_num_type[1]==0)//攻击力<=3,没有1号bomb不行return true;if(attack<=4&&weapon_num_type[1]==0&&weapon_num_type[2]==0)//攻击力<=4,既没有bomb也没有arrow不行return true;if(weapon_num_type[0]==0&&weapon_num_type[1]==0&&weapon_num_type[2]==0)return true;elsereturn false;}void attack_enemy(warrior* penemy,int weapon_nowuse){//伤敌,自伤,武器磨损(但是还未清除)(penemy->health)-=(p_pweapon_storge[weapon_nowuse]->attack);health-=(p_pweapon_storge[weapon_nowuse]->attack_self);(p_pweapon_storge[weapon_nowuse]->life)-=1;}virtual ~warrior(){}// 析构函数里面不需要写delete,在对象自动销毁的时候会自动调用析构函数,然后delete
};class dragon:public warrior{//已经改好吼叫
private :weapon* pW;//初始武器string sweapon_type;double morale;
public :virtual void init_otherinfo(int strength,int strength_need){pW=weapon_point(number%3);pW->init(0);morale=double(strength)/double(strength_need);sweapon_type=return_weapon_type(pW->wnumber);p_pweapon_storge[0]=pW;weapon_numbers=1;weapon_num_type[number%3]=1;}/*virtual void print_specialinfo(){cout<<"It has a "<<sweapon_type<<",and it's morale is ";printf("%.2lf\n",morale);}*/virtual void yell(int time){cout<<modify_time(time)<<" "<<stribe<<" dragon "<<number<<" yelled in city "<<now_city<<endl;}
};class ninja:public warrior{//已经改好bomb无伤
private:weapon* pW_1,*pW_2;//初始化两件武器string sweapon_type_1,sweapon_type_2;
public:virtual void init_otherinfo(int strength,int strength_need){pW_1=weapon_point(number%3);pW_2=weapon_point((number+1)%3);pW_1->init(1);pW_2->init(1);//将两把初始武器按照ninja信息初始化sweapon_type_1=return_weapon_type(pW_1->wnumber);sweapon_type_2=return_weapon_type(pW_2->wnumber);p_pweapon_storge[0]=pW_1;p_pweapon_storge[1]=pW_2;weapon_numbers=2;weapon_num_type[number%3]=1;weapon_num_type[(number+1)%3]=1;}/*virtual void print_specialinfo(){cout<<"It has a "<<sweapon_type_1<<" and a "<<sweapon_type_2<<endl;}*/
};class iceman:public warrior{//已经改好自伤
private:weapon* pW;string sweapon_type;
public:virtual void init_otherinfo(int strength,int strength_need){pW=weapon_point(number%3);pW->init(2);sweapon_type=return_weapon_type(pW->wnumber);p_pweapon_storge[0]=pW;weapon_numbers=1;weapon_num_type[number%3]=1;}/*virtual void print_specialinfo(){cout<<"It has a "<<sweapon_type<<endl;}*/virtual void self_hurt(){health-=int(health/10);}
};class lion:public warrior{//已经增加逃跑设定和忠诚度降低设定
private:weapon* pW;string sweapon_type;int loyal;
public:virtual void init_otherinfo(int strength,int strength_need){pW=weapon_point(number%3);pW->init(3);sweapon_type=return_weapon_type(pW->wnumber);loyal=strength;p_pweapon_storge[0]=pW;weapon_numbers=1;weapon_num_type[number%3]=1;}virtual void print_specialinfo(){cout<<"Its loyalty is "<<loyal<<endl;}virtual void loyal_decrease_(){loyal-=loyal_decrease;}virtual bool run_away_test(int time){//1代表太跑了,0代表没逃跑if(loyal<=0){cout<<modify_time(time)<<" "<<stribe<<" lion "<<number<<" ran away"<<endl;return true;}elsereturn false;}};class wolf:public warrior{//已经增加抢武器设定
public:virtual void wolf_rob(warrior* penemy,int time){if(penemy->weapon_numbers>0&&penemy->type!="wolf"){//对方有武器且对方不是狼qsort(penemy->p_pweapon_storge,penemy->weapon_numbers,sizeof(weapon*),desend_compare);int enemy_min_weapon=penemy->p_pweapon_storge[0]->wnumber,rob_num=0;while(weapon_numbers<10){if(penemy->p_pweapon_storge[0]==NULL)//对方没有武器了就不抢了break;if(penemy->p_pweapon_storge[0]->wnumber!=enemy_min_weapon)//同一个编号抢完了就不抢了break;weapon* ptemp=penemy->p_pweapon_storge[0];int life_remain=ptemp->life;erase_move<weapon*>(penemy->p_pweapon_storge,0,penemy->weapon_numbers);//这个函数会自动把对方的武器总数减少,不需要自己加ptemp->init(4);//改写武器攻击力等ptemp->life=life_remain;p_pweapon_storge[weapon_numbers]=ptemp;weapon_numbers++;rob_num++;}weapon_num_type[enemy_min_weapon]+=rob_num;penemy->weapon_num_type[enemy_min_weapon]-=rob_num;cout<<modify_time(time)<<" "<<stribe<<" wolf "<<number<<" took "<<rob_num<<" "<<return_weapon_type(enemy_min_weapon)<<" from "<<penemy->stribe<<" "<<penemy->type<<" "<<penemy->number<<" in city "<<now_city<<endl;}}
};warrior* type_point(int seq){//可以根据seq这个序数返回对映派生武士类的指针,赋值给一个基类的指针if(seq==0){dragon* pd=new dragon;return pd;}if(seq==1){ninja* pn=new ninja;return pn;}if(seq==2){iceman* pi=new iceman;return pi;}if(seq==3){lion* pl=new lion;return pl;}if(seq==4){wolf* pw=new wolf;return pw;}
/*
注意此处要用指针new一块地址出来,否则每一次调用该函数给的地址可能会重复,发生0xC0000005错误!!!
*/
}class city{///fight 函数写在这里面,还没写
private:int NO;
public:warrior *pwarrior_red,*pwarrior_blue;city(){pwarrior_red=NULL;pwarrior_blue=NULL;}void init(int i){NO=i;}void fight(int time){//使用时应先保证两个指针均不为空warrior *w_1=NULL,*w_2=NULL;//记录先手、后手。!!!!!!败方要从cities中删去!!!!!!!//双方整理武器qsort(pwarrior_red->p_pweapon_storge,pwarrior_red->weapon_numbers,sizeof(weapon*),asend_compare);qsort(pwarrior_blue->p_pweapon_storge,pwarrior_blue->weapon_numbers,sizeof(weapon*),asend_compare);//双方决定先后手if(NO%2==1){//奇数城市红方先动手w_1=pwarrior_red;w_2=pwarrior_blue;}else if(NO%2==0){//偶数城市蓝方先动手w_1=pwarrior_blue;w_2=pwarrior_red;}int weapon1_use=0,weapon2_use=0;//记录双方当前所用武器//开始战斗while(true){if(w_1->no_attack()==true&&w_2->no_attack()==true&&w_1->weapon_num_type[1]==0&&w_1->weapon_num_type[2]==0&&w_2->weapon_num_type[1]==0&&w_2->weapon_num_type[2]==0){//以均活下来的平局结束//注意,武器没有变化的要求是把生命值有限的武器都用完了cout<<modify_time(time)<<" both red "<<pwarrior_red->type<<" "<<pwarrior_red->number<<" and blue "<<pwarrior_blue->type<<" "<<pwarrior_blue->number<<" were alive in city "<<NO<<endl;pwarrior_red->yell(time);pwarrior_blue->yell(time);break;}
/*            //确定先后手本轮使用的武器if(w_1->weapon_numbers>0){//确定w_1本轮武器if(weapon1_use<w_1->weapon_numbers-1)weapon1_use++;elseweapon1_use=0;}if(w_2->weapon_numbers>0){//确定w_2本轮武器if(weapon2_use<w_2->weapon_numbers-1)weapon2_use++;elseweapon2_use=0;}*///先手攻击后手,并删除没有耐久的武器if(w_1->weapon_numbers>0){w_1->attack_enemy(w_2,weapon1_use);//攻击并减少了武器的生命值if(w_1->p_pweapon_storge[weapon1_use]->life<=0){//如果现在用的这把没有生命值了int weapon_damage_typenumber=w_1->p_pweapon_storge[weapon1_use]->wnumber;//现在用坏的这把武器的类型是什么w_1->weapon_num_type[weapon_damage_typenumber]--;//该武器类型数目减少erase_move<weapon*>(w_1->p_pweapon_storge,weapon1_use,w_1->weapon_numbers);//擦除此损坏武器,并将总数-1weapon1_use--;//调整现在用的武器的状态}}//判断死亡情况,死掉的要擦除,赢得龙吼叫if (w_1->death_test()==true && w_2->death_test()==true){//两者都死了cout<<modify_time(time)<<" both red "<<pwarrior_red->type<<" "<<pwarrior_red->number<<" and blue "<<pwarrior_blue->type<<" "<<pwarrior_blue->number<<" died in city "<<NO<<endl;pwarrior_blue=NULL;pwarrior_red=NULL;break;}else if(w_1->death_test()==false && w_2->death_test()==true){//先手的没死,后手的死了cout<<modify_time(time)<<" "<<w_1->stribe<<" "<<w_1->type<<" "<<w_1->number<<" killed "<<w_2->stribe<<" "<<w_2->type<<" "<<w_2->number<<" in city "<<NO<<" remaining "<<w_1->health<<" elements"<<endl;w_1->weapon_get(w_2);if(w_2==pwarrior_blue)pwarrior_blue=NULL;else if(w_2==pwarrior_red)pwarrior_red=NULL;w_1->yell(time);break;}else if(w_1->death_test()==true && w_2->death_test()==false){//先手的死了,后手的没死cout<<modify_time(time)<<" "<<w_2->stribe<<" "<<w_2->type<<" "<<w_2->number<<" killed "<<w_1->stribe<<" "<<w_1->type<<" "<<w_1->number<<" in city "<<NO<<" remaining "<<w_2->health<<" elements"<<endl;w_2->weapon_get(w_1);if(w_1==pwarrior_blue)pwarrior_blue=NULL;else if(w_1==pwarrior_red)pwarrior_red=NULL;w_2->yell(time);break;}//后手攻击先手,并删除没有耐久的武器if(w_2->weapon_numbers>0){w_2->attack_enemy(w_1,weapon2_use);//攻击并减少了武器的生命值if(w_2->p_pweapon_storge[weapon2_use]->life<=0){//如果现在用的这把没有生命值了int weapon_damage_typenumber=w_2->p_pweapon_storge[weapon2_use]->wnumber;//现在用坏的这把武器的类型是什么w_2->weapon_num_type[weapon_damage_typenumber]--;//该武器类型数目减少erase_move<weapon*>(w_2->p_pweapon_storge,weapon2_use,w_2->weapon_numbers);//擦除此损坏武器,并将总数-1weapon2_use--;//调整现在用的武器的状态}}//再次判断死亡情况if (w_1->death_test()==true && w_2->death_test()==true){//两者都死了cout<<modify_time(time)<<" both red "<<pwarrior_red->type<<" "<<pwarrior_red->number<<" and blue "<<pwarrior_blue->type<<" "<<pwarrior_blue->number<<" died in city "<<NO<<endl;pwarrior_blue=NULL;pwarrior_red=NULL;break;}else if(w_1->death_test()==false && w_2->death_test()==true){//先手的没死,后手的死了cout<<modify_time(time)<<" "<<w_1->stribe<<" "<<w_1->type<<" "<<w_1->number<<" killed "<<w_2->stribe<<" "<<w_2->type<<" "<<w_2->number<<" in city "<<NO<<" remaining "<<w_1->health<<" elements"<<endl;w_1->weapon_get(w_2);if(w_2==pwarrior_blue)pwarrior_blue=NULL;else if(w_2==pwarrior_red)pwarrior_red=NULL;w_1->yell(time);break;}else if(w_1->death_test()==true && w_2->death_test()==false){//先手的死了,后手的没死cout<<modify_time(time)<<" "<<w_2->stribe<<" "<<w_2->type<<" "<<w_2->number<<" killed "<<w_1->stribe<<" "<<w_1->type<<" "<<w_1->number<<" in city "<<NO<<" remaining "<<w_2->health<<" elements"<<endl;w_2->weapon_get(w_1);if(w_1==pwarrior_blue)pwarrior_blue=NULL;else if(w_1==pwarrior_red)pwarrior_red=NULL;w_2->yell(time);break;}//开始新的一轮//确定先后手下一轮轮使用的武器if(w_1->weapon_numbers>0){//确定w_1本轮武器if(weapon1_use<w_1->weapon_numbers-1)weapon1_use++;elseweapon1_use=0;}if(w_2->weapon_numbers>0){//确定w_2本轮武器if(weapon2_use<w_2->weapon_numbers-1)weapon2_use++;elseweapon2_use=0;}}}
};bool born_or_stop(city* cities,const int& min_strength,int* stop_done,const int& ti,const int& time,int* strength,int* number_rb,int*plus_rb,int* health_seq,int& warrior_storge,warrior** pwarrior){//执行出生或停止操作//如果为false则停止,为true则继续if (stop_done[ti]==1)//stop_done 看是否已经停止过了,防止重复打印停止语句return false;if(strength[ti]<min_strength){//用stop看是否要进行结束动作//string stribe_=(ti==0)?"red":"blue";//0代表红方,1代表蓝方//cout<<modify_time(time)<<" "<<stribe_<<" headquarter stops making warriors"<<endl;stop_done[ti]=1;return false;}string type=warrior_seq[ti][(number_rb[ti]+plus_rb[ti]-1)%5];//找出当前想要创建的武士类型int seq=return_seq(type);if (strength[ti]>=health_seq[seq]){//如果本次可以直接按顺序创造warrior_storge+=1;strength[ti]-=health_seq[seq];warrior* pW;pW=type_point(seq);pW->init_basicinfo(ti,number_rb[ti],plus_rb[ti]);pW->init_otherinfo(strength[ti],health_seq[seq]);pW->print_born(time);pW->print_specialinfo();pwarrior[warrior_storge-1]=pW;///这行可以考虑删了number_rb[ti]+=1;if(ti==0)//如果红方出生,记在红司令部cities[0].pwarrior_red=pW;if(ti==1)//如果蓝方出生,记在蓝司令部cities[city_num+1].pwarrior_blue=pW;return true;}else{//在魔兽1/2中需要进行递归,此处由于规则有变化,进行了修改stop_done[ti]=1;return false;}
}bool onehour(city* cities,int& hours,bool& red_win,bool& blue_win,int& strength,int& min_strength,int& T,int* strength_rb,int* number_rb,int* plus_rb,int* warrior_storge_rb,warrior** pwarrior_r,warrior** pwarrior_b,int* stop_done){//只要能进这个循环,就说明还没有人获胜//1) 武士降生,完成int time=60*hours+0;born_or_stop(cities,min_strength,stop_done,0,time,strength_rb,number_rb,plus_rb,health_seq,warrior_storge_rb[0],pwarrior_r);//红方降生born_or_stop(cities,min_strength,stop_done,1,time,strength_rb,number_rb,plus_rb,health_seq,warrior_storge_rb[1],pwarrior_b);//蓝方降生//2) lion逃跑,完成time=60*hours+5;if(time>T)return false;for(int i=0;i<=city_num+1;++i){if(cities[i].pwarrior_red!=NULL){bool test;test=cities[i].pwarrior_red->run_away_test(time);if(test==true){warrior_storge_rb[0]-=1;cities[i].pwarrior_red=NULL;}}if(cities[i].pwarrior_blue!=NULL){bool test;test=cities[i].pwarrior_blue->run_away_test(time);if(test==true){warrior_storge_rb[1]-=1;cities[i].pwarrior_blue=NULL;}}}//3) 武士前进到某一城市 && 7) 武士抵达敌军司令部 && 8) 司令部被占领time=60*hours+10;if(time>T)return false;for(int i=0;i<=city_num;++i){//双方移动并进行自伤、忠诚降低if (cities[i+1].pwarrior_blue!=NULL){cities[i].pwarrior_blue=cities[i+1].pwarrior_blue;//蓝方前进cities[i].pwarrior_blue->now_city=i;cities[i].pwarrior_blue->self_hurt();//iceman自伤cities[i].pwarrior_blue->loyal_decrease_();//lion忠诚减少}elsecities[i].pwarrior_blue=NULL;int j=city_num+1-i;//以下红方前进if (cities[j-1].pwarrior_red!=NULL){cities[j].pwarrior_red=cities[j-1].pwarrior_red;cities[j].pwarrior_red->now_city=j;cities[j].pwarrior_red->self_hurt();cities[j].pwarrior_red->loyal_decrease_();}elsecities[j].pwarrior_red=NULL;}cities[0].pwarrior_red=NULL;cities[city_num+1].pwarrior_blue=NULL;//移动全部完成if(cities[0].pwarrior_blue!=NULL){///红方基地被蓝方占领blue_win=true;cities[0].pwarrior_blue->arrive_enemybase(time);cout<<modify_time(time)<<" red headquarter was taken"<<endl;}for(int ii=1;ii<=city_num;++ii){if(cities[ii].pwarrior_red!=NULL)cities[ii].pwarrior_red->arrive_city(time);if(cities[ii].pwarrior_blue!=NULL)cities[ii].pwarrior_blue->arrive_city(time);}if(cities[city_num+1].pwarrior_red!=NULL){///蓝方基地被红方占领red_win=true;cities[city_num+1].pwarrior_red->arrive_enemybase(time);cout<<modify_time(time)<<" blue headquarter was taken"<<endl;}if(red_win==true||blue_win==true)//如果有人占领了对方司令部就全部结束return true;//4) wolf抢敌人的武器time=60*hours+35;if(time>T)return false;for(int i=1;i<=city_num;++i){if(cities[i].pwarrior_red!=NULL&&cities[i].pwarrior_blue!=NULL){cities[i].pwarrior_red->wolf_rob(cities[i].pwarrior_blue,time);cities[i].pwarrior_blue->wolf_rob(cities[i].pwarrior_red,time);}}//4.5) 战斗+捡武器 && 5) 报告战斗情况 && 6) 武士欢呼time=60*hours+40;if(time>T)return false;for(int i=1;i<=city_num;++i){if(cities[i].pwarrior_red!=NULL&&cities[i].pwarrior_blue!=NULL)cities[i].fight(time);}//9)司令部报告生命元数量time=60*hours+50;if(time>T)return false;cout<<modify_time(time)<<" "<<strength_rb[0]<<" elements in red headquarter"<<endl;cout<<modify_time(time)<<" "<<strength_rb[1]<<" elements in blue headquarter"<<endl;//10)武士报告情况time=60*hours+55;if(time>T)return false;for(int i=0;i<=city_num+1;++i){if(cities[i].pwarrior_red!=NULL){warrior* pw;pw=cities[i].pwarrior_red;cout<<modify_time(time)<<" red "<<pw->type<<" "<<pw->number<<" has "<<pw->weapon_num_type[0]<<" sword "<<pw->weapon_num_type[1]<<" bomb "<<pw->weapon_num_type[2]<<" arrow and "<<pw->health<<" elements"<<endl;}if(cities[i].pwarrior_blue!=NULL){warrior* pw;pw=cities[i].pwarrior_blue;cout<<modify_time(time)<<" blue "<<pw->type<<" "<<pw->number<<" has "<<pw->weapon_num_type[0]<<" sword "<<pw->weapon_num_type[1]<<" bomb "<<pw->weapon_num_type[2]<<" arrow and "<<pw->health<<" elements"<<endl;}
}
}int main(){//真正的main函数//freopen("datapub.in","r",stdin);//freopen("myout.out","w",stdout);int case_n;cin>>case_n;for(int i_i=0;i_i<case_n;++i_i){cout<<"Case "<<i_i+1<<":"<<endl;int hours=0;bool red_win=false,blue_win=false;int strength,min_strength=10001,T;//生命源总量,min_strength作用是判断是否停止生产cin>>strength>>city_num>>loyal_decrease>>T;for(int j=0;j<5;++j){//读入了这个case生产每个武士需要耗费多少生命源cin>>health_seq[j];if (health_seq[j]<min_strength)min_strength=health_seq[j];}for(int j=0;j<5;++j){//读入了这个case每个武士的攻击力cin>>attack_seq[j];}int strength_rb[2]={strength,strength};//当前时间,红方生命源,蓝方生命源int number_rb[2]={1,1},plus_rb[2]={0,0};//number_rb记录红蓝双方目前的编号;plus用于生产不了的时候同时向后加一个int warrior_storge_rb[2]={0,0};//库存多少武士warrior *pwarrior_r[int(T/60)+5],*pwarrior_b[int(T/60)+5];///按照顺序产生的各个士兵们,考虑后续把这个删掉也可以memset(pwarrior_r,NULL,(int(T/60)+5)*sizeof(warrior*));memset(pwarrior_b,NULL,(int(T/60)+5)*sizeof(warrior*));int stop_done[2]={0,0};city cities[city_num+2];for(int j=0;j<=city_num+1;++j)cities[j].init(j);for(hours=0;hours<=int(T/60);++hours){onehour(cities,hours,red_win,blue_win,strength,min_strength,T,strength_rb,number_rb,plus_rb,warrior_storge_rb,pwarrior_r,pwarrior_b,stop_done);if(red_win==true||blue_win==true)break;}}return 0;
}

【魔兽终极版】

#include<iostream>
#include<cstring>
#include<cstdio>
#include<cstdlib>
using namespace std;char stemp[100];string warrior_seq[2][5]={{"iceman","lion","wolf","ninja","dragon"},{"lion","dragon","ninja","iceman","wolf"}};//第一行→红方产生武士顺序;第二行→蓝方
int health_seq[5]={0,0,0,0,0};//全局变量,保存该case下各武士的生命值
int attack_seq[5]={0,0,0,0,0};//全局变量,保存该case下各武士的攻击力
int loyal_decrease=0,city_num=0,arrow_attack=0;//全局变量,保存该case下lion每次降低多少loyal,一共多少城市,弓箭的攻击力int return_seq(string type){//返回武士在health_seq,attack_seq中的编号if (type=="dragon")return 0;if (type=="ninja")return 1;if (type=="iceman")return 2;if (type=="lion")return 3;if (type=="wolf")return 4;
}string return_weapon_type(int i){if(i==0)return "sword";if(i==1)return "bomb";if(i==2)return "arrow";
}string modify_time(int time){//修正输出的时间格式    ***oj上只有atoi,没有itoa(用sprintf替代)int hour=time/60,minutes=time%60;char chour[7]="000:",cminutes[3]="00";if(hour>0&&hour<10)sprintf(chour+2,"%d",hour);else if(10<=hour&&hour<100)sprintf(chour+1,"%d",hour);else if(100<=hour)sprintf(chour,"%d",hour);chour[3]=':';//使用sprintf的时候末尾会自动粘贴一个\0过去,覆盖了原本的冒号if(minutes>0&&minutes<10)sprintf(cminutes+1,"%d",minutes);else if(10<=minutes)sprintf(cminutes,"%d",minutes);strcat(chour,cminutes);return chour;
}class weapon{public:int wnumber;string type;int attack,life;weapon(){life=3;}virtual void init(int user_attack=0){}virtual void weapon_damage(){}//将剑的攻击乘数修改,弓的生命降低virtual ~weapon(){}
};class sword:public weapon{public:virtual void init(int user_attack=0){type="sword";wnumber=0;attack=int(0.2*user_attack);life=100000;}virtual void weapon_damage(){attack=int(0.8*attack);}
};class bomb:public weapon{public:virtual void init(int user_attack=0){type="bomb";wnumber=1;attack=0;life=100000;}
};class arrow:public weapon{public:virtual void init(int user_attack=0){type="arrow";wnumber=2;attack=arrow_attack;life=3;}virtual void weapon_damage(){life--;}
};weapon* weapon_point(int wnumber){//可以根据seq这个序数返回对映派生武士类的指针,赋值给一个基类的指针if(wnumber==0){sword* sp=new sword;return sp;}if(wnumber==1){bomb* bp=new bomb;return bp;}if(wnumber==2){arrow* ap=new arrow;return ap;}}class warrior{public:int tribe;string stribe;//0代表红方,1代表蓝方int number;//武士编号string type;//武士类型int attack;int health;//该武士的生命值int now_city,weapon_num_type[3],war_acquire;//now_city武士现在在第几号城市;每种武器是否有;war_acquire记录每次作战能获得什么weapon* weapon_store[3];//三种武器的库void init_basicinfo(int itribe,int inumber){//初始化武士的基本信息tribe=itribe;number=inumber;stribe=(tribe==0)?"red":"blue";//0代表红方,1代表蓝方type=warrior_seq[tribe][(number-1)%5];//武士类型health=health_seq[return_seq(type)];//该武士的生命值attack=attack_seq[return_seq(type)];memset(weapon_num_type,0,sizeof(int)*3);memset(weapon_store,NULL,sizeof(weapon*)*3);war_acquire=(tribe==0)?1:(-1);//红色胜利一次记+1,蓝色胜利一次记-1if(tribe==0)now_city=0;elsenow_city=city_num+1;}virtual void init_otherinfo(int strength,int strength_need){}//注意,strength是其降生后剩余的生命源数量↑void print_born(int time){//输出武士降生cout<<modify_time(time)<<" "<<stribe<<" "<<type<<" "<<number<<" born"<<endl;}virtual void print_specialinfo(){}virtual void yell(int time,string& rep){}virtual void self_hurt(){}virtual bool run_away_test(int time){return false;}virtual void loyal_decrease_(){}virtual void morale_change(bool win){}virtual void wolf_rob(warrior* penemy){}void arrive_city(int time){//前进一步之后要先给iceman减血再arrive——city!!!!!!cout<<modify_time(time)<<" "<<stribe<<" "<<type<<" "<<number<<" marched to city "<<now_city<<" with "<<health<<" elements and force "<<attack<<endl;}void arrive_enemybase(int time){string enemy_stribe=(tribe==0)?"blue":"red";cout<<modify_time(time)<<" "<<stribe<<" "<<type<<" "<<number<<" reached "<<enemy_stribe<<" headquarter"<<" with "<<health<<" elements and force "<<attack<<endl;}bool death_test(){//true为战死if(health<=0)return true;elsereturn false;}void attack_enemy(int time,warrior* penemy,int NO,string& rep){//伤敌int all_attack=attack;if(weapon_num_type[0]>0){all_attack+=weapon_store[0]->attack;weapon_store[0]->weapon_damage();//剑的损伤,如果坏的太严重就扔了if((weapon_store[0]->attack)<=0){weapon_num_type[0]=0;delete weapon_store[0];weapon_store[0]=NULL;}}penemy->health-=all_attack;rep+=modify_time(time);rep+=" ";rep+=stribe;rep+=" ";rep+=type;rep+=" ";sprintf(stemp,"%d",number);rep+=stemp;memset(stemp,'\0',100);rep+=" attacked ";rep+=penemy->stribe;rep+=" ";rep+=penemy->type;rep+=" ";sprintf(stemp,"%d",penemy->number);rep+=stemp;memset(stemp,'\0',100);rep+=" in city ";sprintf(stemp,"%d",NO);rep+=stemp;memset(stemp,'\0',100);rep+=" with ";sprintf(stemp,"%d",health);rep+=stemp;memset(stemp,'\0',100);rep+=" elements and force ";sprintf(stemp,"%d",attack);rep+=stemp;memset(stemp,'\0',100);rep+="\n";}virtual void attack_back(int time,warrior* penemy,int NO,string& rep){//反击,对于ninja要改为空int all_attack=int(attack/2);if(weapon_num_type[0]>0){all_attack+=weapon_store[0]->attack;weapon_store[0]->weapon_damage();//剑的损伤,如果坏的太严重就扔了if((weapon_store[0]->attack)<=0){weapon_num_type[0]=0;delete weapon_store[0];weapon_store[0]=NULL;}}penemy->health-=all_attack;rep+=modify_time(time);rep+=" ";rep+=stribe;rep+=" ";rep+=type;rep+=" ";sprintf(stemp,"%d",number);rep+=stemp;memset(stemp,'\0',100);rep+=" fought back against ";rep+=penemy->stribe;rep+=" ";rep+=penemy->type;rep+=" ";sprintf(stemp,"%d",penemy->number);rep+=stemp;memset(stemp,'\0',100);rep+=" in city ";sprintf(stemp,"%d",NO);rep+=stemp;memset(stemp,'\0',100);rep+="\n";}void shot(warrior* penemy,int time){if(weapon_num_type[2]>0 && penemy!=NULL){penemy->health-=arrow_attack;weapon_store[2]->weapon_damage();if(penemy->health<=0)//如果打死了cout<<modify_time(time)<<" "<<stribe<<" "<<type<<" "<<number<<" shot and killed "<<penemy->stribe<<" "<<penemy->type<<" "<<penemy->number<<endl;else//如果没打死cout<<modify_time(time)<<" "<<stribe<<" "<<type<<" "<<number<<" shot"<<endl;if(weapon_store[2]->life<=0){//如果弓打坏了就deletedelete weapon_store[2];weapon_store[2]=NULL;weapon_num_type[2]=0;}}}bool usebomb(warrior* penemy,bool first_attack){//first_attack 为是否先手攻击的判断if(weapon_num_type[1]>0){//如果有炸弹int self_actual_attack=0,enemy_actual_attack=0;if(first_attack==true){//如果先手攻击self_actual_attack+=attack;enemy_actual_attack+=int((penemy->attack)/2);}else if(first_attack==false){//如果后手攻击self_actual_attack+=int(attack/2);enemy_actual_attack+=penemy->attack;}if(weapon_num_type[0]>0)self_actual_attack+=weapon_store[0]->attack;if(penemy->weapon_num_type[0]>0)enemy_actual_attack+=penemy->weapon_store[0]->attack;if(penemy->type=="ninja" && first_attack==1)//ninja不反击enemy_actual_attack=0;if((first_attack==true && penemy->health>self_actual_attack && health<=enemy_actual_attack)||(first_attack==false && health<=enemy_actual_attack))//先手攻击且打不死对方且对方会反击死自己||后手攻击且对方会杀死自己return true;}return false;}virtual ~warrior(){}// 析构函数里面不需要写delete,在对象自动销毁的时候会自动调用析构函数,然后delete
};class dragon:public warrior{//已经改好吼叫
private :double morale;
public :virtual void init_otherinfo(int strength,int strength_need){morale=double(strength)/double(strength_need);if(number%3==0 && int(0.2*attack)==0)//如果是废剑,就不做了return;weapon_store[number%3]=weapon_point(number%3);weapon_store[number%3]->init(attack);weapon_num_type[number%3]=1;}virtual void print_specialinfo(){printf("Its morale is %.2lf\n",morale);}virtual void morale_change(bool win){if(win==true)morale+=0.2;elsemorale-=0.2;}virtual void yell(int time,string& rep){if(morale>0.8){rep+=modify_time(time);rep+=" ";rep+=stribe;rep+=" dragon ";sprintf(stemp,"%d",number);rep+=stemp;memset(stemp,'\0',100);rep+=" yelled in city ";sprintf(stemp,"%d",now_city);rep+=stemp;memset(stemp,'\0',100);rep+="\n";}}
};class ninja:public warrior{private:bool do1=true,do2=true;//测试两件武器是否是废剑,false代表为废
public:virtual void init_otherinfo(int strength,int strength_need){if(number%3==0 && int(0.2*attack)==0)do1=false;if((number+1)%3==0 && int(0.2*attack)==0)do2=false;if(do1==true){weapon_store[number%3]=weapon_point(number%3);weapon_store[number%3]->init(attack);weapon_num_type[number%3]=1;}if(do2==true){weapon_store[(number+1)%3]=weapon_point((number+1)%3);weapon_store[(number+1)%3]->init(attack);weapon_num_type[(number+1)%3]=1;}}virtual void attack_back(int time,warrior* penemy,int NO,string& rep){}
};class iceman:public warrior{//已经改好自伤
public:virtual void init_otherinfo(int strength,int strength_need){if(number%3==0 && int(0.2*attack)==0)//如果是废剑,就不做了return;weapon_store[number%3]=weapon_point(number%3);weapon_store[number%3]->init(attack);weapon_num_type[number%3]=1;}virtual void self_hurt(){health-=9;attack+=20;if(health<=0)health=1;}
};class lion:public warrior{//已经增加逃跑设定和忠诚度降低设定
private:int loyal;
public:virtual void init_otherinfo(int strength,int strength_need){/*        if(number%3==0 && int(0.2*attack)==0)//如果是废剑,就不做了return;weapon_store[number%3]=weapon_point(number%3);weapon_store[number%3]->init(attack);weapon_num_type[number%3]=1;*/loyal=strength;}virtual void print_specialinfo(){cout<<"Its loyalty is "<<loyal<<endl;}virtual void loyal_decrease_(){loyal-=loyal_decrease;}virtual bool run_away_test(int time){//1代表太跑了,0代表没逃跑if(loyal<=0){cout<<modify_time(time)<<" "<<stribe<<" lion "<<number<<" ran away"<<endl;return true;}elsereturn false;}};class wolf:public warrior{//已经增加抢武器设定
public:virtual void wolf_rob(warrior* penemy){for(int i=0;i<=2;++i){if(penemy->weapon_store[i]!=NULL && weapon_store[i]==NULL){weapon_store[i]=penemy->weapon_store[i];weapon_num_type[i]=1;}}}
};warrior* type_point(int seq){//可以根据seq这个序数返回对映派生武士类的指针,赋值给一个基类的指针if(seq==0){dragon* pd=new dragon;return pd;}if(seq==1){ninja* pn=new ninja;return pn;}if(seq==2){iceman* pi=new iceman;return pi;}if(seq==3){lion* pl=new lion;return pl;}if(seq==4){wolf* pw=new wolf;return pw;}
/*
注意此处要用指针new一块地址出来,否则每一次调用该函数给的地址可能会重复,发生0xC0000005错误!!!
*/
}class city{public:int this_war,war;//this_war记录本次战斗结果,war记录总体战况string flag;//当前旗帜int NO,strength,process;//NO记录城市编号,该城市生命源,precess为基地占领进度int just_rise;//为1表示旗子刚刚升起warrior *pwarrior_red,*pwarrior_blue;void init(int i){NO=i;pwarrior_red=NULL;pwarrior_blue=NULL;this_war=0;//本次战况war=0;//总战况process=0;strength=0;just_rise=0;flag="none";}void fight(int time,warrior* &pwinner,string& rep){this_war=0;just_rise=0;pwinner=NULL;//以下判断先后手warrior *w_1=NULL,*w_2=NULL;if(NO%2==1){w_1=pwarrior_red;w_2=pwarrior_blue;}else{w_1=pwarrior_blue;w_2=pwarrior_red;}if(flag=="red"){w_1=pwarrior_red;w_2=pwarrior_blue;}else if(flag=="blue"){w_1=pwarrior_blue;w_2=pwarrior_red;}//以上判断先后手if(pwarrior_blue->health<=0 && pwarrior_red->health<=0){//两者都是被射死的,不算平局delete pwarrior_blue;delete pwarrior_red;pwarrior_blue=NULL;pwarrior_red=NULL;}else if(pwarrior_blue->health<=0 && pwarrior_red->health>0){//只有红方存活this_war=1;pwarrior_red->morale_change(true);pwinner=pwarrior_red;pwarrior_red->wolf_rob(pwarrior_blue);//狼抢尸体if(w_1->health>0)w_1->yell(time,rep);//龙吼delete pwarrior_blue;pwarrior_blue=NULL;if(war==0){war+=this_war;}else if(war==1){war+=this_war;if(flag!="red"){just_rise=1;//旗子刚刚升起flag="red";}}else if(war>=2){war+=this_war;}else if(war<=-1){war=0;war+=this_war;}}else if(pwarrior_blue->health>0 && pwarrior_red->health<=0){//只有蓝方存活this_war=-1;pwarrior_blue->morale_change(true);pwinner=pwarrior_blue;pwarrior_blue->wolf_rob(pwarrior_red);//狼抢尸体if(w_1->health>0)w_1->yell(time,rep);//龙吼delete pwarrior_red;pwarrior_red=NULL;if(war==0){war+=this_war;}else if(war==-1){war+=this_war;if(flag!="blue"){just_rise=1;//旗子刚刚升起flag="blue";}}else if(war<=-2){war+=this_war;}else if(war>=1){war=0;war+=this_war;}}else if(pwarrior_blue->health>0 && pwarrior_red->health>0){//两者都有血,正常开战int lion_1_life=(w_1->type=="lion")?(w_1->health):0;int lion_2_life=(w_2->type=="lion")?(w_2->health):0;w_1->attack_enemy(time,w_2,NO,rep);if(w_2->death_test()==true){//w2死了,胜者为w1pwinner=w_1;rep+=modify_time(time);rep+=" ";rep+=w_2->stribe;rep+=" ";rep+=w_2->type;rep+=" ";sprintf(stemp,"%d",w_2->number);rep+=stemp;memset(stemp,'\0',100);rep+=" was killed in city ";sprintf(stemp,"%d",NO);rep+=stemp;memset(stemp,'\0',100);rep+="\n";w_1->morale_change(true);w_1->yell(time,rep);//龙吼w_1->health+=lion_2_life;w_1->wolf_rob(w_2);this_war=w_1->war_acquire;if(war==0){war+=this_war;}else if(war*this_war<0){//两者异号war=0;war+=this_war;}else if(war*this_war>0 && war==this_war){//两者同号且刚升起来war+=this_war;if(flag!=w_1->stribe){just_rise=1;//刚刚升起flag=w_1->stribe;}}else if(war*this_war>0 && war*war>this_war*this_war){war+=this_war;}if(pwarrior_blue==w_2){delete pwarrior_blue;pwarrior_blue=NULL;}else if(pwarrior_red==w_2){delete pwarrior_red;pwarrior_red=NULL;}}else{//w2没死,发起反击w_2->attack_back(time,w_1,NO,rep);if(w_1->death_test()==true){//w1死了,胜者为w2pwinner=w_2;rep+=modify_time(time);rep+=" ";rep+=w_1->stribe;rep+=" ";rep+=w_1->type;rep+=" ";sprintf(stemp,"%d",w_1->number);rep+=stemp;memset(stemp,'\0',100);rep+=" was killed in city ";sprintf(stemp,"%d",NO);rep+=stemp;memset(stemp,'\0',100);rep+="\n";w_2->morale_change(true);//还击不吼w_2->health+=lion_1_life;w_2->wolf_rob(w_1);this_war=w_2->war_acquire;if(war==0){war+=this_war;}else if(war*this_war<0){//两者异号war=0;war+=this_war;}else if(war*this_war>0 && war==this_war){//两者同号war+=this_war;if(flag!=w_2->stribe){just_rise=1;flag=w_2->stribe;}}else if(war*this_war>0 && war*war>this_war*this_war){war+=this_war;}if(pwarrior_blue==w_1){delete pwarrior_blue;pwarrior_blue=NULL;}else if(pwarrior_red==w_1){delete pwarrior_red;pwarrior_red=NULL;}}else{//两者都没死,成为平局this_war=0;war=0;w_1->loyal_decrease_();w_1->morale_change(false);w_2->loyal_decrease_();w_2->morale_change(false);w_1->yell(time,rep);//龙吼}}}}
};void born_or_stop(city* cities,const int& ti,const int& time,int* strength_rb,int* number_rb,int* health_seq,int& warrior_storge){//执行出生或停止操作//如果为false则停止,为true则继续string type=warrior_seq[ti][(number_rb[ti]-1)%5];//找出当前想要创建的武士类型int seq=return_seq(type);if (strength_rb[ti]>=health_seq[seq]){//如果本次可以直接按顺序创造warrior_storge+=1;strength_rb[ti]-=health_seq[seq];warrior* pW;pW=type_point(seq);pW->init_basicinfo(ti,number_rb[ti]);pW->init_otherinfo(strength_rb[ti],health_seq[seq]);pW->print_born(time);pW->print_specialinfo();number_rb[ti]+=1;if(ti==0)//如果红方出生,记在红司令部cities[0].pwarrior_red=pW;if(ti==1)//如果蓝方出生,记在蓝司令部cities[city_num+1].pwarrior_blue=pW;}
}void report(warrior* pw,int time){//武士汇报工作int a=pw->weapon_num_type[2],b=pw->weapon_num_type[1],s=pw->weapon_num_type[0];int s_attack=0,a_life=0;if(s>0)s_attack=pw->weapon_store[0]->attack;if(a>0)a_life=pw->weapon_store[2]->life;cout<<modify_time(time)<<" "<<pw->stribe<<" "<<pw->type<<" "<<pw->number<<" has ";if(a==0&&b==0&&s==0)cout<<"no weapon"<<endl;else if(a==1&&b==0&&s==0)cout<<"arrow("<<a_life<<")"<<endl;else if(a==0&&b==1&&s==0)cout<<"bomb"<<endl;else if(a==0&&b==0&&s==1)cout<<"sword("<<s_attack<<")"<<endl;else if(a==1&&b==1&&s==0)cout<<"arrow("<<a_life<<"),bomb"<<endl;else if(a==1&&b==0&&s==1)cout<<"arrow("<<a_life<<"),sword("<<s_attack<<")"<<endl;else if(a==0&&b==1&&s==1)cout<<"bomb,sword("<<s_attack<<")"<<endl;else if(a==1&&b==1&&s==1)cout<<"arrow("<<a_life<<"),bomb,sword("<<s_attack<<")"<<endl;
}bool onehour(city* cities,int& hours,bool& red_win,bool& blue_win,int& T,int* strength_rb,int* number_rb,int* warrior_storge_rb,warrior** out_range_warrior){//只要能进这个循环,就说明还没有人获胜//1) 武士降生 OKint time=60*hours+0;born_or_stop(cities,0,time,strength_rb,number_rb,health_seq,warrior_storge_rb[0]);//红方降生born_or_stop(cities,1,time,strength_rb,number_rb,health_seq,warrior_storge_rb[1]);//蓝方降生//2) lion逃跑 OKtime=60*hours+5;if(time>T)return false;for(int i=0;i<=city_num+1;++i){if(cities[i].pwarrior_red!=NULL){bool test;test=cities[i].pwarrior_red->run_away_test(time);if(test==true){warrior_storge_rb[0]-=1;delete cities[i].pwarrior_red;cities[i].pwarrior_red=NULL;}}if(cities[i].pwarrior_blue!=NULL){bool test;test=cities[i].pwarrior_blue->run_away_test(time);if(test==true){warrior_storge_rb[1]-=1;delete cities[i].pwarrior_blue;cities[i].pwarrior_blue=NULL;}}}//3) 武士前进到某一城市 && 7) 武士抵达敌军司令部 && 8) 司令部被占领time=60*hours+10;if(time>T)return false;for(int i=0;i<=city_num;++i){//双方移动并进行自伤if (cities[i+1].pwarrior_blue!=NULL){cities[i].pwarrior_blue=cities[i+1].pwarrior_blue;//蓝方前进cities[i].pwarrior_blue->now_city=i;if((city_num+1-i)%2==0)//如果iceman前进了偶数步cities[i].pwarrior_blue->self_hurt();//iceman自伤}elsecities[i].pwarrior_blue=NULL;int j=city_num+1-i;//以下红方前进if (cities[j-1].pwarrior_red!=NULL){cities[j].pwarrior_red=cities[j-1].pwarrior_red;cities[j].pwarrior_red->now_city=j;if(j%2==0)cities[j].pwarrior_red->self_hurt();}elsecities[j].pwarrior_red=NULL;}cities[0].pwarrior_red=NULL;cities[city_num+1].pwarrior_blue=NULL;//移动全部完成if(cities[0].pwarrior_blue!=NULL){//红方基地被蓝方占领cities[0].process++;if(cities[0].process==2)blue_win=true;cities[0].pwarrior_blue->arrive_enemybase(time);out_range_warrior[0]=cities[0].pwarrior_blue;cities[0].pwarrior_blue=NULL;if(blue_win==true)cout<<modify_time(time)<<" red headquarter was taken"<<endl;}for(int ii=1;ii<=city_num;++ii){if(cities[ii].pwarrior_red!=NULL)cities[ii].pwarrior_red->arrive_city(time);if(cities[ii].pwarrior_blue!=NULL)cities[ii].pwarrior_blue->arrive_city(time);}if(cities[city_num+1].pwarrior_red!=NULL){//蓝方基地被红方占领cities[city_num+1].process++;if(cities[city_num+1].process==2)red_win=true;cities[city_num+1].pwarrior_red->arrive_enemybase(time);out_range_warrior[1]=cities[city_num+1].pwarrior_red;cities[city_num+1].pwarrior_red=NULL;if(red_win==true)cout<<modify_time(time)<<" blue headquarter was taken"<<endl;}if(red_win==true||blue_win==true)//如果有人占领了对方司令部就全部结束return true;//每个城市产生10个生命源time=60*hours+20;if(time>T)return false;for(int i=1;i<=city_num;++i)cities[i].strength+=10;//只有一个武士,取走该城市所有的生命源time=60*hours+30;if(time>T)return false;for(int i=1;i<=city_num;++i){if(cities[i].pwarrior_blue==NULL&&cities[i].pwarrior_red!=NULL){//只有红武士strength_rb[0]+=cities[i].strength;cout<<modify_time(time)<<" red "<<cities[i].pwarrior_red->type<<" "<<cities[i].pwarrior_red->number<<" earned "<<cities[i].strength<<" elements for his headquarter"<<endl;cities[i].strength=0;}else if(cities[i].pwarrior_blue!=NULL&&cities[i].pwarrior_red==NULL){//只有蓝武士strength_rb[1]+=cities[i].strength;cout<<modify_time(time)<<" blue "<<cities[i].pwarrior_blue->type<<" "<<cities[i].pwarrior_blue->number<<" earned "<<cities[i].strength<<" elements for his headquarter"<<endl;cities[i].strength=0;}}//4) 武士放箭time=60*hours+35;if(time>T)return false;for(int i=1;i<=city_num;++i){if(cities[i].pwarrior_red!=NULL){if(cities[i].pwarrior_red->weapon_num_type[2]>0 && cities[i+1].pwarrior_blue!=NULL)//本方有人且有箭,下一格有人cities[i].pwarrior_red->shot(cities[i+1].pwarrior_blue,time);}if(cities[i].pwarrior_blue!=NULL){if(cities[i].pwarrior_blue->weapon_num_type[2]>0 && cities[i-1].pwarrior_red!=NULL)cities[i].pwarrior_blue->shot(cities[i-1].pwarrior_red,time);}}//5)武士使用bombtime=60*hours+38;if(time>T)return false;for(int i=1;i<=city_num;++i){if(cities[i].pwarrior_red!=NULL && cities[i].pwarrior_blue!=NULL){if(cities[i].pwarrior_red->health>0 && cities[i].pwarrior_blue->health>0){//由于放箭不清除指针,所以本次必须要判断是不是双方还活着warrior *w_1=NULL,*w_2=NULL;if(i%2==1){w_1=cities[i].pwarrior_red;w_2=cities[i].pwarrior_blue;}else{w_1=cities[i].pwarrior_blue;w_2=cities[i].pwarrior_red;}if(cities[i].flag=="red"){w_1=cities[i].pwarrior_red;w_2=cities[i].pwarrior_blue;}else if(cities[i].flag=="blue"){w_1=cities[i].pwarrior_blue;w_2=cities[i].pwarrior_red;}//以上,按照规则完整地判断了先后手,可以在fight函数中复用if(cities[i].pwarrior_red->usebomb(cities[i].pwarrior_blue,w_1==cities[i].pwarrior_red)==true){cout<<modify_time(time)<<" red "<<cities[i].pwarrior_red->type<<" "<<cities[i].pwarrior_red->number<<" used a bomb and killed blue "<<cities[i].pwarrior_blue->type<<" "<<cities[i].pwarrior_blue->number<<endl;delete cities[i].pwarrior_red;delete cities[i].pwarrior_blue;cities[i].pwarrior_red=NULL;cities[i].pwarrior_blue=NULL;}else if(cities[i].pwarrior_blue->usebomb(cities[i].pwarrior_red,w_1==cities[i].pwarrior_blue)==true){cout<<modify_time(time)<<" blue "<<cities[i].pwarrior_blue->type<<" "<<cities[i].pwarrior_blue->number<<" used a bomb and killed red "<<cities[i].pwarrior_red->type<<" "<<cities[i].pwarrior_red->number<<endl;delete cities[i].pwarrior_red;delete cities[i].pwarrior_blue;cities[i].pwarrior_red=NULL;cities[i].pwarrior_blue=NULL;//看样例的输出,如果发现可以两者同时输出用炸弹,则修改此处的else if为if且删去上面的delete操作!!!}}}}//6) 武士主动进攻   7) 武士反击   8) 武士战死+lion送初始生命   lion减少loyal   狼抢武器   9) 武士欢呼    10) 武士获取生命元( elements ) +奖励+回收给基地   11) 旗帜升起time=60*hours+40;if(time>T)return false;warrior *pwinner[city_num];memset(pwinner,NULL,city_num*sizeof(weapon*));string rep[city_num+5];memset(rep,'\0',(city_num+5)*sizeof(rep[0]));for(int i=1;i<=city_num;++i){if(cities[i].pwarrior_blue==NULL && cities[i].pwarrior_red!=NULL){if(cities[i].pwarrior_red->health<=0){//只有红战士且被射死了delete cities[i].pwarrior_red;cities[i].pwarrior_red=NULL;}}else if(cities[i].pwarrior_blue!=NULL && cities[i].pwarrior_red==NULL){if(cities[i].pwarrior_blue->health<=0){//只有蓝武士且被射死了delete cities[i].pwarrior_blue;cities[i].pwarrior_blue=NULL;}}else if(cities[i].pwarrior_blue!=NULL && cities[i].pwarrior_red!=NULL)cities[i].fight(time,pwinner[i],rep[i]);//两者都有就开战吧}for(int i=1;i<=city_num;++i){//发放奖励int j=city_num+1-i;//j用给红色奖励,i用给蓝色奖励if(pwinner[j]!=NULL && pwinner[j]==cities[j].pwarrior_red && strength_rb[0]>=8){strength_rb[0]-=8;pwinner[j]->health+=8;}if(pwinner[i]!=NULL && pwinner[i]==cities[i].pwarrior_blue && strength_rb[1]>=8){strength_rb[1]-=8;pwinner[i]->health+=8;}}for(int i=1;i<=city_num;++i){//回收生命源if(pwinner[i]!=NULL && pwinner[i]==cities[i].pwarrior_red){strength_rb[0]+=cities[i].strength;//cout<<modify_time(time)<<" red "<<pwinner[i]->type<<" "<<pwinner[i]->number<<" earned "<<cities[i].strength<<" elements for his headquarter"<<endl;rep[i]+=modify_time(time);rep[i]+=" red ";rep[i]+=pwinner[i]->type;rep[i]+=" ";sprintf(stemp,"%d",pwinner[i]->number);rep[i]+=stemp;memset(stemp,'\0',100);rep[i]+=" earned ";sprintf(stemp,"%d",cities[i].strength);rep[i]+=stemp;memset(stemp,'\0',100);rep[i]+=" elements for his headquarter";rep[i]+="\n";cities[i].strength=0;}else if(pwinner[i]!=NULL && pwinner[i]==cities[i].pwarrior_blue){strength_rb[1]+=cities[i].strength;//cout<<modify_time(time)<<" blue "<<pwinner[i]->type<<" "<<pwinner[i]->number<<" earned "<<cities[i].strength<<" elements for his headquarter"<<endl;rep[i]+=modify_time(time);rep[i]+=" blue ";rep[i]+=pwinner[i]->type;rep[i]+=" ";sprintf(stemp,"%d",pwinner[i]->number);rep[i]+=stemp;memset(stemp,'\0',100);rep[i]+=" earned ";sprintf(stemp,"%d",cities[i].strength);rep[i]+=stemp;memset(stemp,'\0',100);rep[i]+=" elements for his headquarter";rep[i]+="\n";cities[i].strength=0;}}for(int i=1;i<=city_num;++i){//插旗子if(cities[i].just_rise==1){cities[i].just_rise=0;rep[i]+=modify_time(time);rep[i]+=" ";rep[i]+=cities[i].flag;rep[i]+=" flag raised in city ";sprintf(stemp,"%d",cities[i].NO);rep[i]+=stemp;memset(stemp,'\0',100);rep[i]+="\n";}cout<<rep[i];//rep[i]一定自带换行}//9)司令部报告生命元数量time=60*hours+50;if(time>T)return false;cout<<modify_time(time)<<" "<<strength_rb[0]<<" elements in red headquarter"<<endl;cout<<modify_time(time)<<" "<<strength_rb[1]<<" elements in blue headquarter"<<endl;//10)武士报告情况time=60*hours+55;if(time>T)return false;for(int i=0;i<=city_num+1;++i){if(cities[i].pwarrior_red!=NULL)report(cities[i].pwarrior_red,time);}if(out_range_warrior[1]!=NULL)report(out_range_warrior[1],time);//汇报之前走到终点的if(out_range_warrior[0]!=NULL)report(out_range_warrior[0],time);//汇报之前走到终点的for(int i=0;i<=city_num+1;++i){if(cities[i].pwarrior_blue!=NULL)report(cities[i].pwarrior_blue,time);}
}int main(){//freopen("data.in","r",stdin);//freopen("myout.out","w",stdout);int case_n;//现在是第几个casecin>>case_n;for(int i=0;i<case_n;++i){memset(stemp,'\0',100);cout<<"Case "<<i+1<<":"<<endl;int hours=0;warrior* out_range_warrior[2]={NULL,NULL};//记录走到对方终点,但是还没赢的两个战士bool red_win=false,blue_win=false;int strength,T;//生命源总量,输出到第几个时间cin>>strength>>city_num>>arrow_attack>>loyal_decrease>>T;for(int j=0;j<5;++j)//读入了这个case生产每个武士需要耗费多少生命源cin>>health_seq[j];for(int j=0;j<5;++j)//读入了这个case每个武士的攻击力cin>>attack_seq[j];int strength_rb[2]={strength,strength},number_rb[2]={1,1},warrior_storge_rb[2]={0,0};//红蓝方生命源,红蓝方目前的需要,红蓝方的武士总数city cities[city_num+2];for(int j=0;j<=city_num+1;++j)cities[j].init(j);for(hours=0;hours<=int(T/60);++hours){onehour(cities,hours,red_win,blue_win,T,strength_rb,number_rb,warrior_storge_rb,out_range_warrior);if(red_win==true||blue_win==true)break;}}return 0;
}

北大程设 魔兽终极版总结相关推荐

  1. C++程序设计 第6周 魔兽终极版

    完全没有想到一个单元作业就会如此的复杂,可以说是一个小型模拟游戏.写了整整4天的代码,外加1天调试,要不是对编程有满腔的热情,绝对是坚持不下来的,毕竟这道题有很多人放弃了.虽然最终的代码很丑,不仅啰嗦 ...

  2. 程设大作业之魔兽世界

    [前言]:在学习了一些看上去只是能让程序更好看更清晰的类的知识之后...为了让我们真的觉得类是个好东西,丧心病狂的作业--魔兽出现了...然而...emmmm... 好吧,这篇博客主要就是记录一下自己 ...

  3. 【程设】魔兽世界终极版!

    魔兽世界终极版 总时间限制:  6000ms  内存限制:  65536kB   描述 魔兽世界的西面是红魔军的司令部,东面是蓝魔军的司令部.两个司令部之间是依次排列的若干城市,城市从西向东依次编号为 ...

  4. 打造メンアットワーク!魔兽学院men at work2《永远的羁绊》 中文终极版(刺杀事件、H补丁)

    这个是我玩的第一个GALGAME,看到这个译名估计很多人都不大明白.曾经一度还有人以为和魔兽争霸有什么关系.其实繁体版译名就是永远的羁绊.本名为MAN AT WORK !2,山本大妈出品.   这个游 ...

  5. WF工作流设计器(WPF版)

    转自:http://www.cnblogs.com/foundation/archive/2008/10/28/1321186.html#_Toc212901141 这是一个WPF版的工作流设计器, ...

  6. matlab 30案例 目录,MATLAB-智能算法30个案例分析-终极版(带目录).doc

    MATLAB-智能算法30个案例分析-终极版(带目录) MATLAB 智能算法30个案例分析(终极版) 1?基于遗传算法的TSP算法(王辉)? 2?基于遗传算法和非线性规划的函数寻优算法(史峰)? 3 ...

  7. 重磅:服务器基础知识全解终极版(145页PPT)

    重磅:服务器基础知识全解终极版(145页PPT) 2020-12-26   阅 1  转 19 终极版来啦,本文内容共145页PPT干货,针对历史发布内容在CPU.内存.GPU.硬盘.网卡等9个章节做 ...

  8. 打造新圣魔大战简体中文终极版(H补丁、不能安装、运行问题)

    原文地址为: 打造新圣魔大战简体中文终极版(H补丁.不能安装.运行问题) 最近玩通了新圣魔大战,感觉很好玩,我玩的这个是迅雷搜索找到的152 MB的新圣魔大战中文版.新圣魔大战(Castle Fant ...

  9. 阿里巴巴Java开发手册终极版网页版v1.3.0

    前言 一 .编程规约 ( 一 ) 命名风格 ( 二 ) 常量定义 ( 三 ) 代码格式 ( 四 ) OOP规约 ( 五 ) 集合处理 ( 六 ) 并发处理 ( 七 ) 控制语句 ( 八 ) 注释规约 ...

最新文章

  1. 市政管网检测机器人收费标准_泰州泰兴新街镇市政管道机器人检测怎么收费
  2. 网友提问:SAP FUNCTION使用cl_http_client POST REQUEST的问题
  3. Android CardView卡片布局 标签: 控件
  4. 江西冶金职业技术学院计算机,计算机基础知识江西冶金职业技术学院.ppt
  5. 如何用C#将tif格式的图片转化成jpg?
  6. 查看java/jdk版本
  7. IDEA的依赖包报红问题
  8. 今天搞事情,angularjs项目实例分析
  9. js前端实现ios12和ios13+摇一摇功能
  10. vue报错elementUI使用datepicker报错Avoid mutating a prop directly since the value will be overwritten whene
  11. 企业为什么要上云?企业上云的好处和优势有哪些
  12. JMeter Address Already in use 错误解决
  13. html代码房地产,HTML白色宽屏形式房地产动态网页模板代码
  14. 基于MRS-Hudi构建数据湖的典型应用场景介绍
  15. java zgc_现在该关注ZGC和昏暗的Nashorn的明星了:Java影响者参与其中
  16. Android学习笔记之activity间传递传递参数
  17. 西门子em235模块的功能_上海西门子S7-300FM351定位功能模块,西门子信号板6ES7288-5AQ01-0AA0...
  18. css flex布局 —— 容器属性 flex-wrap
  19. java 递归搜索文件_Java递归搜索指定文件夹下的匹配文件
  20. Polkadot(波卡链):白皮书-畅想一种异构的多链架构

热门文章

  1. 自助售卖 | 京品高科咖啡系统
  2. 【视频教程】基于Fragstats的土地利用景观格局分析应用
  3. VMware下win7到ubuntu的快捷键
  4. 读京东技术解密,感桑田沧海变迁
  5. 脑袋决定屁股:学习应该多依赖软件,让 4 + 30 = 304 成为可能
  6. STM32按键的检测IO口上拉下拉电阻
  7. 利用队列解密QQ号码(三种方法)-->改编自《啊哈!算法》
  8. XMeter Cloud 专业版亮点抢先看
  9. 小猪CMS修改登录入口和退出修改
  10. ImportError lib64libstdc++.so.6 version `GLIBCXX_3.4.29’ not found