首页
登录 | 注册

【程序设计实习】之【魔兽世界3】

鉴于比赛已经结束,我就没必要弄个奇怪的标题掖着了,公开出来供大家交流。

没啥好说的,垒代码吧

需要注意的,1:千万注意在使用指针时确定它是否指着什么东西;2:STL库很完备,复制构造函数和等号都重载好了,不劳您费心。 3:以目前阶段vector和string造成的“内存泄漏”完全可以无视,vector该clear就clear,就知道该析构掉的析构好了,空间释不释放先不用考虑,那些swap什么的高级技巧就不用考虑了先。

翠花,上代码……注意,这次加Copyright了,转载请注意(毕竟写了快一周,肝火都熬起来了)

我就不写注释了,因为函数名写的不对付

//P.S.为防止有同学Copy&Paste,我特意写错了点东西hhh~相信您一定能看出来

//============================================================================
// Name        : Warcraft3.cpp
// Author      : MorroWind
// Version     : 1.0
// Copyright   : ©2018-2018 MorroWind. All rights reserved.
// Description : A simulation of the famous game Dota
//============================================================================

#include <iostream>
#include <algorithm>
#include <cstdio>
#include <cstring>
#include <string>
#include <cmath>
#include <vector>
using namespace std;
const string h[5] = {"dragon", "ninja", "iceman", "lion", "wolf"};
const string w[3] = {"sword", "bomb", "arrow"};
const int red[5] = {2, 3, 4, 1, 0};
const int blue[5] = {3, 0, 1, 2, 4};
const int interval[7] = {5, 5, 25, 5, 10, 5, 5};
int data_set;
int M,N,K,T;//M:initial_health N:numbers of cities K:lion's loyalty decrease T:limit time
int cost[5];
int melee[5];

class weapon{
protected:
    int dura;
    int a_on_enemy;
    int a_on_user;
    int per_aoe;
    int per_aou;
    int id;
public:
    weapon(){id=-1;a_on_enemy=0;a_on_user=0;dura=0;per_aoe=0;per_aou=0;}
    weapon(int dura, int per_aoe, int per_aou, int user_attack, int id){
        this->dura = dura;
        this->id = id;
        this->per_aoe = per_aoe;
        this->per_aou = per_aou;
        cal_attack(user_attack);
    }
    void cal_attack(int user_attack){
        a_on_enemy = (int)(floor((double)user_attack*this->per_aoe/10));
        a_on_user = (int)(floor((double)a_on_enemy*this->per_aou/10));
    }
    int get_aoe() {return a_on_enemy;};
    int get_aou() {return a_on_user;}
    int get_d() const{return dura;}
    int get_id() const {return id;}
    void damage(){--dura;}
};

bool cmp1(const weapon &t, const weapon &a) {
       if(t.get_id() == a.get_id()) return t.get_d() < a.get_d();
       else return t.get_id() < a.get_id();
}

bool cmp2(const weapon &t, const weapon &a) {
	if(t.get_id() == a.get_id()) return t.get_d() > a.get_d();
	else return t.get_id() < a.get_id();
}

class sword: public weapon{
public:
    sword(): weapon(){}
    sword(int user_attack): weapon(100000000, 2, 0, user_attack, 0) {}
};

class bomb: public weapon{
public:
    bomb(): weapon(){}
    bomb(int user_attack, bool isninja): weapon(1, 4, isninja? 0 : 5, user_attack, 1) {}
};

class arrow: public weapon{
public:
    arrow(): weapon(){}
    arrow(int user_attack): weapon(2, 3, 0, user_attack, 2) {}
};

class warrior{
protected:
    int health;
    int attack;
    vector <weapon> weapon_list;
    vector <weapon> package1;
    vector <weapon> package2;
    int which_use, p;
    string name;
    int id;
    int loyalty;
public:
    warrior(){
    	health = 0;
    	attack = 0;
    	id = -1;
    	loyalty = -1;
    	which_use = 0;
    	p = 0;
    }
    /*warrior(const warrior &a){
        health = a.health;
        attack = a.attack;
        weapon_list = a.weapon_list;
        package1 = a.package1;
        package2 = a.package2;
        which_use = a.which_use;
        p = a.p;
        name = a.name;
        id = a.id;
        loyalty = a.loyalty;
    }
    warrior &operator = (const warrior a){
        health = a.health;
        attack = a.attack;
        weapon_list = a.weapon_list;
        package1 = a.package1;
        package2 = a.package2;
        which_use = a.which_use;
        p = a.p;
        name = a.name;
        id = a.id;
        loyalty = a.loyalty;
    }*/
    virtual ~warrior(){//vector<city>(cities).swap(cities);
       /* vector <weapon>(weapon_list).swap(weapon_list);
        vector <weapon>(package1).swap(package1);
        vector <weapon>(package2).swap(package2);*/

    }
    static weapon new_weapon(int type, int ori_attack, string user_name){
        if(type==0) return sword(ori_attack);
        if(type==1&&user_name=="ninja") return bomb(ori_attack, true);
        if(type==1&&user_name!="ninja") return bomb(ori_attack, false);
        return arrow(ori_attack);
    }
    warrior(string name, int id, int health, int attack, int loyalty){
        this->name = name;
        this->id = id;
        this->health = health;
        this->attack = attack;
        this->loyalty = loyalty;
        if(name!="wolf") weapon_list.push_back(new_weapon(id%3,attack,name));
        if(name=="ninja") weapon_list.push_back(new_weapon((id+1)%3,attack,name));
        which_use = 0;
        p = 0;
    }
    void get_ready_to_fight(){
    	sort(weapon_list.begin(), weapon_list.end(), cmp1);
    	which_use = 1;
    	p = 0;
    	weapon tmp;
    	for(int i=0; i<weapon_list.size(); i++) package1.push_back(weapon_list[i]);
    }
    void rearmed(){
    	if(which_use == 1){
    		weapon_list.clear();
    		for(; p<package1.size(); p++){
    			weapon_list.push_back(package1[p]);
    		}
    		for(p=0; p<package2.size(); p++){
    			weapon_list.push_back(package2[p]);
    		}
    	}else{
    		weapon_list.clear();
    		for(; p<package2.size(); p++){
    			weapon_list.push_back(package2[p]);
    		}
    		for(p=0; p<package1.size(); p++){
    			weapon_list.push_back(package1[p]);
    		}
    	}
    	p=-1;
    	package1.clear();
    	package2.clear();
    }
    int get_weapon_left(){
    	if(which_use==1) return package2.size()+package1.size()-p;
    	else return package1.size()+package2.size()-p;
    }
    bool can_deal_damage(){
    	int bomb_num, arrow_num, sword_num;
    	if(which_use == 1){
    	    for(int i=p; i<package1.size(); i++){
    	    	int tmp=package1[i].get_id();
    	    	if(tmp==1||tmp==2) return true;
    	    	else if(package1[i].get_aoe()>0) return true;
    	   	}
    	    for(int i=0; i<package2.size(); i++){
    	    	int tmp=package2[i].get_id();
    	    	if(tmp==1||tmp==2) return true;
    	    	else if(package2[i].get_aoe()>0) return true;
    	   	}
    	}else{
    	    for(int i=p; i<package2.size(); i++){
    	    	int tmp=package2[i].get_id();
    	    	if(tmp==1||tmp==2) return true;
    	    	else if(package2[i].get_aoe()>0) return true;
    	    }
    	    for(int i=0; i<package1.size(); i++){
    	    	int tmp=package1[i].get_id();
    	    	if(tmp==1||tmp==2) return true;
    	    	else if(package1[i].get_aoe()>0) return true;
    	    }
    	}
    	return false;
    }
    void launch_attack(warrior &a){//after confirming it still have weapons
    	if(which_use==1){
    		a.health -= package1[p].get_aoe();
    		this->health -= package1[p].get_aou();
    		package1[p].damage();
    		if(package1[p].get_d()>0) package2.push_back(package1[p]);
    		if(p == package1.size()-1){
    			which_use = 2;
    			p = 0;
    			package1.clear();
    		}else p++;
    	}
    	else if(which_use==2){
    		a.health -= package2[p].get_aoe();
    		this->health -= package2[p].get_aou();
    		package2[p].damage();
    		if(package2[p].get_d()>0) package1.push_back(package2[p]);
    		if(p == package2.size()-1){
    		    which_use = 1;
    		    p = 0;
    		    package2.clear();
    		}else p++;
    	}
    }
    void sort2(){
    	sort(weapon_list.begin(), weapon_list.end(), cmp2);
    }
    weapon give_weapon(){//has already been sorted
    	if(weapon_list.size()>0){
    		weapon ret = weapon_list[0];
    		weapon_list.erase(weapon_list.begin());
    		return ret;
    	}
    	weapon ret;
    	return ret;
    }
    void grab_weapon(weapon tmp){
    	if(tmp.get_id() != -1 && weapon_list.size() < 10){
    		if(tmp.get_id()==1) tmp = bomb(attack, name==string("ninja"));
    		else tmp.cal_attack(attack);
    		weapon_list.push_back(tmp);
    	}
    }
    void loyalty_decrease(int KK){
    	loyalty -= KK;
    }
    bool melt(){
    	int d_health = (int)(floor((double)health * 1 / 10));
    	health -= d_health;
    	return health > 0;
    }
    int get_id() const {return id;}
    string get_name() const{
    	return name;
    }
    int get_health() const {return health;}
    int get_attack() const {return this->attack;}
    int get_loyalty() const {return this->loyalty;}
    int get_first_weapon_id() const {
    	if(weapon_list.size()==0) return -1;
    	return this->weapon_list[0].get_id();}
    int get_weapon_num() const{return this->weapon_list.size();}
    int get_full_weapon_status(){
    	int num_sword=0, num_bomb=0, num_arrow=0;
    	for(int i=0; i<weapon_list.size(); i++){
    		if(weapon_list[i].get_id()==0) num_sword++;
    		if(weapon_list[i].get_id()==1) num_bomb++;
    		if(weapon_list[i].get_id()==2) num_arrow++;
    	}
    	return num_sword*10000 + num_bomb*100 + num_arrow;
    }
    void test() {
       	name = string("abc");
    }
};

class dragon: public warrior{
public:
	dragon(int id) :warrior(string("dragon"), id, cost[0], melee[0], 1) {}
	~dragon(){
		  /* vector <weapon>(weapon_list).swap(weapon_list);
		        vector <weapon>(package1).swap(package1);
		        vector <weapon>(package2).swap(package2);*/

	};
};

class ninja: public warrior{
public:
	ninja(int id) :warrior(string("ninja"), id, cost[1], melee[1], 1) {}
	~ninja(){
		  /* vector <weapon>(weapon_list).swap(weapon_list);
		        vector <weapon>(package1).swap(package1);
		        vector <weapon>(package2).swap(package2);*/

	};
};

class iceman: public warrior{//Pay Attention! Be careful of iceman's health
public:
	iceman(int id): warrior(string("iceman"), id, cost[2], melee[2], 1){}
	~iceman(){
		  /* vector <weapon>(weapon_list).swap(weapon_list);
		        vector <weapon>(package1).swap(package1);
		        vector <weapon>(package2).swap(package2);*/

	};
};

class lion: public warrior{
public:
	lion(int id, int loyalty): warrior(string("lion"), id, cost[3], melee[3], loyalty) {}
	~lion(){
		  /* vector <weapon>(weapon_list).swap(weapon_list);
		        vector <weapon>(package1).swap(package1);
		        vector <weapon>(package2).swap(package2);*/
	};
};

class wolf: public warrior{
public:
	wolf(int id): warrior(string("wolf"), id, cost[4], melee[4], 1) {}
	~wolf(){
		  /* vector <weapon>(weapon_list).swap(weapon_list);
		        vector <weapon>(package1).swap(package1);
		        vector <weapon>(package2).swap(package2);*/

	};
};

class city{
protected:
	bool is_red;
	bool is_blue;
	int id;
public:
	warrior *red;
	warrior ared;
	warrior *blue;
	city(){
		id=-1;
		is_red = false;
		is_blue = false;
		red = NULL;
		blue = NULL;
	}
	city(const city &a){
		id = a.id;
		is_red = a.is_red;
		is_blue = a.is_blue;
		if(red!=NULL) delete red;
		if(blue!=NULL) delete blue;
		red = NULL;
		blue = NULL;
		if(a.is_red){
			red = new warrior;
			*red = *a.red;
		}
		if(a.is_blue){
			blue = new warrior;
			*blue = *(a.blue);
		}
	}
	~city(){
		if(red!=NULL) delete red;
		if(blue!=NULL) delete blue;
		red = NULL;
		blue = NULL;
	}
	void give_id(int id){this->id = id;}
	city &operator = (const city a){
		is_red = a.is_red;
		is_blue = a.is_blue;
		if(red!=NULL) delete red;
		if(blue!=NULL) delete blue;
		red = NULL;
		blue = NULL;
		if(a.is_red){
			red = new warrior;
			*red = *a.red;
		}
		if(a.is_blue){
			blue = new warrior;
			*blue = *(a.blue);
		}
		return *this;
	}
	warrior send_red(){
		if(is_red==false) {
			warrior ret;
			red = NULL;
			return ret;
		}
		else{
			is_red = false;
			warrior ret = *red;
			delete red;
			red = NULL;
			return ret;
		}
	}
	void rec_red(warrior a){
	    red = NULL;
		if(red!=NULL){
			is_red = false;
			delete red;
	    	red = NULL;
		}
		if(a.get_id()!= -1){
			is_red = true;
			ared = a;
			red = new warrior();
			*red = a;
			//delete red;
			if(a.get_name()==string("lion")&&id!=0) red->loyalty_decrease(K);
			if(a.get_name()==string("iceman")&&id!=0){
				bool is_alive = red->melt();
				if(!is_alive){
					delete red;
					red = NULL;
					is_red = false;
				}
			}
		}
	}
	warrior send_blue(){
		if(is_blue==false) {
			warrior ret;
			blue = NULL;
			return ret;
		}
		else{
			is_blue = false;
			warrior ret = *blue;
			delete blue;
			blue = NULL;
			return ret;
		}
	}
	void rec_blue(warrior a){
		if(blue!=NULL){
			is_blue = false;
			delete blue;
			blue = NULL;
		}
		if(a.get_id()!= -1){
			is_blue = true;
			blue = new warrior;
			*blue = a;
			if(a.get_name()==string("lion")&&id!=N+1) blue->loyalty_decrease(K);
		    if(a.get_name()==string("iceman")&&id!=N+1){
		    	bool is_alive = blue->melt();
		    	if(!is_alive){
			    	delete blue;
			    	blue = NULL;
			    	is_blue = false;
		    	}
	    	}
		}

	}
	void report_loyalty(string color){
		if(color=="red") cout<<"Its loyalty is "<<red->get_loyalty()<<endl;
		if(color=="blue") cout<<"Its loyalty is "<<blue->get_loyalty()<<endl;
	}
	void flee(int color, int time){
		if(color==0&&is_red&&red->get_name()=="lion"&&red->get_loyalty()<=0){
			is_red = false;
			printf("%03d:05 red lion %d ran away\n", time, red->get_id());
			delete red;
			red = NULL;
		}else if(color==1&&is_blue&&blue->get_name()=="lion"&&blue->get_loyalty()<=0){
			is_blue = false;
			printf("%03d:05 blue lion %d ran away\n", time, blue->get_id());
			delete blue;
			blue = NULL;
		}
	}
	void report_warrior(int time){
		if(is_red&&id!=0&&id!=N+1){//000:10 blue lion 1 marched to city 1 with 10 elements and force 5
			printf("%03d:10 ", time);
			cout<<"red "<<red->get_name()<<" "<<red->get_id()<<" marched to city ";
			cout<<id<<" with "<<red->get_health()<<" elements and force "<<red->get_attack()<<endl;
		}
		if(is_blue&&id!=0&&id!=N+1){
			printf("%03d:10 ", time);
			cout<<"blue "<<blue->get_name()<<" "<<blue->get_id()<<" marched to city ";
			cout<<id<<" with "<<blue->get_health()<<" elements and force "<<blue->get_attack()<<endl;
		}
	}
	void wolf_grab_weapon(int time){
		if(is_red&&is_blue){
			if(red->get_name()==string("wolf")&&blue->get_name()!=string("wolf")){
				blue->sort2();
				int weapon_type = blue->get_first_weapon_id(),cnt = 0;
				while(weapon_type!=-1 &&blue->get_first_weapon_id()==weapon_type&&red->get_weapon_num()<10){
					red->grab_weapon(blue->give_weapon());
					cnt++;
				}
				if(weapon_type!=-1&&cnt>0){//000:35 blue wolf 2 took 3 bomb from red dragon 2 in city 4
					//in order to avoid the wolf has more than 10 wenpons
					printf("%03d:35 red wolf %d took %d " ,time ,red->get_id(), cnt);
					cout<<w[weapon_type];
					printf(" from blue ");
					cout<<blue->get_name();
					printf(" %d in city %d\n", blue->get_id(), id);
				}
			}
			if(blue->get_name()==string("wolf")&&red->get_name()!=string("wolf")){

				red->sort2();
				int weapon_type = red->get_first_weapon_id(),cnt = 0;
				//if(blue->get_id()== 5) cout<<weapon_type<<endl;
				while(weapon_type!=-1 &&red->get_first_weapon_id()==weapon_type&&blue->get_weapon_num()<10){
					blue->grab_weapon(red->give_weapon());
					cnt++;
				}
				if(weapon_type!=-1&&cnt>0){//000:35 blue wolf 2 took 3 bomb from red dragon 2 in city 4
									//in order to avoid the wolf has more than 10 wenpons
					printf("%03d:35 blue wolf %d took %d " ,time ,blue->get_id(), cnt);
					cout<<w[weapon_type];
					printf(" from red ");
					cout<<red->get_name();
					printf(" %d in city %d\n", red->get_id(), id);
				}
			}
		}
	}
	void report_status(int time){
		if(is_red){//000:55 blue wolf 2 has 2 sword 3 bomb 0 arrow and 7 elements
			printf("%03d:55 red ", time);
			cout<<red->get_name()<<" "<<red->get_id()<<" has ";
			int full_weapon_status = red->get_full_weapon_status();
			int num_arrow = full_weapon_status % 100; full_weapon_status /= 100;
			int num_bomb = full_weapon_status % 100; full_weapon_status /= 100;
			int num_sword = full_weapon_status;
			printf("%d sword %d bomb %d arrow and %d elements\n", num_sword, num_bomb, num_arrow, red->get_health());
		}
		if(is_blue){//000:55 blue wolf 2 has 2 sword 3 bomb 0 arrow and 7 elements
			printf("%03d:55 blue ", time);
			cout<<blue->get_name()<<" "<<blue->get_id()<<" has ";
			int full_weapon_status = blue->get_full_weapon_status();
			int num_arrow = full_weapon_status % 100; full_weapon_status /= 100;
			int num_bomb = full_weapon_status % 100; full_weapon_status /= 100;
			int num_sword = full_weapon_status;
			printf("%d sword %d bomb %d arrow and %d elements\n", num_sword, num_bomb, num_arrow, blue->get_health());
		}
	}
	int get_status(){
		if(red->get_health()>0&&blue->get_health()>0) return -1;//not over
		if(red->get_health()>0&&blue->get_health()<=0) return 1;//red win
		if(red->get_health()<=0&&blue->get_health()>0) return 2;//blue win
		//if(red->get_health()<0&&blue->get_health()<0)
		return 0;//all dead, draw
	}
	void fight(int time){
		if(is_red&&is_blue){
			red->get_ready_to_fight();
			blue->get_ready_to_fight();
			int status=-1; //0: draw 1:red win 2:blue win
			if(id%2==1){
				while(1){
					if(red->get_weapon_left()==0&&blue->get_weapon_left()==0){
						status=0;
						break;
					}
					if(!red->can_deal_damage()&&!blue->can_deal_damage()){
						status=0;
						break;
					}
					if(status==-1&&red->get_weapon_left()>0) red->launch_attack(*blue);
					status = get_status();
					if(status==-1&&blue->get_weapon_left()>0) blue->launch_attack(*red);
					status = get_status();
					if(status!=-1) break;
				}
			}else{
				while(1){
					if(red->get_weapon_left()==0&&blue->get_weapon_left()==0){
						status=0;
						break;
					}
					if(!red->can_deal_damage()&&!blue->can_deal_damage()){
						status=0;
						break;
					}
					if(status==-1&&blue->get_weapon_left()>0) blue->launch_attack(*red);
					status = get_status();
					if(status==-1&&red->get_weapon_left()>0) red->launch_attack(*blue);
					status = get_status();
					if(status!=-1) break;
				}
			}
			red->rearmed(); blue->rearmed();
			if(status==0){
				if(red->get_health()<=0&&blue->get_health()<=0){//000:40 both red iceman 1 and blue lion 12 died in city 2
					printf("%03d:40 both red ", time); cout<<red->get_name();
					printf(" %d and blue ", red->get_id()); cout<<blue->get_name();
					printf(" %d died in city %d\n", blue->get_id(), id);
					delete red;
					red = NULL;
					is_red = false;
					delete blue;
					blue = NULL;
					is_blue = false;
				}else{//000:40 both red iceman 1 and blue lion 12 were alive in city 2
					printf("%03d:40 both red ", time); cout<<red->get_name();
					printf(" %d and blue ", red->get_id()); cout<<blue->get_name();
					printf(" %d were alive in city %d\n", blue->get_id(), id);
					if(red->get_name()==string("dragon"))
							printf("%03d:40 red dragon %d yelled in city %d\n", time, red->get_id(), id);//003:40 blue dragon 2 yelled in city 4
					if(blue->get_name()==string("dragon"))
							printf("%03d:40 blue dragon %d yelled in city %d\n", time, blue->get_id(), id);//003:40 blue dragon 2 yelled in city 4
				}
			}else if(status==1){//000:40 red iceman 1 killed blue lion 12 in city 2 remaining 20 elements
				while(red->get_weapon_num()<10 && blue->get_weapon_num()>0){
					red->grab_weapon(blue->give_weapon());
				}
				printf("%03d:40 red ", time); cout<<red->get_name();
				printf(" %d killed blue ", red->get_id()); cout<<blue->get_name();
				printf(" %d in city %d remaining %d elements\n", blue->get_id(), id, red->get_health());
				if(red->get_name()==string("dragon"))
					printf("%03d:40 red dragon %d yelled in city %d\n", time, red->get_id(), id);//003:40 blue dragon 2 yelled in city 4
				delete blue;
				blue = NULL;
				is_blue = false;
			}else if(status==2){//
				while(blue->get_weapon_num()<10 && red->get_weapon_num()>0){
					blue->grab_weapon(red->give_weapon());
				}
				printf("%03d:40 blue ", time); cout<<blue->get_name();
				printf(" %d killed red ", blue->get_id()); cout<<red->get_name();
				printf(" %d in city %d remaining %d elements\n", red->get_id(), id, blue->get_health());
				if(blue->get_name()==string("dragon"))
					printf("%03d:40 blue dragon %d yelled in city %d\n", time, blue->get_id(), id);//003:40 blue dragon 2 yelled in city 4
				delete red;
				red = NULL;
				is_red = false;
			}
		}
	}
	bool isover(int time){//001:10 red iceman 1 reached blue headquarter with 20 elements and force 30
						  //004:10 blue headquarter was taken
	    if(id==0&&is_blue==true){
	    	 printf("%03d:10 blue ", time); cout<<blue->get_name();
	    	 printf(" %d reached red headquarter with %d elements and force %d\n", blue->get_id(),  blue->get_health(), blue->get_attack());
	    	 printf("%03d:10 red headquarter was taken\n", time);
	    	 return true;
	    }else if(id==N+1&&is_red==true){
	    	printf("%03d:10 red ", time); cout<<red->get_name();
	        printf(" %d reached blue headquarter with %d elements and force %d\n", red->get_id(),  red->get_health(), red->get_attack());
	        printf("%03d:10 blue headquarter was taken\n", time);
	        return true;
	    }
	    return false;
	}
};


class player{
private:
    int order[5]; //the order making warriors
    int health;  //the health point the commando left
    int status;  //the warrior id that should be made according to the order
    int num[5];  //the number of each warriors
    bool canmake;
    int counter;
    string name;
public:
        player(string name, const int *a, int health){
        	counter = 0;
            this->health = health;
            memset(num, 0, sizeof(num));
            for(int i=0; i<5; i++)
                *(order+i) = *(a+i);
            status = 0;
            canmake = false;
            if(health>=cost[order[status]]) canmake = true;
            this->name = name;
        }
        int make(city &next){//return the kind of warrior that has been made recently,and if it can't make any warrior
        		   //then return -1
        	int type = -1;
        	if(health >= cost[order[status]]){
        		health -= cost[order[status]];
        		type = order[status];
        		counter++;
        		warrior p;
        		if(type==0) p = dragon(counter);
        		if(type==1) p = ninja(counter);
        		if(type==2) p = iceman(counter);
        		if(type==3) p = lion(counter, health);
        		if(type==4) p = wolf(counter);
        		if(name=="red") next.rec_red(p);
        		else if(name=="blue") next.rec_blue(p);
        		status = (status + 1) % 5;
        		if(health < cost[order[status]]) {canmake = false;}
        	}
        	return counter*10+type;
        }
        bool iscan() { return canmake;}
        int get_health()  {return this->health;}
};

