-- Evolution of the world in the Game of Life -- -- NAME, STUDENT NUMBER <-- ADD YOUR DETAILS HERE module GameOfLife (initWorld, evolve, Cell, Board, Location, World) where -- Data types to be used represent the world state in the Game of Life -- ------------------------------------------------------------------- -- Type used to denote a single cell on the board -- -- * The value `True' represents live cells -- type Cell = Bool -- Representation of the board on which the Game of Life unfolds -- -- * Each sublist represents a column of the board -- -- * The cell represented by the the first element of the first column is -- located at the lower left corner of the board when displayed -- type Board = [[Cell]] -- The type used to index the board in the Game of Life -- -- * The location "(0, 0)" represents the lower left corner of the board (ie, -- the origin of the world) -- type Location = (Int, Int) -- Representation of the world -- -- * The location determines the index of top right corner of the board (ie, -- the corner opposite of the origin); indicies for the board can range from -- "(0,0)" up to that location. -- type World = (Location, Board) -- The main functions -- ------------------ -- Initialise the world from a string -- -- * The character '*' represents live cells -- -- * The characeter '.' represents dead cells -- -- * Each row of the board is terminated by a newline -- -- initWorld ".*.\n.*.\n***\n" -- => -- ((2,2),[[True,False,False],[True,True,True],[True,False,False]]) -- -- We shall call this "worldExample" in the following comments. -- -- ADD YOUR OWN SAMPLE INVOCATIONS -- initWorld :: String -> World initWorld = error "The function initWorld is not implemented yet" -- Given a world in the game, produce the next state of the world -- -- evolve ((2,2),[[True,False,False],[True,True,True],[True,False,False]]) -- => -- ((2,2),[[True,False,False],[True,False,False],[True,False,False]]) -- -- ADD YOUR OWN SAMPLE INVOCATIONS -- evolve :: World -> World evolve = error "The function evolve is not implemented" -- Some auxilliary functions for computing new world states -- -------------------------------------------------------- -- Given a game world and a location, yield the liveness at that location -- -- getCell worldExample (0,1) => False -- getCell worldExample (1,1) => True -- getCell worldExample (5,5) => *** Exception: Cell (5,5) is out of bounds -- -- ADD YOUR OWN SAMPLE INVOCATIONS -- getCell :: World -> Location -> Cell getCell = error "The function getCell is not implemented" -- Update a location in the world with the given liveness -- -- setCell worldExample (0,0) False -- => -- ((2,2),[[False,False,False],[True,True,True],[True,False,False]]) -- setCell worldExample (3,4) True -- => -- *** Exception: Cell (3,4) is out of bounds -- -- ADD YOUR OWN SAMPLE INVOCATIONS -- setCell :: World -> Location -> Cell -> World setCell = error "The function setCell is not implemented" -- Compute the next-generation state for the cell at the given location -- -- evolveCell worldExample (1,1) => False -- evolveCell worldExample (2,0) => True -- ADD YOUR OWN SAMPLE INVOCATIONS -- evolveCell :: World -> Location -> Cell evolveCell = error "The function evolveCell is not implemented"