Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Chapter 3 knight Monster clarification #430

Closed
ipochi opened this issue Sep 29, 2021 · 2 comments · Fixed by #432
Closed

Chapter 3 knight Monster clarification #430

ipochi opened this issue Sep 29, 2021 · 2 comments · Fixed by #432
Assignees
Labels
chapter3 question Further information is requested

Comments

@ipochi
Copy link

ipochi commented Sep 29, 2021

@vrom911 @chshersh Some clarifications needed please ?

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:

balrog :: Monster
balrog = Monster {
          monsterHealth = 97,
          monsterAttack = 5,
          monsterGold   = 70
         }

arthur :: Knight
arthur = Knight {
          knightHealth = 93,
          knightAttack = 7,
          knightGold   = 82
         }


fight (Knight _ knightHealth knightAttack knightGold) (Monster monsterHealth monsterAttack monsterGold)
    | knightAttack >= monsterHealth = knightGold + monsterGold
    | monsterAttack >= knightHealth = -1
    | otherwise = knightGold

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.

@ipochi
Copy link
Author

ipochi commented Sep 29, 2021

also

 Neither the knight nor the monster wins.

If there are multiple rounds in the fight, wouldn't there be a situation where there will always be a winner.

@chshersh
Copy link
Contributor

chshersh commented Oct 1, 2021

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.

I'll open a PR with clarification.

@chshersh chshersh added chapter3 question Further information is requested labels Oct 1, 2021
@chshersh chshersh self-assigned this Oct 1, 2021
chshersh added a commit that referenced this issue Oct 1, 2021
vrom911 pushed a commit that referenced this issue Oct 1, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
chapter3 question Further information is requested
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants