Advertisement
Coriic

Untitled

May 23rd, 2017
108
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 iterate [element] = mapToCharacter element
  22.           iterate (element:listOfCoordinates) = (mapToCharacter element) ++ iterate(listOfCoordinates)
  23.           where mapToCharacter (Coordinates coordinates) =
  24.             |member coordinates board = lookup coordinates map
  25.             |otherwise "  "
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement