|
@@ -0,0 +1,35 @@
|
|
|
+-- Mine Sweeper Lab
|
|
|
+
|
|
|
+-- Import section
|
|
|
+
|
|
|
+import Data.Char
|
|
|
+
|
|
|
+
|
|
|
+-- Types
|
|
|
+
|
|
|
+data Cell = Covered Int Bool Bool -- number of bombs around ; has bomb ; has flag
|
|
|
+ | Uncovered Int -- number of bombs around
|
|
|
+ | Selected
|
|
|
+
|
|
|
+data Grid = Grid [[Cell]]
|
|
|
+
|
|
|
+
|
|
|
+-- Methods
|
|
|
+
|
|
|
+instance Show Cell where
|
|
|
+ show ( Covered _ _ hasFlag ) = if hasFlag then "[F]" else "[ ]"
|
|
|
+ show ( Uncovered n ) = ['(', intToDigit n, ')']
|
|
|
+ show Selected = ">x<"
|
|
|
+
|
|
|
+instance Show Grid where
|
|
|
+ show (Grid a) = unlines $ map (unwords . map show) a
|
|
|
+
|
|
|
+-- Functions
|
|
|
+
|
|
|
+
|
|
|
+-- Testing data
|
|
|
+
|
|
|
+tinyGrid = Grid [
|
|
|
+ [Covered 2 True False, Uncovered 2, Covered 2 True False],
|
|
|
+ [Selected, Uncovered 0, Covered 2 True True]
|
|
|
+ ]
|