[Programming homework] World of Warcraft III: War

After writing for ten hours, I’m going to hang up.
record it.
A huge amount of code is sacrificed for readability.
I forgot to use vector to cause count maintenance in many places to be troublesome.
I feel that it can be maintained and changed to the next assignment!

/*
Modeling:
weapons, soldiers, players, cities, events
Weapon: Contains the reduction of the number of uses, number 012
Considering that the attack power and other mechanisms are different when weapons attack, it is too bloated to use id to distinguish in cweapon
Therefore, according to the content learned in this lesson, derivation and splitting are carried out, and polymorphic attacks are carried out. Taking into account the number of weapons that can occur after each use
The amount changes, so it should be updated at all times.
Soldiers: including weapons, etc., attack and defense judgment, special mechanism
Same as weapon concerns, derivation and splitting, always update
Player: Soldier production;
City: Contains two cwarrior pointers, one red and one blue. When the soldiers move forward, they scan in reverse.
event:
00: Soldier production
05: The lion escapes
10: Soldiers move forward (iceman loses blood, note that the tail of the change is removed, so he will not walk to death) (judgment ends)
35: Wolf grabs weapons
40: Combat:
Set the first move:
Weapon sort 1:
Judgment: If there are no weapons, the battle ends (tie).
Single-step combat: extract the current weapon attack power (skip all steps if none), attack the opponent,
Bomb anti-injury (ninja special), weapon life reduction, weapon breakage
Judgment: If both sides have no weapons, the battle ends (tie)
If one side is hit to 0, the battle ends (wins).
If both sides are hit to 0, the battle is over (tie).
Check the infinite loop: the two sides only have swords and their attack power is 0, and the battle ends (tie).
Weapon Capture (Prerequisite: Win): Weapon Rank 2, Weapon Damage, New Weapon
*Destroy dead soldiers: Note that the destruction is placed after the weapons are seized.
Report the combat situation:
Dragon cheers: I have fought, and I am not dead (red first, blue later)
50: The number of life units reported by the player (red first and blue later)
55: Soldiers report weapon status (from west to east, red first and blue later)
*/

#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--;
}
// Get weapon attack power
};
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 arrow :public cweapon {<!-- -->
public:
arrow():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 arrow;
}
virtual void lifelose() = 0;//Specially for iceman's mobile blood loss.
virtual void loyallose(int _loyaltylose) = 0;//Specially for lion loyalty loss.
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;//Determine whether to continue to make warriors, if it is 1, stop;
int lifeyuan;//life yuan
cwarrior* warrior[22];//maintain the currently surviving soldiers
int warrior_count;//will decrease, maintain array pointer
int warrior_id;//will not decrease, record soldier number
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 & amp; 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 & amp; 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 & amp; player) {<!-- -->
//Extract what is recorded in the pointer, save the subscript of the array under the corresponding player, and delete according to the subscript
// After deleting, move the monster behind
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 grabs b
//1: Sort b's weapons 2
sort_weapon_grab(b->weapon, b->weapon_count, cweapon_cmp_grab);
//Note: Sort according to inverse priority, start from the back, easy to delete
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 & amp; & amp; !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 & amp; & amp; !be_fighteder_weapon_count)
{<!-- -->
return false;
}
if (all_sword_fighter & amp; & amp; 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 grabs b
//1: Sort b's weapons 2
sort_weapon_grab(b->weapon, b->weapon_count, cweapon_cmp_grab);
//Note: Sort according to inverse priority, start from the back, easy to delete
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;
\t\t
+ + a->weapon_count; + + taken_count;
a->weapon[i] = b->weapon[bpos];
b->weapon[bpos] = NULL;
--b->weapon_count;
}
}
void battle(cplayer & amp; R, cplayer & amp; 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 is alive, 1 point is the winner, 2 is dead
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;
//Can't choose a weapon, leave
+ + 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 & amp; & amp; be_fighteder->life > 0) {<!-- -->
winner = be_fighteder; loser = fighter;
win_lose = 1;
break;
}
if (fighter->life <= 0 & amp; & amp; be_fighteder->life <= 0) {<!-- -->
win_lose = 2;
break;
}
if (fighter->life > 0 & amp; & amp; 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 {<!-- -->//No winner
if (win_lose == 2) {<!-- -->//both die
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 & amp; R,cplayer & amp; B, int _life, int city_count, int K, int T, int Hour) {<!-- -->
\t/*event:
00: Soldier production
05: The lion escapes
10: Soldiers move forward (iceman loses blood, note that the tail of the change is removed, so he will not walk to death) (judgment ends)
35: Wolf grabs weapons
40: Combat:
Set the first move:
Weapon sort 1:
Judgment: If there is no weapon, the endless loop (the two sides only have swords and the attack power is 0) the battle ends (tie).
Single-step combat: extract the current weapon attack power (skip all steps if none), attack the opponent,
Bomb anti-injury (ninja special), weapon life reduction, weapon breakage
Judgment:
If one side is hit to 0, the battle ends (wins).
If both sides are hit to 0, the battle is over (tie).
Weapon capture (prerequisite: win): Weapon sort 2, new weapon
*Destroy dead soldiers: Note that the destruction is placed after the weapons are seized.
Report the combat situation:
Dragon cheers: I have fought, and I am not dead (red first, blue later)
50: The number of life units reported by the player (red first and blue later)
55: Soldiers report weapon status (from west to east, red first and blue later)*/

//00: soldier production
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 escapes
if (T < 5) return true;
for (int i = 0; i <= city_count + 1; + + i) {<!-- -->
if (City[i]["red"]!=NULL & amp; & amp;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 & amp; & amp; 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: Soldiers advance, iceman loses health, lion loyalty loses
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 grabs weapons
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" & amp; & amp; City[i]["blue"]->name != "wolf") {<!-- -- >
weapon_steal("red", "blue", City[i]["red"], City[i]["blue"], i, Hour);
//The output is carried out in weapon_steal
}
if (City[i]["blue"]->name == "wolf" & amp; & amp; City[i]["red"]->name != "wolf") {<!-- -- >
weapon_steal("blue","red", City[i]["blue"], City[i]["red"], i, Hour);
//The output is carried out in weapon_steal
}
}
//40: battle
if (T < 40) return true;
for (int i = 1; i <= city_count; + + i) {<!-- -->
if (City[i]["red"] != NULL & amp; & amp; City[i]["blue"] != NULL) {<!-- -->
battle(R,B,City[i]["red"],City[i]["blue"],i,Hour);
}
}
//50: The player reports the state of the life element
if (T < 50) return true;
print_player_lifeyuan(R, "red", Hour); print_player_lifeyuan(B,"blue", Hour);
//55: Soldiers report weapon status
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( & amp; stream, "datapub.in", "r", stdin);
//freopen_s( & amp; stream, "my.txt", "w", stdout);
int t;
cin >> t;
\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;
}