Advertisement
Guest User

Untitled

a guest
Apr 5th, 2020
227
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. robot (name,attack,hp)  = \message -> message (name,attack,hp)
  2.  
  3. name (n,_,_) = n
  4. attack (_,a,_) = a
  5. hp (_,_,hp) = hp
  6.  
  7. getName aRobot = aRobot name
  8. getAttack aRobot = aRobot attack
  9. getHP aRobot = aRobot hp
  10.  
  11. nameSet name (n,a,h) = robot (name, a, h)
  12. attackSet attack (n,a,h) = robot (n, attack, h)
  13. hpSet hp (n,a,h) = robot (n,a,hp)
  14.  
  15. setName aRobot newName = aRobot (nameSet newName)
  16. setAttack aRobot newAttack = aRobot (attackSet newAttack)
  17. setHP aRobot newHP = aRobot (hpSet newHP)
  18.  
  19. printRobot aRobot = aRobot (\(n,a,h) -> n ++
  20.                                         " attack:" ++ (show a) ++
  21.                                         " hp:"++ (show h))
  22.  
  23. damageSet attackDamage (n,a,h) = robot (n,a,h-attackDamage)
  24.  
  25. damage aRobot attackDamage = aRobot (damageSet attackDamage)
  26.  
  27. fight aRobot defender = damage defender attack
  28.   where attack = if getHP aRobot > 10
  29.                  then getAttack aRobot
  30.                  else 0
  31.  
  32.  
  33. getLifes robots = map getHP robots
  34.  
  35.  
  36. round3 a b = if a3HP >= b3HP
  37.               then a3
  38.               else b3
  39.     where b1 = fight a b
  40.           a1 = fight b1 a
  41.           b2 = fight a1 b2
  42.           a2 = fight b2 a1
  43.           b3 = fight a2 b2
  44.           a3 = fight b3 a2
  45.           a3HP = getHP a3
  46.           b3HP = getHP b3
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement