You are a villager from a rural village. Your dream is to go to Rome and become an eques for the Imperial. However, on the road to Rome, you meet many fighters with various reasons to challenge you to a fight. You have to defeat all of them to arrive in Rome successfully. Assume every fighter (including you) has 4 integers for their status: HP, ATK, DEF, TYPE. When 2 fighters fight, they will both attack and take damage simultaneously. First, the damage will be calculated using the ATK of one fighter subtracted by the DEF of the other fighter to the minimum of 1. Second, depending on the TYPE of 2 fighters the dmg will change accordingly: • The Normal type (not Fibonacci and not Prime) is weak to only Prime or only Fibonacci type and takes 2x damage. • The Prime type is weak to the Fibonacci type and takes 2x damage. • The Fibonacci type is only weak to the type that is both Prime and Fibonacci and takes 2x damage (Fibonacci in this assignment start with 1, 1). • The number that is both Fibonacci and Prime is weak to normal type and takes 3x damage. Finally, the fighter who has HP<=0 first will lose. The winner will get half the loser’s ATK (round up) added to his ATK and the loser 2xDEF added to his HP and 1 added to his DEF After each round of the fight (1 round mean 2 fighter get to attack once), the program announced the atk of the round and the status of both fighters:
(In this example your TYPE is 2 which is both Fibonacci and Prime number vs fighter #1 TYPE 4 which is a normal number, so you take x3 damage. The #1 meaning he is the first fighter you fight on your road to Rome). If you win the system will announce:
If the fight is a draw the system will announce:
If you lose the system will announce:
If you defeat all the fighters on the road, the system will announce:
This exercise will receive these data from standard input (keyboard): Your status: HP, ATK, DEF, TYPE. The number of fighters you will meet on the road: nFighter. The status of each fighter you will meet on the road: eHP, eATK, eDEF, eTYP.
What I have tried:
#include <stdio.h>
#include <math.h>
struct villager{
int HP,ATK,DEF,TYPE;
};
int checkfibonacci(int n)
{
int a = 0;
int b = 1;
if (n==a || n==b) return 1;
int c = a+b;
while(c<=n)
{
if(c == n) return 1;
a = b;
b = c;
c = a + b;
}
return 0;
}
int primenumber(int soA)
{
if (soA < 2)
return 0;
for (int i = 2; i <= sqrt((float)soA); i ++)
{
if (soA%i==0)
{
return 0;
}
}
return 1;
}
int checkTYPE(int n){
if (primenumber(n)==0 && checkfibonacci(n)==0) return 1;
else if( primenumber(n)==1 && checkfibonacci(n)==0) return 2;
else if (primenumber(n)==0 && checkfibonacci(n)==1) return 3;
else if (primenumber(n)==1 && checkfibonacci(n)==1) return 4;
};
int main () {
int n;
scanf("%d", &n);
printf("%d\n", primenumber(n));
printf("%d\n", checkfibonacci(n));
printf("\n");
int numberofplayer = 0, TYPE = 0;
do {
scanf("%d", & numberofplayer);
printf("the number of player : ");
}
while (numberofplayer <=1 );
int matrix[numberofplayer][4];
printf("input the statistic of player \n");
for (int i=0;i <numberofplayer;i++){
for (int j;j<4;j++){
scanf("%d", &matrix[i].[j]);
if (matrix[i][j]<0){
printf("input statistic of player again ");
break;
}
}
}
}