[Haskell-beginners] Game of Life try

Емануела Моллова emanuela.mollova at gmail.com
Fri Jan 4 21:41:36 CET 2013


Hello all! :) I'm new to Haskell and I would like to try to implement a
simple version of Game of Life. I can imagine it in C++ for example, but I
have a little difficulties in Haskell. All I can think for is a mutable
array with all elements - 0 in the beginning and the user to be able to
write in the coordinates of the cells, which are alive and this cells to
become 1. Then to iterate through the array (but I'm not sure if I can
iterate, there is no 'while' here) and to make the changes (but maybe I
will need a new array for the changes, because when the first change
happens, it will affect the result). Also I was thinking of how to make it
visible, so I tried to make all 0-s red and all 1-s green, and after each
iteration to clear the screen with ANSI so that it looks a bit like
animation, but none of these ideas work... Here is an orientation in my
ideas:

import Data.Array.IO
import System.Console.ANSI

main :: IO ()
main = do
        arr <- newArray ((1,1), (10,10)) 0 :: IO (IOArray (Int, Int) Int)
writeAraay arr (1,1) 1
a <- readArray (1,1)
 setSGR [SetColor Foreground Dull Red]
        putStr [a]

Could you please suggest me what is a good place to store the information
about my cells (mutable, unmutable array, lists, tuples...) and any ideas
and tutorials at all would be really appreciated! Thank you very much in
advance! :)
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.haskell.org/pipermail/beginners/attachments/20130104/c61c2c14/attachment.htm>


More information about the Beginners mailing list