From 6cfbeaac61330be9aa59989cf4667dcf79c38151 Mon Sep 17 00:00:00 2001 From: David Tchepak Date: Mon, 5 Dec 2011 18:58:23 +1100 Subject: [PATCH] Adding some comments in a vain attempt to organise the functions --- life.hs | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/life.hs b/life.hs index b202a9c..99357ac 100644 --- a/life.hs +++ b/life.hs @@ -35,6 +35,8 @@ 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 @@ -42,6 +44,8 @@ life gens world = do 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 ] @@ -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) @@ -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