vector <city> cities;
int main()
{
	//freopen("data.txt","r",stdin);
	//freopen("myans.txt","w",stdout);
    scanf("%d", &data_set);
    int case_time = 1;
    while(case_time <= data_set){

        cin>>M>>N>>K>>T;
        for(int i=0;i<=N+1;i++){
        	cities.push_back(city());
        	cities[i].give_id(i);
        }

        for(int i=0;i<5;i++) cin>>cost[i];
        for(int i=0;i<5;i++) cin>>melee[i];
       player Red(string("red"), red, M);
       player Blue(string("blue"), blue, M);
        printf("Case %d:\n", case_time);

        for(int timing=0, con=0, hour=-1; timing<=T; timing+=interval[con], con=(con+1)%7){
            if(con==0) hour++;
            if(con==0){
            	if(Red.iscan()){
            		int info = Red.make(cities[0]);
            		printf("%03d:%02d red ", hour, timing-60*hour);
            		cout<<h[info%10]<<" "<<info/10<<" born"<<endl;
            		if(h[info%10]=="lion") cities[0].report_loyalty("red");
            	}
           	if(Blue.iscan()){
            		int info = Blue.make(cities[N+1]);
            		printf("%03d:%02d blue ", hour, timing-60*hour);
            		cout<<h[info%10]<<" "<<info/10<<" born"<<endl;
            		if(h[info%10]=="lion") cities[N+1].report_loyalty("blue");
            	}
            }
            if(con==1){
            	cities[0].flee(0, hour);
            	for(int i=1;i<=N;i++) {
            		cities[i].flee(0, hour);
            		cities[i].flee(1, hour);
            	}
            	cities[N+1].flee(1, hour);
            }
            if(con==2){
            	for(int i=0;i<=N;i++) cities[i].rec_blue(cities[i+1].send_blue());
            	for(int i=N+1;i>=1;i--) cities[i].rec_red(cities[i-1].send_red());
            	bool isover = cities[0].isover(hour);
            	for(int i=1;i<=N;i++) cities[i].report_warrior(hour);
            	isover = cities[N+1].isover(hour) || isover;
            	if(isover) break;
            }
            if(con==3){
            	for(int i=0;i<=N+1;i++)
            		cities[i].wolf_grab_weapon(hour);
            }
            if(con==4){
            	for(int i=0;i<=N+1;i++)
            		cities[i].fight(hour);
            }
            if(con==5){//001:50 20 elements in red headquarter
            	printf("%03d:50 %d elements in red headquarter\n", hour, Red.get_health());
            	printf("%03d:50 %d elements in blue headquarter\n", hour, Blue.get_health());
            }
            if(con==6){
            	for(int i=0;i<=N+1;i++)
            		cities[i].report_status(hour);
            }
        }
        ++case_time;
        cities.clear();
    }
    return 0;
}




2020 jeepxie.net webmaster#jeepxie.net
10 q. 0.008 s.
京ICP备10005923号