Created
July 16, 2014 09:29
-
-
Save znd-milktea/5378cb1f0f82c98a3775 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
data Warrior = Warrior {attack :: Int} | |
data Monster = Monster {hitPoint :: Int, defence :: Int} | |
data Attack = Normal | Critical | Gira | Begirama | |
battle :: Warrior -> Monster -> [Attack] -> Int | |
battle w m as = (hitPoint m) - (sum $ map damage as) | |
where | |
damage Normal | |
| d < 1 = 1 | |
| otherwise = d | |
where | |
d = truncate $ ((realToFrac $ attack w) - ((realToFrac $ defence m) / 2)) / 2 | |
damage Critical = attack w | |
damage Gira = 12 | |
damage Begirama = 65 | |
{- | |
case 1 | |
battle (Warrior 5) (Monster 80 5) [Gira, Begirama, Gira] | |
case 2 | |
battle (Warrior 30) (Monster 100 10) [Normal, Critical, Begirama] | |
case 3 | |
battle (Warrior 40) (Monster 200 100) [Normal, Gira, Normal, Critical, Gira, Begirama] | |
-} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment