This is a read-only archive of the old Scratch 1.x Forums.
Try searching the current Scratch discussion forums.

#1 2012-10-28 02:50:31

zubblewu
Scratcher
Registered: 2011-02-17
Posts: 1000+

The game of life help

I'm currently attempting  simulation of the game of life, and what I have so far isn't detecting when it has numbers.

when gf clicked
set [paused v] to [yes]
clear
hide
delete (all v) of [oldgrid v]
delete (all v) of [newgrid v]
set [pixradius v] to [160]
set [cellradius v] to [4]
set [placementscale v] to (((2) * (pixradius)) / ((2) * (cellradius)))
repeat (((cellradius) * (cellradius)) * (4))  
add [0] to [oldgrid v]
add [0] to [newgrid v]
end
forever  
if <(paused) = [yes]>
set [out of bounds v] to [no]
go to x: (((round (((mouse x) + ((placementscale) / (2))) / (placementscale))) * (placementscale)) - ((placementscale) / (2))) y: ((((round (((mouse y) + ((placementscale) / (2))) / (placementscale))) * (placementscale)) - ((placementscale) / (2))) + (1))
if <( [abs v] of (x position)) > (pixradius)> 
set [out of bounds v] to [yes]
if <(x position) > (pixradius)>
set x to (pixradius)
else
set x to ((0) - (pixradius))
end
end
if <( [abs v] of (y position)) > ((pixradius) + (1))> 
set [out of bounds v] to [yes]
if <(y position) > ((pixradius) + (1))>
set y to ((pixradius) + (1))
else
set y to ((0) - (pixradius))
end
end
if <mouse down?> 
if <(out of bounds) = [no]> 
if <(round ((((round (((x position) + ((placementscale) / (2))) / (placementscale))) * (placementscale)) - ((placementscale) / (2))) / (placementscale))) > [0]>
set [mouse column v] to ((4) + (round ((((round (((x position) + ((placementscale) / (2))) / (placementscale))) * (placementscale)) - ((placementscale) / (2))) / (placementscale))))
else
set [mouse column v] to ((5) + (round ((((round (((x position) + ((placementscale) / (2))) / (placementscale))) * (placementscale)) - ((placementscale) / (2))) / (placementscale))))
end
set [mouse row v] to ( [abs v] of ((4) - (round (((((round (((mouse y) + ((placementscale) / (2))) / (placementscale))) * (placementscale)) - ((placementscale) / (2))) + (1)) / (placementscale)))))
if <touching color [#000008]?>
switch to costume [background2 v]
replace item ((( [sqrt v] of (length of [oldgrid v] )) * (mouse row)) + (mouse column)) of [oldgrid v] with [0]
else
switch to costume [background1 v]
replace item ((( [sqrt v] of (length of [oldgrid v] )) * (mouse row)) + (mouse column)) of [oldgrid v] with [1]
end
stamp
wait until <not <mouse down?>>
end
end
else
set [currentrowcheck v] to [0]
set [currentcolumncheck v] to [1]
repeat (length of [oldgrid v] )  
set [temporaryneighborvalue v] to [0]
if <(currentrowcheck) = [0]>
set [tempscanrow v] to (( [sqrt v] of (length of [oldgrid v] )) - (1))
else
set [tempscanrow v] to ((currentrowcheck) + (1))
end
if <(currentcolumncheck) = [1]>
set [tempscancolumn v] to ( [sqrt v] of (length of [oldgrid v] ))
else
set [tempscancolumn v] to ((currentcolumncheck) - (1))
end
if <(item (((tempscanrow) * ( [sqrt v] of (length of [oldgrid v] ))) + (tempscancolumn)) of [newgrid v] ) = [1]> 
change [temporaryneighborvalue v] by (1)
end
set [tempscancolumn v] to (currentcolumncheck)
if <(item (((tempscanrow) * ( [sqrt v] of (length of [oldgrid v] ))) + (tempscancolumn)) of [newgrid v] ) = [1]> 
change [temporaryneighborvalue v] by (1)
end
if <(currentcolumncheck) = ( [sqrt v] of (length of [oldgrid v] ))>
set [tempscancolumn v] to [1]
else
set [tempscancolumn v] to ((currentcolumncheck) + (1))
end
if <(item (((tempscanrow) * ( [sqrt v] of (length of [oldgrid v] ))) + (tempscancolumn)) of [newgrid v] ) = [1]> 
change [temporaryneighborvalue v] by (1)
end
set [tempscanrow v] to (currentrowcheck)
end
end
end
If anyone could help, that would be amazing.

Last edited by zubblewu (2012-10-28 19:06:22)


........................................................................................................................................................................................................................................

Offline

 

#2 2012-10-28 04:08:37

notaloser
Scratcher
Registered: 2011-12-06
Posts: 100+

Re: The game of life help

Oh My God!!!! you actually type that: ^^^?

I don't understand the script, im sorry. it will be better if you just uploaded what you have made so far.


http://gifs.gifbin.com/1238409599_nom_nom.gifhttp://cdn3.lolzsquad.com/wp-content/uploads/2012/10/Come-here-I-want-to-tell-you-something.-.gif

Offline

 

#3 2012-10-28 10:18:22

zubblewu
Scratcher
Registered: 2011-02-17
Posts: 1000+

Re: The game of life help

notaloser wrote:

Oh My God!!!! you actually type that: ^^^?

I don't understand the script, im sorry. it will be better if you just uploaded what you have made so far.

Nope  tongue . But it's a lot easier imho for people to reply with the script right there. And if you want' the project so far is uploaded as my newest one.


........................................................................................................................................................................................................................................

Offline

 

#4 2012-10-28 10:40:39

Molybdenum
Scratcher
Registered: 2012-06-17
Posts: 1000+

Re: The game of life help

Seems like CAs are a new trend.

This shows how to use variable size arrays to make a CA.


"The Enrichment Center is required to remind you that you will be baked, and then there will be cake."
(|Balls and Platforms: Stay on!|) (|NaOS-H: An operating system... Or is it?|)

Offline

 

#5 2012-10-28 12:04:35

amcerbu
Scratcher
Registered: 2009-07-21
Posts: 500+

Re: The game of life help

Just a small piece of advice:  I wouldn't do it with a bunch of "rows," but with a long array that "wraps around" at the end of each line (sort of like the level storing system in Music Marathon).  When you check cell n's neighbors, you find the values of item n + 1, n - 1, n + width, and n - width of the data list.

Also, Life is played on a theoretically infinite grid, so you'll have to figure out a way to deal with edges - will cells adjacent to edges measure the edge as a live neighbor, or an empty cell?  You'll have to decide a feasible size for the game (coincidentally, I was thinking of making one myself, but perhaps in C++ instead), taking into account the computation speed/rendering problem and the size of the Scratch viewing screen.

Anyway, good luck!

Last edited by amcerbu (2012-10-28 12:08:23)

Offline

 

#6 2012-10-28 12:51:05

zubblewu
Scratcher
Registered: 2011-02-17
Posts: 1000+

Re: The game of life help

amcerbu wrote:

Just a small piece of advice:  I wouldn't do it with a bunch of "rows," but with a long array that "wraps around" at the end of each line (sort of like the level storing system in Music Marathon).  When you check cell n's neighbors, you find the values of item n + 1, n - 1, n + width, and n - width of the data list.

Also, Life is played on a theoretically infinite grid, so you'll have to figure out a way to deal with edges - will cells adjacent to edges measure the edge as a live neighbor, or an empty cell?  You'll have to decide a feasible size for the game (coincidentally, I was thinking of making one myself, but perhaps in C++ instead), taking into account the computation speed/rendering problem and the size of the Scratch viewing screen.

Anyway, good luck!

Thanks! And yeah, I was thinking of using one long list, but I didn't for computational reasons. Looks like I'll have to anyway. In terms of edges, I was just going to have them wrap around (like taking into account cells adjacent to it on the other side).


........................................................................................................................................................................................................................................

Offline

 

#7 2012-10-28 13:09:35

amcerbu
Scratcher
Registered: 2009-07-21
Posts: 500+

Re: The game of life help

Yeah.  In fact, I had been thinking of what the Game of Life would look like played on the surface of a torus (basically, a square where the edges would wrap around).  Anyway, I look forward to seeing it!

http://upload.wikimedia.org/wikipedia/commons/3/37/Projection_color_torus.png

Last edited by amcerbu (2012-10-28 13:10:59)

Offline

 

#8 2012-10-28 13:11:36

zubblewu
Scratcher
Registered: 2011-02-17
Posts: 1000+

Re: The game of life help

Thanks! I've already finished positioning and I'm halfway done with a versatile script that should pretty much work for all perfect squares, as long as you fill in a few parameters.


........................................................................................................................................................................................................................................

Offline

 

#9 2012-10-28 13:22:35

Molybdenum
Scratcher
Registered: 2012-06-17
Posts: 1000+

Re: The game of life help

That's exactly what I said.

EDIT: Wait, who am I talking to?

Last edited by Molybdenum (2012-10-28 13:22:53)


"The Enrichment Center is required to remind you that you will be baked, and then there will be cake."
(|Balls and Platforms: Stay on!|) (|NaOS-H: An operating system... Or is it?|)

Offline

 

#10 2012-10-28 13:24:16

zubblewu
Scratcher
Registered: 2011-02-17
Posts: 1000+

Re: The game of life help

Molybdenum wrote:

That's exactly what I said.

EDIT: Wait, who am I talking to?

I don't know. And I'm to lazy to download anything. [mindblown]Also, I clicked the quote button exactly when you edited (or within 1 second)  yikes [/mindblown]

Last edited by zubblewu (2012-10-28 13:24:49)


........................................................................................................................................................................................................................................

Offline

 

#11 2012-10-28 18:54:01

zubblewu
Scratcher
Registered: 2011-02-17
Posts: 1000+

Re: The game of life help

I've totally rescripted it now. However, the part of it I have done (1/2 of the checking for neighbors I believe) isn't working. It's not finding that it has any neighbors, even when it does.


........................................................................................................................................................................................................................................

Offline

 

Board footer