在郭老师的魔兽二代码基础上一通乱改得到的。
初期思路混乱,于是代码混乱。
有个疑点:为什么我new出来的都没有delete却是可以的呢?
#include <iostream>
#include <cstdio>
#include <cstring>
#include <string>
#include <cmath>
#include <algorithm>
using namespace std;
#define WARRIOR_NUM 5
#define WEAPON_NUM 3
#define MAX_WARRIORS 1000
enum { DRAGON,NINJA,ICEMAN,LION,WOLF };
/*
char * CWarrior::Names[WARRIOR_NUM] = { "dragon","ninja","iceman","lion","wolf" };
红方司令部按照 iceman、lion、wolf、ninja、dragon 的顺序制造武士。
蓝方司令部按照 lion、dragon、ninja、iceman、wolf 的顺序制造武士。
*/
int n,k;//n cities,lion loses k loyalty per step
bool warStopped=false;
class CHeadquarter;
class CWarrior;
CWarrior* city[25][2];
class CWeapon
{
public:
int nKindNo;//0sword 1bomb 2arrow
int nNo;//number in warriors hands
int nTimesLeft;
virtual int nForce(int userForce){return 0;};
virtual void useWeapon(CWarrior* user, CWarrior* taker){
}
static const char * Names[WEAPON_NUM];
CWeapon(int no_){
nNo=no_;
nTimesLeft=2;
}
};
bool compare(CWeapon* w1,CWeapon* w2){
if (w1->nKindNo<w2->nKindNo) return true;
else if(w1->nKindNo>w2->nKindNo) return false;
else if(w1->nKindNo==2&&w2->nKindNo==2){
if(w1->nTimesLeft<w2->nTimesLeft){
return true;
}
else{
return false;
}
}
return false;
}
bool recompare(CWeapon* w1,CWeapon* w2){
if (w1->nKindNo<w2->nKindNo) return true;
else if(w1->nKindNo>w2->nKindNo) return false;
else if(w1->nKindNo==2&&w2->nKindNo==2){
if(w1->nTimesLeft<w2->nTimesLeft){
return false;
}
else{
return true;
}
}
return false;
}
class CWarrior
{
public:
CHeadquarter * pHeadquarter;
int nNo;//"no."in its headquarter
int location;
static const char * Names[WARRIOR_NUM];
static int InitialLifeValue [WARRIOR_NUM];
static int Attack [WARRIOR_NUM];
int nLoyalty=100;
int lifeValue;
int attack;
CWeapon* wp[11];
int weaponCount;
CWarrior( CHeadquarter * p,int nNo_);
virtual int getType()=0;
virtual void PrintResult(int nTime,int nKindNo);
virtual void PrintResult(int nTime) = 0;
~CWarrior(){
for(int i=0;i<10;i++){
if(wp[i]!=NULL){
delete wp[i];
}
}
}
virtual void wMarch(int dir,int _time){
city[location][dir]=NULL;
location+=pow(-1,dir);
city[location][dir]=this;
}
void takeBlow(CWeapon* w,CWarrior* user){
lifeValue-= (w->nForce(user->attack));
}
void takeBackfire(CWeapon* w){
lifeValue-=((w->nForce(attack))/2);
}
void ditchWeapon(int n){
weaponCount--;
for(int i=n;i<=weaponCount;i++){
wp[i]=wp[i+1];
if(wp[i]!=NULL)
wp[i]->nNo=i;
}
wp[weaponCount]=NULL;
}
void sortWeapon(){
sort(wp,wp+weaponCount,compare);
}
void resortWeapon(){
sort(wp,wp+weaponCount,recompare);
}
bool isStable(){
if(this==NULL) return true;
for(int i=0;i<weaponCount;i++){
if(wp[i]->nForce(attack)>0||wp[i]->nKindNo!=0)
return false;
}
return true;
}
void wReportWeapon(int _time);
void rob(CWarrior* W){
W->resortWeapon();
for(int i=0;i<W->weaponCount;i++){
W->wp[i]->nNo=i;
}
while(weaponCount<10&&W->weaponCount>0){
wp[weaponCount]=W->wp[0];
wp[weaponCount]->nNo=weaponCount;
W->ditchWeapon(0);
weaponCount++;
}
}
};
class CSword:public CWeapon{
public:
CSword(int no_):CWeapon(no_){
CWeapon::nKindNo=0;};
int nForce(int userForce){
return userForce*2/10;
}
void useWeapon(CWarrior* user, CWarrior* taker){
taker->takeBlow(this,user);
}
};
class CBomb:public CWeapon{
public:
CBomb(int no_):CWeapon(no_){CWeapon::nKindNo=1;};
int nForce(int userForce){
return userForce*4/10;
}
void useWeapon(CWarrior* user, CWarrior* taker){
taker->takeBlow(this,user);
if(user->getType()!=2)
user->takeBackfire(this);
user->ditchWeapon(nNo);
}
};
class CArrow:public CWeapon{
public:
CArrow(int no_):CWeapon(no_){CWeapon::nKindNo=2;};
int nForce(int userForce){
return userForce*3/10;
}
void useWeapon(CWarrior* user,CWarrior* taker){
taker->takeBlow(this,user);
nTimesLeft--;
if(nTimesLeft<=0){
user->ditchWeapon(nNo);
}
}
};
class CDragon;
class CNinja;
class CIceman;
class CLion;
class CWolf;
class CHeadquarter
{
private:
int nTotalLifeValue;
bool bStopped;
int nCurMakingSeqIdx;
int anWarriorNum[WARRIOR_NUM];
int nTotalWarriorNum;
CWarrior * pWarriors[MAX_WARRIORS];
public:
int nColor;
friend class CWarrior;
static int MakingSeq[2][WARRIOR_NUM];
void Init(int nColor_, int lv);
~CHeadquarter () ;
int Produce(int nTime);
void GetColor( char * szColor);
int GetTotalLifeValue() { return nTotalLifeValue; }
void March(int dir,int _time){
for(int i=0;i<nTotalWarriorNum;i++){
if(pWarriors[i]!=NULL){
pWarriors[i]->wMarch(dir,_time);
}
}
}
void CheckRun(int _time){
for(int i=0;i<nTotalWarriorNum;i++){
if((pWarriors[i]!=NULL)&&(pWarriors[i]->getType()==4)&&(pWarriors[i]->nLoyalty<=0)&&(pWarriors[i]->location!=(((n+1)+(n+1)*pow(-1,nColor))/2))){
char szColor[20];
pWarriors[i]->pHeadquarter->GetColor(szColor);
int hour= _time/60,minute=_time%60;
printf("%03d:%02d %s lion %d ran away\n",hour,minute,szColor,pWarriors[i]->nNo);
//cout<<city[pWarriors[i]->location][nColor]->nNo<<endl;
city[pWarriors[i]->location][nColor]=NULL;
pWarriors[i]=NULL;
}
}
}
void loseWarrior(CWarrior* W){
pWarriors[W->nNo-1]=NULL;
}
void ReportLifeValue(int _time){
int hour=_time/60,minute=_time%60;
char szcolor[20];
GetColor(szcolor);
printf("%03d:%02d %d elements in %s headquarter\n",hour,minute,nTotalLifeValue,szcolor);
}
/*void ReportWeapon(int _time){
for(int i=0;i<nTotalWarriorNum;i++){
if(pWarriors[i]!=NULL){
pWarriors[i]->wReportWeapon(_time);
}
}
}*/
};
class CDragon:public CWarrior
{
private:
double fmorale;
//int lifeValue;
//int attack;
//int location;
public:
int type=1;
void Countmorale()
{
fmorale = pHeadquarter -> GetTotalLifeValue() /(double)CWarrior::InitialLifeValue [0];
}
CDragon( CHeadquarter * p,int nNo_):
CWarrior(p,nNo_) {
weaponCount=1;
switch(nNo % WEAPON_NUM){
case 0:
wp[0]=new CSword(0);
break;
case 1:
wp[0]=new CBomb(0);
break;
case 2:
wp[0]=new CArrow(0);
break;
}
lifeValue=InitialLifeValue[DRAGON];
attack=Attack[DRAGON];
if(p->nColor==1){
location=n+1;
}
else{
location=0;
}
Countmorale();
}
void PrintResult(int nTime)
{
CWarrior::PrintResult(nTime,DRAGON);
/*printf("It has a %s,and it's morale is %.2f\n",
CWeapon::Names[wp[0]->nKindNo], fmorale);*/
}
virtual void wMarch(int dir,int _time){
city[location][dir]=NULL;
location+=pow(-1,dir);
int hour=_time/60;
int minute=_time%60;
char szColor[20];
pHeadquarter->GetColor(szColor);
//printf("%03d:%02d %s dragon %d marched to city %d with %d elements and force %d\n",hour,minute, szColor, nNo, location,lifeValue,attack);
city[location][dir]=this;
if((location==0&&dir==1)||(location==n+1&&dir==0)){
warStopped=true;
/*
string opColor;
if(szColor=="red") opColor="blue";
else opColor="red";
printf("%03d:%02d %s dragon %d reached %s headquarter with %d elements and force %d\n",hour,minute, szColor, nNo, opColor.c_str(),lifeValue,attack);
printf("%03d:%02d %s headquarter was taken\n",hour,minute, opColor.c_str());*/
}
}
int getType(){
return type;
}
};
class CNinja:public CWarrior
{
private:
//int lifeValue;
//int attack;
//int location;
public:
int type=2;
CNinja( CHeadquarter * p,int nNo_):
CWarrior(p,nNo_) {
weaponCount=2;
switch(nNo % WEAPON_NUM){
case 0:
wp[0]=new CSword(0);
wp[1]=new CBomb(1);
break;
case 1:
wp[0]=new CBomb(0);
wp[1]=new CArrow(1);
break;
case 2:
wp[0]=new CArrow(0);
wp[1]=new CSword(1);
break;
}
lifeValue=InitialLifeValue[NINJA];
attack=Attack[NINJA];
if(p->nColor==1){
location=n+1;
}
else{
location=0;
}
}
void PrintResult(int nTime)
{
CWarrior::PrintResult(nTime,NINJA);
/*printf("It has a %s and a %s\n",
CWeapon::Names[wp[0]->nKindNo],
CWeapon::Names[wp[1]->nKindNo]);*/
}
virtual void wMarch(int dir,int _time){
city[location][dir]=NULL;
location+=pow(-1,dir);
int hour=_time/60;
int minute=_time%60;
char szColor[20];
pHeadquarter->GetColor(szColor);
//printf("%03d:%02d %s ninja %d marched to city %d with %d elements and force %d\n",hour,minute, szColor, nNo, location,lifeValue,attack);
city[location][dir]=this;
if((location==0&&dir==1)||(location==n+1&&dir==0)){
warStopped=true;
/*string opColor;
if(szColor=="red") opColor="blue";
else opColor="red";
printf("%03d:%02d %s ninja %d reached %s headquarter with %d elements and force %d\n",hour,minute, szColor, nNo, opColor,lifeValue,attack);
printf("%03d:%02d %s headquarter was taken\n",hour,minute, opColor);*/
}
}
int getType(){
return type;
}
};
class CIceman:public CWarrior
{
private:
//int lifeValue;
//int attack;
//int location;
//CWeapon* wp[10];
public:
int type=3;
CIceman( CHeadquarter * p,int nNo_):
CWarrior(p,nNo_)
{
weaponCount=1;
switch(nNo % WEAPON_NUM){
case 0:
wp[0]=new CSword(0);
break;
case 1:
wp[0]=new CBomb(0);
break;
case 2:
wp[0]=new CArrow(0);
break;
}
lifeValue=InitialLifeValue[ICEMAN];
attack=Attack[ICEMAN];
char szcolor[20];
p->GetColor(szcolor);
if(p->nColor==1){
location=n+1;
}
else{
location=0;
}
}
void PrintResult(int nTime)
{
CWarrior::PrintResult(nTime,ICEMAN);
/*printf("It has a %s\n",
CWeapon::Names[wp[0]->nKindNo]);
cout<<weaponCount<<'!'<<endl;*/
}
virtual void wMarch(int dir,int _time){
city[location][dir]=NULL;
location+=pow(-1,dir);
int hour=_time/60;
int minute=_time%60;
char szColor[20];
pHeadquarter->GetColor(szColor);
city[location][dir]=this;
lifeValue-=(lifeValue/10);
//printf("%03d:%02d %s iceman %d marched to city %d with %d elements and force %d\n",hour,minute, szColor, nNo, location,lifeValue,attack);
if((location==0&&dir==1)||(location==n+1&&dir==0)){
warStopped=true;
/*string opColor;
if(szColor=="red") opColor="blue";
else opColor="red";
printf("%03d:%02d %s iceman %d reached %s headquarter with %d elements and force %d\n",hour,minute, szColor, nNo, opColor,lifeValue,attack);
printf("%03d:%02d %s headquarter was taken\n",hour,minute, opColor);*/
}
}
int getType(){
return type;
}
};
class CLion:public CWarrior
{
private:
//int lifeValue;
//int attack;
//int location;
public:
int type=4;
void CountLoyalty()
{
nLoyalty = pHeadquarter ->GetTotalLifeValue();
}
CLion( CHeadquarter * p,int nNo_):
CWarrior(p,nNo_) {
weaponCount=1;
CountLoyalty();
switch(nNo % WEAPON_NUM){
case 0:
wp[0]=new CSword(0);
break;
case 1:
wp[0]=new CBomb(0);
break;
case 2:
wp[0]=new CArrow(0);
break;
}
lifeValue=InitialLifeValue[LION];
attack=Attack[LION];
if(p->nColor==1){
location=n+1;
//cout<<"lion in red"<<endl;
}
else{
location=0;
//cout<<"in blue"<<endl;
}
//cout<<"location now "<<location<<endl;
}
void PrintResult(int nTime)
{
CWarrior::PrintResult(nTime,LION);
CountLoyalty();
printf("Its loyalty is %d\n",nLoyalty);
//cout<<weaponCount<<endl;
}
virtual void wMarch(int dir,int _time){
city[location][dir]=NULL;
location+=pow(-1,dir);
int hour=_time/60;
int minute=_time%60;
char szColor[20];
pHeadquarter->GetColor(szColor);
//printf("%03d:%02d %s lion %d marched to city %d with %d elements and force %d\n",hour,minute, szColor, nNo, location,lifeValue,attack);
city[location][dir]=this;
nLoyalty-=k;
if((location==0&&dir==1)||(location==n+1&&dir==0)){
warStopped=true;
/*
string opColor;
if(szColor=="red") opColor="blue";
else opColor="red";
printf("%03d:%02d %s lion %d reached %s headquarter with %d elements and force %d\n",hour,minute, szColor, nNo, opColor,lifeValue,attack);
printf("%03d:%02d %s headquarter was taken\n",hour,minute, opColor);*/
}
}
int getType(){
return type;
}
};
class CWolf:public CWarrior
{
private:
//int lifeValue;
//int attack;
//int location;
public:
int type=5;
CWolf( CHeadquarter * p,int nNo_):
CWarrior(p,nNo_) {
weaponCount=0;
lifeValue=InitialLifeValue[WOLF];
attack=Attack[WOLF];
if(p->nColor==1){
location=n+1;
}
else{
location=0;
}
}
void PrintResult(int nTime)
{
CWarrior::PrintResult(nTime,WOLF);
}
virtual void wMarch(int dir,int _time){
city[location][dir]=NULL;
location+=pow(-1,dir);
int hour=_time/60;
int minute=_time%60;
char szColor[20];
pHeadquarter->GetColor(szColor);
//printf("%03d:%02d %s wolf %d marched to city %d with %d elements and force %d\n",hour,minute, szColor, nNo, location,lifeValue,attack);
city[location][dir]=this;
if((location==0&&dir==1)||(location==n+1&&dir==0)){
warStopped=true;
/*
string opColor;
if(szColor=="red") opColor="blue";
else opColor="red";
printf("%03d:%02d %s wolf %d reached %s headquarter with %d elements and force %d\n",hour,minute, szColor, nNo, opColor,lifeValue,attack);
printf("%03d:%02d %s headquarter was taken\n",hour,minute, opColor);*/
}
}
int getType(){
return type;
}
};
CWarrior::CWarrior( CHeadquarter * p,int nNo_) {
nNo = nNo_;
pHeadquarter = p;
for(int i=0;i<10;i++){
wp[i]=NULL;
}
}
void CWarrior::PrintResult(int nTime,int nKindNo)
{
char szColor[20];
pHeadquarter->GetColor(szColor);
int hour=nTime/60,minute=nTime%60;
printf("%03d:%02d %s %s %d born\n" ,
hour, minute, szColor, Names[nKindNo], nNo);
}
void CHeadquarter::Init(int nColor_, int lv)
{
nColor = nColor_;
nTotalLifeValue = lv;
bStopped = false;
nCurMakingSeqIdx = 0;
nTotalWarriorNum = 0;
for( int i = 0;i < WARRIOR_NUM;i ++ )
anWarriorNum[i] = 0;
}
CHeadquarter::~CHeadquarter () {
int i;
for( i = 0;i < nTotalWarriorNum; i ++ )
if(pWarriors[i]!=NULL){
delete pWarriors[i];
}
}
int CHeadquarter::Produce(int nTime)
{
int nSearchingTimes = 0;
if( bStopped )
return 0;
/*while( CWarrior::InitialLifeValue[MakingSeq[nColor][nCurMakingSeqIdx]] > nTotalLifeValue &&
nSearchingTimes < WARRIOR_NUM ) {
nCurMakingSeqIdx = ( nCurMakingSeqIdx + 1 ) % WARRIOR_NUM ;
nSearchingTimes ++;
}*/
int nKindNo = MakingSeq[nColor][nCurMakingSeqIdx];
if( CWarrior::InitialLifeValue[nKindNo] > nTotalLifeValue ) {
bStopped = true;
/*if( nColor == 0)
printf("%03d red headquarter stops making warriors\n",nTime);
else
printf("%03d blue headquarter stops making warriors\n",nTime);*/
return 0;
}
nTotalLifeValue -= CWarrior::InitialLifeValue[nKindNo];
nCurMakingSeqIdx = ( nCurMakingSeqIdx + 1 ) % WARRIOR_NUM ;
int nTmp = anWarriorNum[nKindNo];
anWarriorNum[nKindNo] ++;
switch( nKindNo ) {
case DRAGON:
pWarriors[nTotalWarriorNum] = new CDragon( this,nTotalWarriorNum+1);
break;
case NINJA:
pWarriors[nTotalWarriorNum] = new CNinja( this,nTotalWarriorNum+1);
break;
case ICEMAN:
pWarriors[nTotalWarriorNum] = new CIceman( this,nTotalWarriorNum+1);
break;
case LION:
pWarriors[nTotalWarriorNum] = new CLion( this,nTotalWarriorNum+1);
break;
case WOLF:
pWarriors[nTotalWarriorNum] = new CWolf( this,nTotalWarriorNum+1);
break;
}
pWarriors[nTotalWarriorNum]->PrintResult(nTime);
nTotalWarriorNum ++;
return 1;
}
void CHeadquarter::GetColor( char * szColor)
{
if( nColor == 0)
strcpy(szColor,"red");
else
strcpy(szColor,"blue");
}
void ReportWeapon(int i, int _time){
if(city[i][0]!=NULL){
city[i][0]->wReportWeapon(_time);
}
if(city[i][1]!=NULL){
city[i][1]->wReportWeapon(_time);
}
}
void CWarrior::wReportWeapon(int _time){
int wnum[3]={0};
for(int i=0;i<weaponCount;i++){
if(wp[i]!=NULL){
wnum[wp[i]->nKindNo]++;
}
}
char szname[20];
pHeadquarter->GetColor(szname);
int hour=_time/60,minute=_time%60;
printf("%03d:%02d %s %s %d has %d sword %d bomb %d arrow and %d elements\n",hour,minute,szname,Names[getType()-1],nNo,wnum[0],wnum[1],wnum[2],lifeValue);
}
const char * CWeapon::Names[WEAPON_NUM] = {"sword","bomb","arrow" };
const char * CWarrior::Names[WARRIOR_NUM] = { "dragon","ninja","iceman","lion","wolf" };
int CWarrior::InitialLifeValue [WARRIOR_NUM];
int CWarrior::Attack[WARRIOR_NUM];
int CHeadquarter::MakingSeq[2][WARRIOR_NUM] = { { 2,3,4,1,0 },{3,0,1,2,4} };
void CheckRob(int i,int _time){
if(city[i][0]!=NULL&&city[i][1]!=NULL){
if(((city[i][0]->getType())==5)&&(city[i][1]->getType()!=5)&&(city[i][1]->weaponCount>0)){
int robnum=0;
city[i][1]->resortWeapon();
for(int j=0;j<city[i][1]->weaponCount;j++){
city[i][1]->wp[j]->nNo=j;
}
int wpkind=city[i][1]->wp[0]->nKindNo;
while((city[i][0]->weaponCount<10)&&(city[i][1]->weaponCount>0)&&(city[i][1]->wp[0]->nKindNo==wpkind)){
city[i][0]->wp[city[i][0]->weaponCount]=city[i][1]->wp[0];
city[i][1]->ditchWeapon(0);
city[i][0]->wp[city[i][0]->weaponCount]->nNo=city[i][0]->weaponCount;
city[i][0]->weaponCount++;
robnum++;
}
int hour=_time/60,minute=_time%60;
printf("%03d:%02d red wolf %d took %d %s from blue %s %d in city %d\n",hour,minute,city[i][0]->nNo,robnum,CWeapon::Names[wpkind],city[i][1]->Names[city[i][1]->getType()-1],city[i][1]->nNo,i);
}
if(((city[i][0]->getType())!=5)&&(city[i][1]->getType()==5)&&(city[i][0]->weaponCount>0)){
int robnum=0;
city[i][0]->resortWeapon();
for(int j=0;j<city[i][0]->weaponCount;j++){
city[i][0]->wp[j]->nNo=j;
}
int wpkind=city[i][0]->wp[0]->nKindNo;
while((city[i][1]->weaponCount<10)&&(city[i][0]->weaponCount>0)&&(city[i][0]->wp[0]->nKindNo==wpkind)){
city[i][1]->wp[city[i][1]->weaponCount]=city[i][0]->wp[0];
city[i][0]->ditchWeapon(0);
city[i][1]->wp[city[i][1]->weaponCount]->nNo=city[i][1]->weaponCount;
city[i][1]->weaponCount++;
robnum++;
}
int hour=_time/60,minute=_time%60;
char szColor[20],opcolor[20];
city[i][1]->pHeadquarter->GetColor(szColor);
city[i][0]->pHeadquarter->GetColor(opcolor);
printf("%03d:%02d blue wolf %d took %d %s from red %s %d in city %d\n",hour,minute,city[i][1]->nNo,robnum,CWeapon::Names[wpkind],city[i][0]->Names[city[i][0]->getType()-1],city[i][0]->nNo,i);
}
}
}
void printMarch(int i,int _time){
int hour=_time/60,minute=_time%60;
if(i==0&&city[0][1]!=NULL){
printf("%03d:%02d blue %s %d reached red headquarter with %d elements and force %d\n",hour,minute,city[0][1]->Names[city[0][1]->getType()-1],city[0][1]->nNo,city[0][1]->lifeValue,city[0][1]->attack);
printf("%03d:%02d red headquarter was taken\n",hour,minute);
}
else if(i==n+1&&city[n+1][0]!=NULL){
printf("%03d:%02d red %s %d reached blue headquarter with %d elements and force %d\n",hour,minute,city[n+1][0]->Names[city[n+1][0]->getType()-1],city[n+1][0]->nNo,city[n+1][0]->lifeValue,city[n+1][0]->attack);
printf("%03d:%02d blue headquarter was taken\n",hour,minute);
}
else{
for(int j=0;j<2;j++){
if(city[i][j]!=NULL){
char szcolor[20];
city[i][j]->pHeadquarter->GetColor(szcolor);
printf("%03d:%02d %s %s %d marched to city %d with %d elements and force %d\n",hour,minute,szcolor,city[i][j]->Names[city[i][j]->getType()-1],city[i][j]->nNo,i,city[i][j]->lifeValue,city[i][j]->attack);
}
}
}
}
void nFight(int i, int _time){
if(city[i][0]!=NULL&&city[i][1]!=NULL){
int second=i%2,first=1-second;
int index1=0,index2=0;
city[i][0]->sortWeapon();
for(int j=0;j<city[i][0]->weaponCount;j++){
city[i][0]->wp[j]->nNo=j;
}
city[i][1]->sortWeapon();
for(int j=0;j<city[i][1]->weaponCount;j++){
city[i][1]->wp[j]->nNo=j;
}
bool noWeapon1=false,noWeapon2=false;
while((!(city[i][0]->weaponCount==0&&city[i][1]->weaponCount==0))&&(city[i][0]->lifeValue>0)&&(city[i][1]->lifeValue>0)&&(!(city[i][0]->isStable()&&(city[i][1]->isStable())))){
if(city[i][first]->lifeValue>0&&city[i][first]->weaponCount!=0){
CWeapon* wpNow=city[i][first]->wp[index1];
wpNow->useWeapon(city[i][first],city[i][second]);
if((wpNow->nKindNo==1)||(wpNow->nTimesLeft<=0)){
if(city[i][first]->weaponCount!=0)
index1%=(city[i][first]->weaponCount);
}
else{
if(city[i][first]->weaponCount!=0)
index1=(index1+1)%(city[i][first]->weaponCount);
}
}
if(city[i][second]->lifeValue>0&&city[i][second]->weaponCount!=0){
CWeapon* wpNow=city[i][second]->wp[index2];
wpNow->useWeapon(city[i][second],city[i][first]);
if((wpNow->nKindNo==1)||(wpNow->nTimesLeft<=0)){
if(city[i][second]->weaponCount!=0)
index2%=(city[i][second]->weaponCount);
}
else{
if(city[i][second]->weaponCount!=0)
index2=(index2+1)%(city[i][second]->weaponCount);
}
}
}
CWarrior* rwarrior=city[i][0];
CWarrior* bwarrior=city[i][1];
int hour=_time/60,minute=_time%60;
if(rwarrior->lifeValue>0&&bwarrior->lifeValue<=0){
printf("%03d:%02d red %s %d killed blue %s %d in city %d remaining %d elements\n",hour,minute,rwarrior->Names[rwarrior->getType()-1],rwarrior->nNo,bwarrior->Names[bwarrior->getType()-1],bwarrior->nNo,i,rwarrior->lifeValue);
rwarrior->rob(bwarrior);
}
else if(rwarrior->lifeValue<=0&&bwarrior->lifeValue>0){
printf("%03d:%02d blue %s %d killed red %s %d in city %d remaining %d elements\n",hour,minute,bwarrior->Names[bwarrior->getType()-1],bwarrior->nNo,rwarrior->Names[rwarrior->getType()-1],rwarrior->nNo,i,bwarrior->lifeValue);
bwarrior->rob(rwarrior);
}
else if(rwarrior->lifeValue>0&&bwarrior->lifeValue>0){
//printf("%d \n",i);
printf("%03d:%02d both red %s %d and blue %s %d were alive in city %d\n",hour,minute,rwarrior->Names[rwarrior->getType()-1],rwarrior->nNo,bwarrior->Names[bwarrior->getType()-1],bwarrior->nNo,i);
}
else if(rwarrior->lifeValue<=0&&bwarrior->lifeValue<=0){
printf("%03d:%02d both red %s %d and blue %s %d died in city %d\n",hour,minute,rwarrior->Names[rwarrior->getType()-1],rwarrior->nNo,bwarrior->Names[bwarrior->getType()-1],bwarrior->nNo,i);
}
if(rwarrior->lifeValue>0&&rwarrior->getType()==1){
printf("%03d:%02d red dragon %d yelled in city %d\n",hour,minute,rwarrior->nNo,i);
}
if(bwarrior->lifeValue>0&&bwarrior->getType()==1){
printf("%03d:%02d blue dragon %d yelled in city %d\n",hour,minute,bwarrior->nNo,i);
}
for(int j=0;j<2;j++){
if(city[i][j]->lifeValue<=0){
city[i][j]->pHeadquarter->loseWarrior(city[i][j]);
city[i][j]=NULL;
}
}
}
}
int main()
{
int t;
int m;//totalLifeValue for each headquarter
int T;//T minutes
CHeadquarter RedHead,BlueHead;
scanf("%d",&t);
int nCaseNo = 1;
while ( t -- ) {
warStopped=false;
for(int i=0;i<25;i++){
city[i][0]=NULL;
city[i][1]=NULL;
}
printf("Case %d:\n",nCaseNo++);
scanf("%d",&m);//totalLifeValue
cin>>n>>k>>T;
int i;
for(i = 0;i < WARRIOR_NUM;i ++ )
scanf("%d", & CWarrior::InitialLifeValue[i]);
for(i = 0;i < WARRIOR_NUM;i ++ )
scanf("%d", & CWarrior::Attack[i]);
// for(i = 0;i < WEAPON_NUM;i ++ )
// scanf("%d", & CWeapon::InitialForce[i]);
RedHead.Init(0,m);
BlueHead.Init(1,m);
int nTime = 0;
while( nTime<=T && warStopped==false) {
switch(nTime%60){
case 0:
RedHead.Produce(nTime);
BlueHead.Produce(nTime);
break;
case 5:
RedHead.CheckRun(nTime);
BlueHead.CheckRun(nTime);
break;
case 10:
RedHead.March(0,nTime);
BlueHead.March(1,nTime);
for(int i=0;i<=n+1;i++){
printMarch(i,nTime);
}
break;
case 35:
for(int i=1;i<=n;i++){
CheckRob(i,nTime);
}
break;
case 40:
for(int i=1;i<=n;i++){
nFight(i,nTime);
}
break;
case 50:
RedHead.ReportLifeValue(nTime);
BlueHead.ReportLifeValue(nTime);
break;
case 55:
for(int i=0;i<=n+1;i++){
ReportWeapon(i,nTime);
}
default:
break;
}
nTime +=5;
}
}
return 0;
}