Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import Data.Map as Map
- import Data.Maybe
- data Coordinates = Coordinates Int Int deriving Eq
- instance Ord Coordinates where
- compare (Coordinates a b) (Coordinates c d)
- |(b == d) = a `compare` c
- |otherwise = b `compare` d
- data Color = White | Black
- instance Show Color where
- show White = "o"
- show Black = "x"
- data Board = Board (Map Coordinates Color)
- toString (Board map) =
- putStr(iterate([Coordinates x y | y <- [1..19], x <- [1..19]]))
- where
- iterate [element] = (mapToCharacter element) ++ (newLine element)
- iterate (element:listOfCoordinates) = (mapToCharacter element) ++ (newLine element) ++ iterate(listOfCoordinates)
- mapToCharacter coordinates
- | (member coordinates map) = show(fromJust (Map.lookup coordinates map))
- | otherwise = " "
- newLine (Coordinates x y)
- | (x == 19) = "\n"
- | otherwise = ""
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement