Camal (16) [Avatar] Offline
#1
Hi,
I just finished my implementation “Game of Life” in Go. I would love to get some feedback for my written test and approach to it.

https://github.com/midnightrun/game-of-life

Rules :

* A living (`true`) cell with less then 2 living neighbours will die
* A living (`true`) cell with 2 or 3 living neighbours will live
* A dead (`false`) cell with 3 living neighbours will live

I was really lost at line https://github.com/midnightrun/game-of-life/blob/master/main.go#L137 because I was swapping the universes within the function.

Also I really would like a cool animation. The only solution I found was to https://github.com/midnightrun/game-of-life/blob/master/main.go#L126 but this is removing everything, even the prompt.

I was a little messy in the test department but I tried to move my mock into a helper function.

Thanks for any thoughts on this one smilie
Nathan Youngman (53) [Avatar] Offline
#2
Good on you for writing tests -- especially since testing isn't covered in this book.

One thing to watch for is always indexing the universe in the same way. I think this line

future[x][y]


should be:

future[y][x]


If that's a bug, maybe your tests don't have the right expectations?

One other recommendation is to simplify your Alive method. Try to implement it without using any if statements.

Thanks for posting your solution,
Nathan.