06-18-2014, 07:21 PM

This post was last modified: 06-18-2014, 08:52 PM by Anthony.R.Brown.

Edited 0 times

This post was last modified: 06-18-2014, 08:52 PM by Anthony.R.Brown.

Edited 0 times

The Famous GAME OF LIFE (Not! working at the moment!)

An important Game? regarding Computer A.I research!

http://en.wikipedia.org/wiki/Conway's_Game_of_Life

Anthony.

An important Game? regarding Computer A.I research!

http://en.wikipedia.org/wiki/Conway's_Game_of_Life

Anthony.

Code:

`CLS`

RANDOMIZE TIMER

SCREEN 12

COLOR 10

PRINT "Game of life."

INPUT "First coordinate of grid: ", co1

INPUT "Enter second coordinate of grid: ", co2

INPUT "Set color (0 to 15) : ", col

DIM oldgen(co2 - co1, co2 - co1) AS INTEGER 'declaring old gen array

DIM newgen(co2 - co1, co2 - co1) AS INTEGER 'declaring new generation array

CLS

LINE (co1, co1 - 1)-(co2 + 1, co2 + 1), 15, B 'the frame of the whole autotmate

oldgen(75, 75) = 1 ' the following are the coordinates for a glider

oldgen(75, 76) = 1

oldgen(75, 77) = 1

oldgen(74, 77) = 1

oldgen(73, 76) = 1

FOR i = 1 TO (co2 - co1) 'displaying the old generation array (glider...)

FOR j = 1 TO (co2 - co1)

IF oldgen(i, j) > 0 THEN

PSET(j + co1,i + co1),col

END IF

NEXT

NEXT

DO WHILE true 'infinite outer loop repeating the whole algorithm

counter = 0 'initializing counter

FOR i = 1 TO (co2 - co1)

FOR j = 1 TO (co2 - co1)

IF ((j + 1) < (co2 - co1)) AND ((i + 1) < (co2 - co1)) THEN 'see if cell is not on border, and if not

IF oldgen(i - 1, j - 1) > 0 THEN 'checking neighbours and incrementing

counter = counter + 1 'counter for each "living" cell

END IF

IF oldgen(i - 1, j) > 0 THEN

counter = counter + 1

END IF

IF oldgen(i - 1, j + 1) > 0 THEN

counter = counter + 1

END IF

IF oldgen(i, j - 1) > 0 THEN

counter = counter + 1

END IF

IF oldgen(i, j + 1) > 0 THEN

counter = counter + 1

END IF

IF oldgen(i + 1, j - 1) > 0 THEN

counter = counter + 1

END IF

IF oldgen(i + 1, j) > 0 THEN

counter = counter + 1

END IF

IF oldgen(i + 1, j + 1) > 0 THEN

counter = counter + 1

END IF

END IF

IF (oldgen(i, j) > 0) AND ((counter = 2) OR (counter = 3)) THEN 'if the cell

newgen(i, j) = 1 ' is alive and has 2 or 3 neighbours it will be alive in the

END IF 'next step too. so fill newgen array with a 1.

IF (oldgen(i, j) = 0) AND (counter = 3) THEN 'if the cell is dead and has 3

newgen(i, j) = 1 'neighbours, it will be alive in the next step.fill newgen

END IF ' with a 1.

NEXT

NEXT

FOR i = 1 TO (co2 - co1) ' display the new generation

FOR j = 1 TO (co2 - co1)

IF newgen(i, j) > 0 THEN

PSET(j + co1,i + co1),col

END IF

NEXT

NEXT

FOR i = 1 TO (co2 - co1)

FOR j = 1 TO (co2 - co1)

oldgen(i, j) = newgen(i, j)'set oldgen array to newgen array

newgen(i, j) = 0 'reinitialize newgen to 0

NEXT

NEXT

LOOP