|
Post by bplus on Aug 9, 2023 9:36:11 GMT -5
_Title "Quick Conway Life" ' b+ 2023-1-15 Screen _NewImage(710, 710, 32) DefLng A-Z Dim g(69, 69)
For y = 1 To 68 'seed g() For x = 1 To 68 If Rnd < .33 Then g(x, y) = 1 Next Next
While _KeyDown(27) = 0 ReDim ng(69, 69) Cls gen = gen + 1 Print "Gen"; gen For y = 1 To 68 For x = 1 To 68 nc = g(x - 1, y - 1) + g(x, y - 1) + g(x + 1, y - 1) + g(x - 1, y) + g(x + 1, y) + g(x - 1, y + 1) + g(x, y + 1) + g(x + 1, y + 1) If g(x, y) Then Line (x * 10, y * 10)-Step(10, 10), &HFFFFFFFF, BF Line (x * 10, y * 10)-Step(10, 10), &HFF000000, B If nc = 2 Or nc = 3 Then ng(x, y) = 1 Else If nc = 3 Then ng(x, y) = 1 End If Next Next For y = 1 To 68 'transfer ng to g and erase For x = 1 To 68 g(x, y) = ng(x, y) Next Next ReDim ng(69, 69) _Limit 10 Wend
|
|
|
Post by charliejv on Aug 10, 2023 21:43:57 GMT -5
There's just a little something I don't quite understand in your code.
early on, you Dim the array g, but in the loop, you redim the array "ng".
What's going on there?
I might be confused because I've never seen a redim of an array without a previous dim ?
|
|
|
Post by charliejv on Aug 10, 2023 22:11:12 GMT -5
|
|
|
Post by bplus on Aug 11, 2023 5:22:51 GMT -5
There's just a little something I don't quite understand in your code. early on, you Dim the array g, but in the loop, you redim the array "ng". What's going on there? I might be confused because I've never seen a redim of an array without a previous dim ? In QB64, you can create a dynamic array with a REDIM statement to start it off. Here it is used as an alternate way to erase the array and reload it. Yes I could have used Erase instead with a static array made with a regular DIM. Not you got me curious, I may not have needed to erase nor redim but just reload the array. Let me check that: __Title "Quick Conway Life" ' b+ 2023-1-15 fixed 2023-08-11 Screen _NewImage(710, 710, 32) DefLng A-Z Dim g(69, 69), ng(69, 69)
For y = 1 To 68 'seed g() For x = 1 To 68 If Rnd < .33 Then g(x, y) = 1 Next Next
While _KeyDown(27) = 0 Cls gen = gen + 1 Print "Gen"; gen For y = 1 To 68 For x = 1 To 68 nc = g(x - 1, y - 1) + g(x, y - 1) + g(x + 1, y - 1) + g(x - 1, y) + g(x + 1, y) + g(x - 1, y + 1) + g(x, y + 1) + g(x + 1, y + 1) If g(x, y) Then Line (x * 10, y * 10)-Step(10, 10), &HFFFFFFFF, BF Line (x * 10, y * 10)-Step(10, 10), &HFF000000, B If nc = 2 Or nc = 3 Then ng(x, y) = 1 Else If nc = 3 Then ng(x, y) = 1 End If Next Next For y = 1 To 68 'transfer ng to g and erase For x = 1 To 68 g(x, y) = ng(x, y) Next Next Erase ng _Limit 10 _Display Wend
Definitely have to erase the ng array! I also added a _Display because it can get a little blinky without it. Ewh! I had it, ReDim ng(69, 69), in there twice, that wasn't necesssary! OK fixed with standard DIM of ng() array and _Display added, still 36 lines BTW you need the 2nd ng = next generation array because you can't change the g array while you calc the neighbor counts because that would mess up that array for the next cells counts.
|
|
|
Post by bplus on Aug 11, 2023 5:33:25 GMT -5
Yeah I love Conway's Life alllllll the way back to good ole GW Basic. I remember spending hours working out how to graph expanding and shrinking cells when first attempted, I think it was an infinitely expanding board I was working on?
|
|