'---------------------------------------------
'  _ɏzusLife game
'---------------------------------------------
system.err.exit=1'\G[̃vO~

X_SIZE=70
Y_SIZE=20


start:

clr

'f[^쐬

for y=1 to Y_SIZE
	for x=1 to X_SIZE
		'ϐrandɂ胉_ɔzu
		if rand > rand then scr[x][y]="_" else scr[x][y]="#"
	next x
next y

'ʕ\
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
	sleep 100
next y

while 1

'	count=0

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


	for y=1 to Y_SIZE
		for x=1 to X_SIZE

			'a: łZ̎͂3̐ĂZΎ̐ł͐iajB 

			if data[x][y]=="_" then
				Birth = 0
				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]="#"
				endif
			endif

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

			if data[x][y]=="#" then
				Dies = 0
				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 || Dies>3 then
					scr[x][y]="_"
				endif
			endif
		next x
	next y
	
	'ʕ\
	check=""
	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
		check=check+str
	next y

	'ωȂȂċN
	loopcheck check
	if restart<>0 || loopcheck==0 then
		restart=restart+1
		if restart>5 then
			restart=0
			str=""
			for x=1 to X_SIZE
				str=str+" "
			next x
			for y=1 to Y_SIZE
				location y,1
				print str
				sleep 100
			next y
			restart=0
			goto start:
		endif
	endif
	sleep 100
wend

'JԂ̃`FbN
@loopcheck c
	if buf[0]==c || buf[1]==c || buf[2]==c || buf[3]==c || buf[4]==c || buf[5]==c || buf[6]==c || buf[7]==c then
		'ߋ8̂ɓ񂪌
		this=0
	else
		buf[0]=buf[1]
		buf[1]=buf[2]
		buf[2]=buf[3]
		buf[3]=buf[4]
		buf[4]=buf[5]
		buf[5]=buf[6]
		buf[6]=buf[7]
		buf[7]=c
		this=1
	endif
_@



