You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

58 lines
1.5 KiB

9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
  1. module Datatypes where
  2. import Data.Hashable (Hashable(..))
  3. import qualified Data.List as List
  4. import Data.Set (Set)
  5. import qualified Data.Set as Set
  6. type Cell = (Int, Int)
  7. data Board = Board {
  8. boardWidth :: Int,
  9. boardHeight :: Int,
  10. boardFilled :: Set Cell
  11. }
  12. deriving Show
  13. data Unit = Unit {
  14. unitMembers :: Set Cell,
  15. unitPivot :: Cell
  16. }
  17. deriving Show
  18. data Command = MoveW
  19. | MoveE
  20. | MoveSW
  21. | MoveSE
  22. | RotateClockwise
  23. | RotateCounterclockwise
  24. deriving (Show,Eq)
  25. cmdToString :: [Command] -> String
  26. cmdToString (MoveW:cs) = 'p' : cmdToString cs
  27. cmdToString (MoveE:cs) = 'b' : cmdToString cs
  28. cmdToString (MoveSW:cs) = 'a' : cmdToString cs
  29. cmdToString (MoveSE:cs) = 'l' : cmdToString cs
  30. cmdToString (RotateClockwise:cs) = 'd' : cmdToString cs
  31. cmdToString (RotateCounterclockwise:cs) = 'k' : cmdToString cs
  32. cmdToString [] = []
  33. data Game = Game {
  34. gameBoard :: Board,
  35. gameUnits :: [Unit],
  36. oldPositions :: Set Int,
  37. oldLines :: Int,
  38. points :: Int
  39. }
  40. deriving Show
  41. data Notes = OK
  42. | Ended
  43. | Collision
  44. | CollisionWithRowElision
  45. | ErrorZero
  46. deriving (Show,Eq)
  47. instance Hashable Unit where
  48. hashWithSalt salt (Unit members pivot) =
  49. hashWithSalt salt (List.sort (Set.toList members), pivot)