You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Prepare to defend the honour of our kingdom! A monster attacks our brave knight.
Help him to fight this creature!
Define data types for Knights and Monsters, and write the "fight" function.
Both a knight and a monster have the following properties:
✦ Health (the number of health points)
✦ Attack (the number of attack units)
✦ Gold (the number of coins)
When a monster fights a knight, the knight hits first, and the monster hits back
only if it survives (health is bigger than zero). A hit decreases the amount of
health by the number represented in the "attack" field.
Implement the "fight" function, that takes a monster and a knight, performs the
fight following the above rules and returns the amount of gold the knight has
after the fight. The battle has the following possible outcomes:
⊛ Knight wins and takes the loot from the monster and adds it to their own
earned treasure
⊛ Monster defeats the knight. In that case return -1
⊛ Neither the knight nor the monster wins. On such an occasion, the knight
doesn't earn any money and keeps what they had before.
It seems the question is not really clear, should this be interpreted as a fight between knight and monster with multiple rounds
or a single round ?
Based on this commit from a PR and many other PR's which are similar and accepted as an answer. I don't understand, how can the below function be true based on the following data:
Based on the first condition knightAttack >= monsterHealth will be false, hence Arthur loses, but in fact if the fight goes on until either is dead (health 0) then Arthur would win.
The text was updated successfully, but these errors were encountered:
Hi @ipochi, the task assumes only a single round. Multiple rounds are only in the boss task. But in the beginning, we just want a simple function so that people can learn how to work with records and their fields 🙂 And because of that it's possible that nobody wins.
@vrom911 @chshersh Some clarifications needed please ?
It seems the question is not really clear, should this be interpreted as a fight between knight and monster with multiple rounds
or a single round ?
Based on this commit from a PR and many other PR's which are similar and accepted as an answer. I don't understand, how can the below function be true based on the following data:
Based on the first condition
knightAttack >= monsterHealth
will be false, hence Arthur loses, but in fact if the fight goes on until either is dead (health 0) then Arthur would win.The text was updated successfully, but these errors were encountered: