Thanks for the reply. I thought my code was right, but here is the code that made me think it is not. It is suposed to be Gosper's Glider Gun (see animation at the top of http://en.wikipedia.org/wiki/Conway%27s_Game_of_Life ), and it works for the first cycle, then it starts going crazy. Do you know why?
Const gw=80 Const gh=60 Graphics gw,gh,0,3 SetBuffer BackBuffer() Dim pixel(gw,gh) Dim pixel2(gw,gh) SeedRnd(MilliSecs()) pixel(1+5,5+5)=1 pixel(1+5,6+5)=1 pixel(2+5,5+5)=1 pixel(2+5,6+5)=1 pixel(11+5,5+5)=1 pixel(11+5,6+5)=1 pixel(11+5,7+5)=1 pixel(12+5,4+5)=1 pixel(12+5,8+5)=1 pixel(13+5,3+5)=1 pixel(13+5,9+5)=1 pixel(14+5,3+5)=1 pixel(14+5,9+5)=1 pixel(15+5,6+5)=1 pixel(16+5,4+5)=1 pixel(16+5,8+5)=1 pixel(17+5,5+5)=1 pixel(17+5,6+5)=1 pixel(17+5,7+5)=1 pixel(18+5,6+5)=1 pixel(21+5,3+5)=1 pixel(21+5,4+5)=1 pixel(21+5,5+5)=1 pixel(22+5,3+5)=1 pixel(22+5,4+5)=1 pixel(22+5,5+5)=1 pixel(23+5,2+5)=1 pixel(23+5,6+5)=1 pixel(25+5,1+5)=1 pixel(25+5,2+5)=1 pixel(25+5,6+5)=1 pixel(25+5,7+5)=1 pixel(35+5,2+5)=1 pixel(35+5,3+5)=1 pixel(36+5,2+5)=1 pixel(36+5,3+5)=1 For x=0 To gw-1 For y=0 To gh-1 pixel2(x,y)=pixel(x,y) Next Next Delay 1000 While Not KeyDown(1) LockBuffer BackBuffer() For x=1 To gw-2 For y=1 To gh-2 If pixel2(x,y)=1 Then WritePixelFast x,y,-1 If pixel2(x,y)=0 Then WritePixelFast x,y,$ff000000 neibors=0 If pixel(x+1,y+1)=1 Then neibors=neibors+1 If pixel(x-1,y-1)=1 Then neibors=neibors+1 If pixel(x+1,y-1)=1 Then neibors=neibors+1 If pixel(x-1,y+1)=1 Then neibors=neibors+1 If pixel(x,y+1)=1 Then neibors=neibors+1 If pixel(x,y-1)=1 Then neibors=neibors+1 If pixel(x+1,y)=1 Then neibors=neibors+1 If pixel(x-1,y)=1 Then neibors=neibors+1 If pixel(x,y)=1 If Not(neibors=2 Or neibors=3) Then pixel2(x,y)=0 Else If (neibors=3) Then pixel2(x,y)=1 EndIf Next Next For x=0 To gw-1 For y=0 To gh-1 pixel(x,y)=pixel2(x,y) Next Next UnlockBuffer() Delay 50 Flip Wend End