Advertisement
Coriic

Untitled

May 23rd, 2017
101
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. import Data.Map as Map
  2. import Data.Maybe
  3.  
  4. data Coordinates = Coordinates Int Int deriving Eq
  5.  
  6. instance Ord Coordinates where
  7.     compare (Coordinates a b) (Coordinates c d)
  8.         |(b == d) = a `compare` c
  9.         |otherwise = b `compare` d
  10.  
  11. data Color = White | Black
  12.  
  13. instance Show Color where
  14.    show White = "o"
  15.    show Black = "x"
  16.  
  17. data Board = Board (Map Coordinates Color)
  18.  
  19. toString (Board map) =
  20.     putStr(iterate([Coordinates x y | y <- [1..19], x <- [1..19]]))
  21.         where
  22.             iterate [element] = (mapToCharacter element) ++ (newLine element)
  23.             iterate (element:listOfCoordinates) = (mapToCharacter element) ++ (newLine element) ++ iterate(listOfCoordinates)
  24.             mapToCharacter coordinates
  25.                 | (member coordinates map) = show(fromJust (Map.lookup coordinates map))
  26.                 | otherwise = " "
  27.             newLine (Coordinates x y)
  28.                 | (x == 19) = "\n"
  29.                 | otherwise = ""
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement