Created
November 19, 2014 11:45
-
-
Save wrist/70122fec3ffadb2285fc to your computer and use it in GitHub Desktop.
SugoiHaskell@Osaka Problem07(DQ)
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
-- 問題 https://gist.github.com/fujiyan/483893d875ff7e350ef1 | |
-- 他の方々の解答 | |
-- https://gist.github.com/iseebi/8f3f7388313c1a6005f9 | |
-- https://gist.github.com/fujiyan/5378cb1f0f82c98a3775 | |
data Attack = Normal | Critical | Gira | Begirama deriving Show | |
data Warrior = Warrior { | |
attack :: Int | |
} deriving Show | |
data Monster = Monster { | |
hitPoint :: Int, | |
defence :: Int | |
} deriving Show | |
battle :: Warrior -> Monster -> [Attack] -> Int | |
battle w m [] = (hitPoint m) | |
battle w m (x:xs) = (battle w m xs) - case x of | |
Normal -> if d < 1 then 1 else d where d = truncate $ ((realToFrac $ attack w) - ((realToFrac $ defence m) / 2)) / 2 | |
Critical -> attack w | |
Gira -> 12 | |
Begirama -> 65 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment