魔兽终极版

#include <cstdio>
#include <iostream>
#include <cstring>
using namespace std;
int myHour, myMinute;
int N, R, K;
int draE, ninE, iceE, lionE, wolfE;
int draF, ninF, iceF, lionF, wolfF;
int comerR, comerB;
void rWin(int);
void bWin(int);
class Weapon {
public:
	int force;
	int id;
	string name;
	int frequency;
	Weapon(int force_, int id_) {
		force = force_; id = id_;
	}
};
class Sword :public Weapon {
public:
	Sword(int force_) :Weapon(force_, 0) { name = "sword"; }
};
class Bomb :public Weapon {
public:
	Bomb() :Weapon(0, 1) { name = "bomb"; }
};
class Arrow :public Weapon {
public:
	Arrow() :Weapon(R, 2) { frequency = 3; name = "arrow"; }
};
class Warriors {
public:
	string name;
	string head;
	int idNumber;
	int elements;
	int wForce;
	int wCity;
	float morale;
	int loyalty;
	int steps;
	Sword *sword;
	Bomb *bomb;
	Arrow *arrow;
	Warriors() { wCity = 0; sword = NULL; bomb = NULL; arrow = NULL; steps = 0; }
	virtual void attack(Warriors *w) = 0;
	virtual void fightBack(Warriors *w) = 0;
	virtual void hurted(int v) = 0;
	void equipWeapon(int v);
	virtual void yell() {};
	virtual void killed(Warriors *w) = 0;
	virtual void getWeapon(Warriors *w) {};
};
void Warriors::equipWeapon(int v) {
	if (v == 0 && wForce >= 5) {
		this->sword = new Sword(wForce * 0.2);
	}
	if (v == 1) {
		this->bomb = new Bomb;
	}
	if (v == 2) {
		this->arrow = new Arrow;
	}
}

class Dragon :public Warriors {
public:
	Dragon(float morale_) { wForce = draF; elements = draE; name = "dragon"; morale = morale_; }
	void attack(Warriors *w1) {
		//攻击
		int tempE = 0;
		printf("%03d:%02d %s %s %d attacked %s %s %d in city %d with %d elements and force %d\n", myHour, myMinute, head.data(), name.data(), idNumber, w1->head.data(), w1->name.data(), w1->idNumber, wCity, elements, wForce);
		if (strcmp(w1->name.data(), "lion") == 0) tempE = w1->elements;
		if (!sword)w1->hurted(wForce);
		else { w1->hurted(wForce + sword->force); sword->force *= 0.8; if (sword->force == 0) { delete sword; sword = NULL; } }
		if (w1->elements > 0) {
			morale -= 0.2;
			w1->fightBack(this);
		}
		else {
			elements += tempE;
			morale += 0.2;
			w1->killed(this);
		}
		if (elements > 0) { yell(); }
	}
	void fightBack(Warriors *w1) {
		//反击
		int tempE = 0;
		printf("%03d:%02d %s %s %d fought back against %s %s %d in city %d\n", myHour, myMinute, head.data(), name.data(), idNumber, w1->head.data(), w1->name.data(), w1->idNumber, wCity);
		if (strcmp(w1->name.data(), "lion") == 0) tempE = w1->elements;
		if (!sword)w1->hurted(wForce / 2);
		else {
			w1->hurted(wForce / 2 + sword->force); sword->force *= 0.8; if (sword->force == 0) { delete sword; sword = NULL; }
		}
		if (w1->elements <= 0) {
			elements += tempE;
			w1->killed(this);
		}
	}
	void hurted(int harm) {
		elements -= harm;
	}
	void yell() {
		if (morale > 0.8) {
			//欢呼
			printf("%03d:%02d %s dragon %d yelled in city %d\n", myHour, myMinute, head.data(), idNumber, wCity);
		}
	}
	void killed(Warriors *w1) {
		//被w1杀死了
		printf("%03d:%02d %s %s %d was killed in city %d\n", myHour, myMinute, head.data(), name.data(), idNumber, wCity);
	}
};
class Ninja :public Warriors {
public:
	Ninja() { elements = ninE; wForce = ninF; name = "ninja"; }
	void attack(Warriors *w1) {
		//攻击
		int tempE = 0;
		printf("%03d:%02d %s %s %d attacked %s %s %d in city %d with %d elements and force %d\n", myHour, myMinute, head.data(), name.data(), idNumber, w1->head.data(), w1->name.data(), w1->idNumber, wCity, elements, wForce);
		if (strcmp(w1->name.data(), "lion") == 0) tempE = w1->elements;
		if (!sword)w1->hurted(wForce);
		else {
			w1->hurted(wForce + sword->force); sword->force *= 0.8; if (sword->force == 0) { delete sword; sword = NULL; }
		}
		if (w1->elements > 0) {
			w1->fightBack(this);
		}
		else {
			elements += tempE;
			w1->killed(this);
		}
	}
	void fightBack(Warriors *w1) {
		//反击
	}
	void hurted(int harm) {
		elements -= harm;
	}
	void killed(Warriors *w1) {
		//被w1杀死了
		printf("%03d:%02d %s %s %d was killed in city %d\n", myHour, myMinute, head.data(), name.data(), idNumber, wCity);
	}
};
class Iceman :public Warriors {
public:
	Iceman() { steps = 0; elements = iceE; wForce = iceF; name = "iceman"; }
	void attack(Warriors *w1) {
		//攻击
		int tempE = 0;
		printf("%03d:%02d %s %s %d attacked %s %s %d in city %d with %d elements and force %d\n", myHour, myMinute, head.data(), name.data(), idNumber, w1->head.data(), w1->name.data(), w1->idNumber, wCity, elements, wForce);
		if (strcmp(w1->name.data(), "lion") == 0) tempE = w1->elements;
		if (!sword)w1->hurted(wForce);
		else {
			w1->hurted(wForce + sword->force); sword->force *= 0.8; if (sword->force == 0) { delete sword; sword = NULL; }
		}
		if (w1->elements > 0) {
			w1->fightBack(this);
		}
		else {
			elements += tempE;
			w1->killed(this);
		}
	}
	void fightBack(Warriors *w1) {
		//反击
		int tempE = 0;
		printf("%03d:%02d %s %s %d fought back against %s %s %d in city %d\n", myHour, myMinute, head.data(), name.data(), idNumber, w1->head.data(), w1->name.data(), w1->idNumber, wCity);
		if (strcmp(w1->name.data(), "lion") == 0) tempE = w1->elements;
		if (!sword)w1->hurted(wForce / 2);
		else {
			w1->hurted(wForce / 2 + sword->force); sword->force *= 0.8; if (sword->force == 0) { delete sword; sword = NULL; }
		}
		if (w1->elements <= 0) { elements += tempE; w1->killed(this); }
	}
	void hurted(int harm) {
		elements -= harm;
	}
	void killed(Warriors *w1) {
		//被w1杀死了
		printf("%03d:%02d %s %s %d was killed in city %d\n", myHour, myMinute, head.data(), name.data(), idNumber, wCity);
	}
};

class Lion :public Warriors {
public:
	Lion() { elements = lionE; wForce = lionF; name = "lion"; }
	void attack(Warriors *w1) {
		//攻击
		int tempE = 0;
		printf("%03d:%02d %s %s %d attacked %s %s %d in city %d with %d elements and force %d\n", myHour, myMinute, head.data(), name.data(), idNumber, w1->head.data(), w1->name.data(), w1->idNumber, wCity, elements, wForce);
		if (strcmp(w1->name.data(), "lion") == 0) tempE = w1->elements;
		w1->hurted(wForce);
		if (w1->elements > 0) {
			loyalty -= K;
			w1->fightBack(this);
		}
		else {
			elements += tempE;
			w1->killed(this);
		}
	}
	void fightBack(Warriors *w1) {
		//反击
		int tempE = 0;
		printf("%03d:%02d %s %s %d fought back against %s %s %d in city %d\n", myHour, myMinute, head.data(), name.data(), idNumber, w1->head.data(), w1->name.data(), w1->idNumber, wCity);
		if (strcmp(w1->name.data(), "lion") == 0) tempE = w1->elements;
		w1->hurted(wForce / 2);
		if (w1->elements <= 0) { elements += tempE; w1->killed(this); }
		else { loyalty -= K; }
	}
	void hurted(int harm) {
		elements -= harm;
	}
	void killed(Warriors *w1) {
		//被w1杀死了
		printf("%03d:%02d %s %s %d was killed in city %d\n", myHour, myMinute, head.data(), name.data(), idNumber, wCity);
	}
};
class Wolf :public Warriors {
public:
	Wolf() { elements = wolfE; wForce = wolfF; name = "wolf"; }
	void attack(Warriors *w1) {
		//攻击
		int tempE = 0;
		printf("%03d:%02d %s %s %d attacked %s %s %d in city %d with %d elements and force %d\n", myHour, myMinute, head.data(), name.data(), idNumber, w1->head.data(), w1->name.data(), w1->idNumber, wCity, elements, wForce);
		if (strcmp(w1->name.data(), "lion") == 0) tempE = w1->elements;
		if (!sword)w1->hurted(wForce);
		else {
			w1->hurted(wForce + sword->force); sword->force *= 0.8; if (sword->force == 0) { delete sword; sword = NULL; }
		}
		if (w1->elements > 0) {
			w1->fightBack(this);
		}
		else {
			elements += tempE;
			w1->killed(this);
		}
	}
	void fightBack(Warriors *w1) {
		//反击
		int tempE = 0;
		printf("%03d:%02d %s %s %d fought back against %s %s %d in city %d\n", myHour, myMinute, head.data(), name.data(), idNumber, w1->head.data(), w1->name.data(), w1->idNumber, wCity);
		if (strcmp(w1->name.data(), "lion") == 0) tempE = w1->elements;
		if (!sword)w1->hurted(wForce / 2);
		else {
			w1->hurted(wForce / 2 + sword->force); sword->force *= 0.8; if (sword->force == 0) { delete sword; sword = NULL; }
		}
		if (w1->elements <= 0) { elements += tempE; w1->killed(this); }
	}
	void hurted(int harm) {
		elements -= harm;
	}
	void killed(Warriors *w1) {
		//被w1杀死了
		printf("%03d:%02d %s %s %d was killed in city %d\n", myHour, myMinute, head.data(), name.data(), idNumber, wCity);
	}
	void getWeapon(Warriors *w1) {
		if (w1->arrow && !arrow) {
			arrow = new Arrow;
			arrow->frequency = w1->arrow->frequency;
		}
		if (w1->bomb && !bomb) {
			bomb = new Bomb;
		}
		if (w1->sword && !sword) {
			sword = new Sword(w1->sword->force);
		}
	}
};
class City {
public:
	char flag;
	int M;
	bool rf, bf, fight;
	Warriors *r;
	Warriors *b;
	City() { flag = '0'; r = NULL; b = NULL; rf = false; bf = false; fight = false; }
	void rise(int n, int i_) {
		if ((flag == '0' || flag == 'b') && n == 0) { printf("%03d:%02d red flag raised in city %d\n", myHour, myMinute, i_); flag = 'r'; }
		else if (flag == '0' || flag == 'r') { printf("%03d:%02d blue flag raised in city %d\n", myHour, myMinute, i_); flag = 'b'; }
	}
};
City city[22];
class Headquarter :public City {
public:
	string name;
	Dragon *dragon;
	Ninja *ninja;
	Iceman *iceman;
	Lion *lion;
	Wolf *wolf;
	Warriors *firstReacher;
	int wNum;
	Headquarter(const char *s) :name(s) { wNum = 0; dragon = NULL; ninja = NULL;  iceman = NULL;  lion = NULL;  wolf = NULL; firstReacher = NULL; }
	virtual void born(int *, int) = 0;
	virtual void toEscape() = 0;
	virtual void toMarch(int i) = 0;
	virtual void toFirstEarn(int) = 0;
	virtual void toUseBomb(int) = 0;
	virtual void  reach() = 0;
	virtual bool take() = 0;
	virtual void toShot(int i) = 0;
	virtual void report() = 0;
};

