程序设计实习MOOC/3129/B:魔兽世界之一:备战

B:魔兽世界之一:备战

总时间限制: 1000ms 内存限制: 65536kB
描述
魔兽世界的西面是红魔军的司令部,东面是蓝魔军的司令部。两个司令部之间是依次排列的若干城市。
红司令部,City 1,City 2,……,City n,蓝司令部

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

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

武士在刚降生的时候有一个生命值。

在每个整点,双方的司令部中各有一个武士降生。

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

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

制造武士需要生命元。

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

如果司令部中的生命元不足以制造某个按顺序应该制造的武士,那么司令部就试图制造下一个。如果所有武士都不能制造了,则司令部停止制造武士。

给定一个时间,和双方司令部的初始生命元数目,要求你将从0点0分开始到双方司令部停止制造武士为止的所有事件按顺序输出。
一共有两种事件,其对应的输出样例如下:

1) 武士降生
输出样例: 004 blue lion 5 born with strength 5,2 lion in red headquarter
表示在4点整,编号为5的蓝魔lion武士降生,它降生时生命值为5,降生后蓝魔司令部里共有2个lion武士。(为简单起见,不考虑单词的复数形式)注意,每制造出一个新的武士,都要输出此时司令部里共有多少个该种武士。

2) 司令部停止制造武士
输出样例: 010 red headquarter stops making warriors
表示在10点整,红方司令部停止制造武士

输出事件时:

首先按时间顺序输出;

同一时间发生的事件,先输出红司令部的,再输出蓝司令部的。

输入
第一行是一个整数,代表测试数据组数。

每组测试数据共两行。

第一行:一个整数M。其含义为, 每个司令部一开始都有M个生命元( 1 <= M <= 10000)。

第二行:五个整数,依次是 dragon 、ninja、iceman、lion、wolf 的初始生命值。它们都大于0小于等于10000。
输出
对每组测试数据,要求输出从0时0分开始,到双方司令部都停止制造武士为止的所有事件。
对每组测试数据,首先输出"Case:n" n是测试数据的编号,从1开始 。
接下来按恰当的顺序和格式输出所有事件。每个事件都以事件发生的时间开头,时间以小时为单位,有三位。
样例输入

1
20
3 4 5 6 7

样例输出

Case:1
000 red iceman 1 born with strength 5,1 iceman in red headquarter
000 blue lion 1 born with strength 6,1 lion in blue headquarter
001 red lion 2 born with strength 6,1 lion in red headquarter
001 blue dragon 2 born with strength 3,1 dragon in blue headquarter
002 red wolf 3 born with strength 7,1 wolf in red headquarter
002 blue ninja 3 born with strength 4,1 ninja in blue headquarter
003 red headquarter stops making warriors
003 blue iceman 4 born with strength 5,1 iceman in blue headquarter
004 blue headquarter stops making warriors

题解分析

我定义了两个类:武士类wushi和司令营类headquarter。

武士类wushi

武士wushi类有六个静态成员:
1.字符串数组wushiName[5]存放五种武士的种类名称,通过输入获取
2.红魔武士的建造顺序,存放在整型数组redWushiSeq[5]中,为固定值
3.蓝魔武士的建造顺序,存放在整型数组redWushiSeq[5]中,为固定值
4.用一个整型数组wushiNum[12]存放不同种类的武士的数量。下标为0-5的六个元素存放的是红魔武士的数量,下标为5的元素存放红魔武士的总数量,即红魔武士编号。下标为6-11的六个元素存放的是蓝魔武士的数量,下标为11的元素存放蓝魔武士的总数量,即红魔武士编号。
5.武士的生命值数组wushiLife[5],存放不同种类武士的生命值,通过输入获取
6.最小武士的生命值minWushiLife,int类型

