Conway's Game of Life

BlitzMax Forums/BlitzMax Tutorials/Conway's Game of Life

The forum is locked. These are the original blitzbasic.com forums, kept so they can still be read. No new topics, replies or edits can be made here. To join in, head over to the Blitz3D+ forums.

And there is a bug...

Change the GM_NextFrame function to the one below. I noticed this after my last post. I broke one of the rules. If a cell has exactly three neighbours it stays alive OR gives birth. I noticed there was a problem when I tried to do a glider. It didn't work! So here's the updated function.

Function GM_NextFrame(id:Int)
	Local TargetFrame:Int = 0
	If id = 0
		TargetFrame = 1
	End If 
	HK_ClearBoard(TargetFrame)
	
	For y = 0 To 28
		For x = 0 To 39
			Local NCount:Int = GM_KeepAlive(id, x, y)
			Select NCount
				Case 2
					If GameBoard[id, x, y] = TLifeCell.ALIVE
						GameBoard[TargetFrame, x, y] = TLifeCell.ALIVE
					End If 
				Case 3 
					GameBoard[TargetFrame, x, y] = TLifeCell.ALIVE
				Default				
					GameBoard[TargetFrame, x, y] = TLifeCell.DEAD
			End Select
		Next
	Next	
	
	CURRENT_BOARD = TargetFrame
		
End Function