class Red :public Headquarter {
public:
	Warriors *firstReacher;
	Red(const char *s) :Headquarter(s) { firstReacher = NULL; }
	void born(int *order, int n) {
		if (order[n] == 0) {
			wNum++;
			city[0].M -= draE;
			dragon = new Dragon((double)city[0].M / (double)draE);
			dragon->head = "red";
			dragon->equipWeapon(wNum % 3);
			city[0].r = dragon;
			printf("%03d:%02d red dragon %d born\n", myHour, myMinute, wNum);
			printf("Its morale is %.2f\n", dragon->morale);
		}
		else if (order[n] == 1) {
			wNum++;
			city[0].M -= ninE;
			ninja = new Ninja;
			ninja->head = "red";
			ninja->equipWeapon(wNum % 3);
			ninja->equipWeapon((wNum + 1) % 3);
			city[0].r = ninja;
			printf("%03d:%02d red ninja %d born\n", myHour, myMinute, wNum);
		}
		else if (order[n] == 2) {
			wNum++;
			city[0].M -= iceE;
			iceman = new Iceman;
			iceman->head = "red";
			iceman->equipWeapon(wNum % 3);
			city[0].r = iceman;
			printf("%03d:%02d red iceman %d born\n", myHour, myMinute, wNum);
		}
		else if (order[n] == 3) {
			wNum++;
			city[0].M -= lionE;
			lion = new Lion;
			lion->head = "red";
			lion->loyalty = city[0].M;
			city[0].r = lion;
			printf("%03d:%02d red lion %d born\n", myHour, myMinute, wNum);
			printf("Its loyalty is %d\n", lion->loyalty);
		}
		else if (order[n] == 4) {
			wNum++;
			city[0].M -= wolfE;
			wolf = new Wolf;
			wolf->head = "red";
			city[0].r = wolf;
			printf("%03d:%02d red wolf %d born\n", myHour, myMinute, wNum);
		}
		city[0].r->idNumber = wNum;
		city[0].r->wCity = 0;
	}
	void toEscape() {
		for (int i = 0; i <= N; i++) {
			if (city[i].r && strcmp(city[i].r->name.data(), "lion") == 0) {
				if (city[i].r->loyalty <= 0) {
					printf("%03d:%02d red lion %d ran away\n", myHour, myMinute, city[i].r->idNumber);
					delete city[i].r;
					city[i].r = NULL;
				}
			}
		}
	}
	void toMarch(int i) {
		if (city[i].r) {
			city[i].r->wCity++;
			city[i + 1].r = city[i].r;
			city[i].r = NULL;
			if (strcmp(city[i + 1].r->name.data(), "iceman") == 0) {
				city[i + 1].r->steps++;
				if (city[i + 1].r->steps % 2 == 0) {
					city[i + 1].r->elements -= 9;
					city[i + 1].r->wForce += 20;
					if (city[i + 1].r->elements <= 0) {
						city[i + 1].r->elements = 1;
					}
				}
			}
		}
	}
	void toFirstEarn(int i) {
		if (city[i].r && !city[i].b) {
			city[0].M += city[i].M;
			printf("%03d:%02d red %s %d earned %d elements for his headquarter\n", myHour, myMinute, city[i].r->name.data(), city[i].r->idNumber, city[i].M);
			city[i].M = 0;
		}
	}
	void toUseBomb(int i) {
		if ((city[i].flag == 'r' || (city[i].flag == '0' && i % 2 != 0)) && strcmp(city[i].b->name.data(), "ninja") != 0 && (city[i].r->wForce + (city[i].r->sword ? city[i].r->sword->force : 0)) < city[i].b->elements) {
			if ((city[i].b->wForce / 2 + (city[i].b->sword ? city[i].b->sword->force : 0)) >= city[i].r->elements)
			{

				printf("%03d:%02d red %s %d used a bomb and killed blue %s %d\n", myHour, myMinute, city[i].r->name.data(), city[i].r->idNumber, city[i].b->name.data(), city[i].b->idNumber);
				delete city[i].r, city[i].b;
				city[i].r = NULL;
				city[i].b = NULL;
			}
		}
		else if ((city[i].flag == 'b' || (city[i].flag == '0' && i % 2 == 0))) {
			if ((city[i].b->wForce + (city[i].b->sword ? city[i].b->sword->force : 0) >= city[i].r->elements)) {
				printf("%03d:%02d red %s %d used a bomb and killed blue %s %d\n", myHour, myMinute, city[i].r->name.data(), city[i].r->idNumber, city[i].b->name.data(), city[i].b->idNumber);
				delete city[i].r, city[i].b;
				city[i].r = NULL;
				city[i].b = NULL;
			}
		}
	}
	void reach() {
		comerR++;
		take();
	}
	bool take() {
		if (comerR == 2) {
			printf("%03d:%02d blue headquarter was taken\n", myHour, myMinute);
			return true;
		}
		else return false;
	}
	void report() {
		for (int i = 1; i <= N + 1; i++) {
			int a = 0, b = 0, s = 0;
			if (city[i].r) {
				printf("%03d:%02d red %s %d has ", myHour, myMinute, city[i].r->name.data(), city[i].r->idNumber);
				if (city[i].r->sword || city[i].r->bomb || city[i].r->arrow) {
					if (city[i].r->arrow && !a) { printf("arrow(%d)", city[i].r->arrow->frequency); a = 1; }
					else if (city[i].r->bomb && !b) { printf("bomb"); b = 1; }
					else if (city[i].r->sword && !s) { printf("sword(%d)", city[i].r->sword->force); s = 1; }
					if (city[i].r->bomb && !b) { printf(",bomb");}
					else if (city[i].r->sword && !s) { printf(",sword(%d)", city[i].r->sword->force); s = 1; }
					if (city[i].r->sword && !s) { printf(",sword(%d)", city[i].r->sword->force); }
				}
				else { printf("no weapon"); }
				printf("\n");
			}
		}
	}
	void toShot(int i) {
		city[i + 1].b->elements -= R;
		city[i].r->arrow->frequency--;
		if (city[i].r->arrow->frequency == 0) { delete city[i].r->arrow; city[i].r->arrow = NULL; }
		printf("%03d:%02d red %s %d shot", myHour, myMinute, city[i].r->name.data(), city[i].r->idNumber);
		if (city[i + 1].b->elements <= 0) {
			printf(" and killed blue %s %d\n", city[i + 1].b->name.data(), city[i + 1].b->idNumber);
		}
		else {
			printf("\n");
		}
	}
};
class Blue :public Headquarter {
public:
	Blue(const char *s) :Headquarter(s) {}
	void born(int *order, int n) {
		if (order[n] == 0) {
			wNum++;
			city[N + 1].M -= draE;
			dragon = new Dragon((double)city[N + 1].M / (double)draE);
			dragon->head = "blue";
			dragon->equipWeapon(wNum % 3);
			city[N + 1].b = dragon;
			printf("%03d:%02d blue dragon %d born\n", myHour, myMinute, wNum);
			printf("Its morale is %.2f\n", dragon->morale);
		}
		else if (order[n] == 1) {
			wNum++;
			city[N + 1].M -= ninE;
			ninja = new Ninja;
			ninja->head = "blue";
			ninja->equipWeapon(wNum % 3);
			ninja->equipWeapon((wNum + 1) % 3);
			city[N + 1].b = ninja;
			printf("%03d:%02d blue ninja %d born\n", myHour, myMinute, wNum);
		}
		else if (order[n] == 2) {
			wNum++;
			city[N + 1].M -= iceE;
			iceman = new Iceman;
			iceman->head = "blue";
			iceman->equipWeapon(wNum % 3);
			city[N + 1].b = iceman;
			printf("%03d:%02d blue iceman %d born\n", myHour, myMinute, wNum);
		}
		else if (order[n] == 3) {
			wNum++;
			city[N + 1].M -= lionE;
			lion = new Lion;
			lion->head = "blue";
			lion->loyalty = city[N + 1].M;
			city[N + 1].b = lion;
			printf("%03d:%02d blue lion %d born\n", myHour, myMinute, wNum);
			printf("Its loyalty is %d\n", lion->loyalty);
		}
		else if (order[n] == 4) {
			wNum++;
			city[N + 1].M -= wolfE;
			wolf = new Wolf;
			wolf->head = "blue";
			city[N + 1].b = wolf;
			printf("%03d:%02d blue wolf %d born\n", myHour, myMinute, wNum);
		}
		city[N + 1].b->idNumber = wNum;
		city[N + 1].b->wCity = N + 1;
	}
	void toEscape() {
		for (int i = 1; i <= N + 1; i++) {
			if (city[i].b && strcmp(city[i].b->name.data(), "lion") == 0) {
				if (city[i].b->loyalty <= 0) {
					printf("%03d:%02d blue lion %d ran away\n", myHour, myMinute, city[i].b->idNumber);
					delete city[i].b;
					city[i].b = NULL;
				}
			}
		}
	}
	void toMarch(int i) {
		city[i].b->wCity--;
		city[i - 1].b = city[i].b;
		city[i].b = NULL;
		if (strcmp(city[i - 1].b->name.data(), "iceman") == 0) {
			city[i - 1].b->steps++;
			if (city[i - 1].b->steps % 2 == 0) {
				city[i - 1].b->elements -= 9;
				city[i - 1].b->wForce += 20;
				if (city[i - 1].b->elements <= 0) {
					city[i - 1].b->elements = 1;
				}
			}
		}
	}
	void toShot(int i) {
		city[i - 1].r->elements -= R;
		city[i].b->arrow->frequency--;
		if (city[i].b->arrow->frequency == 0) { delete city[i].b->arrow; city[i].b->arrow = NULL; }
		printf("%03d:%02d blue %s %d shot", myHour, myMinute, city[i].b->name.data(), city[i].b->idNumber);
		if (city[i - 1].r->elements <= 0) {
			printf(" and killed red %s %d\n", city[i - 1].r->name.data(), city[i - 1].r->idNumber);
		}
		else {
			printf("\n");
		}
	}
	void toFirstEarn(int i) {
		if (city[i].b && !city[i].r) {
			city[N + 1].M += city[i].M;
			printf("%03d:%02d blue %s %d earned %d elements for his headquarter\n", myHour, myMinute, city[i].b->name.data(), city[i].b->idNumber, city[i].M);
			city[i].M = 0;
		}
	}
	void toUseBomb(int i) {
		if ((city[i].flag == 'b' || (city[i].flag == '0' && i % 2 == 0)) && strcmp(city[i].r->name.data(), "ninja") != 0 && (city[i].b->wForce + (city[i].b->sword ? city[i].b->sword->force : 0)) < city[i].r->elements) {
			if ((city[i].r->wForce / 2 + (city[i].r->sword ? city[i].r->sword->force : 0)) >= city[i].b->elements) {
				printf("%03d:%02d blue %s %d used a bomb and killed red %s %d\n", myHour, myMinute, city[i].b->name.data(), city[i].b->idNumber, city[i].r->name.data(), city[i].r->idNumber);
				delete city[i].r, city[i].b;
				city[i].r = NULL;
				city[i].b = NULL;
			}
		}
		else if ((city[i].flag == 'r' || (city[i].flag == '0' && i % 2 != 0))) {
			if ((city[i].r->wForce + (city[i].r->sword ? city[i].r->sword->force : 0) >= city[i].b->elements)) {
				printf("%03d:%02d blue %s %d used a bomb and killed red %s %d\n", myHour, myMinute, city[i].b->name.data(), city[i].b->idNumber, city[i].r->name.data(), city[i].r->idNumber);
				delete city[i].r, city[i].b;
				city[i].r = NULL;
				city[i].b = NULL;
			}
		}
	}
	void reach() {
		printf("%03d:%02d ", myHour, myMinute);
		printf("blue %s %d reached red headquarter with %d elements and force %d\n", city[0].b->name.data(), city[0].b->idNumber, city[0].b->elements, city[0].b->wForce);
		comerB++;
		take();
	}
	bool take() {
		if (comerB == 2) {
			printf("%03d:%02d red headquarter was taken\n", myHour, myMinute);
			return true;
		}
		else return false;
	}
	void report() {
		for (int i = 0; i <= N; i++) {
			int a = 0, b = 0, s = 0;
			if (city[i].b) {
				printf("%03d:%02d blue %s %d has ", myHour, myMinute, city[i].b->name.data(), city[i].b->idNumber);
				if (city[i].b->sword || city[i].b->bomb || city[i].b->arrow) {
					if (city[i].b->arrow && !a) { printf("arrow(%d)", city[i].b->arrow->frequency); a = 1; }
					else if (city[i].b->bomb && !b) { printf("bomb"); b = 1; }
					else if (city[i].b->sword && !s) { printf("sword(%d)", city[i].b->sword->force); s = 1; }
					if (city[i].b->bomb && !b) { printf(",bomb"); b = 1; }
					else if (city[i].b->sword && !s) { printf(",sword(%d)", city[i].b->sword->force); s = 1; }
					if (city[i].b->sword && !s) { printf(",sword(%d)", city[i].b->sword->force); s = 1; }
				}
				else { printf("no weapon"); }
				printf("\n");
			}
		}
	}
};

void toFight(int i) {
	if (city[i].flag == 'r' && city[i].b->elements > 0) city[i].r->attack(city[i].b);
	else if (city[i].flag == 'b' && city[i].r->elements > 0) city[i].b->attack(city[i].r);
	else if (i % 2 != 0) city[i].r->attack(city[i].b);
	else if (i % 2 == 0) city[i].b->attack(city[i].r);
	if (city[i].b->elements <= 0) {
		rWin(i);
	}
	else if (city[i].r->elements <= 0) {
		bWin(i);
	}
	else {
		city[i].rf = city[i].bf = false;
	}
}
void rWin(int i) {
	if (strcmp(city[i].r->name.data(), "wolf") == 0) { city[i].r->getWeapon(city[i].b); }	
	printf("%03d:%02d red %s %d earned %d elements for his headquarter\n", myHour, myMinute, city[i].r->name.data(), city[i].r->idNumber, city[i].M);
	delete city[i].b;
	city[i].b = NULL;
	if (city[i].rf && (city[i].flag != 'r')) city[i].rise(0, i);
	city[i].rf = true;
	city[i].bf = false;
}
void bWin(int i) {
	if (strcmp(city[i].b->name.data(), "wolf") == 0) { city[i].b->getWeapon(city[i].r); }
	printf("%03d:%02d blue %s %d earned %d elements for his headquarter\n", myHour, myMinute, city[i].b->name.data(), city[i].b->idNumber, city[i].M);
	delete city[i].r;
	city[i].r = NULL;
	if (city[i].bf && city[i].flag != 'b') city[i].rise(1, i);
	city[i].bf = true;
	city[i].rf = false;
}
int main() {
	//freopen("D:/in.txt","r",stdin);  
	//freopen("D:/out.txt","w",stdout);
	int t, M, T;
	cin >> t;
	int tmp;
	for (tmp = 1; tmp <= t; tmp++) {
		cin >> M >> N >> R >> K >> T;
		cin >> draE >> ninE >> iceE >> lionE >> wolfE;
		cin >> draF >> ninF >> iceF >> lionF >> wolfF;
		int r[5] = { iceE, lionE, wolfE, ninE, draE }, b[5] = { lionE, draE, ninE, iceE, wolfE };
		int r1[5] = { 2,3,4,1,0 }, b1[5] = { 3,0,1,2,4 };
		cout << "Case " << tmp << ":" << endl;
		Red red("red"); Blue blue("blue");
		red.M = M; blue.M = M;
		city[0].M = red.M; city[N + 1].M = blue.M;
		int i = 0, j = 0;
		while ((myHour * 60 + myMinute) <= T) {
			if (city[0].M >= r[i]) {
				red.born(r1, i);
				i++;
			}
			if (city[N + 1].M >= b[j]) {
				blue.born(b1, j);
				j++;
			}
			if (i == 5) i = 0;
			if (j == 5) j = 0;
			myMinute = 5;//5
			if ((myHour * 60 + myMinute) > T)break;
			red.toEscape();
			blue.toEscape();
			myMinute = 10;//10
			if ((myHour * 60 + myMinute) > T)break;
			for (int i = 1; i <= N + 1; i++) {
				if (city[N - i + 1].r) { red.toMarch(N - i + 1); }
				if (city[i].b) { blue.toMarch(i); if (i == 1) blue.reach(); }
			}
			for (int i = 1; i <= N; i++) {
				if (city[i].r) {
					printf("%03d:%02d red %s %d marched to city %d with %d elements and force %d\n", myHour, myMinute, city[i].r->name.data(), city[i].r->idNumber, i, city[i].r->elements, city[i].r->wForce);
				}
				if (city[i].b) {
					printf("%03d:%02d blue %s %d marched to city %d with %d elements and force %d\n", myHour, myMinute, city[i].b->name.data(), city[i].b->idNumber, i, city[i].b->elements, city[i].b->wForce);
				}
			}
			if (city[N + 1].r && city[N + 1].r != red.firstReacher) {
				printf("%03d:%02d ", myHour, myMinute);
				printf("red %s %d reached blue headquarter with %d elements and force %d\n", city[N + 1].r->name.data(), city[N + 1].r->idNumber, city[N + 1].r->elements, city[N + 1].r->wForce);
				red.firstReacher = city[N + 1].r;
				red.reach();
			}
			if (comerR == 2 || comerB == 2) break;
			myMinute = 20;//20
			if ((myHour * 60 + myMinute) > T)break;
			for (int i = 1; i <= N; i++) {
				city[i].M += 10;
			}
			myMinute = 30;//30
			if ((myHour * 60 + myMinute) > T)break;
			for (int i = 1; i < N + 1; i++) {
				red.toFirstEarn(i);
				blue.toFirstEarn(i);
			}
			myMinute = 35;//35
			if ((myHour * 60 + myMinute) > T)break;
			for (int i = 1; i <= N; i++) {
				if (city[i].r && city[i].r->arrow && city[i + 1].b) red.toShot(i);
				if (city[i].b && city[i].b->arrow && city[i - 1].r)blue.toShot(i);
			}
			myMinute = 38;//38
			if ((myHour * 60 + myMinute) > T)break;
			for (int i = 1; i <= N; i++) {
				if (city[i].r && city[i].b) {
					if (city[i].r->elements > 0 && city[i].b->elements > 0) {
						if (city[i].r->bomb) red.toUseBomb(i);
						if (city[i].b && city[i].b->bomb) blue.toUseBomb(i);
					}
				}
			}
			myMinute = 40;//40
			if ((myHour * 60 + myMinute) > T)break;
			for (int i = 1; i <= N; i++) {
				if (city[i].r && city[i].b) {
					city[i].fight = true;
					if (city[i].r->elements > 0 && city[i].b->elements > 0) {
						toFight(i);
					}
					else if (city[i].b->elements > 0 && city[i].r->elements <= 0) {
						if ( city[i].flag == 'b' || (city[i].flag == '0' && (i % 2) == 0)) {
							if (strcmp(city[i].b->name.data(), "dragon") == 0) {
								city[i].b->yell();
							}
						}
						bWin(i);
					}
					else if (city[i].r ->elements > 0 && city[i].b->elements <= 0) {
						if (city[i].flag == 'r' || (city[i].flag == '0' && (i % 2) != 0)) {
							if (strcmp(city[i].r->name.data(), "dragon") == 0) {
								city[i].r->yell();
							}
						}
						rWin(i);
					}
				}
				else {
					city[i].fight = false;
				}
			}
			for (int i = 1; i <= N; i++) {
				if (city[i].fight && city[i].r && city[i].r->elements > 0 && city[i].rf) {
					if (city[0].M >= 8) {
						city[i].r->elements += 8;
						city[0].M -= 8;
					}
					city[0].M += city[i].M;
					city[i].M = 0;
				}
				else if (city[i].r && city[i].r->elements <= 0) {
					delete city[i].r;
					city[i].r = NULL;
				}
				if (city[N - i + 1].fight && city[N - i + 1].b && city[N - i + 1].b->elements > 0 && city[N - i + 1].bf) {
					if (city[N + 1].M >= 8) {
						city[N - i + 1].b->elements += 8;
						city[N + 1].M -= 8;
					}
					city[N + 1].M += city[N - i + 1].M;
					city[N - i + 1].M = 0;
				}
				else if (city[N - i + 1].b && city[N - i + 1].b->elements <= 0) {
					delete city[N - i + 1].b;
					city[N - i + 1].b = NULL;
				}
			}
			myMinute = 50;//50
			if ((myHour * 60 + myMinute) > T)break;
			printf("%03d:%02d %d elements in red headquarter\n", myHour, myMinute, city[0].M);
			printf("%03d:%02d %d elements in blue headquarter\n", myHour, myMinute, city[N + 1].M);
			myMinute = 55;//55
			if ((myHour * 60 + myMinute) > T)break;
			red.report();
			blue.report();
			myHour++; myMinute = 0;//next hour
		}
		for (int i = 0; i <= N + 1; i++) {
			city[i].M = 0;
			city[i].flag = '0';
			delete city[i].r;
			delete city[i].b;
			city[i].bf = false;
			city[i].rf = false;
			city[i].fight = false;
			city[i].r = NULL;
			city[i].b = NULL;
		}
		comerR = comerB = 0;
		myHour = 0;
		myMinute = 0;
	}
	//fclose(stdin);  
	//fclose(stdout);
	return 0;
}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值