LoginLogin

Game of Life Code doesn't work

Root / Programming Questions / [.]

KevinTheDumbCatCreated:
So I have uploaded some Code here: QRYPDE83. Can somebody please tell me why it doesn't work?

Well first, you should use FOR instead of WHILE:
DEF RANDOM BOARD
Y=3
X=3
WHILE Y<26
CELLS[X+2,Y+2]=RND(2)
INC X,2
IF X==47 THEN X=3 INC Y,2
WEND
NEIGHBORCHECK
END
can be:
DEF RANDOM BOARD
 VAR X,Y
 FOR Y=3 TO 26-1 STEP 2
  FOR X=3 TO 47-1 STEP 2
   CELLS[X+2,Y+2]=RND(2)
  NEXT
 NEXT
 NEIGHBORCHECK
END
Anyway, I assume the main problem is with the edges This is because everything outside the board is treated as a living cell (because you made 0 = alive and 1 = dead, and it starts out filled with 0s)

Well first, you should use FOR instead of WHILE:
DEF RANDOM BOARD
Y=3
X=3
WHILE Y<26
CELLS[X+2,Y+2]=RND(2)
INC X,2
IF X==47 THEN X=3 INC Y,2
WEND
NEIGHBORCHECK
END
can be:
DEF RANDOM BOARD
 VAR X,Y
 FOR Y=3 TO 26-1 STEP 2
  FOR X=3 TO 47-1 STEP 2
   CELLS[X+2,Y+2]=RND(2)
  NEXT
 NEXT
 NEIGHBORCHECK
END
Anyway, I assume the main problem is with the edges This is because everything outside the board is treated as a living cell (because you made 0 = alive and 1 = dead, and it starts out filled with 0s)
Thanks! After changing the zeros and ones around, it works! And I've changed the while-loops to for-loops!