Advertisement
Guest User

Untitled

a guest
Nov 23rd, 2014
116
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.78 KB | None | 0 0
  1. genBoardSpec :: Int -> Rand BoardSpec
  2. genBoardSpec b = return (nub (createFirstBoard b))
  3.  
  4. createFirstBoard :: Int -> BoardSpec
  5. createFirstBoard i = createBoardFromPoints xs ys bs
  6. where (xs, ys) = splitAt (i * i) (createRandomPoints i)
  7. bs = createRandomBools i
  8.  
  9. createBoardFromPoints :: [Int] -> [Int] -> [Bool] -> BoardSpec
  10. createBoardFromPoints (x:xs) (y:ys) (b:bs) = ((x, y), b) : (createBoardFromPoints xs ys bs)
  11.  
  12. createBoardFromPoints [] [] [] = []
  13.  
  14. createRandomPoints a = runRand 1 (replicateM (2 * (a * a)) (uniform [0..(a - 1)]))
  15. createRandomBools a = convertToBool (runRand 1 (replicateM (a * a) (uniform [0..1])))
  16.  
  17. convertToBool :: [Int] -> [Bool]
  18. convertToBool (x:xs)
  19. | x == 1 = True : convertToBool xs
  20. | x == 0 = False : convertToBool xs
  21.  
  22. convertToBool [] = []
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement