ALL of structures you might use typedef enum type { ATTACK, DEFEND, HEAL } decis
ID: 3765427 • Letter: A
Question
ALL of structures you might use
typedef enum type
{
ATTACK,
DEFEND,
HEAL
} decisionType;
typedef struct bossDecision_
{
decisionType type;
struct bossDecision_* next;
} bossDecision;
typedef struct bossDecisionNode_
{
struct bossDecisionNode_* leftNode;
struct bossDecisionNode_* rightNode;
int healthMin;
int healthMax;
bossDecision* topOfStack;
} bossDecisionNode;
typedef struct shield
{
char name[50];
int price;
int defense;
int weight;
} Shield;
typedef struct sword
{
char name[50];
int price;
int damage;
} Sword;
typedef struct hero
{
char name[30];
int health;
int maxHealth;
int defense;
int speed;
int attack;
int luck;
decisionType decision;
Shield* shield;
Sword* sword;
//can only heal fully once, so false means hero heals for a fraction
bool hasHealed;
} Hero;
typedef struct boss
{
char name[30];
int health;
int maxHealth;
int defense;
int speed;
int attack;
int luck;
bossDecisionNode* root;
decisionType nextAction;
} Boss;
typedef struct players
{
Hero* hero;
Boss* boss;
struct players* next;
} Player;
Explanation / Answer
bossDecision* getNewListInTree(bossDecisionNode* root,int currentBossHealth)
{
//creating a temp variable for root of the tree
bossDecisionNode *temp =root;
//if the currentHealth is in range of temp min and max
//we return it
if(temp->healthMin<=currentBossHealth && temp->healthMax>=currentBossHealth)return temp->topOfStack;
//else
//first we go through the left sub-tree
bossDecision *decision = getNewListInTree(temp->leftNode,currentBossHealth);
//if no correct decision is found
if(decision == NULL)
{
//we go through the right sub-tree
decision = getNewListInTree(temp->rightNode,currentBossHealth);
}
return decision;
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.