欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

C++面向对象程序设计大作业:魔兽世界(三):开战

程序员文章站 2024-03-17 18:06:40
...

C++面向对象程序设计大作业:魔兽世界(三):开战


问题描述

问题来自于北京大学郭炜老师的C++慕课的大作业

魔兽世界的西面是红魔军的司令部,东面是蓝魔军的司令部。两个司令部之间是依次排列的若干城市,城市从西向东依次编号为1,2,3 … N ( N <= 20)。红魔军的司令部算作编号为0的城市,蓝魔军的司令部算作编号为N+1的城市。司令部有生命元,用于制造武士。

两军的司令部都会制造武士。武士一共有dragon 、ninja、iceman、lion、wolf 五种。每种武士都有编号、生命值、攻击力这三种属性。

双方的武士编号都是从1开始计算。红方制造出来的第n 个武士,编号就是n。同样,蓝方制造出来的第n 个武士,编号也是n。

武士在刚降生的时候有一个初始的生命值,生命值在战斗中会发生变化,如果生命值减少到0(生命值变为负数时应当做变为0处理),则武士死亡(消失)。

武士可以拥有武器。武器有三种,sword, bomb,和arrow,编号分别为0,1,2。
sword的攻击力是使用者当前攻击力的20%(去尾取整)。
bomb的攻击力是使用者当前攻击力的40%(去尾取整),但是也会导致使用者受到攻击,对使用者的攻击力是对敌人取整后的攻击力的1/2(去尾取整)。Bomb一旦使用就没了。
arrow的攻击力是使用者当前攻击力的30%(去尾取整)。一个arrow用两次就没了。

武士降生后就朝对方司令部走,在经过的城市如果遇到敌人(同一时刻每个城市最多只可能有1个蓝武士和一个红武士),就会发生战斗。战斗的规则是:

  1. 在奇数编号城市,红武士先发起攻击

  2. 在偶数编号城市,蓝武士先发起攻击

  3. 战斗开始前,双方先对自己的武器排好使用顺序,然后再一件一件地按顺序使用。编号小的武器,排在前面。若有多支arrow,用过的排在前面。排好序后,攻击者按此排序依次对敌人一件一件地使用武器。如果一种武器有多件,那就都要用上。每使用一件武器,被攻击者生命值要减去武器攻击力。如果任何一方生命值减为0或小于0即为死去。有一方死去,则战斗结束。

  4. 双方轮流使用武器,甲用过一件,就轮到乙用。某一方把自己所有的武器都用过一轮后,就从头开始再用一轮。如果某一方没有武器了,那就挨打直到死去或敌人武器用完。武器排序只在战斗前进行,战斗中不会重新排序。

  5. 如果双方武器都用完且都还活着,则战斗以平局结束。如果双方都死了,也算平局。

  6. 有可能由于武士自身攻击力太低,而导致武器攻击力为0。攻击力为0的武器也要使用。如果战斗中双方的生命值和武器的状态都不再发生变化,则战斗结束,算平局。

  7. 战斗的胜方获得对方手里的武器。武士手里武器总数不超过10件。缴获武器时,按照武器种类编号从小到大缴获。如果有多件arrow,优先缴获没用过的。

  8. 如果战斗开始前双方都没有武器,则战斗视为平局。如果先攻击方没有武器,则由后攻击方攻击。

不同的武士有不同的特点。

编号为n的dragon降生时即获得编号为n%3 的武器。dragon在战斗结束后,如果还没有战死,就会欢呼。

编号为n的ninjia降生时即获得编号为n%3 和(n+1)%3的武器。ninja 使用bomb不会让自己受伤。

编号为n的iceman降生时即获得编号为n%3 的武器。iceman每前进一步,生命值减少10%(减少的量要去尾取整)。

编号为n的lion降生时即获得编号为n%3 的武器。lion 有“忠诚度”这个属性,其初始值等于它降生之后其司令部剩余生命元的数目。每前进一步忠诚度就降低K。忠诚度降至0或0以下,则该lion逃离战场,永远消失。但是已经到达敌人司令部的lion不会逃跑。lion在己方司令部可能逃跑。

wolf降生时没有武器,但是在战斗开始前会抢到敌人编号最小的那种武器。如果敌人有多件这样的武器,则全部抢来。Wolf手里武器也不能超过10件。如果敌人arrow太多没法都抢来,那就先抢没用过的。如果敌人也是wolf,则不抢武器。

以下是不同时间会发生的不同事件:

在每个整点,即每个小时的第0分, 双方的司令部中各有一个武士降生。

红方司令部按照iceman、lion、wolf、ninja、dragon 的顺序制造武士。

蓝方司令部按照lion、dragon、ninja、iceman、wolf 的顺序制造武士。

制造武士需要生命元。

制造一个初始生命值为m 的武士,司令部中的生命元就要减少m 个。

如果司令部中的生命元不足以制造某本该造的武士,那就从此停止制造武士。

在每个小时的第5分,该逃跑的lion就在这一时刻逃跑了。

在每个小时的第10分:所有的武士朝敌人司令部方向前进一步。即从己方司令部走到相邻城市,或从一个城市走到下一个城市。或从和敌军司令部相邻的城市到达敌军司令部。

在每个小时的第35分:在有wolf及其敌人的城市,wolf要抢夺对方的武器。

在每个小时的第40分:在有两个武士的城市,会发生战斗。

在每个小时的第50分,司令部报告它拥有的生命元数量。

在每个小时的第55分,每个武士报告其拥有的武器情况。

武士到达对方司令部后就算完成任务了,从此就呆在那里无所事事。

任何一方的司令部里若是出现了敌人,则认为该司令部已被敌人占领。

任何一方的司令部被敌人占领,则战争结束。战争结束之后就不会发生任何事情了。

给定一个时间,要求你将从0点0分开始到此时间为止的所有事件按顺序输出。事件及其对应的输出样例如下:

  1. 武士降生

输出样例:000:00 blue dragon 1 born

表示在0点0分,编号为1的蓝魔dragon武士降生

如果造出的是lion,那么还要多输出一行,例:

000:00 blue lion 1 born

Its loyalty is 24

表示该lion降生时的忠诚度是24

  1. lion逃跑

输出样例:000:05 blue lion 1 ran away

表示在0点5分,编号为1的蓝魔lion武士逃走

  1. 武士前进到某一城市

输出样例:

000:10 red iceman 1 marched to city 1 with 20 elements and force 30

表示在0点10分,红魔1号武士iceman前进到1号城市,此时他生命值为20,攻击力为30

对于iceman,输出的生命值应该是变化后的数值

  1. wolf抢敌人的武器

000:35 blue wolf 2 took 3 bomb from red dragon 2 in city 4

表示在0点35分,4号城市中,红魔1号武士wolf 抢走蓝魔2号武士dragon 3个bomb。为简单起见,武器不写复数形式

  1. 报告战斗情况

战斗只有3种可能的输出结果:

000:40 red iceman 1 killed blue lion 12 in city 2 remaining 20 elements

表示在0点40分,1号城市中,红魔1号武士iceman 杀死蓝魔12号武士lion后,剩下生命值20

000:40 both red iceman 1 and blue lion 12 died in city 2

注意,把红武士写前面

000:40 both red iceman 1 and blue lion 12 were alive in city 2

注意,把红武士写前面

  1. 武士欢呼

输出样例:003:40 blue dragon 2 yelled in city 4

  1. 武士抵达敌军司令部

输出样例:001:10 red iceman 1 reached blue headquarter with 20 elements and force 30

(此时他生命值为20,攻击力为30)对于iceman,输出的生命值和攻击力应该是变化后的数值

  1. 司令部被占领

输出样例:003:10 blue headquarter was taken

9)司令部报告生命元数量

000:50 100 elements in red headquarter

000:50 120 elements in blue headquarter

表示在0点50分,红方司令部有100个生命元,蓝方有120个

10)武士报告情况

000:55 blue wolf 2 has 2 sword 3 bomb 0 arrow and 7 elements

为简单起见,武器都不写复数形式。elements一律写复数,哪怕只有1个

交代武器情况时,次序依次是:sword,bomb, arrow。

输出事件时:

首先按时间顺序输出;

同一时间发生的事件,按发生地点从西向东依次输出. 武士前进的事件, 算是发生在目的地。

在一次战斗中有可能发生上面的 5 至 6 号事件。这些事件都算同时发生,其时间就是战斗开始时间。一次战斗中的这些事件,序号小的应该先输出。

两个武士同时抵达同一城市,则先输出红武士的前进事件,后输出蓝武士的。

对于同一城市,同一时间发生的事情,先输出红方的,后输出蓝方的。

显然,8号事件发生之前的一瞬间一定发生了7号事件。输出时,这两件事算同一时间发生,但是应先输出7号事件

虽然任何一方的司令部被占领之后,就不会有任何事情发生了。但和司令部被占领同时发生的事件,全都要输出。

输入第一行是t,代表测试数据组数

每组样例共三行。

第一行,4个整数 M,N,K, T。其含义为:
每个司令部一开始都有M个生命元( 1 <= M <= 100000)
两个司令部之间一共有N个城市( 1 <= N <= 20 )
lion每前进一步,忠诚度就降低K。(0<=K<=100)
要求输出从0时0分开始,到时间T为止(包括T) 的所有事件。T以分钟为单位,0 <= T <= 6000

第二行:五个整数,依次是 dragon 、ninja、iceman、lion、wolf 的初始生命值。它们都大于0小于等于200

第三行:五个整数,依次是 dragon 、ninja、iceman、lion、wolf 的攻击力。它们都大于0小于等于200输出对每组数据,先输出一行:

Case n:

如对第一组数据就输出 Case 1:

然后按恰当的顺序和格式输出到时间T为止发生的所有事件。每个事件都以事件发生的时间开头,时间格式是“时: 分”,“时”有三位,“分”有两位。样例输入

1
20 1 10 400
20 20 30 10 20
5 5 5 5 5
样例输出

Case 1:
000:00 blue lion 1 born
Its loyalty is 10
000:10 blue lion 1 marched to city 1 with 10 elements and force 5
000:50 20 elements in red headquarter
000:50 10 elements in blue headquarter
000:55 blue lion 1 has 0 sword 1 bomb 0 arrow and 10 elements
001:05 blue lion 1 ran away
001:50 20 elements in red headquarter
001:50 10 elements in blue headquarter
002:50 20 elements in red headquarter
002:50 10 elements in blue headquarter
003:50 20 elements in red headquarter
003:50 10 elements in blue headquarter
004:50 20 elements in red headquarter
004:50 10 elements in blue headquarter
005:50 20 elements in red headquarter
005:50 10 elements in blue headquarter
提示

请注意浮点数精度误差问题。OJ上的编译器编译出来的可执行程序,在这方面和你电脑上执行的程序很可能会不一致。5 * 0.3 的结果,有的机器上可能是 15.00000001,去尾取整得到15,有的机器上可能是14.9999999,去尾取整后就变成14。因此,本题不要写 5 * 0.3,要写 5 * 3 / 10。

来源

Guo Wei


问题分析

这是我2018年上慕课学习的时候课程最后的大作业,好像占了总成绩的5分还是10分来着。这个大作业的庞大和复杂程度是毋庸置疑的,好像分成四个阶段,以上的问题是第三阶段,此外还有个“终极版”。
当然这个问题也是显然超出我能力范围的¯⌓¯。我记得前两个阶段在课程学习过程中,我是自己写出来的,但这个第三阶段和第二阶段的跨度也太大了。书本上老师对此大作业的描述是“学生普遍反映,这样的程序确实需要面向对象的程序设计方法来编写,否则不但在程序设计时思路难以理清,要修改时更是会非常麻烦。”这话一点不假,然而我觉得即使是用了面向对象,这问题一样难以理清。。Σ_(꒪ཀ꒪」∠)

我当时也上网找了人家写好的,但是人家写的,和老师给出的第二阶段的“参考程序”是无法衔接的,我就想把两者结合起来,以第二阶段老师的“参考程序”为基础,结合网上看来的别人的思路和逻辑,然后写了出来,好不容易好不容易编译通过,但是程序运行不起来。拿IDE直接调试,遇到变量的复杂繁多,费头脑的指针变量,盘根交错的函数调用关系……,发现根本没法调试。为此,我还到处发帖、百度询问:“怎样调试复杂大型程序?”͡[๏̯͡๏] 然而并没有找到什么对我有用的答案。。最后只能放弃。

2019,2020年,我都把这个大作业翻出来再努力过,前段时间看到网上有人说打log调试程序,我啪的一下就站起来了,很快啊!我以前怎么没这样调试程序?马上就用小黄鸭调试法+printf大法开始调试,一发不可收拾,发现特别管用,每次调试,每天调试都有进步,根本停不下来。经过好久好久,终于干成功了。此时程序已经和当初写好的相差很大很大了。搞完之后。。终于舒服了。。

写完总结一下,有这么几个值得注意的问题:

  1. 我参考了这位老哥写的程序的逻辑别人写的,但是经过仔细研究,他这个程序逻辑和问题描述不符合(在战斗部分的武器使用和战斗结尾的武器获取部分),拿示例的基础测试数据是对的,但是拿其他测试数据可能不对。我自己想破了头脑改了自己觉得符合题意的逻辑,用老师给的11组测试数据,是没问题的,但有没有隐藏错误就不知道了。
  2. 我想在老师给的第二阶段参考程序的基础上写第三阶段,比较死板,可能不是好方法。(但不参考我也是一点头绪都没有的。。)
  3. 调试我程序的N多N多错误中,大概六成是指针应用错误(内存泄漏+空悬指针),写的复杂了,指针的错误真的是防不胜防。教训就是以后 使用、释放指针前一定要判断是否有意义,不用指针的时候一定要置NULL 。另外这也凸显智能指针(auto_ptr/shared_ptr)的优势,不过这些没咋学我还不会用。。;另外三成错误是逻辑本身错误;另外一成是低级语法错误(括号对不上,==写成=)之类。
  4. 我看着那位老哥写的程序也被带跑偏了,他的类成员全部写成public,后面全是直接的指针一级一级访问,我跟着写,也是这样。。最后程序完成后我想改回来,想把该封装的封装起来,才发现,,,太麻烦了!!我把武器类、武士类改了改,其他的类就放弃修改了。。
  5. 题目要求“同一时间发生的事件,按发生地点从西向东依次输出. 武士前进的事件, 算是发生在目的地;两个武士同时抵达同一城市,则先输出红武士的前进事件,后输出蓝武士的。”,我的程序在每小时第10分钟武士前进到某一城市的情况的输出顺序和该要求不符。 我是先把红军武士前进情况全输出来,再把蓝军武士前进情况输出来。因为我没想得出怎么改才能满足这个要求。。。除此之外,其他输出都正确。

另外,11组测试数据和结果太长了,我在这上不挂了。。。。找郭炜老师《C++面向对象程序设计》慕课的配套资料里应该有。


代码

在windows环境下用Code::Blocks编写编译的。

#include <iostream>
#include <cstdio>
#include <cstring>
#include <cstdlib>

const int WARRIOR_NUM = 5;//五种武士
const int WEAPON_NUM = 3;//三种武器
const int WEAPON_MAX = 10;//一个武士最多10把武器
enum {DRAGON, NINJA, ICEMAN, LION, WOLF};
enum {SWORD, BOMB, ARROW};

using namespace std;

class Headquarter;
class Dragon;
class Ninja;
class Iceman;
class Lion;
class Wolf;
class Warrior;
class City;

class Weapon
{
    protected:
        int WeaponKind;
        int WeaponForce;
        static char *WeaponName[WEAPON_NUM];
        Warrior *pWarrior;//该武器属于哪个武士
        bool Used; //为arrow准备的,标志arrow是否用过。
        Weapon(int kind, Warrior *p);
        friend int compareWeapon (const void *p, const void *q);//qsort函数的比较函数,用过的arrow排前面
        friend int compareWeapon2 (const void *p, const void *q);//qsort函数的比较函数,没用过的arrow排前面
        friend class Warrior;
        friend class Dragon;
        friend class Ninja;
        friend class Iceman;
        friend class Lion;
        friend class Wolf;
};

class Warrior
{
    protected:
        Headquarter *pHeadquarter; //武士属于红还是蓝司令部
        City *pCity;//武士目前在哪个City
        int OrderInMaking;//武士的种类
        int OrderInTotal;//武士是红/蓝司令部制造的第几个武士
        Weapon *Weaponptr[WEAPON_MAX];//武士拥有的武器数组
        int SumWeap;//武器总数
        int UsedArrow;//用过的Arrow的数量
        int NumOfWeapon[WEAPON_NUM];//各种武器有多少把
        int Life;
    public:
        friend class Weapon;
        friend class Headquarter;
        friend class City;
        friend class Dragon;
        friend class Ninja;
        friend class Iceman;
        friend class Lion;
        friend class Wolf;
        friend void RedWarriorMove(City * leftCity, City *rightCity, int Time);
        friend void BlueWarriorMove(City *rightCity, City * leftCity, int Time);
        static char *WarriorName[WARRIOR_NUM];//存武士名字的全局字符串数组
        static int InitLifeValue[WARRIOR_NUM];//存武士初始生命值的全局数组
        static int AttackForce[WARRIOR_NUM];//存武士攻击力的全局数组
        Warrior(Headquarter *_p, int _oim, int _oit): pHeadquarter(_p),
                                                      OrderInMaking(_oim),
                                                      OrderInTotal(_oit),
                                                      SumWeap(0),
                                                      UsedArrow(0),
                                                      Life(InitLifeValue[OrderInMaking])
        {
            for (int i = 0; i < WEAPON_NUM; ++i)
                NumOfWeapon[i] = 0;
            for (int i = 0; i < WEAPON_MAX; ++i)
                Weaponptr[i] = NULL;
        }
        virtual ~Warrior()
        {
            for (int i = 0; i < SumWeap; i++)
                if (Weaponptr[i])
                    delete Weaponptr[i];
        }
        virtual void PrintResult(int Time);//武士降生时报告情况
        virtual void IcemanMove() {}
        virtual bool LionEscape(int Time)
        {
            return 0;
        }
        virtual void LionMove() {}
        virtual void Rob(Warrior *enemy, int Time) {}
        void CaptureWeapon(Warrior *another);//击败对方武士后抢夺武器
        void ArrangeWeapon();//战斗之前把武器排好序
        void WarriorAnnounce(int Time);//每小时55钟的时候报告情况
        void OneTimeAttack(Warrior *another, int OrderInWeaponptr);//攻击对方
        int WarriorKind() {return OrderInMaking;}
        int WarriorOrderInTotal() {return OrderInTotal;}
};

class City
{
    public:
        int Cityname;
        Warrior *redwarrior;
        Warrior *bluewarrior;
        bool ishead;//该City是否为司令部
        friend void RedWarriorMove(City * leftCity, City *rightCity, int Time);
        friend void BlueWarriorMove(City *rightCity, City * leftCity, int Time);
        bool attackResult(int Time, Headquarter * Red, Headquarter * Blue);//每小时的40分报告战斗情况
        void Battling(int Time, Headquarter * Red, Headquarter * Blue);//City发生战斗
        void RedInit(Headquarter *p);//红司令部成为最左的City
        void BlueInit(Headquarter *p);//蓝司令部成为最右的City
};

class Headquarter
{
    public:
        friend class Warrior;
        friend class City;
        int Color;
        int TotalLifeValue;//总共有多少生命元
        int CurOrderInMaking;//接下来准备产生哪种武士
        int TotalWarriorNum;//总共有多少活着的武士
        int NumOfWarrior[WARRIOR_NUM];//每种武士有多少个
        Warrior *Wptr[1000];//武士数组
        bool Stop;//该司令部是否有足够生命元继续生产武士
        static bool MainFlag;//全局量,标志是否被占领
        static int MakingOrder[2][WARRIOR_NUM];//存放武士制造顺序的数组
        Headquarter(bool _color, int _lifevalue): Color(_color),
                                                  TotalLifeValue(_lifevalue),
                                                  CurOrderInMaking(0),
                                                  TotalWarriorNum(0),
                                                  Stop(false)
        {
            for (int i = 0; i < WARRIOR_NUM; i++)
                NumOfWarrior[i] = 0;
            for (int i = 0; i < 1000; ++i)
                Wptr[i] = NULL;
        }
        ~Headquarter()
        {
            for (int i = 0; i < TotalWarriorNum; i++)
                if (Wptr[i])
                    delete Wptr[i];
        }
        void Produce(int Time);//武士降生
        void GetColor(char *HeadquarterName);//get “red” or “blue”
        void HeadAnnounce(int Time);//每小时的50分司令部报告生命元数量
        int GetTotalLifeValue() { return TotalLifeValue; }
        void DestroyWarrior(int number) {
            Wptr[number] = NULL;
        }
};

class Dragon: public Warrior
{
        friend class Headquarter;
        friend class City;
        friend class Ninja;
        friend class Iceman;
        friend class Lion;
        friend class Wolf;
    public:
        Dragon(Headquarter *_p, int _oim, int _oit): Warrior(_p, _oim, _oit)
        {
            int kind = OrderInTotal % WEAPON_NUM;
            Weaponptr[SumWeap] = new Weapon(kind, this);
            NumOfWeapon[kind]++;
            SumWeap++;
        }
        void PrintResult(int Time)
        {
            Warrior::PrintResult(Time);
        }
};

class Ninja: public Warrior
{
        friend class Headquarter;
        friend class City;
        friend class Dragon;
        friend class Iceman;
        friend class Lion;
        friend class Wolf;
    public:
        Ninja(Headquarter *_p, int _oim, int _oit): Warrior(_p, _oim, _oit)
        {
            int kind = OrderInTotal % WEAPON_NUM;
            Weaponptr[SumWeap] = new Weapon(kind,this);
            NumOfWeapon[kind]++;
            SumWeap++;
            kind = (OrderInTotal + 1) % WEAPON_NUM;
            Weaponptr[SumWeap] = new Weapon(kind,this);
            NumOfWeapon[kind]++;
            SumWeap++;
        }
        void PrintResult(int Time)
        {
            Warrior::PrintResult(Time);
        }
};

class Iceman: public Warrior
{
        friend class Headquarter;
        friend class City;
        friend class Dragon;
        friend class Lion;
        friend class Wolf;
        friend class Ninja;
    public:
        Iceman(Headquarter *_p, int _oim, int _oit): Warrior(_p, _oim, _oit)
        {
            int kind = OrderInTotal % WEAPON_NUM;
            Weaponptr[SumWeap] = new Weapon(kind,this);
            NumOfWeapon[kind]++;
            SumWeap++;
        }
        void PrintResult(int Time)
        {
            Warrior::PrintResult(Time);
        }
        void IcemanMove()
        {
            Life -= Life / 10;
        }
};

class Lion: public Warrior
{
        friend class Headquarter;
        friend class City;
        friend class Dragon;
        friend class Iceman;
        friend class Wolf;
        friend class Ninja;
    protected:
        int Loyalty;
    public:
        static int LoyaltyDecrease;//每前进一步忠诚度降低值
        void GetLoyalty()
        {
            Loyalty = pHeadquarter->GetTotalLifeValue();
        }
        Lion(Headquarter *_p, int _oim, int _oit): Warrior(_p, _oim, _oit)
        {
            GetLoyalty();
            int kind = OrderInTotal % WEAPON_NUM;
            Weaponptr[SumWeap] = new Weapon(kind,this);
            NumOfWeapon[kind]++;
            SumWeap++;
        }
        void PrintResult(int Time)
        {
            Warrior::PrintResult(Time);
            printf("It's loyalty is %d\n", Loyalty);
        }
        bool LionEscape(int Time) {
            if (Loyalty>0) return 0;
            char HeadquarterName[20];
            pHeadquarter->GetColor(HeadquarterName);
            printf("%.3d:05 %s lion %d ran away\n", Time, HeadquarterName, OrderInTotal);
            return 1;
        } //judge whether the lion escapes
        void LionMove() {
            Loyalty-=LoyaltyDecrease;
        }
};

class Wolf: public Warrior
{
        friend class Headquarter;
        friend class City;
        friend class Dragon;
        friend class Iceman;
        friend class Lion;
        friend class Ninja;
    public:
        Wolf(Headquarter *_p, int _oim, int _oit): Warrior(_p, _oim, _oit) {}
        void PrintResult(int Time)
        {
            Warrior::PrintResult(Time);
        }
        void Rob(Warrior *enemy, int Time);
};

int compareWeapon (const void *p, const void *q) //usedarrow排前面
{
    const Weapon ** p1 = (const Weapon **)p;
    const Weapon ** q1 = (const Weapon **)q;
    if ((*p1)->WeaponKind < (*q1)->WeaponKind) return -1;
    else if ((*p1)->WeaponKind == ARROW && (*q1)->WeaponKind == ARROW) {
        if ((*p1)->Used == (*q1)->Used) return 0;
        else if ((*p1)->Used > (*q1)->Used) return -1;
        else return 1;
    }
    else if ((*p1)->WeaponKind ==  (*q1)->WeaponKind) return 0;
    else return 1;
}

int compareWeapon2 (const void *p, const void *q) //usedarrow排后面
{
    const Weapon ** p1 = (const Weapon **)p;
    const Weapon ** q1 = (const Weapon **)q;
    if ((*p1)->WeaponKind < (*q1)->WeaponKind) return -1;
    else if ((*p1)->WeaponKind == ARROW && (*q1)->WeaponKind == ARROW) {
        if ((*p1)->Used == (*q1)->Used) return 0;
        else if ((*p1)->Used < (*q1)->Used) return -1;
        else return 1;
    }
    else if ((*p1)->WeaponKind ==  (*q1)->WeaponKind) return 0;
    else return 1;
}

void Wolf::Rob(Warrior *enemy, int Time)
{
    if (enemy->OrderInMaking == WOLF) return;
    if (SumWeap == 10 || enemy->SumWeap == 0) return;

    int i_ = 0, used_change = 0;//used-change是抢的用过的arrow的数量
    for (; i_ < WEAPON_NUM; ++i_)
        if (enemy->NumOfWeapon[i_] > 0) break;
    int robNum = min(enemy->NumOfWeapon[i_], WEAPON_MAX - SumWeap);
    if (i_ == ARROW) {
        if (enemy->NumOfWeapon[ARROW] - enemy->UsedArrow < robNum) {
            used_change =  robNum - (enemy->NumOfWeapon[ARROW] - enemy->UsedArrow);
            enemy->UsedArrow -= used_change;
            UsedArrow += used_change;
        }
    }
    for (int i = 0; i < robNum; ++i)
        Weaponptr[SumWeap+i] = new Weapon(i_,this);
    if (i_ == ARROW) {
        for (int i = 0; i < used_change; i++)
            Weaponptr[SumWeap+i]->Used = true;
    }
    SumWeap += robNum;
    NumOfWeapon[i_] += robNum;
    if (i_ != ARROW) {
    for (int i = 0, cnt = 0; i < enemy->SumWeap && cnt < robNum; ++i)
        if (enemy->Weaponptr[i]->WeaponKind == i_) {
            delete enemy->Weaponptr[i];
            enemy->Weaponptr[i] = NULL;
            ++cnt;
        }
    }
    else {
        for (int i = 0, cnt = 0; i < enemy->SumWeap && cnt < (robNum - used_change); ++i)
            if (enemy->Weaponptr[i]->WeaponKind == i_) {
                if (!(enemy->Weaponptr[i]->Used)) {
                    delete enemy->Weaponptr[i];
                    enemy->Weaponptr[i] = NULL;
                    ++cnt;
                }
            }
        for (int i = 0, cnt = 0; i < enemy->SumWeap && cnt < used_change; ++i)
            if (enemy->Weaponptr[i]->WeaponKind == i_) {
                if (enemy->Weaponptr[i]->Used) {
                    delete enemy->Weaponptr[i];
                    enemy->Weaponptr[i] = NULL;
                    ++cnt;
                }
            }
    }
    //抢完之后要给武器数组进行及时排好序:
    Weapon *Weaponptr_tmp[WEAPON_MAX];
    for (int i = 0; i < WEAPON_MAX; i++)
        Weaponptr_tmp[i] = NULL;
    for (int i = 0, k = 0; i < WEAPON_MAX; ++i)
    if (enemy->Weaponptr[i]) {
        Weaponptr_tmp[k] = enemy->Weaponptr[i];
        k++;
    }
    for (int i = 0; i < WEAPON_MAX; ++i)
        enemy->Weaponptr[i] = Weaponptr_tmp[i];
    for (int i = 0; i < WEAPON_MAX; ++i)
        Weaponptr_tmp[i] = NULL;

    enemy->SumWeap -= robNum;
    enemy->NumOfWeapon[i_] -= robNum;
    if (enemy->SumWeap > 0) qsort(enemy->Weaponptr, enemy->SumWeap, sizeof(Weapon *), compareWeapon);
    qsort(Weaponptr, SumWeap, sizeof(Weapon *), compareWeapon);
            //000:35 blue wolf 2 took 3 bomb from red dragon 2 in city 4
    char HeadquarterName1[20];
    pHeadquarter->GetColor(HeadquarterName1);
    char HeadquarterName2[20];
    enemy->pHeadquarter->GetColor(HeadquarterName2);
    printf("%.3d:35 %s wolf %d took %d %s from %s %s %d in city %d\n", Time, HeadquarterName1, OrderInTotal,
                                                                        robNum, Weapon::WeaponName[i_], HeadquarterName2,
                                                                        WarriorName[enemy->OrderInMaking], enemy->OrderInTotal,
                                                                        pCity->Cityname);
}

Weapon::Weapon(int kind, Warrior *p): WeaponKind(kind), pWarrior(p), Used(false)
{
    switch (kind) {
        case SWORD: WeaponForce = p->AttackForce[pWarrior->OrderInMaking] / 5;
                    break;
        case BOMB : WeaponForce = p->AttackForce[pWarrior->OrderInMaking] * 2 / 5;
                    break;
        case ARROW: WeaponForce = p->AttackForce[pWarrior->OrderInMaking] * 3 / 10;
                    break;
    }
}

void City::RedInit(Headquarter *p)
{
    redwarrior = p->Wptr[p->TotalWarriorNum-1];
    redwarrior->pCity = this;
}

void City::BlueInit(Headquarter *p)
{
    bluewarrior = p->Wptr[p->TotalWarriorNum-1];
    bluewarrior->pCity = this;
}

void Warrior::PrintResult(int Time)
{
    char HeadquarterName[20];
    pHeadquarter->GetColor(HeadquarterName);
    printf("%.3d:00 %s %s %d born\n", Time, HeadquarterName, WarriorName[OrderInMaking], OrderInTotal);
}

void Headquarter::Produce(int Time)
{
    if (Stop) return;

    if (Warrior::InitLifeValue[MakingOrder[Color][CurOrderInMaking]] > TotalLifeValue) {
        Stop = true;
        return;
    }

    int Kind = MakingOrder[Color][CurOrderInMaking];
    TotalLifeValue -= Warrior::InitLifeValue[Kind];
    CurOrderInMaking = (CurOrderInMaking + 1) % WARRIOR_NUM;
    switch (Kind) {
        case DRAGON: Wptr[TotalWarriorNum] = new Dragon(this, Kind, TotalWarriorNum+1);
                     break;
        case NINJA : Wptr[TotalWarriorNum] = new Ninja(this, Kind, TotalWarriorNum+1);
                     break;
        case ICEMAN: Wptr[TotalWarriorNum] = new Iceman(this, Kind, TotalWarriorNum+1);
                     break;
        case LION  : Wptr[TotalWarriorNum] = new Lion(this, Kind, TotalWarriorNum+1);
                     break;
        case WOLF  : Wptr[TotalWarriorNum] = new Wolf(this, Kind, TotalWarriorNum+1);
                     break;
    }
    NumOfWarrior[Kind]++;
    Wptr[TotalWarriorNum]->PrintResult(Time);
    TotalWarriorNum++;
}

void Headquarter::GetColor(char *HeadquarterName)
{
    if (Color == 0)
        strcpy(HeadquarterName, "red");
    else
        strcpy(HeadquarterName, "blue");
}

void RedWarriorMove(City * leftCity, City *rightCity, int Time)//从左往右
{
    if (leftCity->redwarrior) {
        if (leftCity->redwarrior->OrderInMaking == ICEMAN) leftCity->redwarrior->IcemanMove();
        if (leftCity->redwarrior->OrderInMaking == LION) leftCity->redwarrior->LionMove();
        char HeadquarterName[20];
        leftCity->redwarrior->pHeadquarter->GetColor(HeadquarterName);
        if (!rightCity->ishead)
        //000:10 red iceman 1 marched to city 1 with 20 elements and force 30
            printf("%.3d:10 %s %s %d marched to city %d with %d elements and force %d\n", Time, HeadquarterName, Warrior::WarriorName[leftCity->redwarrior->OrderInMaking],
                                                                                          leftCity->redwarrior->OrderInTotal, rightCity->Cityname, leftCity->redwarrior->Life,
                                                                                          Warrior::AttackForce[leftCity->redwarrior->OrderInMaking]);
        else if (rightCity->ishead) {
        //001:10 red iceman 1 reached blue headquarter with 20 elements and force 30
            printf("%.3d:10 %s %s %d reached blue headquarter with %d elements and force %d\n", Time, HeadquarterName, Warrior::WarriorName[leftCity->redwarrior->OrderInMaking],
                                                                                                leftCity->redwarrior->OrderInTotal, leftCity->redwarrior->Life,
                                                                                                Warrior::AttackForce[leftCity->redwarrior->OrderInMaking]);
            printf("%.3d:10 blue headquarter was taken\n",Time);//004:10 blue headquarter was taken
            Headquarter::MainFlag = 0;
        }
        rightCity->redwarrior = leftCity->redwarrior;
        leftCity->redwarrior = NULL;
        rightCity->redwarrior->pCity = rightCity;
    }
}

void BlueWarriorMove(City *rightCity, City * leftCity, int Time)
{//从you往zuo
    if (rightCity->bluewarrior) {
        if (rightCity->bluewarrior->OrderInMaking == ICEMAN) rightCity->bluewarrior->IcemanMove();
        if (rightCity->bluewarrior->OrderInMaking == LION) rightCity->bluewarrior->LionMove();
        char HeadquarterName[20];
        rightCity->bluewarrior->pHeadquarter->GetColor(HeadquarterName);
        if (!leftCity->ishead)
        //000:10 red iceman 1 marched to city 1 with 20 elements and force 30
            printf("%.3d:10 %s %s %d marched to city %d with %d elements and force %d\n", Time, HeadquarterName, Warrior::WarriorName[rightCity->bluewarrior->OrderInMaking],
                                                                                          rightCity->bluewarrior->OrderInTotal, leftCity->Cityname, rightCity->bluewarrior->Life,
                                                                                          Warrior::AttackForce[rightCity->bluewarrior->OrderInMaking]);
        else if (leftCity->ishead) {
        //001:10 red iceman 1 reached blue headquarter with 20 elements and force 30
            printf("%.3d:10 %s %s %d reached red headquarter with %d elements and force %d\n", Time, HeadquarterName, Warrior::WarriorName[rightCity->bluewarrior->OrderInMaking],
                                                                                               rightCity->bluewarrior->OrderInTotal, rightCity->bluewarrior->Life,
                                                                                               Warrior::AttackForce[rightCity->bluewarrior->OrderInMaking]);
            printf("%.3d:10 red headquarter was taken\n",Time);//004:10 blue headquarter was taken
            Headquarter::MainFlag = 0;
        }
        leftCity->bluewarrior = rightCity->bluewarrior;
        rightCity->bluewarrior = NULL;
        leftCity->bluewarrior->pCity = leftCity;
    }
}

void Warrior::OneTimeAttack(Warrior *another, int OrderInWeaponptr)
{
    int usingKind = Weaponptr[OrderInWeaponptr]->WeaponKind;
    switch (usingKind) {
        case SWORD: another->Life -= Weaponptr[OrderInWeaponptr]->WeaponForce;
                    break;
        case BOMB : another->Life -= Weaponptr[OrderInWeaponptr]->WeaponForce;
                    if (OrderInMaking != NINJA) {
                        Life -= Weaponptr[OrderInWeaponptr]->WeaponForce / 2;
                    }
                    delete Weaponptr[OrderInWeaponptr];
                    Weaponptr[OrderInWeaponptr] = NULL;
                    NumOfWeapon[usingKind]--;
                    break;
        case ARROW: another->Life -= Weaponptr[OrderInWeaponptr]->WeaponForce;
                    if (Weaponptr[OrderInWeaponptr]->Used) {
                        delete Weaponptr[OrderInWeaponptr];
                        Weaponptr[OrderInWeaponptr] = NULL;
                        NumOfWeapon[usingKind]--;
                        UsedArrow--;
                    }
                    else{
                        UsedArrow++;
                        Weaponptr[OrderInWeaponptr]->Used = true;
                    }
                    break;
    }
}

void Warrior::ArrangeWeapon()
{
    SumWeap = NumOfWeapon[0] +  NumOfWeapon[1] + NumOfWeapon[2];

    Weapon *Weaponptr_tmp[WEAPON_MAX];
    for (int i = 0; i < WEAPON_MAX; i++)
        Weaponptr_tmp[i] = NULL;
    for (int i = 0, k = 0; i < WEAPON_MAX; ++i)
    if (Weaponptr[i]) {
        Weaponptr_tmp[k] = Weaponptr[i];
        k++;
    }
    for (int i = 0; i < WEAPON_MAX; ++i)
        Weaponptr[i] = Weaponptr_tmp[i];
    for (int i = 0; i < WEAPON_MAX; ++i)
        Weaponptr_tmp[i] = NULL;

    if (SumWeap > 0) qsort(Weaponptr, SumWeap, sizeof(Weapon *), compareWeapon);
}

void Warrior::CaptureWeapon(Warrior *another)
{
    if ((WEAPON_MAX - SumWeap) > 0 && another->SumWeap > 0) {//自己武器没满,且对方还有武器,才要拿
        int add;
        if ((WEAPON_MAX - SumWeap) >= another->SumWeap) {
            add = another->SumWeap;
            Weapon *Weaponptr_tmp[add];
            for (int i = 0; i < add; i++) {
                int kind = another->Weaponptr[i]->WeaponKind;
                bool used = another->Weaponptr[i]->Used;
                Weaponptr_tmp[i] = new Weapon(kind, this);
                if (kind == ARROW && used)
                    Weaponptr_tmp[i]->Used = true;
            }
            for (int i = 0; i < add; i++)
                Weaponptr[SumWeap+i] = Weaponptr_tmp[i];
            SumWeap += add;
            NumOfWeapon[SWORD] += another->NumOfWeapon[SWORD];
            NumOfWeapon[BOMB] += another->NumOfWeapon[BOMB];
            NumOfWeapon[ARROW] += another->NumOfWeapon[ARROW];
        }
        else {
            qsort(another->Weaponptr, another->SumWeap, sizeof(Weapon *), compareWeapon2);//把another没用过的排在前面

            add = WEAPON_MAX - SumWeap;
            Weapon *Weaponptr_tmp[add];
            for (int i = 0; i < add; ++i) {
                int kind = another->Weaponptr[i]->WeaponKind;
                bool used = another->Weaponptr[i]->Used;
                Weaponptr_tmp[i] = new Weapon(kind, this);
                if (kind == ARROW && used)
                    Weaponptr_tmp[i]->Used = true;
                if (kind == SWORD) NumOfWeapon[SWORD]++;
                if (kind == BOMB) NumOfWeapon[BOMB]++;
                if (kind == ARROW) NumOfWeapon[ARROW]++;
            }
            for (int i = 0; i < add; i++)
                Weaponptr[SumWeap+i] = Weaponptr_tmp[i];
            SumWeap += add;
        }
    }
}

