main.hs 739 B

1234567891011121314151617181920212223242526272829303132333435
  1. -- Mine Sweeper Lab
  2. -- Import section
  3. import Data.Char
  4. -- Types
  5. data Cell = Covered Int Bool Bool -- number of bombs around ; has bomb ; has flag
  6. | Uncovered Int -- number of bombs around
  7. | Selected
  8. data Grid = Grid [[Cell]]
  9. -- Methods
  10. instance Show Cell where
  11. show ( Covered _ _ hasFlag ) = if hasFlag then "[F]" else "[ ]"
  12. show ( Uncovered n ) = ['(', intToDigit n, ')']
  13. show Selected = ">x<"
  14. instance Show Grid where
  15. show (Grid a) = unlines $ map (unwords . map show) a
  16. -- Functions
  17. -- Testing data
  18. tinyGrid = Grid [
  19. [Covered 2 True False, Uncovered 2, Covered 2 True False],
  20. [Selected, Uncovered 0, Covered 2 True True]
  21. ]