写了十个小时,,要挂了。
记录一下。
为了可读性牺牲了巨量码量。
搞忘了用vector导致很多地方的count维护比较费心。
感觉可以维护一下改成下一次作业!
/*
建模:
武器,士兵,玩家,城市,事件
武器:包含使用次数的减少,编号012
考虑到武器攻击时攻击力等机制各有不同,如果使用id区分在cweapon里写太过臃肿
故根据本课所学内容进行派生拆分,多态进行攻击。考虑到每次使用后都可能发生武器数
量变化,故应该时刻进行update。
士兵:包含武器等,攻防判定,特殊机制
与武器顾虑相同,派生拆分,时刻update
玩家:士兵生产;
城市:包含两个cwarrior指针,一个红,一个蓝。士兵前进即反向扫描一遍。
事件:
00:士兵生产
05:lion逃跑
10:士兵前进(iceman掉血,注意是变化量去尾,所以不会走死)(判定结束)
35:wolf抢武器
40:战斗:
定先手:
武器排序1:
判定:如果均无武器,战斗结束(平)。
单步战斗:提取当前武器攻击力(如无则跳过所有步骤),攻击对方,
bomb反伤(ninja特殊),武器寿命降低,武器折损
判定:如果双方都没有武器,战斗结束(平)
如果一方被打到0,战斗结束(胜)。
如果两方都被打到0,战斗结束(平)。
检验死循环:双方只剩下sword且攻击力为0,战斗结束(平)。
武器缴获(前提:胜):武器排序2,武器折损,武器新建
*销毁死亡士兵:注意销毁放在武器缴获之后。
报告战斗情况:
dragon欢呼:战斗过,且没死(红先蓝后)
50:玩家报告生命元数量(红先蓝后)
55:士兵报告武器状态(自西向东,红先蓝后)
*/
#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<algorithm>
#include<iomanip>
#include<unordered_map>
using namespace std;
const int inf = 0x3f3f3f3f;
//-------------------------------------------------------------
unordered_map<const char*, int>life, atk;
class cweapon {
public:
const char* name;
int id, usetime;
public:
cweapon(int _id):id(_id),usetime(0) {
name = new char[7];
if (_id == 0)name = "sword", usetime = inf;
if (_id == 1)name = "bomb", usetime = 1;
if (_id == 2)name = "arrow", usetime = 2;
}
virtual ~cweapon() {
//delete name;
}
virtual int get_atk(int user_atk) = 0;
void modify_usetime() {
usetime--;
}
//获取武器攻击力
};
class csword :public cweapon {
public:
csword():cweapon(0){}
virtual ~csword(){}
int get_atk(int user_atk) {return user_atk * 2 / 10;}
void modify_usetime(){}
};
class cbomb :public cweapon {
public:
cbomb():cweapon(1){}
virtual ~cbomb() {}
int get_atk(int user_atk) {return user_atk * 4 / 10;}
void modify_usetime() {usetime--;}
};
class carrow :public cweapon {
public:
carrow():cweapon(2){}
virtual ~carrow() {}
int get_atk(int user_atk) {return user_atk * 3 / 10;}
void modify_usetime() { usetime--; }
};
//--------------------------------------------------------------
class cwarrior{
public:
int id,life, atk, city;
const char* name;
cweapon* weapon[11];
int weapon_count;
int weapon_pos;
int warrior_count;
cwarrior(int _id,int _life,int _atk,const char* _name,int _warrior_count):
id(_id),life(_life),atk(_atk),weapon_count(0),name(_name),warrior_count(_warrior_count) {}
virtual ~cwarrior() {
//delete[] weapon;
}
void new_weapon(int _id) {
++weapon_count;
if (_id == 0)weapon[weapon_count] = new csword;
if (_id == 1)weapon[weapon_count] = new cbomb;
if (_id == 2)weapon[weapon_count] = new carrow;
}
virtual void lifelose() = 0;//特别针对iceman的移动丢血。
virtual void loyaltylose(int _loyaltylose) = 0;//特别针对lion忠诚度丢失。
void hurt(int damage) {
life -= damage;
}
virtual void back_hurt(int damage) = 0;
virtual int get_loyalty() = 0;
};
class cdragon :public cwarrior {
public:
cdragon(int _id,int _life,int _atk, int _warrior_count) :
cwarrior(_id, _life, _atk,"dragon", _warrior_count) {
new_weapon(id % 3);
}
virtual ~cdragon(){}
void lifelose(){}
void loyaltylose(int _loyaltylose){}
void back_hurt(int damage) {
life -= damage;
}
int get_loyalty() { return 0; }
};
class cninja :public cwarrior {
public:
cninja(int _id,int _life,int _atk, int _warrior_count) :
cwarrior(_id, _life, _atk, "ninja", _warrior_count) {
new_weapon(id % 3); new_weapon((id + 1) % 3);
}
virtual ~cninja() {}
void lifelose() {}
void loyaltylose(int _loyaltylose){}
void back_hurt(int damage) {}
int get_loyalty() { return 0; }
};
class ciceman :public cwarrior {
public:
ciceman(int _id, int _life, int _atk, int _warrior_count) :
cwarrior(_id, _life, _atk, "iceman", _warrior_count) {
new_weapon(id % 3);
}
virtual ~ciceman() {}
void lifelose() {
life = life - life / 10;
}
void loyaltylose(int _loyaltylose){}
void back_hurt(int damage) {
life -= damage;
}
int get_loyalty() { return 0; }
};
class clion :public cwarrior {
public:
int loyalty;
clion(int _id, int _life, int _atk,int _rest, int _warrior_count) :
cwarrior(_id, _life, _atk, "lion", _warrior_count) {
new_weapon(id % 3); loyalty = _rest;
}
virtual ~clion() {}
void lifelose() {}
void loyaltylose(int _loyaltylose) {
loyalty -= _loyaltylose;
}
void back_hurt(int damage) {
life -= damage;
}
int get_loyalty() { return loyalty; }
};
class cwolf :public cwarrior {
public:
cwolf(int _id, int _life, int _atk,int _warrior_count) :
cwarrior(_id, _life, _atk,"wolf",_warrior_count) {}
virtual ~cwolf() {}
void lifelose() {}
void loyaltylose(int _loyaltylose){}
void back_hurt(int damage) {
life -= damage;
}
int get_loyalty() { return 0; }
};
//------------------------------------------------------------
unordered_map<const char*, cwarrior* > City[22];
class cplayer {
public:
int flag;//判定是否还要继续制造武士,为1则停止;
int lifeyuan;//生命元
cwarrior* warrior[22];//维护当前仍存活士兵
int warrior_count;//会减少,维护数组指针
int warrior_id;//不会减少,记录士兵编号
unordered_map<int, const char*> new_baby;
int new_pos;
cplayer(int _lifeyuan,char c){
lifeyuan = _lifeyuan;
warrior_count = 0; new_pos = 0; warrior_id = 0; flag = 0;
if (c == 'R') {
new_baby.insert({ 0,"iceman" });
new_baby.insert({ 1,"lion" });
new_baby.insert({ 2,"wolf" });
new_baby.insert({ 3,"ninja" });
new_baby.insert({ 4,"dragon" });
}
else {
new_baby.insert({ 0,"lion" });
new_baby.insert({ 1,"dragon" });
new_baby.insert({ 2,"ninja" });
new_baby.insert({ 3,"iceman" });
new_baby.insert({ 4,"wolf" });
}
}
~cplayer() {
//delete[] warrior;
}
bool new_warrior(const char* _player,int city_count) {
const char* name = new_baby[new_pos];
int _life = life[name];
if (_life > lifeyuan)return false;
++warrior_id;
lifeyuan -= _life;
++warrior_count;
if (name == "dragon") {
warrior[warrior_count] = new cdragon(warrior_id, life["dragon"], atk["dragon"], warrior_count);
}
else if (name == "ninja") {
warrior[warrior_count] = new cninja(warrior_id, life["ninja"], atk["ninja"], warrior_count);
}
else if (name == "iceman") {
warrior[warrior_count] = new ciceman(warrior_id, life["iceman"], atk["iceman"], warrior_count);
}
else if (name == "lion") {
warrior[warrior_count] = new clion(warrior_id, life["lion"], atk["lion"], lifeyuan, warrior_count);
}
else if (name == "wolf") {
warrior[warrior_count] = new cwolf(warrior_id, life["wolf"], atk["wolf"], warrior_count);
}
++new_pos;
new_pos %= 5;
if (_player == "red")City[0]["red"] = warrior[warrior_count];
else City[city_count+1]["blue"] = warrior[warrior_count];
return true;
}
};
//----------------------------------------------------------------------------------------
void print_2num(int t) {
if (t < 10)cout << "0";
cout << t;
}
void print_3num(int Hour) {
if (Hour < 10)cout << "00";
else if (Hour < 100)cout << "0";
cout << Hour;
}
void print_time(int Hour, int t) {
print_3num(Hour); cout << ":"; print_2num(t); cout << " ";
}
void print_lion_born(int loyalty) {
cout << "Its loyalty is " << loyalty << endl;
}
void print_player_newwarrior(const char* name, cplayer& player,int Hour) {
print_time(Hour, 0);
cout << name << " ";
int pos = player.warrior_count;
cout << player.warrior[pos]->name << " " << player.warrior[pos]->id << " born" << endl;
if (player.warrior[pos]->name == "lion") {
print_lion_born(player.warrior[pos]->get_loyalty());
}
}
void print_lion_escaped(const char* name, cwarrior* warrior, int Hour) {
print_time(Hour, 5);
cout << name << " " << "lion " << warrior->id << " ran away" << endl;
}
void print_who_is_reached(const char* winner_name,const char* loser_name, cwarrior* warrior, int Hour) {
print_time(Hour, 10);
cout << winner_name << " " << warrior->name << " " << warrior->id <<
" reached "<<loser_name<<" headquarter with " << warrior->life << " elements and force " << warrior->atk << endl;
}
void print_who_is_taken(const char* name, int Hour) {
print_time(Hour, 10);
cout << name << " headquarter was taken" << endl;
}
void print_marched(const char* name, cwarrior* warrior, int city_number, int Hour) {
print_time(Hour, 10);
cout << name << " " << warrior->name << " " << warrior->id << " marched to city " << city_number
<< " with " << warrior->life << " elements and force " << warrior->atk<<endl;
}
void print_player_lifeyuan(cplayer& player,const char* name, int Hour) {
print_time(Hour, 50);
cout << player.lifeyuan << " elements in " << name << " headquarter" << endl;
}
void print_warrior_weapon(const char* name,cwarrior* warrior, int Hour) {
print_time(Hour, 55);
cout << name << " " << warrior->name << " " << warrior->id << " has ";
int weapon_count[3] = { 0 };
for (int i = 1; i <= warrior->weapon_count; ++i) {
weapon_count[warrior->weapon[i]->id]++;
}
cout << weapon_count[0] << " sword ";
cout << weapon_count[1] << " bomb ";
cout << weapon_count[2] << " arrow ";
cout << "and " << warrior->life << " elements";
cout << endl;
}
void print_grab_weapon(const char* graber, const char* be_grabeder,
cwarrior* a, cwarrior* b, const char* weapon_name, int taken_count, int city_number, int Hour) {
print_time(Hour, 35);
cout << graber << " " << a->name << " " << a->id << " took " << taken_count << " "
<< weapon_name << " from " << be_grabeder << " " << b->name << " " << b->id
<< " in city " << city_number << endl;
}
void print_win_lose(const char* winner_name, cwarrior* winner,
const char* loser_name, cwarrior* loser, int city_number,int Hour) {
print_time(Hour, 40);
cout << winner_name << " " << winner->name << " " << winner->id << " killed " <<
loser_name << " " << loser->name << " " << loser->id << " in city " <<
city_number << " remaining " << winner->life << " elements" << endl;
}
void print_die_together(cwarrior* a, cwarrior* b,int city_number,int Hour) {
print_time(Hour, 40);
cout << "both red " << a->name << " " << a->id
<< " and blue " << b->name << " " << b->id << " died in city " << city_number << endl;
}
void print_alive_together(cwarrior* a, cwarrior* b, int city_number, int Hour) {
print_time(Hour, 40);
cout << "both red " << a->name << " " << a->id
<< " and blue " << b->name << " " << b->id << " were alive in city " << city_number << endl;
}
void print_yelled(const char* name, cwarrior* warrior, int city_number, int Hour) {
print_time(Hour, 40);
cout << name << " " << warrior->name << " " << warrior->id << " yelled in city " << city_number << endl;
}
//----------------------------------------------------------------------------------------
void prepare(int N) {
int _life, _atk;
cin >> _life; life.insert({ "dragon", _life });
cin >> _life; life.insert({ "ninja",_life });
cin >> _life; life.insert({ "iceman", _life });
cin >> _life; life.insert({ "lion",_life });
cin >> _life; life.insert({ "wolf",_life });
cin >> _atk; atk.insert({ "dragon", _atk });
cin >> _atk; atk.insert({ "ninja",_atk });
cin >> _atk; atk.insert({ "iceman", _atk });
cin >> _atk; atk.insert({ "lion",_atk });
cin >> _atk; atk.insert({ "wolf",_atk });
for (int i = 0; i <= N + 1; ++i) {
City[i]["red"] = NULL;
City[i]["blue"] = NULL;
}
}
void Delete_warrior(cwarrior* poorguy, cplayer& player) {
//提取指针所记载的,其在对应玩家下保存数组的下标,根据下标进行delete
//删除后,将后面的怪物前移
int warrior_count = poorguy->warrior_count;
//delete player.warrior[warrior_count];
for (int i = warrior_count; i < player.warrior_count; ++i) {
player.warrior[i] = player.warrior[i + 1];
player.warrior[i]->warrior_count = i;
}
player.warrior[player.warrior_count] = NULL;
player.warrior_count--;
}
bool cweapon_cmp_attack(cweapon* a, cweapon* b) {
if (a->id != b->id)return a->id < b->id;
if (a->id == 2)return a->usetime < b->usetime;
return true;
}
bool cweapon_cmp_grab(cweapon* a, cweapon* b) {
if (a->id != b->id)return a->id < b->id;
if (a->id == 2)return a->usetime > b->usetime;
return true;
}
void sort_weapon_grab(cweapon** weapon, int size,bool(*cmp)(cweapon*, cweapon*)) {
for (int i = 1; i < size; ++i) {
for (int j = 1; j <=size-i; ++j) {
if (cmp(weapon[j], weapon[j+1])) {
swap(weapon[j], weapon[j+1]);
}
}
}
}
void sort_weapon_battle(cweapon** weapon, int size, bool(*cmp)(cweapon*, cweapon*)) {
for (int i = 1; i < size; ++i) {
for (int j = 1; j <=size-i; ++j) {
if (!cmp(weapon[j], weapon[j+1])) {
swap(weapon[j], weapon[j+1]);
}
}
}
}
void weapon_steal(const char* graber,const char* be_grabeder,cwarrior* a, cwarrior* b, int city_number,int Hour) {
//a抢b的
//1:给b的武器排序2
sort_weapon_grab(b->weapon,b->weapon_count, cweapon_cmp_grab);
//注:按照逆优先级排序,从后面开始拿,方便删除
if (!b->weapon_count)return;
int bpos = b->weapon_count+1;
int weapon_id = b->weapon[bpos - 1]->id;
const char* weapon_name = b->weapon[bpos - 1]->name;
int taken_count = 0;
for (int i = a->weapon_count + 1; i <= 10; ++i) {
--bpos;
if (!bpos)break;
if (b->weapon[bpos]->id != weapon_id)break;
++a->weapon_count; ++taken_count;
a->weapon[i] = b->weapon[bpos];
b->weapon[bpos] = NULL;
--b->weapon_count;
}
print_grab_weapon(graber, be_grabeder, a, b, weapon_name, taken_count, city_number,Hour);
}
bool check_before(cwarrior* fighter, cwarrior* be_fighteder) {
if (!fighter->weapon_count && !be_fighteder->weapon_count)return false;
bool all_sword_fighter = true;
int fighter_weapon_count = 0;
int be_fighteder_weapon_count = 0;
for (int i = 1; i <= fighter->weapon_count; ++i) {
if (!fighter->weapon[i]->usetime)continue;
++fighter_weapon_count;
if (fighter->weapon[i]->name != "sword") {
all_sword_fighter = false; break;
}
}
bool all_sword_be_fighteder = true;
for (int i = 1; i <= be_fighteder->weapon_count; ++i) {
if (!be_fighteder->weapon[i]->usetime)continue;
++be_fighteder_weapon_count;
if (be_fighteder->weapon[i]->name != "sword") {
all_sword_be_fighteder = false; break;
}
}
if (!fighter_weapon_count && !be_fighteder_weapon_count)
{
return false;
}
if (all_sword_fighter && all_sword_be_fighteder) {
bool no_atk = true;
if (fighter->weapon_count) {
if (fighter->weapon[1]->get_atk(fighter->atk)) {
no_atk = false;
}
}
if (be_fighteder->weapon_count) {
if (be_fighteder->weapon[1]->get_atk(be_fighteder->atk)) {
no_atk = false;
}
}
if (no_atk)return false;
}
return true;
}
bool choose_weapon(cwarrior* fighter,cweapon* &choice) {
if (!fighter->weapon_count)return false;
choice = fighter->weapon[fighter->weapon_pos];
for (int i = 1; i <= fighter->weapon_count;++i) {
if (choice->usetime)return true;
++fighter->weapon_pos;
if (fighter->weapon_pos == fighter->weapon_count+1)
fighter->weapon_pos = 1;
choice = fighter->weapon[fighter->weapon_pos];
}
return false;
}
void reorganize_weapon(cwarrior* warrior) {
cweapon* temp[12];
int now_size = 0;
for (int i = 1; i <= warrior->weapon_count; ++i) {
if (warrior->weapon[i]->usetime)temp[++now_size] = warrior->weapon[i];
//else delete warrior->weapon[i];
}
warrior->weapon_count = now_size;
for (int i = 1; i <= now_size; ++i)
warrior->weapon[i] = temp[i];
}
void pick_up_weapon(cwarrior* a, cwarrior* b) {
//a抢b的
//1:给b的武器排序2
sort_weapon_grab(b->weapon, b->weapon_count, cweapon_cmp_grab);
//注:按照逆优先级排序,从后面开始拿,方便删除
if (!b->weapon_count)return;
int bpos = b->weapon_count + 1;
const char* weapon_name = b->weapon[bpos - 1]->name;
int taken_count = 0;
for (int i = a->weapon_count + 1; i <= 10; ++i) {
--bpos;
if (!bpos)break;
if (!b->weapon[bpos]->usetime)continue;
++a->weapon_count; ++taken_count;
a->weapon[i] = b->weapon[bpos];
b->weapon[bpos] = NULL;
--b->weapon_count;
}
}
void battle(cplayer& R, cplayer& B, cwarrior* red_warrior, cwarrior* blue_warrior, int city_number, int Hour) {
cwarrior* fighter;
cwarrior* be_fighteder;
cwarrior* winner=red_warrior;
cwarrior* loser=blue_warrior;
int win_lose = 0;//0都活,1分出胜负,2都死
if (city_number & 1) {
fighter = red_warrior;
be_fighteder = blue_warrior;
}
else {
fighter = blue_warrior;
be_fighteder = red_warrior;
}
sort_weapon_battle(fighter->weapon, fighter->weapon_count, cweapon_cmp_attack);
sort_weapon_battle(be_fighteder->weapon, be_fighteder->weapon_count, cweapon_cmp_attack);
fighter->weapon_pos = 1; be_fighteder->weapon_pos = 1;
while (check_before(fighter, be_fighteder)) {
/*print_warrior_weapon("XXXXXXX", fighter, 0);
print_warrior_weapon("OOOOOOO", be_fighteder, 0);
if (fighter->name == "ninja") {
for (int i = 1; i <= fighter->weapon_count; ++i) {
cout << fighter->weapon[i]->name << " " << fighter->weapon[i]->usetime << endl;
}
}
*/
cweapon* weapon_choice=fighter->weapon[1];
//cout << fighter->weapon_count << endl << fighter->weapon_pos << endl;
if (!choose_weapon(fighter, weapon_choice)) {
swap(fighter, be_fighteder);
continue;
}
//cout << weapon_choice->name << endl;
//选不出武器,走人
++fighter->weapon_pos;
if (fighter->weapon_pos == fighter->weapon_count + 1)
fighter->weapon_pos = 1;
int atk = weapon_choice->get_atk(fighter->atk);
be_fighteder->hurt(atk);
if (weapon_choice->name == "bomb") {
fighter->back_hurt(atk / 2);
}
weapon_choice->modify_usetime();
if (fighter->life <= 0 && be_fighteder->life > 0) {
winner = be_fighteder; loser = fighter;
win_lose = 1;
break;
}
if (fighter->life <= 0 && be_fighteder->life <= 0) {
win_lose = 2;
break;
}
if (fighter->life > 0 && be_fighteder->life <= 0) {
winner = fighter; loser = be_fighteder;
win_lose = 1;
break;
}
swap(fighter, be_fighteder);
}
reorganize_weapon(winner); reorganize_weapon(loser);
if (win_lose==1) {
if (loser == red_warrior)
print_win_lose("blue", winner, "red", loser, city_number,Hour);
else print_win_lose("red", winner, "blue", loser, city_number,Hour);
pick_up_weapon(winner, loser);
if (loser == red_warrior)
{
Delete_warrior(loser, R);
City[city_number]["red"] = NULL;
if (winner->name == "dragon") {
print_yelled("blue", blue_warrior, city_number, Hour);
}
}
else
{
Delete_warrior(loser, B);
City[city_number]["blue"] = NULL;
if (winner->name == "dragon") {
print_yelled("red", red_warrior, city_number, Hour);
}
}
}
else {//未分出胜负
if (win_lose == 2) {//同归于尽
print_die_together(red_warrior, blue_warrior,city_number,Hour);
City[city_number]["red"] = NULL;
City[city_number]["blue"] = NULL;
}
else {
print_alive_together(red_warrior,blue_warrior,city_number,Hour);
if (red_warrior->name == "dragon") {
print_yelled("red", red_warrior, city_number, Hour);
}
if (blue_warrior->name == "dragon") {
print_yelled("blue", blue_warrior, city_number, Hour);
}
}
}
}
bool work(cplayer& R,cplayer& B,int _life,int city_count,int K,int T,int Hour) {
/*事件:
00:士兵生产
05:lion逃跑
10:士兵前进(iceman掉血,注意是变化量去尾,所以不会走死)(判定结束)
35:wolf抢武器
40:战斗:
定先手:
武器排序1:
判定:如果均无武器,死循环(双方只剩下sword且攻击力为0)战斗结束(平)。
单步战斗:提取当前武器攻击力(如无则跳过所有步骤),攻击对方,
bomb反伤(ninja特殊),武器寿命降低,武器折损
判定:
如果一方被打到0,战斗结束(胜)。
如果两方都被打到0,战斗结束(平)。
武器缴获(前提:胜):武器排序2,武器新建
*销毁死亡士兵:注意销毁放在武器缴获之后。
报告战斗情况:
dragon欢呼:战斗过,且没死(红先蓝后)
50:玩家报告生命元数量(红先蓝后)
55:士兵报告武器状态(自西向东,红先蓝后)*/
//00:士兵生产
if (!R.flag) {
if (!R.new_warrior("red", city_count))R.flag = 1;
else
print_player_newwarrior("red", R,Hour);
}
if (!B.flag) {
if (!B.new_warrior("blue", city_count))B.flag = 1;
else print_player_newwarrior("blue", B, Hour);
}
//05:lion逃跑
if (T < 5)return true;
for (int i = 0; i <= city_count + 1; ++i) {
if (City[i]["red"]!=NULL&&City[i]["red"]->name == "lion") {
if (City[i]["red"]->get_loyalty() <= 0) {
print_lion_escaped("red", City[i]["red"], Hour);
Delete_warrior(City[i]["red"],R);
City[i]["red"] = NULL;
}
}
if (City[i]["blue"] != NULL && City[i]["blue"]->name == "lion") {
if (City[i]["blue"]->get_loyalty() <= 0) {
print_lion_escaped("blue", City[i]["blue"], Hour);
Delete_warrior(City[i]["blue"],B);
City[i]["blue"] = NULL;
}
}
}
//10:士兵前进,iceman生命值丢失,lion忠诚度丢失
if (T < 10)return true;
for (int i = city_count + 1; i >= 1; --i) {
City[i]["red"] = City[i - 1]["red"];
if (City[i]["red"] != NULL) {
City[i]["red"]->lifelose();
City[i]["red"]->loyaltylose(K);
}
}
City[0]["red"] = NULL;
for (int i = 0; i <= city_count; ++i) {
City[i]["blue"] = City[i + 1]["blue"];
if (City[i]["blue"] != NULL) {
City[i]["blue"]->lifelose();
City[i]["blue"]->loyaltylose(K);
}
}
City[city_count + 1]["blue"] = NULL;
int flag = 0;
if (City[0]["blue"] != NULL) {
print_who_is_reached("blue","red", City[0]["blue"], Hour);
print_who_is_taken("red", Hour);
flag = 1;
}
for (int i = 1; i <= city_count; ++i) {
if (City[i]["red"] != NULL) {
print_marched("red", City[i]["red"], i, Hour);
}
if (City[i]["blue"] != NULL) {
print_marched("blue", City[i]["blue"], i, Hour);
}
}
if (City[city_count + 1]["red"] != NULL) {
print_who_is_reached("red","blue", City[city_count+1]["red"], Hour);
print_who_is_taken("blue", Hour);
flag = 1;
}
if (flag)return false;
//35:wolf抢武器
if (T < 35)return true;
for (int i = 1; i <= city_count; ++i) {
if (City[i]["red"] == NULL || City[i]["blue"] == NULL)continue;
if (City[i]["red"]->name == "wolf" && City[i]["blue"]->name != "wolf") {
weapon_steal("red","blue",City[i]["red"], City[i]["blue"], i,Hour);
//输出在weapon_steal中进行
}
if (City[i]["blue"]->name == "wolf" && City[i]["red"]->name != "wolf") {
weapon_steal("blue","red",City[i]["blue"], City[i]["red"], i,Hour);
//输出在weapon_steal中进行
}
}
//40:战斗
if (T < 40)return true;
for (int i = 1; i <= city_count; ++i) {
if (City[i]["red"] != NULL && City[i]["blue"] != NULL) {
battle(R,B,City[i]["red"],City[i]["blue"],i,Hour);
}
}
//50:玩家报告生命元状态
if (T < 50)return true;
print_player_lifeyuan(R, "red",Hour); print_player_lifeyuan(B,"blue", Hour);
//55:士兵报告武器状态
if (T < 55)return true;
for (int i = 1; i <= city_count; ++i) {
if (City[i]["red"] != NULL)print_warrior_weapon("red",City[i]["red"], Hour);
if (City[i]["blue"] != NULL)print_warrior_weapon("blue",City[i]["blue"], Hour);
}
return true;
}
signed main() {
//FILE* stream;
//freopen_s(&stream, "datapub.in", "r", stdin);
//freopen_s(&stream, "my.txt", "w", stdout);
int t;
cin >> t;
for(int Case=1;Case<=t;++Case){
life.clear(); atk.clear();
cout << "Case " << Case << ":" << endl;
int M, N, K, T;
cin >> M >> N >> K >> T;
for (int i = 0; i <= N + 1; ++i)City[i].clear();
cplayer R(M,'R'), B(M,'B');
prepare(N);
int Hour = 0;
while (T>=0) {
int _hour = T / 60;
if (_hour)
{
if (!work(R, B, M, N, K, 60,Hour))break;
}
else if (!work(R, B, M, N, K, T,Hour))break;
++Hour; T -= 60;
}
}
return 0;
}