'---------------------------------------------
'  Life game
'---------------------------------------------
system.err.exit=1'\G[̃vO~

X_SIZE=50
Y_SIZE=20

clr

'f[^쐬

for y=1 to Y_SIZE
	for x=1 to X_SIZE
		scr[x][y]="_"
	next x
next y

'gliderguns̏ݒ
scr[25][ 1]="#"
scr[23][ 2]="#"
scr[25][ 2]="#"
scr[13][ 3]="#"
scr[14][ 3]="#"
scr[21][ 3]="#"
scr[22][ 3]="#"
scr[35][ 3]="#"
scr[36][ 3]="#"
scr[12][ 4]="#"
scr[16][ 4]="#"
scr[21][ 4]="#"
scr[22][ 4]="#"
scr[35][ 4]="#"
scr[36][ 4]="#"
scr[1 ][ 5]="#"
scr[2 ][ 5]="#"
scr[11][ 5]="#"
scr[17][ 5]="#"
scr[21][ 5]="#"
scr[22][ 5]="#"
scr[1 ][ 6]="#"
scr[2 ][ 6]="#"
scr[11][ 6]="#"
scr[15][ 6]="#"
scr[17][ 6]="#"
scr[18][ 6]="#"
scr[23][ 6]="#"
scr[25][ 6]="#"
scr[11][ 7]="#"
scr[17][ 7]="#"
scr[25][ 7]="#"
scr[12][ 8]="#"
scr[16][ 8]="#"
scr[13][ 9]="#"
scr[14][ 9]="#"


'C[^[̏ݒ
scr[31][17]="#"
scr[31][18]="#"
scr[32][17]="#"
scr[33][18]="#"
scr[33][19]="#"
scr[33][20]="#"
scr[34][20]="#"


while 1
	for y=1 to Y_SIZE
		for x=1 to X_SIZE
			data[x][y]=scr[x][y]
		next x
	next y

	'goto scr_print:

	for y=1 to Y_SIZE
		for x=1 to X_SIZE
			'a: łZ̎͂3̐ĂZΎ̐ł͐iajB 
			Birth = 0
			if data[x][y]<>"_" then goto Birth_end:
			if data[x-1][y]=="#" then Birth = Birth + 1
			if data[x+1][y]=="#" then Birth = Birth + 1
			if data[x][y-1]=="#" then Birth = Birth + 1
			if data[x][y+1]=="#" then Birth = Birth + 1
			if data[x+1][y+1]=="#" then Birth = Birth + 1
			if data[x+1][y-1]=="#" then Birth = Birth + 1
			if data[x-1][y+1]=="#" then Birth = Birth + 1
			if data[x-1][y-1]=="#" then Birth = Birth + 1
			if Birth==3 then scr[x][y]="#"

			Birth_end:

			'ێ: ĂZ̎͂23̐ĂZΎ̐łcB 
			'S: ȊȌꍇɂ͎̐ł͎ʁB

			Dies = 0
			if data[x][y]<>"#" then goto Dies_end:
			if data[x-1][y]=="#" then Dies = Dies + 1
			if data[x+1][y]=="#" then Dies = Dies + 1
			if data[x][y-1]=="#" then Dies = Dies + 1
			if data[x][y+1]=="#" then Dies = Dies + 1
			if data[x+1][y+1]=="#" then Dies = Dies + 1
			if data[x+1][y-1]=="#" then Dies = Dies + 1
			if data[x-1][y+1]=="#" then Dies = Dies + 1
			if data[x-1][y-1]=="#" then Dies = Dies + 1
			if Dies<2 then scr[x][y]="_"
			if Dies>3 then scr[x][y]="_"

			Dies_end:
		next x
	next y

	scr_print:

	for y=1 to Y_SIZE
		str=""
		for x=1 to X_SIZE
			str=str+scr[x][y]
		next x
		location y,1
		print str
	next y

	location 1,1
	print ""
	location 1,1
	print ""
	location 1,1
	print ""
	location 1,1
	print ""

	sleep 100
wend


