Skip to content

Instantly share code, notes, and snippets.

@wrist
Created November 19, 2014 11:45
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save wrist/70122fec3ffadb2285fc to your computer and use it in GitHub Desktop.
Save wrist/70122fec3ffadb2285fc to your computer and use it in GitHub Desktop.
SugoiHaskell@Osaka Problem07(DQ)
-- 問題 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