武士类还有两个普通成员变量:
1.整型变量headquarterType代表该武士属于哪个司令营,0表示红魔武士,6表示蓝魔武士
2.整型变量type表示武士种类,比如0代表dragon武士(0 dragon 、1 ninja、2 iceman、3 lion、4 wolf)
通过这两个普通成员变量headquarterTypetype就可以知道该武士是哪个司令营的何种武士,比如headquarterType==0并且type==0则表示该武士是红魔司令营的dragon武士。
武士类构造函数:武士wushi类的构造函数中会执行对应种类type的武士数量增一的操作。
武士类还有两个普通成员函数getNo()getWushiNum(),一个静态成员函数minLife()getNo()返回武士的编号,getWushiNum()返回该种武士在所在的司令营中的数量,minLife()返回最小武士生命值。

武士类wushi代码

class wushi
{
public:
    static string   wushiName[5];                   //武士种类名称
    static int      redWushiSeq[5];                 //红魔武士顺序
    static int      blueWushiSeq[5];                //蓝魔武士顺序
    static int      wushiNum[12];                   //武士数量 0-5红 6-11蓝
    static int      wushiLife[5];                   //武士的生命值数组
    static int      minWushiLife;                   //武士生命值的最小值
    int             headquarterType;                //司令营 0红 6蓝
    int             type;                           //武士种类 0 dragon 、1 ninja、2 iceman、3 lion、4 wolf
    wushi(int t, int h): type(t), headquarterType(h)
    {
        wushiNum[h + 5]++;                          //总数
        wushiNum[h + t]++;                          //对应武士种类
    }
    /** 获取编号值 */
    int getNo()
    {
        return wushiNum[headquarterType + 5];
    }
    /** 获取当前武士种类的数量 */
    int getWushiNum()
    {
        return wushiNum[headquarterType + type];
    }
    /** 计算最小武士生命值并返回 */
    static int minLife();
};
int wushi::minLife()
{
    int minL = wushiLife[0];
    for(int i = 1; i < 5; i++)
    {
        if(minL > wushiLife[i])
        {
            minL = wushiLife[i];
        }
    }
    return minL;
}

司令营类headquarter

司令营类headquarter有一个静态成员变量totaLife表示总生命元。
司令营类headquarter有四个普通成员变量:
1.司令营的类型headquarterType,标识是红魔司令营还是蓝魔司令营,int型,0表示红,6表示蓝
2.司令营的剩余生命元life,int
3.司令营是否停止建造武士isStop,bool
4.当前准备建造的武士的循环次序号seq (初始时为0,建造司令营中的第一个武士则次序号seq为0,建造第二个次序号seq为1,建造第三个次序号seq为2,...,第五个次序号seq为0,依次循环下去)
司令营类headquarter的构造函数需要指定司令营的类型,确定是红魔司令营还是蓝魔司令营。司令营剩余生命值life初始化为总生命元totaLifeisStopfalseseq初始值为0

司令营类有两个普通成员函数bulidWushi()stopBulid()bulidWushi()在指定的时刻建造武士,stopBulid()在指定时刻停止建造武士的任务。

司令营类headquarter代码

class headquarter
{
public:
    static int  totaLife;                           //总生命元
    int         headquarterType;                    //司令营 0红 6蓝
    int         life;                               //剩余生命元
    bool        isStop;                             //是否停止建造武士
    int         seq;                                //当前建造武士次序号
    headquarter(int hT): headquarterType(hT), life(totaLife), isStop(false), seq(0) {}
    void bulidWushi(int time, wushi bwushi);
    void stopBulid(int time);
};
void headquarter::bulidWushi(int time, wushi bwushi)
{
    cout.fill('0');                             //设置填充字符
    cout.width(3);                              //设置域宽
    cout << time;
    cout << (headquarterType == RED ? " red " : " blue ")
         << wushi::wushiName[bwushi.type]
         << " "
         << bwushi.getNo()
         << " born with strength "
         << wushi::wushiLife[bwushi.type]
         << ","
         << bwushi.getWushiNum()
         << " "
         << wushi::wushiName[bwushi.type]
         << " in"
         << (headquarterType == RED ? " red " : " blue ")
         << "headquarter"
         << endl;
    life -= wushi::wushiLife[bwushi.type];
    seq = (seq + 1) % 5;                        //下一个
}
void headquarter::stopBulid(int time)
{
    isStop = true;
    cout.fill('0');                             //设置填充字符
    cout.width(3);                              //设置域宽
    cout << time;
    cout << (headquarterType == RED ? " red " : " blue ")
         << "headquarter stops making warriors"
         << endl;
}

输出时刻time的格式为三个字符宽度,不足三位则填充“0”,代码如下

    cout.fill('0');                             //设置填充字符
    cout.width(3);                              //设置域宽
    cout << time;

静态成员要在所有函数外面单独声明

/** 静态成员声明 */
string  wushi::wushiName[]      = {"dragon", "ninja", "iceman", "lion", "wolf"};    //武士种类名称
int     wushi::redWushiSeq[]    = {2, 3, 4, 1, 0};                                  //红魔武士顺序
int     wushi::blueWushiSeq[]   = {3, 0, 1, 2, 4};                                  //蓝魔武士顺序
int     wushi::wushiNum[]       = {0};                                              //武士数量 0-5红 6-11蓝
int     wushi::minWushiLife     = 0;                                                //武士生命值的最小值
int     headquarter::totaLife;                                                      //司令营的总生命元
int     wushi::wushiLife[5];                                                        //各种武士的生命值

完整代码

#include<iostream>
#include<string.h>
#include<cstdio>
using namespace std;
const int RED   = 0;
const int BLUE  = 6;
class wushi
{
public:
    static string   wushiName[5];                   //武士种类名称
    static int      redWushiSeq[5];                 //红魔武士顺序
    static int      blueWushiSeq[5];                //蓝魔武士顺序
    static int      wushiNum[12];                   //武士数量 0-5红 6-11蓝
    static int      wushiLife[5];                   //武士的生命值数组
    static int      minWushiLife;                   //武士生命值的最小值
    int             headquarterType;                //司令营 0红 6蓝
    int             type;                           //武士种类 0 dragon 、1 ninja、2 iceman、3 lion、4 wolf
    wushi(int t, int h): type(t), headquarterType(h)
    {
        wushiNum[h + 5]++;                          //总数
        wushiNum[h + t]++;                          //对应武士种类
    }
    /** 获取编号值 */
    int getNo()
    {
        return wushiNum[headquarterType + 5];
    }
    /** 获取当前武士种类的数量 */
    int getWushiNum()
    {
        return wushiNum[headquarterType + type];
    }
    /** 计算最小武士生命值并返回 */
    static int minLife();
};
int wushi::minLife()
{
    int minL = wushiLife[0];
    for(int i = 1; i < 5; i++)
    {
        if(minL > wushiLife[i])
        {
            minL = wushiLife[i];
        }
    }
    return minL;
}
class headquarter
{
public:
    static int  totaLife;                           //总生命元
    int         headquarterType;                    //司令营 0红 6蓝
    int         life;                               //剩余生命元
    bool        isStop;                             //是否停止建造武士
    int         seq;                                //当前建造武士次序号
    headquarter(int hT): headquarterType(hT), life(totaLife), isStop(false), seq(0) {}
    void bulidWushi(int time, wushi bwushi);
    void stopBulid(int time);
};
void headquarter::bulidWushi(int time, wushi bwushi)
{
    cout.fill('0');                             //设置填充字符
    cout.width(3);                              //设置域宽
    cout << time;
    cout << (headquarterType == RED ? " red " : " blue ")
         << wushi::wushiName[bwushi.type]
         << " "
         << bwushi.getNo()
         << " born with strength "
         << wushi::wushiLife[bwushi.type]
         << ","
         << bwushi.getWushiNum()
         << " "
         << wushi::wushiName[bwushi.type]
         << " in"
         << (headquarterType == RED ? " red " : " blue ")
         << "headquarter"
         << endl;
    life -= wushi::wushiLife[bwushi.type];
    seq = (seq + 1) % 5;                        //下一个
}
void headquarter::stopBulid(int time)
{
    isStop = true;
    cout.fill('0');                             //设置填充字符
    cout.width(3);                              //设置域宽
    cout << time;
    cout << (headquarterType == RED ? " red " : " blue ")
         << "headquarter stops making warriors"
         << endl;
}
/** 静态成员声明 */
string  wushi::wushiName[]      = {"dragon", "ninja", "iceman", "lion", "wolf"};    //武士种类名称
int     wushi::redWushiSeq[]    = {2, 3, 4, 1, 0};                                  //红魔武士顺序
int     wushi::blueWushiSeq[]   = {3, 0, 1, 2, 4};                                  //蓝魔武士顺序
int     wushi::wushiNum[]       = {0};                                              //武士数量 0-5红 6-11蓝
int     wushi::minWushiLife     = 0;                                                //武士生命值的最小值
int     headquarter::totaLife;                                                      //司令营的总生命元
int     wushi::wushiLife[5];                                                        //各种武士的生命值
int main()
{
    //freopen("in.txt","r",stdin);
    //freopen("mout.txt","w",stdout);
    int testn;                  //测试数据组数
    int casen   = 0;            //当前测试组数
    int time    = 0;            //时刻
    cin >> testn;               //输入测试数据组数
    while(testn > casen)
    {
        time = 0;
        casen++;                //当前测试数据组
        memset(wushi::wushiNum, 0, sizeof(int) * 12);
        /* 输入总生命元和武士生命值 */
        cin >> headquarter::totaLife
            >> wushi::wushiLife[0]
            >> wushi::wushiLife[1]
            >> wushi::wushiLife[2]
            >> wushi::wushiLife[3]
            >> wushi::wushiLife[4];
        cout << "Case:" << casen << endl;                   //输出当前测试数据组
        headquarter redH(RED);                              //红魔司令营
        headquarter blueH(BLUE);                            //蓝魔司令营
        wushi::minWushiLife = wushi::minLife();             //求出武士生命最小值
        while(!redH.isStop || !blueH.isStop)                //红魔或者蓝魔有一方还没有停止建造则继续建造
        {
            if(!redH.isStop)                                //红魔还没有停止建造
            {
                int wType = wushi::redWushiSeq[redH.seq];   //当前准备建造的武士种类
                if(redH.life >= wushi::wushiLife[wType])
                {
                    /* 造武士 */
                    wushi wRed(wType, RED);
                    redH.bulidWushi(time, wRed);
                }
                else if(redH.life >= wushi::minWushiLife)
                {
                    /* 当前生命元不足,造下一个武士 */
                    redH.seq = (redH.seq + 1) % 5;          //下一个
                    wType = wushi::redWushiSeq[redH.seq];
                    while(redH.life < wushi::wushiLife[wType])
                    {
                        redH.seq = (redH.seq + 1) % 5;      //下一个
                        wType = wushi::redWushiSeq[redH.seq];
                    }
                    wushi wRed(wType, RED);
                    redH.bulidWushi(time, wRed);
                }
                else
                {
                    /* 停止建造 */
                    redH.stopBulid(time);
                }
            }
            if(!blueH.isStop)                               //蓝魔还没有停止建造
            {
                int wType = wushi::blueWushiSeq[blueH.seq]; //当前准备建造的武士种类
                if(blueH.life >= wushi::wushiLife[wType])
                {
                    /* 造武士 */
                    wushi wBlue(wType, BLUE);
                    blueH.bulidWushi(time, wBlue);
                }
                else if(blueH.life >= wushi::minWushiLife)
                {
                    /* 当前生命元不足,造下一个武士 */
                    blueH.seq = (blueH.seq + 1) % 5;        //下一个
                    wType = wushi::blueWushiSeq[blueH.seq];
                    while(blueH.life < wushi::wushiLife[wType])
                    {
                        //cout<<"蓝魔生命:"<<blueH.life<<"下个武士生命:"<<wushi::wushiLife[wType]<<endl;
                        blueH.seq = (blueH.seq + 1) % 5;    //下一个
                        wType = wushi::blueWushiSeq[blueH.seq];
                    }
                    wushi wBlue(wType, BLUE);
                    blueH.bulidWushi(time, wBlue);
                }
                else
                {
                    /* 停止建造 */
                    blueH.stopBulid(time);
                }
            }
            time++;                                         //下一时刻
        }
    }
}

