>
#include <stdio.h>
using namespace std;
struct bprototype
{
float attack=21;
float fshield=0.20;
float bshield=0.80;
float ishield=1.20;
float cshield=1.00;
int hp=21;
string priority[4]={"f","b","i","c"};
};
struct fprototype
{
int attack=12;
float fshield=0.60;
float bshield=1.50;
float ishield=0.20;
float cshield=1.00;
float hp=12;
string priority[4]={"i","f","b","c"};
};
struct iprototype
{
int attack=15;
float fshield=1.00;
float bshield=0.04;
float ishield=0.60;
float cshield=1.00;
int hp=5;
string priority[4]={"b","i","f","c"};
};
struct cprototype
{
int attack=0;
float fshield=0.05;
float bshield=0.05;
float ishield=0.05;
float cshield=1.00;
float hp=300;
string priority[4]={"f","b","i","c"};
};
class attackpackage
{
public:
int fattack;
int battack;
int iattack;
int cattack;
attackpackage(int f,int b,int i,int c)
{
fattack=f;
battack=b;
iattack=i;
cattack=c;
}
};
class fleet
{
fprototype fp;
bprototype bp;
iprototype ip;
cprototype cp;
int bomber;
int fighter;
int interceptor;
int carrier;
public:
fleet(int f,int b,int i,int c)
{
fighter=f;
bomber=b;
interceptor=i;
carrier=c;
}
attackpackage attack()
{
fprototype fp;
bprototype bp;
iprototype ip;
cprototype cp;
attackpackage at(fighter*fp.attack,bomber*bp.attack,interceptor*ip.attack,carrier*cp.attack);
return at;
}
int null()
{
if(fighter==0&&bomber==0&&interceptor==0)
{
return 0;
}
return 1;
}
void defend(attackpackage at)
{
int pcounter=0;
while(at.fattack!=0&&pcounter<4)
{
if(fp.priority[pcounter]=="f")
{
if(fighter*fp.hp>=at.fattack*fp.fshield)
{
fighter=fighter-int(at.fattack*fp.fshield/fp.hp)-1;
at.fattack=0;
}
else
{
at.fattack=at.fattack-int(fighter*fp.hp/fp.fshield);
fighter=0;
}
}
if(fp.priority[pcounter]=="b")
{
if(bomber*bp.hp>=at.fattack*bp.fshield)
{
bomber=bomber-int(at.fattack*bp.fshield/bp.hp)-1;
at.fattack=0;
}
else
{
at.fattack=at.fattack-int(bomber*bp.hp/bp.fshield);
bomber=0;
}
}
if(fp.priority[pcounter]=="i")
{
if(interceptor*ip.hp>=at.fattack*ip.fshield)
{
interceptor=interceptor-int(at.fattack*ip.fshield/ip.hp)-1;
at.fattack=0;
}
else
{
at.fattack=at.fattack-int(interceptor*ip.hp/ip.fshield);
interceptor=0;
}
}
if(fp.priority[pcounter]=="c")
{
if(carrier*cp.hp>=at.fattack*cp.fshield)
{
carrier=carrier-int(at.fattack*cp.fshield/cp.hp);
at.fattack=0;
}
else
{
at.fattack=at.fattack-int(carrier*cp.hp/cp.fshield);
carrier=0;
}
}
pcounter++;
}
pcounter=0;
while(at.battack!=0&&pcounter<4)
{
if(bp.priority[pcounter]=="f")
{
if(fighter*fp.hp>=at.battack*fp.bshield)
{
fighter=fighter-int(at.battack*fp.bshield/fp.hp)-1;
at.battack=0;
}
else
{
at.battack=at.battack-int(fighter*fp.hp/fp.bshield);
fighter=0;
}
}
if(bp.priority[pcounter]=="b")
{
if(bomber*bp.hp>=at.battack*bp.bshield)
{
bomber=bomber-int(at.battack*bp.bshield/bp.hp)-1;
at.battack=0;
}
else
{
at.battack=at.battack-int(bomber*bp.hp/bp.bshield);
bomber=0;
}
}
if(bp.priority[pcounter]=="i")
{
if(interceptor*ip.hp>=at.battack*ip.bshield)
{
interceptor=interceptor-int(at.battack*ip.bshield/ip.hp)-1;
at.battack=0;
}
else
{
at.battack=at.battack-int(interceptor*ip.hp/ip.bshield);
interceptor=0;
}
}
if(bp.priority[pcounter]=="c")
{
if(carrier*cp.hp>=at.battack*cp.bshield)
{
carrier=carrier-int(at.battack*cp.bshield/cp.hp);
at.battack=0;
}
else
{
at.battack=at.battack-int(carrier*cp.hp/cp.bshield);
carrier=0;
}
}
pcounter++;
}
pcounter=0;
while(at.iattack!=0&&pcounter<4)
{
if(ip.priority[pcounter]=="f")
{
if(fighter*fp.hp>=at.iattack*fp.ishield)
{
fighter=fighter-int(at.iattack*fp.ishield/fp.hp)-1;
at.iattack=0;
}
else
{
at.iattack=at.iattack-int(fighter*fp.hp/fp.ishield);
fighter=0;
}
}
if(ip.priority[pcounter]=="b")
{
if(bomber*bp.hp>=at.iattack*bp.ishield)
{
bomber=bomber-int(at.iattack*bp.ishield/bp.hp)-1;
at.iattack=0;
}
else
{
at.iattack=at.iattack-int(bomber*bp.hp/bp.ishield);
bomber=0;
}
}
if(ip.priority[pcounter]=="i")
{
if(interceptor*ip.hp>=at.iattack*ip.ishield)
{
interceptor=interceptor-int(at.iattack*ip.ishield/ip.hp)-1;
at.iattack=0;
}
else
{
at.iattack=at.iattack-int(interceptor*ip.hp/ip.ishield);
interceptor=0;
}
}
if(ip.priority[pcounter]=="c")
{
if(carrier*cp.hp>=at.iattack*cp.ishield)
{
carrier=carrier-int(at.iattack*cp.ishield/cp.hp);
at.iattack=0;
}
else
{
at.iattack=at.iattack-int(carrier*cp.hp/cp.ishield);
carrier=0;
}
}
pcounter++;
}
pcounter=0;
while(at.cattack!=0&&pcounter<4)
{
if(ip.priority[pcounter]=="f")
{
if(fighter*fp.hp>=at.cattack*fp.cshield)
{
fighter=fighter-int(at.cattack*fp.cshield/fp.hp)-1;
at.cattack=0;
}
else
{
at.cattack=at.cattack-int(fighter*fp.hp/fp.cshield);
fighter=0;
}
}
if(ip.priority[pcounter]=="b")
{
if(bomber*bp.hp>=at.cattack*bp.cshield)
{
bomber=bomber-int(at.cattack*bp.cshield/bp.hp)-1;
at.cattack=0;
}
else
{
at.cattack=at.cattack-int(bomber*bp.hp/bp.cshield);
bomber=0;
}
}
if(ip.priority[pcounter]=="i")
{
if(fighter*ip.hp>=at.cattack*ip.cshield)
{
interceptor=interceptor-int(at.cattack*ip.cshield/ip.hp)-1;
at.cattack=0;
}
else
{
at.cattack=at.cattack-int(interceptor*ip.hp/ip.cshield);
interceptor=0;
}
}
if(ip.priority[pcounter]=="c")
{
if(carrier*cp.hp>=at.cattack*cp.cshield)
{
carrier=carrier-int(at.cattack*cp.cshield/cp.hp);
at.cattack=0;
}
else
{
at.cattack=at.cattack-int(carrier*cp.hp/cp.cshield);
carrier=0;
}
}
pcounter++;
}
pcounter=0;
}
void printfleet()
{
cout<<"Fighter: "<<fighter<<endl;
cout<<"Bomber: "<<bomber<<endl;
cout<<"Interceptor: "<<interceptor<<endl;
cout<<"Carrier: "<<carrier<<endl<<endl;
}
};
int main()
{
//input should be f,b,i,c
fleet f1(100, 100, 100, 0);
fleet f2(200, 200, 200, 0);
//
attackpackage a1(0,0,0,0);
attackpackage a2(0,0,0,0);
int round=0;
while((f1.null()!=0)&&(f2.null()!=0))
{
a1=f1.attack();
a2=f2.attack();
f1.defend(a2);
f2.defend(a1);
cout<<"Fleet 1"<<endl;
f1.printfleet();
cout<<"Fleet 2"<<endl;
f2.printfleet();
round++;
cout<<"Round "<<round<<endl;
cout<<endl;
}
if(f1.null()==0)
{
cout<<"Fleet 2 has won"<<endl;
//f1.printfleet();
}
else if(f2.null()==0&&f1.null()==0)
{
cout<<"Its a draw"<<endl;
//f2.printfleet();
}
else
{
cout<<"Fleet 1 has won"<<endl;
//f2.printfleet();
}
cout<<"Fleet 1"<<endl;
f1.printfleet();
cout<<"fleet 2"<<endl;
f2.printfleet();
return 0;
}