fork download
  1. >
  2. #include <stdio.h>
  3. using namespace std;
  4.  
  5. struct bprototype
  6. {
  7. float attack=21;
  8. float fshield=0.20;
  9. float bshield=0.80;
  10. float ishield=1.20;
  11. float cshield=1.00;
  12. int hp=21;
  13. string priority[4]={"f","b","i","c"};
  14. };
  15.  
  16. struct fprototype
  17. {
  18. int attack=12;
  19. float fshield=0.60;
  20. float bshield=1.50;
  21. float ishield=0.20;
  22. float cshield=1.00;
  23. float hp=12;
  24. string priority[4]={"i","f","b","c"};
  25. };
  26.  
  27. struct iprototype
  28. {
  29. int attack=15;
  30. float fshield=1.00;
  31. float bshield=0.04;
  32. float ishield=0.60;
  33. float cshield=1.00;
  34. int hp=5;
  35. string priority[4]={"b","i","f","c"};
  36. };
  37.  
  38. struct cprototype
  39. {
  40. int attack=0;
  41. float fshield=0.05;
  42. float bshield=0.05;
  43. float ishield=0.05;
  44. float cshield=1.00;
  45. float hp=300;
  46. string priority[4]={"f","b","i","c"};
  47. };
  48.  
  49.  
  50. class attackpackage
  51. {
  52. public:
  53. int fattack;
  54. int battack;
  55. int iattack;
  56. int cattack;
  57. attackpackage(int f,int b,int i,int c)
  58. {
  59. fattack=f;
  60. battack=b;
  61. iattack=i;
  62. cattack=c;
  63. }
  64. };
  65.  
  66. class fleet
  67. {
  68. fprototype fp;
  69. bprototype bp;
  70. iprototype ip;
  71. cprototype cp;
  72. int bomber;
  73. int fighter;
  74. int interceptor;
  75. int carrier;
  76.  
  77. public:
  78. fleet(int f,int b,int i,int c)
  79. {
  80. fighter=f;
  81. bomber=b;
  82. interceptor=i;
  83. carrier=c;
  84. }
  85.  
  86. attackpackage attack()
  87. {
  88. fprototype fp;
  89. bprototype bp;
  90. iprototype ip;
  91. cprototype cp;
  92. attackpackage at(fighter*fp.attack,bomber*bp.attack,interceptor*ip.attack,carrier*cp.attack);
  93. return at;
  94. }
  95.  
  96. int null()
  97. {
  98. if(fighter==0&&bomber==0&&interceptor==0)
  99. {
  100. return 0;
  101. }
  102. return 1;
  103. }
  104.  
  105. void defend(attackpackage at)
  106. {
  107. int pcounter=0;
  108. while(at.fattack!=0&&pcounter<4)
  109. {
  110. if(fp.priority[pcounter]=="f")
  111. {
  112. if(fighter*fp.hp>=at.fattack*fp.fshield)
  113. {
  114. fighter=fighter-int(at.fattack*fp.fshield/fp.hp)-1;
  115. at.fattack=0;
  116.  
  117. }
  118. else
  119. {
  120. at.fattack=at.fattack-int(fighter*fp.hp/fp.fshield);
  121. fighter=0;
  122. }
  123. }
  124. if(fp.priority[pcounter]=="b")
  125. {
  126. if(bomber*bp.hp>=at.fattack*bp.fshield)
  127. {
  128. bomber=bomber-int(at.fattack*bp.fshield/bp.hp)-1;
  129. at.fattack=0;
  130. }
  131. else
  132. {
  133. at.fattack=at.fattack-int(bomber*bp.hp/bp.fshield);
  134. bomber=0;
  135. }
  136. }
  137. if(fp.priority[pcounter]=="i")
  138. {
  139. if(interceptor*ip.hp>=at.fattack*ip.fshield)
  140. {
  141. interceptor=interceptor-int(at.fattack*ip.fshield/ip.hp)-1;
  142. at.fattack=0;
  143. }
  144. else
  145. {
  146. at.fattack=at.fattack-int(interceptor*ip.hp/ip.fshield);
  147. interceptor=0;
  148. }
  149. }
  150. if(fp.priority[pcounter]=="c")
  151. {
  152. if(carrier*cp.hp>=at.fattack*cp.fshield)
  153. {
  154. carrier=carrier-int(at.fattack*cp.fshield/cp.hp);
  155. at.fattack=0;
  156. }
  157. else
  158. {
  159. at.fattack=at.fattack-int(carrier*cp.hp/cp.fshield);
  160. carrier=0;
  161. }
  162. }
  163. pcounter++;
  164.  
  165. }
  166. pcounter=0;
  167. while(at.battack!=0&&pcounter<4)
  168. {
  169. if(bp.priority[pcounter]=="f")
  170. {
  171. if(fighter*fp.hp>=at.battack*fp.bshield)
  172. {
  173. fighter=fighter-int(at.battack*fp.bshield/fp.hp)-1;
  174. at.battack=0;
  175. }
  176. else
  177. {
  178. at.battack=at.battack-int(fighter*fp.hp/fp.bshield);
  179. fighter=0;
  180. }
  181. }
  182. if(bp.priority[pcounter]=="b")
  183. {
  184. if(bomber*bp.hp>=at.battack*bp.bshield)
  185. {
  186. bomber=bomber-int(at.battack*bp.bshield/bp.hp)-1;
  187. at.battack=0;
  188. }
  189. else
  190. {
  191. at.battack=at.battack-int(bomber*bp.hp/bp.bshield);
  192. bomber=0;
  193. }
  194. }
  195. if(bp.priority[pcounter]=="i")
  196. {
  197. if(interceptor*ip.hp>=at.battack*ip.bshield)
  198. {
  199. interceptor=interceptor-int(at.battack*ip.bshield/ip.hp)-1;
  200. at.battack=0;
  201. }
  202. else
  203. {
  204. at.battack=at.battack-int(interceptor*ip.hp/ip.bshield);
  205. interceptor=0;
  206. }
  207. }
  208. if(bp.priority[pcounter]=="c")
  209. {
  210. if(carrier*cp.hp>=at.battack*cp.bshield)
  211. {
  212. carrier=carrier-int(at.battack*cp.bshield/cp.hp);
  213. at.battack=0;
  214. }
  215. else
  216. {
  217. at.battack=at.battack-int(carrier*cp.hp/cp.bshield);
  218. carrier=0;
  219. }
  220. }
  221. pcounter++;
  222.  
  223. }
  224. pcounter=0;
  225. while(at.iattack!=0&&pcounter<4)
  226. {
  227. if(ip.priority[pcounter]=="f")
  228. {
  229. if(fighter*fp.hp>=at.iattack*fp.ishield)
  230. {
  231. fighter=fighter-int(at.iattack*fp.ishield/fp.hp)-1;
  232. at.iattack=0;
  233. }
  234. else
  235. {
  236. at.iattack=at.iattack-int(fighter*fp.hp/fp.ishield);
  237. fighter=0;
  238. }
  239. }
  240. if(ip.priority[pcounter]=="b")
  241. {
  242. if(bomber*bp.hp>=at.iattack*bp.ishield)
  243. {
  244. bomber=bomber-int(at.iattack*bp.ishield/bp.hp)-1;
  245. at.iattack=0;
  246. }
  247. else
  248. {
  249. at.iattack=at.iattack-int(bomber*bp.hp/bp.ishield);
  250. bomber=0;
  251. }
  252. }
  253. if(ip.priority[pcounter]=="i")
  254. {
  255. if(interceptor*ip.hp>=at.iattack*ip.ishield)
  256. {
  257. interceptor=interceptor-int(at.iattack*ip.ishield/ip.hp)-1;
  258. at.iattack=0;
  259. }
  260. else
  261. {
  262. at.iattack=at.iattack-int(interceptor*ip.hp/ip.ishield);
  263. interceptor=0;
  264. }
  265. }
  266. if(ip.priority[pcounter]=="c")
  267. {
  268. if(carrier*cp.hp>=at.iattack*cp.ishield)
  269. {
  270. carrier=carrier-int(at.iattack*cp.ishield/cp.hp);
  271. at.iattack=0;
  272. }
  273. else
  274. {
  275. at.iattack=at.iattack-int(carrier*cp.hp/cp.ishield);
  276. carrier=0;
  277. }
  278. }
  279. pcounter++;
  280.  
  281. }
  282. pcounter=0;
  283. while(at.cattack!=0&&pcounter<4)
  284. {
  285. if(ip.priority[pcounter]=="f")
  286. {
  287. if(fighter*fp.hp>=at.cattack*fp.cshield)
  288. {
  289. fighter=fighter-int(at.cattack*fp.cshield/fp.hp)-1;
  290. at.cattack=0;
  291. }
  292. else
  293. {
  294. at.cattack=at.cattack-int(fighter*fp.hp/fp.cshield);
  295. fighter=0;
  296. }
  297. }
  298. if(ip.priority[pcounter]=="b")
  299. {
  300. if(bomber*bp.hp>=at.cattack*bp.cshield)
  301. {
  302. bomber=bomber-int(at.cattack*bp.cshield/bp.hp)-1;
  303. at.cattack=0;
  304. }
  305. else
  306. {
  307. at.cattack=at.cattack-int(bomber*bp.hp/bp.cshield);
  308. bomber=0;
  309. }
  310. }
  311. if(ip.priority[pcounter]=="i")
  312. {
  313. if(fighter*ip.hp>=at.cattack*ip.cshield)
  314. {
  315. interceptor=interceptor-int(at.cattack*ip.cshield/ip.hp)-1;
  316. at.cattack=0;
  317. }
  318. else
  319. {
  320. at.cattack=at.cattack-int(interceptor*ip.hp/ip.cshield);
  321. interceptor=0;
  322. }
  323. }
  324. if(ip.priority[pcounter]=="c")
  325. {
  326. if(carrier*cp.hp>=at.cattack*cp.cshield)
  327. {
  328. carrier=carrier-int(at.cattack*cp.cshield/cp.hp);
  329. at.cattack=0;
  330. }
  331. else
  332. {
  333. at.cattack=at.cattack-int(carrier*cp.hp/cp.cshield);
  334. carrier=0;
  335. }
  336. }
  337. pcounter++;
  338.  
  339. }
  340. pcounter=0;
  341.  
  342. }
  343.  
  344. void printfleet()
  345. {
  346. cout<<"Fighter: "<<fighter<<endl;
  347. cout<<"Bomber: "<<bomber<<endl;
  348. cout<<"Interceptor: "<<interceptor<<endl;
  349. cout<<"Carrier: "<<carrier<<endl<<endl;
  350.  
  351. }
  352.  
  353.  
  354. };
  355.  
  356. int main()
  357. {
  358. //input should be f,b,i,c
  359. fleet f1(100, 100, 100, 0);
  360. fleet f2(200, 200, 200, 0);
  361.  
  362. //
  363. attackpackage a1(0,0,0,0);
  364. attackpackage a2(0,0,0,0);
  365. int round=0;
  366. while((f1.null()!=0)&&(f2.null()!=0))
  367. {
  368. a1=f1.attack();
  369. a2=f2.attack();
  370. f1.defend(a2);
  371. f2.defend(a1);
  372.  
  373. cout<<"Fleet 1"<<endl;
  374. f1.printfleet();
  375. cout<<"Fleet 2"<<endl;
  376. f2.printfleet();
  377. round++;
  378. cout<<"Round "<<round<<endl;
  379. cout<<endl;
  380. }
  381.  
  382. if(f1.null()==0)
  383. {
  384. cout<<"Fleet 2 has won"<<endl;
  385. //f1.printfleet();
  386. }
  387. else if(f2.null()==0&&f1.null()==0)
  388. {
  389. cout<<"Its a draw"<<endl;
  390. //f2.printfleet();
  391. }
  392. else
  393. {
  394. cout<<"Fleet 1 has won"<<endl;
  395. //f2.printfleet();
  396. }
  397. cout<<"Fleet 1"<<endl;
  398. f1.printfleet();
  399. cout<<"fleet 2"<<endl;
  400. f2.printfleet();
  401.  
  402. return 0;
  403. }
Compilation error #stdin compilation error #stdout 0s 0KB
stdin
Standard input is empty
compilation info
prog.cpp:1:1: error: expected unqualified-id before ‘>’ token
 >
 ^
stdout
Standard output is empty