第一次写的完整代码

#include<iostream>
#include<string.h>
#include<cstdio>
using namespace std;
class wushiRed
{
public:
    static int wushiNum[6];
    int type;       //武士种类 0 dragon 、1 ninja、2 iceman、3 lion、4 wolf
    int no;         //编号
    int life;       //生命值
    int gong;       //攻击力
    wushiRed(int t, int n, int l, int g = 0): type(t), no(n + 1), life(l), gong(g)
    {
        wushiNum[5]++;//总数
        wushiNum[t]++;//对应武士种类

    }
};
class wushiBlue
{
public:
    int type;       //武士种类 0 dragon 、1 ninja、2 iceman、3 lion、4 wolf
    int no;         //编号
    int life;       //生命值
    int gong;       //攻击力
    static int wushiNum[6];
    wushiBlue(int t, int n, int l, int g = 0): type(t), no(n + 1), life(l), gong(g)
    {
        wushiNum[5]++;//总数
        wushiNum[t]++;//对应武士种类

    }
};
int minLife(int array[], int n)
{
    int min = array[0];
    for(int i = 1; i < n; i++)
    {
        if(min > array[i])
        {
            min = array[i];
        }
    }
    return min;
}
int wushiRed::wushiNum[] = {0};
int wushiBlue::wushiNum[] = {0};
int main()
{
    //freopen("in.txt","r",stdin);
    int testn;              //测试数据组数
    int casen = 0;          //目前测试组数
    int totalLife;          //总的生命元
    int redLife;            //红魔生命元
    int blueLife;           //蓝魔生命元
    int redWushi = 0;           //当前建造红魔武士次序号
    int blueWushi = 0;          //当前建造蓝魔武士次序号
    string wushiName[] = {"dragon", "ninja", "iceman", "lion", "wolf"};
    int redWushiSeq[] = {2, 3, 4, 1, 0};//红魔武士顺序
    int blueWushiSeq[] = {3, 0, 1, 2, 4};//蓝魔武士顺序
    int wushiLife[5];       //武士的生命值数组
    bool redStop = false;   //红魔是否停止
    bool blueStop = false;  //蓝魔是否停止
    int minWushiLife = 0;   //武士生命值的最小值
    int time = 0;           //时刻
    cin >> testn;           //输入测试数据组数
    while(testn > casen)
    {
        memset(wushiRed::wushiNum, 0, sizeof(int) * 6);
        memset(wushiBlue::wushiNum, 0, sizeof(int) * 6);
        time = 0;
        //输入总生命元和武士生命值
        cin >> totalLife >> wushiLife[0] >> wushiLife[1] >> wushiLife[2] >> wushiLife[3] >> wushiLife[4];
        casen++;                                //当前测试数据组
        cout << "Case:" << casen << endl;       //输出当前测试数据组
        minWushiLife = minLife(wushiLife, 5);   //求出武士生命最小值
        //cout<<"最小武士生命:"<<minWushiLife<<endl;
        redLife = totalLife;                    //红魔目前的生命元
        blueLife = totalLife;                   //蓝魔目前的生命元
        redWushi = 0;                           //红魔循环建造武士次序号
        blueWushi = 0;                          //蓝魔循环建造武士次序号
        redStop = false;
        blueStop = false;
        while(!redStop || !blueStop)            //红魔或者蓝魔有一方还没有停止建造
        {
            if(!redStop && redLife >= 0)         //红魔还有生命元并且没有停止建造
            {
                int wType = redWushiSeq[redWushi];//当前准备建造的武士种类
                //cout<<casen<<" 红魔剩余生命:"<<redLife <<"当前武士生命:"<<wushiLife[wType]<<"最小武士生命:"<<minWushiLife<<endl;
                if(redLife >= wushiLife[wType])
                {
                    wushiRed wRed(wType, wushiRed::wushiNum[5], wushiLife[wType]);
                    //cout << "004 blue lion 5 born with strength 5,2 lion in red headquarter" << endl;
                    cout.fill('0');//设置填充字符
                    cout.width(3);//设置域宽
                    cout << time;
                    cout << " red " << wushiName[wType]  << " " << wRed.no << " born with strength " << wushiLife[wType] << "," << wushiRed::wushiNum[wType] << " " << wushiName[wType] << " in red headquarter" << endl;
                    redLife -= wushiLife[wType];
                    redWushi = (redWushi + 1) % 5;//下一个
                }
                else if(redLife >= minWushiLife)
                {
                    for(int i = 0 ; i < 5; i++)
                    {
                        redWushi = (redWushi + 1) % 5;//下一个
                        wType = redWushiSeq[redWushi];
                        if(redLife >= wushiLife[wType])//造武士
                        {
                            wushiRed wRed(wType, wushiRed::wushiNum[5], wushiLife[wType]);
                            //cout << "004 blue lion 5 born with strength 5,2 lion in red headquarter" << endl;
                            cout.fill('0');//设置填充字符
                            cout.width(3);//设置域宽
                            cout << time;
                            cout <<  " red " << wushiName[wType] << " " << wRed.no << " born with strength " << wushiLife[wType] << "," << wushiRed::wushiNum[wType] << " " << wushiName[wType] << " in red headquarter" << endl;
                            redLife -= wushiLife[wType];
                            redWushi = (redWushi + 1) % 5;//下一个
                            break;
                        }
                    }
                }
                else
                {
                    redStop = true;
                    cout.fill('0');//设置填充字符
                    cout.width(3);//设置域宽
                    cout << time;
                    cout << " red headquarter stops making warriors" << endl;
                }
            }

            if(!blueStop && blueLife >= 0)         //蓝魔还有生命元并且没有停止建造
            {
                int wType = blueWushiSeq[blueWushi];//当前准备建造的武士种类
                //cout<<"蓝魔剩余生命:"<<blueLife <<"当前武士生命:"<<wushiLife[wType]<<"最小武士生命:"<<minWushiLife<<endl;
                if(blueLife >= wushiLife[wType])
                {
                    wushiBlue wBlue(wType, wushiBlue::wushiNum[5], wushiLife[wType]);
                    //cout << "004 blue lion 5 born with strength 5,2 lion in red headquarter" << endl;
                    cout.fill('0');//设置填充字符
                    cout.width(3);//设置域宽
                    cout << time;
                    cout << " blue " << wushiName[wType] << " " << wBlue.no << " born with strength " << wushiLife[wType] << "," << wushiBlue::wushiNum[wType] <<  " " << wushiName[wType] << " in blue headquarter" << endl;
                    blueLife -= wushiLife[wType];
                    blueWushi = (blueWushi + 1) % 5;
                }
                else if(blueLife >= minWushiLife)
                {
                    for(int i = 0 ; i < 5; i++)
                    {
                        blueWushi = (blueWushi + 1) % 5;
                        wType = blueWushiSeq[blueWushi];
                        if(blueLife >= wushiLife[wType])//造武士
                        {
                            wushiBlue wBlue(wType, wushiBlue::wushiNum[5], wushiLife[wType]);
                            //cout << "004 blue lion 5 born with strength 5,2 lion in red headquarter" << endl;
                            cout.fill('0');//设置填充字符
                            cout.width(3);//设置域宽
                            cout << time;
                            cout   << " blue " << wushiName[wType]  << " " << wBlue.no << " born with strength " << wushiLife[wType] << "," << wushiBlue::wushiNum[wType] << " " << wushiName[wType] << " in blue headquarter" << endl;
                            blueLife -= wushiLife[wType];
                            blueWushi = (blueWushi + 1) % 5;
                            break;
                        }
                    }
                }
                else
                {
                    blueStop = true;
                    cout.fill('0');//设置填充字符
                    cout.width(3);//设置域宽
                    cout << time;
                    cout  << " blue headquarter stops making warriors" << endl;
                }
            }
            time++;//下一时刻
        }
    }
}
  • 0
    点赞
  • 5
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
问题描述 魔兽世界的西面是红魔军的司令部,东面是蓝魔军的司令部。两个司令部之间是依次排列的若干城市,城市从西向东依次编号为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。 武士降生后就朝对方司令部走,在经过的城市如果遇到敌人(同一时刻每个城市最多只可能有1个蓝武士和一个红武士),就会发生战斗。每次战斗只有一方发起主动进攻一次。被攻击者生命值会减去进攻者的攻击力值和进攻者手中sword的攻击力值。被进攻者若没死,就会发起反击,被反击者的生命值要减去反击者攻击力值的一半(去尾取整)和反击者手中sword的攻击力值。反击可能致敌人于死地。 如果武士在战斗中杀死敌人(不论是主动进攻杀死还是反击杀死),则其司令部会立即向其发送8个生命元作为奖励,使其生命值增加8。当然前提是司令部得有8个生命元。如果司令部的生命元不足以奖励所有的武士,则优先奖励距离敌方司令部近的武士。 如果某武士在某城市的战斗中杀死了敌人,则该武士的司令部立即取得该城市中所有的生命元。注意,司令部总是先完成全部奖励工作,然后才开始从各个打了胜仗的城市回收生命元。对于因司令部生命元不足而领不到奖励的武士,司令部也不会在取得战利品生命元后为其补发奖励。 如果一次战斗的结果是双方都幸存(平局),则双方都不能拿走发生战斗的城市的生命元。 城市可以插旗子,一开始所有城市都没有旗子。在插红旗的城市,以及编号为奇数的无旗城市,由红武士主动发起进攻。在插蓝旗的城市,以及编号为偶数的无旗城市,由蓝武士主动发起进攻。 当某个城市有连续两场战斗都是同一方的武士杀死敌人(两场战斗之间如果有若干个战斗时刻并没有发生战斗,则这两场战斗仍然算是连续的;但如果中间有平局的战斗,就不算连续了) ,那么该城市就会插上胜方的旗帜,若原来插着败方的旗帜,则败方旗帜落下。旗帜一旦插上,就一直插着,直到被敌人更换。一个城市最多只能插一面旗帜,旗帜没被敌人更换前,也不会再次插同颜色的旗。 各种武器有其特点: sword武器的初始攻击力为拥有它的武士的攻击力的20%(去尾取整)。但是sword每经过一次战斗(不论是主动攻击还是反击),就会变钝,攻击力变为本次战斗前的80% (去尾取整)。sword攻击力变为0时,视为武士失去了sword。如果武士降生时得到了一个初始攻击力为0的sword,则视为武士没有sword. arrow有一个攻击力值R。如果下一步要走到的城市有敌人,那么拥有arrow的武士就会放箭攻击下一个城市的敌人(不能攻击对方司令部里的敌人)而不被还击。arrow使敌人的生命值减少R,若减至小于等于0,则敌人被杀死。arrow使用3次后即被耗尽,武士失去arrow。两个相邻的武士可能同时放箭把对方射死。 拥有bomb的武士,在战斗开始前如果判断自己将被杀死(不论主动攻击敌人,或者被敌人主动攻击都可能导致自己被杀死,而且假设武士可以知道敌人的攻击力和生命值),那么就会使用bomb和敌人同归于尽。武士不预测对方是否会使用bomb。 武士使用bomb和敌人同归于尽的情况下,不算是一场战斗,双方都不能拿走城市的生命元,也不影响城市的旗帜。 不同的武士有不同的特点。 dragon可以拥有一件武器。编号为n的dragon降生时即获得编号为 n%3 的武器。dragon还有“士气”这个属性,是个浮点数,其值为它降生后其司令部剩余生命元的数量除以造dragon所需的生命元数量。dragon 在一次在它主动进攻的战斗结束后,如果还没有战死,而且士气值大于0.8,就会欢呼。dragon每取得一次战斗的胜利(敌人被杀死),士气就会增加0.2,每经历一次未能获胜的战斗,士气值就会减少0.2。士气增减发生在欢呼之前。 ninjia可以拥有两件武器。编号为n的ninjia降生时即获得编号为 n%3 和 (n+1)%3的武器。ninja 挨打了也从不反击敌人。 iceman有一件武器。编号为n的iceman降生时即获得编号为 n%3 的武器。iceman 每前进两步,在第2步完成的时候,生命值
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值