bool City::attackResult(int Time, Headquarter * Red, Headquarter * Blue)
{
    if (redwarrior->Life <= 0 && bluewarrior->Life <= 0) {
            //000:40 both red iceman 1 and blue lion 12 died in city 2
        printf("%.3d:40 both red %s %d and blue %s %d died in city %d\n", Time, Warrior::WarriorName[redwarrior->OrderInMaking], redwarrior->OrderInTotal,
                                                                          Warrior::WarriorName[bluewarrior->OrderInMaking], bluewarrior->OrderInTotal, Cityname);
        Red->DestroyWarrior(redwarrior->OrderInTotal-1);
        delete redwarrior;
        redwarrior = NULL;
        Blue->DestroyWarrior(bluewarrior->OrderInTotal-1);
        delete bluewarrior;
        bluewarrior = NULL;
        return 1;
    }
    if (bluewarrior->Life <= 0) {
        redwarrior->ArrangeWeapon();  bluewarrior->ArrangeWeapon();
        redwarrior->CaptureWeapon(bluewarrior);
        redwarrior->ArrangeWeapon();
        //000:40 red iceman 1 killed blue lion 12 in city 2 remaining 20 elements
        printf("%.3d:40 red %s %d killed blue %s %d in city %d remaining %d elements\n", Time, Warrior::WarriorName[redwarrior->OrderInMaking], redwarrior->OrderInTotal,
                                                                                         Warrior::WarriorName[bluewarrior->OrderInMaking], bluewarrior->OrderInTotal, Cityname,
                                                                                         redwarrior->Life);
        Blue->DestroyWarrior(bluewarrior->OrderInTotal-1);
        delete bluewarrior;
        bluewarrior = NULL;
        if (redwarrior->OrderInMaking == DRAGON)
            //003:40 blue dragon 2 yelled in city 4
            printf("%.3d:40 red dragon %d yelled in city %d\n", Time, redwarrior->OrderInTotal, Cityname);
        return 1;
    }
    if (redwarrior->Life <= 0) {
        redwarrior->ArrangeWeapon();  bluewarrior->ArrangeWeapon();
        bluewarrior->CaptureWeapon(redwarrior);
        bluewarrior->ArrangeWeapon();
        //000:40 red iceman 1 killed blue lion 12 in city 2 remaining 20 elements
        printf("%.3d:40 blue %s %d killed red %s %d in city %d remaining %d elements\n", Time, Warrior::WarriorName[bluewarrior->OrderInMaking], bluewarrior->OrderInTotal,
                                                                                         Warrior::WarriorName[redwarrior->OrderInMaking], redwarrior->OrderInTotal, Cityname,
                                                                                         bluewarrior->Life);
        Red->DestroyWarrior(redwarrior->OrderInTotal-1);
        delete redwarrior;
        redwarrior = NULL;
        if (bluewarrior->OrderInMaking == DRAGON)
            //003:40 blue dragon 2 yelled in city 4
            printf("%.3d:40 blue dragon %d yelled in city %d\n", Time, bluewarrior->OrderInTotal, Cityname);
        return 1;
    }
    return 0;
}


void City::Battling(int Time, Headquarter * Red, Headquarter * Blue)
{
    if (!(redwarrior && bluewarrior)) return;//形不成战斗

    bool tempFlag = 0;//标志战斗状态是否不再发生变化,我这里认为如果双方生命值连续五轮不变,那就是平局
    int redlife = redwarrior->Life, bluelife = bluewarrior->Life;
    int i_red = 0, i_blue = 0;//使用的是武士拥有的武器数组中序号为i_red/i_blue的武器

    if (Cityname % 2 ==1) {
        if (redwarrior->SumWeap) {
           if (i_red == redwarrior->SumWeap) i_red = 0;
           if (redwarrior->Weaponptr[i_red]) {
             redwarrior->OneTimeAttack(bluewarrior, i_red);
             if (attackResult(Time, Red, Blue)) return;
             i_red++;
           }
           else {
             int i;
             for (i = i_red; i < redwarrior->SumWeap; i++)
                if (redwarrior->Weaponptr[i]) break;
             if (i < redwarrior->SumWeap) {
                i_red = i;
                redwarrior->OneTimeAttack(bluewarrior, i_red);
                if (attackResult(Time, Red, Blue)) return;
                i_red++;
             }
             else {
                i_red = 0;
                if (redwarrior->Weaponptr[i_red]) {
                   redwarrior->OneTimeAttack(bluewarrior, i_red);
                   if (attackResult(Time, Red, Blue)) return;
                   i_red++;
                }
             }
           }
        }
    }

    int tie_counter = 0;//回合制攻击轮数
    while (!tempFlag) {
        redlife = redwarrior->Life;
        bluelife = bluewarrior->Life;

        if (bluewarrior->SumWeap) {
            if (i_blue == bluewarrior->SumWeap) i_blue = 0;
            if (bluewarrior->Weaponptr[i_blue]) {
                bluewarrior->OneTimeAttack(redwarrior,i_blue);
                if (attackResult(Time, Red, Blue)) return;
                i_blue++;
            }
            else {
                int i;
                for (i = i_blue; i < bluewarrior->SumWeap; i++)
                    if (bluewarrior->Weaponptr[i]) break;
                if (i < bluewarrior->SumWeap) {
                    i_blue = i;
                    bluewarrior->OneTimeAttack(redwarrior,i_blue);
                    if (attackResult(Time, Red, Blue)) return;
                    i_blue++;
                }
                else {
                    i_blue = 0;
                    if (bluewarrior->Weaponptr[i_blue]) {
                        bluewarrior->OneTimeAttack(redwarrior,i_blue);
                        if (attackResult(Time, Red, Blue)) return;
                        i_blue++;
                    }
                }
            }
        }

        if (redwarrior->SumWeap) {
            if (i_red == redwarrior->SumWeap) i_red = 0;
            if (redwarrior->Weaponptr[i_red]) {
                redwarrior->OneTimeAttack(bluewarrior, i_red);
                if (attackResult(Time, Red, Blue)) return;
                i_red++;
            }
            else {
                int i;
                for (i = i_red; i < redwarrior->SumWeap; i++)
                    if (redwarrior->Weaponptr[i]) break;
                if (i < redwarrior->SumWeap) {
                    i_red = i;
                    redwarrior->OneTimeAttack(bluewarrior, i_red);
                    if (attackResult(Time, Red, Blue)) return;
                    i_red++;
                }
                else {
                    i_red = 0;
                    if (redwarrior->Weaponptr[i_red]) {
                        redwarrior->OneTimeAttack(bluewarrior, i_red);
                        if (attackResult(Time, Red, Blue)) return;
                        i_red++;
                    }
                }
            }
        }

        if (redlife == redwarrior->Life && bluelife == bluewarrior->Life)
            tie_counter++;
        else
            tie_counter = 0;

        if (tie_counter >= 5)
            tempFlag = 1;
    }

    if (tempFlag) {
        redwarrior->ArrangeWeapon();  bluewarrior->ArrangeWeapon();//打完了也要记得排个序
            //000:40 both red iceman 1 and blue lion 12 were alive in city 2
        printf("%.3d:40 both red %s %d and blue %s %d were alive in city %d\n", Time, Warrior::WarriorName[redwarrior->OrderInMaking], redwarrior->OrderInTotal,
                                                                                Warrior::WarriorName[bluewarrior->OrderInMaking], bluewarrior->OrderInTotal, Cityname);
        if (redwarrior->OrderInMaking == DRAGON)
            //003:40 blue dragon 2 yelled in city 4
            printf("%.3d:40 red dragon %d yelled in city %d\n", Time, redwarrior->OrderInTotal, Cityname);
        if (bluewarrior->OrderInMaking == DRAGON)
            //003:40 blue dragon 2 yelled in city 4
            printf("%.3d:40 blue dragon %d yelled in city %d\n", Time, bluewarrior->OrderInTotal, Cityname);
    }
}

void Headquarter::HeadAnnounce(int Time)
{
   // 000:50 120 elements in blue headquarter
    char HeadquarterName[20];
    GetColor(HeadquarterName);
    printf("%.3d:50 %d elements in %s headquarter\n", Time, TotalLifeValue, HeadquarterName);
}

void Warrior::WarriorAnnounce(int Time)
{
    //000:55 blue wolf 2 has 2 sword 3 bomb 0 arrow and 7 elements
    char HeadquarterName[20];
    pHeadquarter->GetColor(HeadquarterName);
    printf("%.3d:55 %s %s %d has %d sword %d bomb %d arrow and %d elements\n", Time, HeadquarterName, Warrior::WarriorName[OrderInMaking], OrderInTotal,
                                                                               NumOfWeapon[SWORD], NumOfWeapon[BOMB], NumOfWeapon[ARROW], Life);
}

char * Weapon::WeaponName[WEAPON_NUM] = {"sword","bomb","arrow" };
int Warrior::AttackForce[WARRIOR_NUM];
char * Warrior::WarriorName[WARRIOR_NUM] = {"dragon","ninja","iceman","lion","wolf"};
int Warrior::InitLifeValue[WARRIOR_NUM];
int Headquarter::MakingOrder[2][WARRIOR_NUM] = {{ 2,3,4,1,0 } ,{ 3,0,1,2,4 }};
bool Headquarter::MainFlag = 1;
int Lion::LoyaltyDecrease;

int main()
{
/*第一行是t,代表测试数据组数
每组样例共三行。
第一行,4个整数 M,N,K, T。其含义为:
每个司令部一开始都有M个生命元( 1 <= M <= 100000)
两个司令部之间一共有N个城市( 1 <= N <= 20 )
lion每前进一步,忠诚度就降低K。(0<=K<=100)
要求输出从0时0分开始,到时间T为止(包括T) 的所有事件。T以分钟为单位,0 <= T <= 6000
第二行:五个整数,依次是 dragon 、ninja、iceman、lion、wolf 的初始生命值。它们都大于0小于等于200
第三行:五个整数,依次是 dragon 、ninja、iceman、lion、wolf 的攻击力。它们都大于0小于等于200*/
    int t;
    scanf("%d", &t);
    int Case = 1;
    while (t--) {
        printf("%d\n", Case++);

        int lifeValue, CityNumber, TotalTime, Hour = 0; Headquarter::MainFlag = 1;

        scanf("%d%d%d%d", &lifeValue, &CityNumber, &Lion::LoyaltyDecrease, &TotalTime);
        for (int i = 0; i < WARRIOR_NUM; i++)
            scanf("%d", &Warrior::InitLifeValue[i]);
        for (int i = 0; i < WARRIOR_NUM; i++)
            scanf("%d", &Warrior::AttackForce[i]);

        Headquarter Red(0, lifeValue);
        Headquarter Blue(1, lifeValue);
        City *cities = new City[CityNumber+2];

        for (int i = 0; i < CityNumber+2; ++i) {
            cities[i].redwarrior = NULL;
            cities[i].bluewarrior = NULL;
            cities[i].Cityname = i;
            cities[i].ishead = 0;
        }
        cities[0].ishead = 1;
        cities[CityNumber+1].ishead = 1;

        while (Hour * 60 <= TotalTime) {
            if (!Red.Stop) {
                Red.Produce(Hour);
                if (!Red.Stop)//根据Produce()的写法,这里的两次判断是必须的
                    cities[0].RedInit(&Red);
            }
            if (!Blue.Stop) {
                Blue.Produce(Hour);
                if (!Blue.Stop)
                    cities[CityNumber+1].BlueInit(&Blue);
            }

            if (Hour * 60 + 5 <= TotalTime) {
                for (int i = 0; i <= CityNumber + 1; ++i) {
                    if (cities[i].redwarrior ) {
                        if ( cities[i].redwarrior->WarriorKind() == 3 ) {
                            if (cities[i].redwarrior->LionEscape(Hour)) {
                                Red.DestroyWarrior(cities[i].redwarrior->WarriorOrderInTotal() - 1);
                                delete cities[i].redwarrior;
                                cities[i].redwarrior = NULL;
                            }
                        }
                    }
                    if (cities[i].bluewarrior ) {
                        if( cities[i].bluewarrior->WarriorKind() == 3 ) {
                            if (cities[i].bluewarrior->LionEscape(Hour)) {
                                Blue.DestroyWarrior(cities[i].bluewarrior->WarriorOrderInTotal() - 1);
                                delete cities[i].bluewarrior;
                                cities[i].bluewarrior = NULL;
                            }
                        }
                    }
                }
            }

            if (Hour * 60 + 10 <= TotalTime) {
                int shangxian = CityNumber + 1;
                for (int i = shangxian; i > 0; i--) {
                    RedWarriorMove(&cities[i-1], &cities[i], Hour);
                }
                for (int i = 0; i < shangxian; i++) {
                    BlueWarriorMove(&cities[i+1], &cities[i], Hour);
                }
                if (!Headquarter::MainFlag) break;
            }

            if (Hour * 60 + 35 <= TotalTime) {
                for (int i = 1; i < CityNumber+1; ++i) {
                    if (cities[i].redwarrior && cities[i].bluewarrior) {
                        cities[i].redwarrior->Rob(cities[i].bluewarrior, Hour);
                        cities[i].bluewarrior->Rob(cities[i].redwarrior, Hour);
                    }
                }
            }

            if (Hour * 60 + 40 <= TotalTime) {
                for (int i = 1; i < CityNumber+1; ++i)
                    cities[i].Battling(Hour, &Red, &Blue);
            }

            if (Hour * 60 + 50 <= TotalTime) {
                Red.HeadAnnounce(Hour);
                Blue.HeadAnnounce(Hour);
            }

            if (Hour * 60 + 55 <= TotalTime) {
                for (int i = 1; i < CityNumber+1; ++i) {
                    if (cities[i].redwarrior) cities[i].redwarrior->WarriorAnnounce(Hour);
                    if (cities[i].bluewarrior) cities[i].bluewarrior->WarriorAnnounce(Hour);
                }
            }

            Hour++;
        }
    }

    return 0;
}