Advertisement
Coriic

Untitled

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