Skip to content

Commit

Permalink
Adding some comments in a vain attempt to organise the functions
Browse files Browse the repository at this point in the history
  • Loading branch information
dtchepak committed Dec 5, 2011
1 parent 62297e6 commit 6cfbeaa
Showing 1 changed file with 7 additions and 0 deletions.
7 changes: 7 additions & 0 deletions life.hs
Original file line number Diff line number Diff line change
Expand Up @@ -35,13 +35,17 @@ neighbours (Point x y) = [(Point (x-1) (y-1)), (Point x (y-1)), (Point (x+1) (y-
(Point (x-1) y), (Point (x+1) y),
(Point (x-1) (y+1)), (Point x (y+1)), (Point (x+1) (y+1))]

-- Main game entry

life :: Int -> [Point] -> IO()
life 0 _ = return ()
life gens world = do
putStrLn $ show_world world dimensions
life (gens-1) (tick world)
where dimensions = world_dimensions world

-- Display

show_world :: [Point] -> (Point, Point) -> [Char]
show_world world ((Point startX startY), (Point endX endY)) =
lineBreakAt cells_per_row [ show_point p (p `elem` world) | p<-all_points ]
Expand All @@ -64,6 +68,8 @@ world_dimensions cells = ((Point min_x min_y), (Point max_x max_y))
max_y = maximum [ y | (Point x y) <- cells ]
min_y = minimum [ y | (Point x y) <- cells ]

-- Utils

flatten :: [[a]] -> [a]
flatten [] = []
flatten (x:xs) = x ++ (flatten xs)
Expand All @@ -72,6 +78,7 @@ lineBreakAt :: Int -> [Char] -> [Char]
lineBreakAt n [] = []
lineBreakAt n s = take n s ++ "\n" ++ (lineBreakAt n $ drop n s)

-- Tests

assert_equal :: Eq a => Show a => a -> a -> IO()
assert_equal x y
Expand Down

0 comments on commit 6cfbeaa

Please sign in to comment.