Guest User

Untitled

a guest
Jul 17th, 2018
112
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.85 KB | None | 0 0
  1. module T where
  2.  
  3. import Data.List
  4.  
  5. data Cell a = Blue a | Yellow a | Green a | Red a | Explode a
  6. type Board = [Cell (Int,Int)]
  7.  
  8. getX :: Cell (Int,Int) -> Int
  9. getX _ (x,_) = x
  10.  
  11. getY :: Cell (Int,Int) -> Int
  12. getY _ (_,y) = y
  13.  
  14. distance :: (Int,Int) -> Cell (Int,Int) -> Maybe Int
  15. distance (x,y) _ (x2,y2)
  16. | x == x2 = Just y2 - y
  17. | y == y2 = Just x2 - x
  18. | otherwise = Nothing
  19.  
  20. cellEvolve :: Cell (Int,Int) -> Cell (Int,Int)
  21. cellEvolve Blue (x,y) = Yellow (x,y)
  22. cellEvolve Yellow (x,y) = Green (x,y)
  23. cellEvolve Green (x,y) = Red (x,y)
  24. cellEvolve Red (x,y) = Explode (x,y)
  25.  
  26. explode :: (Int,Int) -> Board -> Board
  27. explode (x,y) b1 =
  28. let matchingRow
  29.  
  30.  
  31. cellFuture :: (Int, Int) -> (Cell (Int,Int) -> Int) -> Cell (Int,Int) -> Maybe Int
  32. cellFuture (x,y) f c
  33. | (f c == f x) = distance (x,y) c
  34. | otherwise = Nothing
  35.  
  36.  
  37. manageExplode :: Board -> Board
  38. manageExplode b1 =
Add Comment
Please, Sign In to add comment