Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- robot (name,attack,hp) = \message -> message (name,attack,hp)
- name (n,_,_) = n
- attack (_,a,_) = a
- hp (_,_,hp) = hp
- getName aRobot = aRobot name
- getAttack aRobot = aRobot attack
- getHP aRobot = aRobot hp
- nameSet name (n,a,h) = robot (name, a, h)
- attackSet attack (n,a,h) = robot (n, attack, h)
- hpSet hp (n,a,h) = robot (n,a,hp)
- setName aRobot newName = aRobot (nameSet newName)
- setAttack aRobot newAttack = aRobot (attackSet newAttack)
- setHP aRobot newHP = aRobot (hpSet newHP)
- printRobot aRobot = aRobot (\(n,a,h) -> n ++
- " attack:" ++ (show a) ++
- " hp:"++ (show h))
- damageSet attackDamage (n,a,h) = robot (n,a,h-attackDamage)
- damage aRobot attackDamage = aRobot (damageSet attackDamage)
- fight aRobot defender = damage defender attack
- where attack = if getHP aRobot > 10
- then getAttack aRobot
- else 0
- getLifes robots = map getHP robots
- round3 a b = if a3HP >= b3HP
- then a3
- else b3
- where b1 = fight a b
- a1 = fight b1 a
- b2 = fight a1 b2
- a2 = fight b2 a1
- b3 = fight a2 b2
- a3 = fight b3 a2
- a3HP = getHP a3
- b3HP = getHP b3
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement