|
Post by B+ on Jul 13, 2021 0:19:19 GMT
' Conway Life.txt for JB v2 B+ started 2018-11-24 ' translated from "Quick Life trans for QB64 11-06.82 2017-11-11by bplus" ' From: quick life.bas SmallBASIC (not MS) B+ G7 ' ' Quote Rules (from Wiki): ' The universe of the Game of Life is an infinite two-dimensional orthogonal grid of square cells, ' each of which is in one of two possible states, alive or dead, or "populated" or "unpopulated". ' Every cell interacts with its eight neighbours, which are the cells that are horizontally, ' vertically, or diagonally adjacent. At each step in time, the following transitions occur: ' 1) Any live cell with fewer than two live neighbours dies, as if caused by underpopulation. ' 2) Any live cell with two or three live neighbours lives on to the next generation. ' 3) Any live cell with more than three live neighbours dies, as if by overpopulation. ' 4) Any dead cell with exactly three live neighbours becomes a live cell, as if by reproduction. ' The initial pattern constitutes the seed of the system. ' The first generation is created by applying the above rules simultaneously to every cell in the ' seed—births and deaths occur simultaneously, and the discrete moment at which this happens is ' sometimes called a tick (in other words, each generation is a pure function of the preceding one). ' The rules continue to be applied repeatedly to create further generations. ' (End Quote)
' Alas in practical applications we do not have infinite board to play Life, so at boundries rules ' break down as neighbor counts are only 5 max on edge and only 3 max at corners.
global XMAX, YMAX
XMAX = 700 YMAX = 700 nomainwin
WindowWidth = XMAX + 8 WindowHeight = YMAX + 32 UpperLeftX = (DisplayWidth - XMAX) / 2 'or delete if XMAX is 1200 or above UpperLeftY = (DisplayHeight - YMAX) / 2 'or delete if YMAX is 700 or above
open "Graphic Title" for graphics_nsb_nf as #gr '<======================= title #gr "trapclose quit" #gr "down" #gr "color white"
an = 70 : s = int(YMAX / an): g = 0 DIM a(an, an), ng(an, an), ls(an, an)
'seed for Conway's Life Classic FOR y = 2 TO an - 1 FOR x = 2 TO an - 1 'for symmetric line IF y = an / 2 OR y = an / 2 + 1 THEN a(x, y) = 1 NEXT NEXT
WHILE 1 scan FOR x = 2 TO an - 1 FOR y = 2 TO an - 1 pc = a(x - 1, y - 1) + a(x - 1, y) + a(x - 1, y + 1) + a(x, y - 1) + a(x, y + 1) + a(x + 1, y - 1) + a(x + 1, y) + a(x + 1, y + 1) ls(x, y) = pc IF a(x, y) THEN 'cell is alive so what is surviveRule 'Classic Conway's Life Rules IF pc = 2 or pc = 3 THEN ng(x, y) = 1 ELSE ng(x, y) = 0 ELSE 'birth? 'Classic Conway's Life Rules IF pc = 3 THEN ng(x, y) = 1 ELSE ng(x, y) = 0 END IF NEXT NEXT
'Classic Conway's Life Rules #gr "fill black" FOR y = 1 TO an FOR x = 1 TO an IF a(x, y) THEN 'show old a with it's neighbor counts br yellow or black call fbox (x - 1) * s + 1, (y - 1) * s + 1, (x - 1) * s + s - 1, (y - 1) * s + s - 1 END IF NEXT NEXT
FOR y = 1 TO an FOR x = 1 TO an a(x, y) = ng(x, y) 'load a() with next generation data NEXT NEXT g = g + 1 call pause 100 WEND
sub fbox x0, y0, x1, y1 #gr "place ";x0;" ";y0 #gr "boxfilled ";x1+1;" ";y1+1 end sub
sub quit H$ close #H$ end end sub
sub pause mil 'tsh version has scan built-in t0 = time$("ms") while time$("ms") < t0 + mil : scan : wend end sub
|
|
|
Post by tsh73 on Jul 13, 2021 7:42:02 GMT
Nice. What third array
ls(an, an) was for?
|
|
|
Post by B+ on Jul 13, 2021 11:06:17 GMT
Nice. What third array ls(an, an) was for? ls stood for light show, I was coloring the cells by neighbor counts and other experiments specially with the rules of life and death = cells on/off
|
|