Xxxrandom chat


02-May-2016 09:52

randfill: stx ;0 for indirect ldx # ;addressing stx randloop: lda $fe ;generate random and # ;pixels on the sta (), Y ;screen jsr inc0103 cmp #

randfill: stx

randfill: stx $01 ;$200 for indirect ldx #$02 ;addressing stx $02randloop: lda $fe ;generate random and #$01 ;pixels on the sta ($01), Y ;screen jsr inc0103 cmp #$00 bne randloop lda $02 cmp #$06 bne randloop clearmem: lda #$df ;set $07df-$0a20 sta $01 ;to $#00 lda #$07 sta $02clearbyte: lda #$00 sta ($01), Y jsr inc0103 cmp #$20 bne clearbyte lda $02 cmp #$0a bne clearbyte starttick:copyscreen: lda #$00 ;set up source sta $01 ;pointer at sta $03 ;$01/$02 and lda #$02 ;dest pointer sta $02 ;at $03/$04 lda #$08 sta $04 ldy #$00copybyte: lda ($01), Y ;copy pixel to sta ($03), Y ;back buffer jsr inc0103 ;increment pointers cmp #$00 ;check to see bne copybyte ;if we're at $600 lda $02 ;if so, we've cmp #$06 ;copied the bne copybyte ;entire screen conway: lda #$df ;apply conway rules sta $01 ;reset the pointer sta $03 ;to $#01df/$#07df lda #$01 ;($200 - $21) sta $02 ;($800 - $21) lda #$07 sta $04onecell: lda #$00 ;process one cell ldy #$01 ;upper cell clc adc ($03), Y ldy #$41 ;lower cell clc adc ($03), Ychkleft: tax ;check to see lda $01 ;if we're at the and #$1f ;left edge tay txa cpy #$1f beq rightcellsleftcells: ldy #$00 ;upper-left cell clc adc ($03), Y ldy #$20 ;left cell clc adc ($03), Y ldy #$40 ;lower-left cell clc adc ($03), Ychkright: tax ;check to see lda $01 ;if we're at the and #$1f ;right edge tay txa cpy #$1e beq evaluaterightcells: ldy #$02 ;upper-right cell clc adc ($03), Y ldy #$22 ;right cell clc adc ($03), Y ldy #$42 ;lower-right cell clc adc ($03), Yevaluate: ldx #$01 ;evaluate total ldy #$21 ;for current cell cmp #$03 ;3 = alive beq storex ldx #$00 cmp #$02 ;2 = alive if bne storex ;c = alive lda ($03), Y and #$01 taxstorex: txa ;store to screen sta ($01), Y jsr inc0103 ;move to next cellconwayloop: cmp #$e0 ;if not last cell, bne onecell ;process next cell lda $02 cmp #$05 bne onecell jmp starttick ;run next tick inc0103: lda $01 ;increment $01 cmp #$ff ;and $03 as 16-bit bne onlyinc01 ;pointers inc $02 inc $04onlyinc01: inc $01 lda $01 sta $03 rts The solution uses one cell thick border around square Petri dish as uninhabited dire land. Sample output contains 3 generations of the blinker and 5 of the glider: See Conway's Game of Life/ALGOL 68 APL2 (Dialog) Example in one line APL \ 1130 example (very old APL dialect via simulator) APL1130From: APL \ 1130 Samples The following APL \ 1130 code will need APL385 font installed to display correctly. See Download APL TT Font ∇LIFE[⎕]∇[0] NG←LIFE CG; W[1] W←CG+(¯1⊖CG)+(1⊖CG)+(¯1⌽CG)+(1⌽CG)[2] W←W+(1⊖1⌽CG)+(¯1⊖1⌽CG)+(1⊖¯1⌽CG)+(¯1⊖¯1⌽CG)[3] NG←(3=W)+(CG∧4=W) ∇ RP←5 5⍴0 0 0 0 0 0 0 1 1 0 0 1 1 0 0 0 0 1 0 0 RP0 0 0 0 00 0 1 1 00 1 1 0 00 0 1 0 00 0 0 0 0 LIFE RP0 0 0 0 00 1 1 1 00 1 0 0 00 1 1 0 00 0 0 0 0 LIFE LIFE RP0 0 1 0 00 1 1 0 01 0 0 1 00 1 1 0 00 0 0 0 0 .................................................. One interacts with the Game of Life by creating an initial configuration and observing how it evolves. Although you should test your implementation on more complex examples such as the glider in a larger universe, show the action of the blinker (three adjoining cells in a row all alive), over three generations, in a 3 by 3 grid. (1,4)=TRUERETURN'' Count the number of neighbours of the point i,j' (Assume i/j +/- 1 will not fall out of world)'FUNCTION count_neighbours(i%,j%) LOCAL count%,l% count%=0 FOR l%=-1 TO 1 IF world! (i%+l%,j%+1) count%=count%+1 ENDIF NEXT l% IF world! (i%+1,j%) count%=count%+1 ENDIF RETURN count%ENDFUNC'' Update the world one step'PROCEDURE update_world LOCAL i%,j% ' compute neighbour counts and store FOR i%=1 TO 30 FOR j%=1 TO 30 ns%(i%,j%)[email protected]_neighbours(i%,j%) NEXT j% NEXT i% ' update the world cells FOR i%=1 TO 30 FOR j%=1 TO 30 IF world!

||

randfill: stx $01 ;$200 for indirect ldx #$02 ;addressing stx $02randloop: lda $fe ;generate random and #$01 ;pixels on the sta ($01), Y ;screen jsr inc0103 cmp #$00 bne randloop lda $02 cmp #$06 bne randloop clearmem: lda #$df ;set $07df-$0a20 sta $01 ;to $#00 lda #$07 sta $02clearbyte: lda #$00 sta ($01), Y jsr inc0103 cmp #$20 bne clearbyte lda $02 cmp #$0a bne clearbyte starttick:copyscreen: lda #$00 ;set up source sta $01 ;pointer at sta $03 ;$01/$02 and lda #$02 ;dest pointer sta $02 ;at $03/$04 lda #$08 sta $04 ldy #$00copybyte: lda ($01), Y ;copy pixel to sta ($03), Y ;back buffer jsr inc0103 ;increment pointers cmp #$00 ;check to see bne copybyte ;if we're at $600 lda $02 ;if so, we've cmp #$06 ;copied the bne copybyte ;entire screen conway: lda #$df ;apply conway rules sta $01 ;reset the pointer sta $03 ;to $#01df/$#07df lda #$01 ;($200 - $21) sta $02 ;($800 - $21) lda #$07 sta $04onecell: lda #$00 ;process one cell ldy #$01 ;upper cell clc adc ($03), Y ldy #$41 ;lower cell clc adc ($03), Ychkleft: tax ;check to see lda $01 ;if we're at the and #$1f ;left edge tay txa cpy #$1f beq rightcellsleftcells: ldy #$00 ;upper-left cell clc adc ($03), Y ldy #$20 ;left cell clc adc ($03), Y ldy #$40 ;lower-left cell clc adc ($03), Ychkright: tax ;check to see lda $01 ;if we're at the and #$1f ;right edge tay txa cpy #$1e beq evaluaterightcells: ldy #$02 ;upper-right cell clc adc ($03), Y ldy #$22 ;right cell clc adc ($03), Y ldy #$42 ;lower-right cell clc adc ($03), Yevaluate: ldx #$01 ;evaluate total ldy #$21 ;for current cell cmp #$03 ;3 = alive beq storex ldx #$00 cmp #$02 ;2 = alive if bne storex ;c = alive lda ($03), Y and #$01 taxstorex: txa ;store to screen sta ($01), Y jsr inc0103 ;move to next cellconwayloop: cmp #$e0 ;if not last cell, bne onecell ;process next cell lda $02 cmp #$05 bne onecell jmp starttick ;run next tick inc0103: lda $01 ;increment $01 cmp #$ff ;and $03 as 16-bit bne onlyinc01 ;pointers inc $02 inc $04onlyinc01: inc $01 lda $01 sta $03 rts The solution uses one cell thick border around square Petri dish as uninhabited dire land. Sample output contains 3 generations of the blinker and 5 of the glider: See Conway's Game of Life/ALGOL 68 APL2 (Dialog) Example in one line APL \ 1130 example (very old APL dialect via simulator) APL1130From: APL \ 1130 Samples The following APL \ 1130 code will need APL385 font installed to display correctly.

See Download APL TT Font ∇LIFE[⎕]∇[0] NG←LIFE CG; W[1] W←CG+(¯1⊖CG)+(1⊖CG)+(¯1⌽CG)+(1⌽CG)[2] W←W+(1⊖1⌽CG)+(¯1⊖1⌽CG)+(1⊖¯1⌽CG)+(¯1⊖¯1⌽CG)[3] NG←(3=W)+(CG∧4=W) ∇ RP←5 5⍴0 0 0 0 0 0 0 1 1 0 0 1 1 0 0 0 0 1 0 0 RP0 0 0 0 00 0 1 1 00 1 1 0 00 0 1 0 00 0 0 0 0 LIFE RP0 0 0 0 00 1 1 1 00 1 0 0 00 1 1 0 00 0 0 0 0 LIFE LIFE RP0 0 1 0 00 1 1 0 01 0 0 1 00 1 1 0 00 0 0 0 0 ..................................................

One interacts with the Game of Life by creating an initial configuration and observing how it evolves.

Although you should test your implementation on more complex examples such as the glider in a larger universe, show the action of the blinker (three adjoining cells in a row all alive), over three generations, in a 3 by 3 grid.

(1,4)=TRUERETURN'' Count the number of neighbours of the point i,j' (Assume i/j +/- 1 will not fall out of world)'FUNCTION count_neighbours(i%,j%) LOCAL count%,l% count%=0 FOR l%=-1 TO 1 IF world! (i%+l%,j%+1) count%=count%+1 ENDIF NEXT l% IF world! (i%+1,j%) count%=count%+1 ENDIF RETURN count%ENDFUNC'' Update the world one step'PROCEDURE update_world LOCAL i%,j% ' compute neighbour counts and store FOR i%=1 TO 30 FOR j%=1 TO 30 ns%(i%,j%)[email protected]_neighbours(i%,j%) NEXT j% NEXT i% ' update the world cells FOR i%=1 TO 30 FOR j%=1 TO 30 IF world!

Thus, while it is somewhat verbose, it fully simulates Conway's Game of Life and is relatively simple to expand to feature different starting shapes.

Define life(pattern) = Prgm Local x,y,nt,count,save,xl,yl,xh,yh Define nt(y,x) = when(pxl Test(y,x), 1, 0) {}→save set Graph("Axes", "Off")→save[1] set Graph("Grid", "Off")→save[2] set Graph("Labels", "Off")→save[3] Fn Off Plot Off Clr Draw If pattern = "blinker" Then 36→yl 40→yh 78→xl 82→xh Pxl On 36,80 Pxl On 38,80 Pxl On 40,80 Else If pattern = "glider" Then 30→yl 40→yh 76→xl 88→xh Pxl On 38,76 Pxl On 36,78 Pxl On 36,80 Pxl On 38,80 Pxl On 40,80 Else If pattern = "r" Then 38-5*2→yl 38+5*2→yh 80-5*2→xl 80+5*2→xh Pxl On 38,78 Pxl On 36,82 Pxl On 36,80 Pxl On 38,80 Pxl On 40,80 End If While get Key() = 0 © Expand upper-left corner to whole cell For y,yl,yh,2 For x,xl,xh,2 If pxl Test(y,x) Then Pxl On y+1,x Pxl On y+1,x+1 Pxl On y, x+1 Else Pxl Off y+1,x Pxl Off y+1,x+1 Pxl Off y, x+1 End If End For End For © Compute next generation For y,yl,yh,2 For x,xl,xh,2 nt(y-1,x-1) + nt(y-1,x) + nt(y-1,x+2) + nt(y,x-1) + nt(y+1,x+2) + nt(y+2,x-1) + nt(y+2,x+1) + nt(y+2,x+2) → count If count = 3 Then Pxl On y,x Else If count ≠ 2 Then Pxl Off y,x End If End For End For End While © Restore changed options set Graph("Axes", save[1]) set Graph("Grid", save[2]) set Graph("Labels", save[3])End Prgm Also see Conway's Game of Life/C Considering that the simplest implementation in C++ would lack any use of the object-oriented paradigm, this code was specifically written to demonstrate the various object-oriented features of C++.

;0 for indirect ldx # ;addressing stx randloop: lda $fe ;generate random and #

randfill: stx $01 ;$200 for indirect ldx #$02 ;addressing stx $02randloop: lda $fe ;generate random and #$01 ;pixels on the sta ($01), Y ;screen jsr inc0103 cmp #$00 bne randloop lda $02 cmp #$06 bne randloop clearmem: lda #$df ;set $07df-$0a20 sta $01 ;to $#00 lda #$07 sta $02clearbyte: lda #$00 sta ($01), Y jsr inc0103 cmp #$20 bne clearbyte lda $02 cmp #$0a bne clearbyte starttick:copyscreen: lda #$00 ;set up source sta $01 ;pointer at sta $03 ;$01/$02 and lda #$02 ;dest pointer sta $02 ;at $03/$04 lda #$08 sta $04 ldy #$00copybyte: lda ($01), Y ;copy pixel to sta ($03), Y ;back buffer jsr inc0103 ;increment pointers cmp #$00 ;check to see bne copybyte ;if we're at $600 lda $02 ;if so, we've cmp #$06 ;copied the bne copybyte ;entire screen conway: lda #$df ;apply conway rules sta $01 ;reset the pointer sta $03 ;to $#01df/$#07df lda #$01 ;($200 - $21) sta $02 ;($800 - $21) lda #$07 sta $04onecell: lda #$00 ;process one cell ldy #$01 ;upper cell clc adc ($03), Y ldy #$41 ;lower cell clc adc ($03), Ychkleft: tax ;check to see lda $01 ;if we're at the and #$1f ;left edge tay txa cpy #$1f beq rightcellsleftcells: ldy #$00 ;upper-left cell clc adc ($03), Y ldy #$20 ;left cell clc adc ($03), Y ldy #$40 ;lower-left cell clc adc ($03), Ychkright: tax ;check to see lda $01 ;if we're at the and #$1f ;right edge tay txa cpy #$1e beq evaluaterightcells: ldy #$02 ;upper-right cell clc adc ($03), Y ldy #$22 ;right cell clc adc ($03), Y ldy #$42 ;lower-right cell clc adc ($03), Yevaluate: ldx #$01 ;evaluate total ldy #$21 ;for current cell cmp #$03 ;3 = alive beq storex ldx #$00 cmp #$02 ;2 = alive if bne storex ;c = alive lda ($03), Y and #$01 taxstorex: txa ;store to screen sta ($01), Y jsr inc0103 ;move to next cellconwayloop: cmp #$e0 ;if not last cell, bne onecell ;process next cell lda $02 cmp #$05 bne onecell jmp starttick ;run next tick inc0103: lda $01 ;increment $01 cmp #$ff ;and $03 as 16-bit bne onlyinc01 ;pointers inc $02 inc $04onlyinc01: inc $01 lda $01 sta $03 rts The solution uses one cell thick border around square Petri dish as uninhabited dire land. Sample output contains 3 generations of the blinker and 5 of the glider: See Conway's Game of Life/ALGOL 68 APL2 (Dialog) Example in one line APL \ 1130 example (very old APL dialect via simulator) APL1130From: APL \ 1130 Samples The following APL \ 1130 code will need APL385 font installed to display correctly. See Download APL TT Font ∇LIFE[⎕]∇[0] NG←LIFE CG; W[1] W←CG+(¯1⊖CG)+(1⊖CG)+(¯1⌽CG)+(1⌽CG)[2] W←W+(1⊖1⌽CG)+(¯1⊖1⌽CG)+(1⊖¯1⌽CG)+(¯1⊖¯1⌽CG)[3] NG←(3=W)+(CG∧4=W) ∇ RP←5 5⍴0 0 0 0 0 0 0 1 1 0 0 1 1 0 0 0 0 1 0 0 RP0 0 0 0 00 0 1 1 00 1 1 0 00 0 1 0 00 0 0 0 0 LIFE RP0 0 0 0 00 1 1 1 00 1 0 0 00 1 1 0 00 0 0 0 0 LIFE LIFE RP0 0 1 0 00 1 1 0 01 0 0 1 00 1 1 0 00 0 0 0 0 .................................................. One interacts with the Game of Life by creating an initial configuration and observing how it evolves. Although you should test your implementation on more complex examples such as the glider in a larger universe, show the action of the blinker (three adjoining cells in a row all alive), over three generations, in a 3 by 3 grid. (1,4)=TRUERETURN'' Count the number of neighbours of the point i,j' (Assume i/j +/- 1 will not fall out of world)'FUNCTION count_neighbours(i%,j%) LOCAL count%,l% count%=0 FOR l%=-1 TO 1 IF world! (i%+l%,j%+1) count%=count%+1 ENDIF NEXT l% IF world! (i%+1,j%) count%=count%+1 ENDIF RETURN count%ENDFUNC'' Update the world one step'PROCEDURE update_world LOCAL i%,j% ' compute neighbour counts and store FOR i%=1 TO 30 FOR j%=1 TO 30 ns%(i%,j%)[email protected]_neighbours(i%,j%) NEXT j% NEXT i% ' update the world cells FOR i%=1 TO 30 FOR j%=1 TO 30 IF world!

||

randfill: stx $01 ;$200 for indirect ldx #$02 ;addressing stx $02randloop: lda $fe ;generate random and #$01 ;pixels on the sta ($01), Y ;screen jsr inc0103 cmp #$00 bne randloop lda $02 cmp #$06 bne randloop clearmem: lda #$df ;set $07df-$0a20 sta $01 ;to $#00 lda #$07 sta $02clearbyte: lda #$00 sta ($01), Y jsr inc0103 cmp #$20 bne clearbyte lda $02 cmp #$0a bne clearbyte starttick:copyscreen: lda #$00 ;set up source sta $01 ;pointer at sta $03 ;$01/$02 and lda #$02 ;dest pointer sta $02 ;at $03/$04 lda #$08 sta $04 ldy #$00copybyte: lda ($01), Y ;copy pixel to sta ($03), Y ;back buffer jsr inc0103 ;increment pointers cmp #$00 ;check to see bne copybyte ;if we're at $600 lda $02 ;if so, we've cmp #$06 ;copied the bne copybyte ;entire screen conway: lda #$df ;apply conway rules sta $01 ;reset the pointer sta $03 ;to $#01df/$#07df lda #$01 ;($200 - $21) sta $02 ;($800 - $21) lda #$07 sta $04onecell: lda #$00 ;process one cell ldy #$01 ;upper cell clc adc ($03), Y ldy #$41 ;lower cell clc adc ($03), Ychkleft: tax ;check to see lda $01 ;if we're at the and #$1f ;left edge tay txa cpy #$1f beq rightcellsleftcells: ldy #$00 ;upper-left cell clc adc ($03), Y ldy #$20 ;left cell clc adc ($03), Y ldy #$40 ;lower-left cell clc adc ($03), Ychkright: tax ;check to see lda $01 ;if we're at the and #$1f ;right edge tay txa cpy #$1e beq evaluaterightcells: ldy #$02 ;upper-right cell clc adc ($03), Y ldy #$22 ;right cell clc adc ($03), Y ldy #$42 ;lower-right cell clc adc ($03), Yevaluate: ldx #$01 ;evaluate total ldy #$21 ;for current cell cmp #$03 ;3 = alive beq storex ldx #$00 cmp #$02 ;2 = alive if bne storex ;c = alive lda ($03), Y and #$01 taxstorex: txa ;store to screen sta ($01), Y jsr inc0103 ;move to next cellconwayloop: cmp #$e0 ;if not last cell, bne onecell ;process next cell lda $02 cmp #$05 bne onecell jmp starttick ;run next tick inc0103: lda $01 ;increment $01 cmp #$ff ;and $03 as 16-bit bne onlyinc01 ;pointers inc $02 inc $04onlyinc01: inc $01 lda $01 sta $03 rts The solution uses one cell thick border around square Petri dish as uninhabited dire land. Sample output contains 3 generations of the blinker and 5 of the glider: See Conway's Game of Life/ALGOL 68 APL2 (Dialog) Example in one line APL \ 1130 example (very old APL dialect via simulator) APL1130From: APL \ 1130 Samples The following APL \ 1130 code will need APL385 font installed to display correctly.

See Download APL TT Font ∇LIFE[⎕]∇[0] NG←LIFE CG; W[1] W←CG+(¯1⊖CG)+(1⊖CG)+(¯1⌽CG)+(1⌽CG)[2] W←W+(1⊖1⌽CG)+(¯1⊖1⌽CG)+(1⊖¯1⌽CG)+(¯1⊖¯1⌽CG)[3] NG←(3=W)+(CG∧4=W) ∇ RP←5 5⍴0 0 0 0 0 0 0 1 1 0 0 1 1 0 0 0 0 1 0 0 RP0 0 0 0 00 0 1 1 00 1 1 0 00 0 1 0 00 0 0 0 0 LIFE RP0 0 0 0 00 1 1 1 00 1 0 0 00 1 1 0 00 0 0 0 0 LIFE LIFE RP0 0 1 0 00 1 1 0 01 0 0 1 00 1 1 0 00 0 0 0 0 ..................................................

One interacts with the Game of Life by creating an initial configuration and observing how it evolves.

Although you should test your implementation on more complex examples such as the glider in a larger universe, show the action of the blinker (three adjoining cells in a row all alive), over three generations, in a 3 by 3 grid.

(1,4)=TRUERETURN'' Count the number of neighbours of the point i,j' (Assume i/j +/- 1 will not fall out of world)'FUNCTION count_neighbours(i%,j%) LOCAL count%,l% count%=0 FOR l%=-1 TO 1 IF world! (i%+l%,j%+1) count%=count%+1 ENDIF NEXT l% IF world! (i%+1,j%) count%=count%+1 ENDIF RETURN count%ENDFUNC'' Update the world one step'PROCEDURE update_world LOCAL i%,j% ' compute neighbour counts and store FOR i%=1 TO 30 FOR j%=1 TO 30 ns%(i%,j%)[email protected]_neighbours(i%,j%) NEXT j% NEXT i% ' update the world cells FOR i%=1 TO 30 FOR j%=1 TO 30 IF world!

Thus, while it is somewhat verbose, it fully simulates Conway's Game of Life and is relatively simple to expand to feature different starting shapes.

Define life(pattern) = Prgm Local x,y,nt,count,save,xl,yl,xh,yh Define nt(y,x) = when(pxl Test(y,x), 1, 0) {}→save set Graph("Axes", "Off")→save[1] set Graph("Grid", "Off")→save[2] set Graph("Labels", "Off")→save[3] Fn Off Plot Off Clr Draw If pattern = "blinker" Then 36→yl 40→yh 78→xl 82→xh Pxl On 36,80 Pxl On 38,80 Pxl On 40,80 Else If pattern = "glider" Then 30→yl 40→yh 76→xl 88→xh Pxl On 38,76 Pxl On 36,78 Pxl On 36,80 Pxl On 38,80 Pxl On 40,80 Else If pattern = "r" Then 38-5*2→yl 38+5*2→yh 80-5*2→xl 80+5*2→xh Pxl On 38,78 Pxl On 36,82 Pxl On 36,80 Pxl On 38,80 Pxl On 40,80 End If While get Key() = 0 © Expand upper-left corner to whole cell For y,yl,yh,2 For x,xl,xh,2 If pxl Test(y,x) Then Pxl On y+1,x Pxl On y+1,x+1 Pxl On y, x+1 Else Pxl Off y+1,x Pxl Off y+1,x+1 Pxl Off y, x+1 End If End For End For © Compute next generation For y,yl,yh,2 For x,xl,xh,2 nt(y-1,x-1) + nt(y-1,x) + nt(y-1,x+2) + nt(y,x-1) + nt(y+1,x+2) + nt(y+2,x-1) + nt(y+2,x+1) + nt(y+2,x+2) → count If count = 3 Then Pxl On y,x Else If count ≠ 2 Then Pxl Off y,x End If End For End For End While © Restore changed options set Graph("Axes", save[1]) set Graph("Grid", save[2]) set Graph("Labels", save[3])End Prgm Also see Conway's Game of Life/C Considering that the simplest implementation in C++ would lack any use of the object-oriented paradigm, this code was specifically written to demonstrate the various object-oriented features of C++.

;pixels on the sta (

randfill: stx $01 ;$200 for indirect ldx #$02 ;addressing stx $02randloop: lda $fe ;generate random and #$01 ;pixels on the sta ($01), Y ;screen jsr inc0103 cmp #$00 bne randloop lda $02 cmp #$06 bne randloop clearmem: lda #$df ;set $07df-$0a20 sta $01 ;to $#00 lda #$07 sta $02clearbyte: lda #$00 sta ($01), Y jsr inc0103 cmp #$20 bne clearbyte lda $02 cmp #$0a bne clearbyte starttick:copyscreen: lda #$00 ;set up source sta $01 ;pointer at sta $03 ;$01/$02 and lda #$02 ;dest pointer sta $02 ;at $03/$04 lda #$08 sta $04 ldy #$00copybyte: lda ($01), Y ;copy pixel to sta ($03), Y ;back buffer jsr inc0103 ;increment pointers cmp #$00 ;check to see bne copybyte ;if we're at $600 lda $02 ;if so, we've cmp #$06 ;copied the bne copybyte ;entire screen conway: lda #$df ;apply conway rules sta $01 ;reset the pointer sta $03 ;to $#01df/$#07df lda #$01 ;($200 - $21) sta $02 ;($800 - $21) lda #$07 sta $04onecell: lda #$00 ;process one cell ldy #$01 ;upper cell clc adc ($03), Y ldy #$41 ;lower cell clc adc ($03), Ychkleft: tax ;check to see lda $01 ;if we're at the and #$1f ;left edge tay txa cpy #$1f beq rightcellsleftcells: ldy #$00 ;upper-left cell clc adc ($03), Y ldy #$20 ;left cell clc adc ($03), Y ldy #$40 ;lower-left cell clc adc ($03), Ychkright: tax ;check to see lda $01 ;if we're at the and #$1f ;right edge tay txa cpy #$1e beq evaluaterightcells: ldy #$02 ;upper-right cell clc adc ($03), Y ldy #$22 ;right cell clc adc ($03), Y ldy #$42 ;lower-right cell clc adc ($03), Yevaluate: ldx #$01 ;evaluate total ldy #$21 ;for current cell cmp #$03 ;3 = alive beq storex ldx #$00 cmp #$02 ;2 = alive if bne storex ;c = alive lda ($03), Y and #$01 taxstorex: txa ;store to screen sta ($01), Y jsr inc0103 ;move to next cellconwayloop: cmp #$e0 ;if not last cell, bne onecell ;process next cell lda $02 cmp #$05 bne onecell jmp starttick ;run next tick inc0103: lda $01 ;increment $01 cmp #$ff ;and $03 as 16-bit bne onlyinc01 ;pointers inc $02 inc $04onlyinc01: inc $01 lda $01 sta $03 rts The solution uses one cell thick border around square Petri dish as uninhabited dire land. Sample output contains 3 generations of the blinker and 5 of the glider: See Conway's Game of Life/ALGOL 68 APL2 (Dialog) Example in one line APL \ 1130 example (very old APL dialect via simulator) APL1130From: APL \ 1130 Samples The following APL \ 1130 code will need APL385 font installed to display correctly. See Download APL TT Font ∇LIFE[⎕]∇[0] NG←LIFE CG; W[1] W←CG+(¯1⊖CG)+(1⊖CG)+(¯1⌽CG)+(1⌽CG)[2] W←W+(1⊖1⌽CG)+(¯1⊖1⌽CG)+(1⊖¯1⌽CG)+(¯1⊖¯1⌽CG)[3] NG←(3=W)+(CG∧4=W) ∇ RP←5 5⍴0 0 0 0 0 0 0 1 1 0 0 1 1 0 0 0 0 1 0 0 RP0 0 0 0 00 0 1 1 00 1 1 0 00 0 1 0 00 0 0 0 0 LIFE RP0 0 0 0 00 1 1 1 00 1 0 0 00 1 1 0 00 0 0 0 0 LIFE LIFE RP0 0 1 0 00 1 1 0 01 0 0 1 00 1 1 0 00 0 0 0 0 .................................................. One interacts with the Game of Life by creating an initial configuration and observing how it evolves. Although you should test your implementation on more complex examples such as the glider in a larger universe, show the action of the blinker (three adjoining cells in a row all alive), over three generations, in a 3 by 3 grid. (1,4)=TRUERETURN'' Count the number of neighbours of the point i,j' (Assume i/j +/- 1 will not fall out of world)'FUNCTION count_neighbours(i%,j%) LOCAL count%,l% count%=0 FOR l%=-1 TO 1 IF world! (i%+l%,j%+1) count%=count%+1 ENDIF NEXT l% IF world! (i%+1,j%) count%=count%+1 ENDIF RETURN count%ENDFUNC'' Update the world one step'PROCEDURE update_world LOCAL i%,j% ' compute neighbour counts and store FOR i%=1 TO 30 FOR j%=1 TO 30 ns%(i%,j%)[email protected]_neighbours(i%,j%) NEXT j% NEXT i% ' update the world cells FOR i%=1 TO 30 FOR j%=1 TO 30 IF world!

||

randfill: stx $01 ;$200 for indirect ldx #$02 ;addressing stx $02randloop: lda $fe ;generate random and #$01 ;pixels on the sta ($01), Y ;screen jsr inc0103 cmp #$00 bne randloop lda $02 cmp #$06 bne randloop clearmem: lda #$df ;set $07df-$0a20 sta $01 ;to $#00 lda #$07 sta $02clearbyte: lda #$00 sta ($01), Y jsr inc0103 cmp #$20 bne clearbyte lda $02 cmp #$0a bne clearbyte starttick:copyscreen: lda #$00 ;set up source sta $01 ;pointer at sta $03 ;$01/$02 and lda #$02 ;dest pointer sta $02 ;at $03/$04 lda #$08 sta $04 ldy #$00copybyte: lda ($01), Y ;copy pixel to sta ($03), Y ;back buffer jsr inc0103 ;increment pointers cmp #$00 ;check to see bne copybyte ;if we're at $600 lda $02 ;if so, we've cmp #$06 ;copied the bne copybyte ;entire screen conway: lda #$df ;apply conway rules sta $01 ;reset the pointer sta $03 ;to $#01df/$#07df lda #$01 ;($200 - $21) sta $02 ;($800 - $21) lda #$07 sta $04onecell: lda #$00 ;process one cell ldy #$01 ;upper cell clc adc ($03), Y ldy #$41 ;lower cell clc adc ($03), Ychkleft: tax ;check to see lda $01 ;if we're at the and #$1f ;left edge tay txa cpy #$1f beq rightcellsleftcells: ldy #$00 ;upper-left cell clc adc ($03), Y ldy #$20 ;left cell clc adc ($03), Y ldy #$40 ;lower-left cell clc adc ($03), Ychkright: tax ;check to see lda $01 ;if we're at the and #$1f ;right edge tay txa cpy #$1e beq evaluaterightcells: ldy #$02 ;upper-right cell clc adc ($03), Y ldy #$22 ;right cell clc adc ($03), Y ldy #$42 ;lower-right cell clc adc ($03), Yevaluate: ldx #$01 ;evaluate total ldy #$21 ;for current cell cmp #$03 ;3 = alive beq storex ldx #$00 cmp #$02 ;2 = alive if bne storex ;c = alive lda ($03), Y and #$01 taxstorex: txa ;store to screen sta ($01), Y jsr inc0103 ;move to next cellconwayloop: cmp #$e0 ;if not last cell, bne onecell ;process next cell lda $02 cmp #$05 bne onecell jmp starttick ;run next tick inc0103: lda $01 ;increment $01 cmp #$ff ;and $03 as 16-bit bne onlyinc01 ;pointers inc $02 inc $04onlyinc01: inc $01 lda $01 sta $03 rts The solution uses one cell thick border around square Petri dish as uninhabited dire land. Sample output contains 3 generations of the blinker and 5 of the glider: See Conway's Game of Life/ALGOL 68 APL2 (Dialog) Example in one line APL \ 1130 example (very old APL dialect via simulator) APL1130From: APL \ 1130 Samples The following APL \ 1130 code will need APL385 font installed to display correctly.

See Download APL TT Font ∇LIFE[⎕]∇[0] NG←LIFE CG; W[1] W←CG+(¯1⊖CG)+(1⊖CG)+(¯1⌽CG)+(1⌽CG)[2] W←W+(1⊖1⌽CG)+(¯1⊖1⌽CG)+(1⊖¯1⌽CG)+(¯1⊖¯1⌽CG)[3] NG←(3=W)+(CG∧4=W) ∇ RP←5 5⍴0 0 0 0 0 0 0 1 1 0 0 1 1 0 0 0 0 1 0 0 RP0 0 0 0 00 0 1 1 00 1 1 0 00 0 1 0 00 0 0 0 0 LIFE RP0 0 0 0 00 1 1 1 00 1 0 0 00 1 1 0 00 0 0 0 0 LIFE LIFE RP0 0 1 0 00 1 1 0 01 0 0 1 00 1 1 0 00 0 0 0 0 ..................................................

One interacts with the Game of Life by creating an initial configuration and observing how it evolves.

Although you should test your implementation on more complex examples such as the glider in a larger universe, show the action of the blinker (three adjoining cells in a row all alive), over three generations, in a 3 by 3 grid.

(1,4)=TRUERETURN'' Count the number of neighbours of the point i,j' (Assume i/j +/- 1 will not fall out of world)'FUNCTION count_neighbours(i%,j%) LOCAL count%,l% count%=0 FOR l%=-1 TO 1 IF world! (i%+l%,j%+1) count%=count%+1 ENDIF NEXT l% IF world! (i%+1,j%) count%=count%+1 ENDIF RETURN count%ENDFUNC'' Update the world one step'PROCEDURE update_world LOCAL i%,j% ' compute neighbour counts and store FOR i%=1 TO 30 FOR j%=1 TO 30 ns%(i%,j%)[email protected]_neighbours(i%,j%) NEXT j% NEXT i% ' update the world cells FOR i%=1 TO 30 FOR j%=1 TO 30 IF world!

Thus, while it is somewhat verbose, it fully simulates Conway's Game of Life and is relatively simple to expand to feature different starting shapes.

Define life(pattern) = Prgm Local x,y,nt,count,save,xl,yl,xh,yh Define nt(y,x) = when(pxl Test(y,x), 1, 0) {}→save set Graph("Axes", "Off")→save[1] set Graph("Grid", "Off")→save[2] set Graph("Labels", "Off")→save[3] Fn Off Plot Off Clr Draw If pattern = "blinker" Then 36→yl 40→yh 78→xl 82→xh Pxl On 36,80 Pxl On 38,80 Pxl On 40,80 Else If pattern = "glider" Then 30→yl 40→yh 76→xl 88→xh Pxl On 38,76 Pxl On 36,78 Pxl On 36,80 Pxl On 38,80 Pxl On 40,80 Else If pattern = "r" Then 38-5*2→yl 38+5*2→yh 80-5*2→xl 80+5*2→xh Pxl On 38,78 Pxl On 36,82 Pxl On 36,80 Pxl On 38,80 Pxl On 40,80 End If While get Key() = 0 © Expand upper-left corner to whole cell For y,yl,yh,2 For x,xl,xh,2 If pxl Test(y,x) Then Pxl On y+1,x Pxl On y+1,x+1 Pxl On y, x+1 Else Pxl Off y+1,x Pxl Off y+1,x+1 Pxl Off y, x+1 End If End For End For © Compute next generation For y,yl,yh,2 For x,xl,xh,2 nt(y-1,x-1) + nt(y-1,x) + nt(y-1,x+2) + nt(y,x-1) + nt(y+1,x+2) + nt(y+2,x-1) + nt(y+2,x+1) + nt(y+2,x+2) → count If count = 3 Then Pxl On y,x Else If count ≠ 2 Then Pxl Off y,x End If End For End For End While © Restore changed options set Graph("Axes", save[1]) set Graph("Grid", save[2]) set Graph("Labels", save[3])End Prgm Also see Conway's Game of Life/C Considering that the simplest implementation in C++ would lack any use of the object-oriented paradigm, this code was specifically written to demonstrate the various object-oriented features of C++.

), Y ;screen jsr inc0103 cmp #

randfill: stx

randfill: stx $01 ;$200 for indirect ldx #$02 ;addressing stx $02randloop: lda $fe ;generate random and #$01 ;pixels on the sta ($01), Y ;screen jsr inc0103 cmp #$00 bne randloop lda $02 cmp #$06 bne randloop clearmem: lda #$df ;set $07df-$0a20 sta $01 ;to $#00 lda #$07 sta $02clearbyte: lda #$00 sta ($01), Y jsr inc0103 cmp #$20 bne clearbyte lda $02 cmp #$0a bne clearbyte starttick:copyscreen: lda #$00 ;set up source sta $01 ;pointer at sta $03 ;$01/$02 and lda #$02 ;dest pointer sta $02 ;at $03/$04 lda #$08 sta $04 ldy #$00copybyte: lda ($01), Y ;copy pixel to sta ($03), Y ;back buffer jsr inc0103 ;increment pointers cmp #$00 ;check to see bne copybyte ;if we're at $600 lda $02 ;if so, we've cmp #$06 ;copied the bne copybyte ;entire screen conway: lda #$df ;apply conway rules sta $01 ;reset the pointer sta $03 ;to $#01df/$#07df lda #$01 ;($200 - $21) sta $02 ;($800 - $21) lda #$07 sta $04onecell: lda #$00 ;process one cell ldy #$01 ;upper cell clc adc ($03), Y ldy #$41 ;lower cell clc adc ($03), Ychkleft: tax ;check to see lda $01 ;if we're at the and #$1f ;left edge tay txa cpy #$1f beq rightcellsleftcells: ldy #$00 ;upper-left cell clc adc ($03), Y ldy #$20 ;left cell clc adc ($03), Y ldy #$40 ;lower-left cell clc adc ($03), Ychkright: tax ;check to see lda $01 ;if we're at the and #$1f ;right edge tay txa cpy #$1e beq evaluaterightcells: ldy #$02 ;upper-right cell clc adc ($03), Y ldy #$22 ;right cell clc adc ($03), Y ldy #$42 ;lower-right cell clc adc ($03), Yevaluate: ldx #$01 ;evaluate total ldy #$21 ;for current cell cmp #$03 ;3 = alive beq storex ldx #$00 cmp #$02 ;2 = alive if bne storex ;c = alive lda ($03), Y and #$01 taxstorex: txa ;store to screen sta ($01), Y jsr inc0103 ;move to next cellconwayloop: cmp #$e0 ;if not last cell, bne onecell ;process next cell lda $02 cmp #$05 bne onecell jmp starttick ;run next tick inc0103: lda $01 ;increment $01 cmp #$ff ;and $03 as 16-bit bne onlyinc01 ;pointers inc $02 inc $04onlyinc01: inc $01 lda $01 sta $03 rts The solution uses one cell thick border around square Petri dish as uninhabited dire land. Sample output contains 3 generations of the blinker and 5 of the glider: See Conway's Game of Life/ALGOL 68 APL2 (Dialog) Example in one line APL \ 1130 example (very old APL dialect via simulator) APL1130From: APL \ 1130 Samples The following APL \ 1130 code will need APL385 font installed to display correctly. See Download APL TT Font ∇LIFE[⎕]∇[0] NG←LIFE CG; W[1] W←CG+(¯1⊖CG)+(1⊖CG)+(¯1⌽CG)+(1⌽CG)[2] W←W+(1⊖1⌽CG)+(¯1⊖1⌽CG)+(1⊖¯1⌽CG)+(¯1⊖¯1⌽CG)[3] NG←(3=W)+(CG∧4=W) ∇ RP←5 5⍴0 0 0 0 0 0 0 1 1 0 0 1 1 0 0 0 0 1 0 0 RP0 0 0 0 00 0 1 1 00 1 1 0 00 0 1 0 00 0 0 0 0 LIFE RP0 0 0 0 00 1 1 1 00 1 0 0 00 1 1 0 00 0 0 0 0 LIFE LIFE RP0 0 1 0 00 1 1 0 01 0 0 1 00 1 1 0 00 0 0 0 0 .................................................. One interacts with the Game of Life by creating an initial configuration and observing how it evolves. Although you should test your implementation on more complex examples such as the glider in a larger universe, show the action of the blinker (three adjoining cells in a row all alive), over three generations, in a 3 by 3 grid. (1,4)=TRUERETURN'' Count the number of neighbours of the point i,j' (Assume i/j +/- 1 will not fall out of world)'FUNCTION count_neighbours(i%,j%) LOCAL count%,l% count%=0 FOR l%=-1 TO 1 IF world! (i%+l%,j%+1) count%=count%+1 ENDIF NEXT l% IF world! (i%+1,j%) count%=count%+1 ENDIF RETURN count%ENDFUNC'' Update the world one step'PROCEDURE update_world LOCAL i%,j% ' compute neighbour counts and store FOR i%=1 TO 30 FOR j%=1 TO 30 ns%(i%,j%)[email protected]_neighbours(i%,j%) NEXT j% NEXT i% ' update the world cells FOR i%=1 TO 30 FOR j%=1 TO 30 IF world!

||

randfill: stx $01 ;$200 for indirect ldx #$02 ;addressing stx $02randloop: lda $fe ;generate random and #$01 ;pixels on the sta ($01), Y ;screen jsr inc0103 cmp #$00 bne randloop lda $02 cmp #$06 bne randloop clearmem: lda #$df ;set $07df-$0a20 sta $01 ;to $#00 lda #$07 sta $02clearbyte: lda #$00 sta ($01), Y jsr inc0103 cmp #$20 bne clearbyte lda $02 cmp #$0a bne clearbyte starttick:copyscreen: lda #$00 ;set up source sta $01 ;pointer at sta $03 ;$01/$02 and lda #$02 ;dest pointer sta $02 ;at $03/$04 lda #$08 sta $04 ldy #$00copybyte: lda ($01), Y ;copy pixel to sta ($03), Y ;back buffer jsr inc0103 ;increment pointers cmp #$00 ;check to see bne copybyte ;if we're at $600 lda $02 ;if so, we've cmp #$06 ;copied the bne copybyte ;entire screen conway: lda #$df ;apply conway rules sta $01 ;reset the pointer sta $03 ;to $#01df/$#07df lda #$01 ;($200 - $21) sta $02 ;($800 - $21) lda #$07 sta $04onecell: lda #$00 ;process one cell ldy #$01 ;upper cell clc adc ($03), Y ldy #$41 ;lower cell clc adc ($03), Ychkleft: tax ;check to see lda $01 ;if we're at the and #$1f ;left edge tay txa cpy #$1f beq rightcellsleftcells: ldy #$00 ;upper-left cell clc adc ($03), Y ldy #$20 ;left cell clc adc ($03), Y ldy #$40 ;lower-left cell clc adc ($03), Ychkright: tax ;check to see lda $01 ;if we're at the and #$1f ;right edge tay txa cpy #$1e beq evaluaterightcells: ldy #$02 ;upper-right cell clc adc ($03), Y ldy #$22 ;right cell clc adc ($03), Y ldy #$42 ;lower-right cell clc adc ($03), Yevaluate: ldx #$01 ;evaluate total ldy #$21 ;for current cell cmp #$03 ;3 = alive beq storex ldx #$00 cmp #$02 ;2 = alive if bne storex ;c = alive lda ($03), Y and #$01 taxstorex: txa ;store to screen sta ($01), Y jsr inc0103 ;move to next cellconwayloop: cmp #$e0 ;if not last cell, bne onecell ;process next cell lda $02 cmp #$05 bne onecell jmp starttick ;run next tick inc0103: lda $01 ;increment $01 cmp #$ff ;and $03 as 16-bit bne onlyinc01 ;pointers inc $02 inc $04onlyinc01: inc $01 lda $01 sta $03 rts The solution uses one cell thick border around square Petri dish as uninhabited dire land. Sample output contains 3 generations of the blinker and 5 of the glider: See Conway's Game of Life/ALGOL 68 APL2 (Dialog) Example in one line APL \ 1130 example (very old APL dialect via simulator) APL1130From: APL \ 1130 Samples The following APL \ 1130 code will need APL385 font installed to display correctly.

See Download APL TT Font ∇LIFE[⎕]∇[0] NG←LIFE CG; W[1] W←CG+(¯1⊖CG)+(1⊖CG)+(¯1⌽CG)+(1⌽CG)[2] W←W+(1⊖1⌽CG)+(¯1⊖1⌽CG)+(1⊖¯1⌽CG)+(¯1⊖¯1⌽CG)[3] NG←(3=W)+(CG∧4=W) ∇ RP←5 5⍴0 0 0 0 0 0 0 1 1 0 0 1 1 0 0 0 0 1 0 0 RP0 0 0 0 00 0 1 1 00 1 1 0 00 0 1 0 00 0 0 0 0 LIFE RP0 0 0 0 00 1 1 1 00 1 0 0 00 1 1 0 00 0 0 0 0 LIFE LIFE RP0 0 1 0 00 1 1 0 01 0 0 1 00 1 1 0 00 0 0 0 0 ..................................................

One interacts with the Game of Life by creating an initial configuration and observing how it evolves.

Although you should test your implementation on more complex examples such as the glider in a larger universe, show the action of the blinker (three adjoining cells in a row all alive), over three generations, in a 3 by 3 grid.

(1,4)=TRUERETURN'' Count the number of neighbours of the point i,j' (Assume i/j +/- 1 will not fall out of world)'FUNCTION count_neighbours(i%,j%) LOCAL count%,l% count%=0 FOR l%=-1 TO 1 IF world! (i%+l%,j%+1) count%=count%+1 ENDIF NEXT l% IF world! (i%+1,j%) count%=count%+1 ENDIF RETURN count%ENDFUNC'' Update the world one step'PROCEDURE update_world LOCAL i%,j% ' compute neighbour counts and store FOR i%=1 TO 30 FOR j%=1 TO 30 ns%(i%,j%)[email protected]_neighbours(i%,j%) NEXT j% NEXT i% ' update the world cells FOR i%=1 TO 30 FOR j%=1 TO 30 IF world!

Thus, while it is somewhat verbose, it fully simulates Conway's Game of Life and is relatively simple to expand to feature different starting shapes.

Define life(pattern) = Prgm Local x,y,nt,count,save,xl,yl,xh,yh Define nt(y,x) = when(pxl Test(y,x), 1, 0) {}→save set Graph("Axes", "Off")→save[1] set Graph("Grid", "Off")→save[2] set Graph("Labels", "Off")→save[3] Fn Off Plot Off Clr Draw If pattern = "blinker" Then 36→yl 40→yh 78→xl 82→xh Pxl On 36,80 Pxl On 38,80 Pxl On 40,80 Else If pattern = "glider" Then 30→yl 40→yh 76→xl 88→xh Pxl On 38,76 Pxl On 36,78 Pxl On 36,80 Pxl On 38,80 Pxl On 40,80 Else If pattern = "r" Then 38-5*2→yl 38+5*2→yh 80-5*2→xl 80+5*2→xh Pxl On 38,78 Pxl On 36,82 Pxl On 36,80 Pxl On 38,80 Pxl On 40,80 End If While get Key() = 0 © Expand upper-left corner to whole cell For y,yl,yh,2 For x,xl,xh,2 If pxl Test(y,x) Then Pxl On y+1,x Pxl On y+1,x+1 Pxl On y, x+1 Else Pxl Off y+1,x Pxl Off y+1,x+1 Pxl Off y, x+1 End If End For End For © Compute next generation For y,yl,yh,2 For x,xl,xh,2 nt(y-1,x-1) + nt(y-1,x) + nt(y-1,x+2) + nt(y,x-1) + nt(y+1,x+2) + nt(y+2,x-1) + nt(y+2,x+1) + nt(y+2,x+2) → count If count = 3 Then Pxl On y,x Else If count ≠ 2 Then Pxl Off y,x End If End For End For End While © Restore changed options set Graph("Axes", save[1]) set Graph("Grid", save[2]) set Graph("Labels", save[3])End Prgm Also see Conway's Game of Life/C Considering that the simplest implementation in C++ would lack any use of the object-oriented paradigm, this code was specifically written to demonstrate the various object-oriented features of C++.

;0 for indirect ldx # ;addressing stx randloop: lda $fe ;generate random and #

randfill: stx $01 ;$200 for indirect ldx #$02 ;addressing stx $02randloop: lda $fe ;generate random and #$01 ;pixels on the sta ($01), Y ;screen jsr inc0103 cmp #$00 bne randloop lda $02 cmp #$06 bne randloop clearmem: lda #$df ;set $07df-$0a20 sta $01 ;to $#00 lda #$07 sta $02clearbyte: lda #$00 sta ($01), Y jsr inc0103 cmp #$20 bne clearbyte lda $02 cmp #$0a bne clearbyte starttick:copyscreen: lda #$00 ;set up source sta $01 ;pointer at sta $03 ;$01/$02 and lda #$02 ;dest pointer sta $02 ;at $03/$04 lda #$08 sta $04 ldy #$00copybyte: lda ($01), Y ;copy pixel to sta ($03), Y ;back buffer jsr inc0103 ;increment pointers cmp #$00 ;check to see bne copybyte ;if we're at $600 lda $02 ;if so, we've cmp #$06 ;copied the bne copybyte ;entire screen conway: lda #$df ;apply conway rules sta $01 ;reset the pointer sta $03 ;to $#01df/$#07df lda #$01 ;($200 - $21) sta $02 ;($800 - $21) lda #$07 sta $04onecell: lda #$00 ;process one cell ldy #$01 ;upper cell clc adc ($03), Y ldy #$41 ;lower cell clc adc ($03), Ychkleft: tax ;check to see lda $01 ;if we're at the and #$1f ;left edge tay txa cpy #$1f beq rightcellsleftcells: ldy #$00 ;upper-left cell clc adc ($03), Y ldy #$20 ;left cell clc adc ($03), Y ldy #$40 ;lower-left cell clc adc ($03), Ychkright: tax ;check to see lda $01 ;if we're at the and #$1f ;right edge tay txa cpy #$1e beq evaluaterightcells: ldy #$02 ;upper-right cell clc adc ($03), Y ldy #$22 ;right cell clc adc ($03), Y ldy #$42 ;lower-right cell clc adc ($03), Yevaluate: ldx #$01 ;evaluate total ldy #$21 ;for current cell cmp #$03 ;3 = alive beq storex ldx #$00 cmp #$02 ;2 = alive if bne storex ;c = alive lda ($03), Y and #$01 taxstorex: txa ;store to screen sta ($01), Y jsr inc0103 ;move to next cellconwayloop: cmp #$e0 ;if not last cell, bne onecell ;process next cell lda $02 cmp #$05 bne onecell jmp starttick ;run next tick inc0103: lda $01 ;increment $01 cmp #$ff ;and $03 as 16-bit bne onlyinc01 ;pointers inc $02 inc $04onlyinc01: inc $01 lda $01 sta $03 rts The solution uses one cell thick border around square Petri dish as uninhabited dire land. Sample output contains 3 generations of the blinker and 5 of the glider: See Conway's Game of Life/ALGOL 68 APL2 (Dialog) Example in one line APL \ 1130 example (very old APL dialect via simulator) APL1130From: APL \ 1130 Samples The following APL \ 1130 code will need APL385 font installed to display correctly. See Download APL TT Font ∇LIFE[⎕]∇[0] NG←LIFE CG; W[1] W←CG+(¯1⊖CG)+(1⊖CG)+(¯1⌽CG)+(1⌽CG)[2] W←W+(1⊖1⌽CG)+(¯1⊖1⌽CG)+(1⊖¯1⌽CG)+(¯1⊖¯1⌽CG)[3] NG←(3=W)+(CG∧4=W) ∇ RP←5 5⍴0 0 0 0 0 0 0 1 1 0 0 1 1 0 0 0 0 1 0 0 RP0 0 0 0 00 0 1 1 00 1 1 0 00 0 1 0 00 0 0 0 0 LIFE RP0 0 0 0 00 1 1 1 00 1 0 0 00 1 1 0 00 0 0 0 0 LIFE LIFE RP0 0 1 0 00 1 1 0 01 0 0 1 00 1 1 0 00 0 0 0 0 .................................................. One interacts with the Game of Life by creating an initial configuration and observing how it evolves. Although you should test your implementation on more complex examples such as the glider in a larger universe, show the action of the blinker (three adjoining cells in a row all alive), over three generations, in a 3 by 3 grid. (1,4)=TRUERETURN'' Count the number of neighbours of the point i,j' (Assume i/j +/- 1 will not fall out of world)'FUNCTION count_neighbours(i%,j%) LOCAL count%,l% count%=0 FOR l%=-1 TO 1 IF world! (i%+l%,j%+1) count%=count%+1 ENDIF NEXT l% IF world! (i%+1,j%) count%=count%+1 ENDIF RETURN count%ENDFUNC'' Update the world one step'PROCEDURE update_world LOCAL i%,j% ' compute neighbour counts and store FOR i%=1 TO 30 FOR j%=1 TO 30 ns%(i%,j%)[email protected]_neighbours(i%,j%) NEXT j% NEXT i% ' update the world cells FOR i%=1 TO 30 FOR j%=1 TO 30 IF world!

||

randfill: stx $01 ;$200 for indirect ldx #$02 ;addressing stx $02randloop: lda $fe ;generate random and #$01 ;pixels on the sta ($01), Y ;screen jsr inc0103 cmp #$00 bne randloop lda $02 cmp #$06 bne randloop clearmem: lda #$df ;set $07df-$0a20 sta $01 ;to $#00 lda #$07 sta $02clearbyte: lda #$00 sta ($01), Y jsr inc0103 cmp #$20 bne clearbyte lda $02 cmp #$0a bne clearbyte starttick:copyscreen: lda #$00 ;set up source sta $01 ;pointer at sta $03 ;$01/$02 and lda #$02 ;dest pointer sta $02 ;at $03/$04 lda #$08 sta $04 ldy #$00copybyte: lda ($01), Y ;copy pixel to sta ($03), Y ;back buffer jsr inc0103 ;increment pointers cmp #$00 ;check to see bne copybyte ;if we're at $600 lda $02 ;if so, we've cmp #$06 ;copied the bne copybyte ;entire screen conway: lda #$df ;apply conway rules sta $01 ;reset the pointer sta $03 ;to $#01df/$#07df lda #$01 ;($200 - $21) sta $02 ;($800 - $21) lda #$07 sta $04onecell: lda #$00 ;process one cell ldy #$01 ;upper cell clc adc ($03), Y ldy #$41 ;lower cell clc adc ($03), Ychkleft: tax ;check to see lda $01 ;if we're at the and #$1f ;left edge tay txa cpy #$1f beq rightcellsleftcells: ldy #$00 ;upper-left cell clc adc ($03), Y ldy #$20 ;left cell clc adc ($03), Y ldy #$40 ;lower-left cell clc adc ($03), Ychkright: tax ;check to see lda $01 ;if we're at the and #$1f ;right edge tay txa cpy #$1e beq evaluaterightcells: ldy #$02 ;upper-right cell clc adc ($03), Y ldy #$22 ;right cell clc adc ($03), Y ldy #$42 ;lower-right cell clc adc ($03), Yevaluate: ldx #$01 ;evaluate total ldy #$21 ;for current cell cmp #$03 ;3 = alive beq storex ldx #$00 cmp #$02 ;2 = alive if bne storex ;c = alive lda ($03), Y and #$01 taxstorex: txa ;store to screen sta ($01), Y jsr inc0103 ;move to next cellconwayloop: cmp #$e0 ;if not last cell, bne onecell ;process next cell lda $02 cmp #$05 bne onecell jmp starttick ;run next tick inc0103: lda $01 ;increment $01 cmp #$ff ;and $03 as 16-bit bne onlyinc01 ;pointers inc $02 inc $04onlyinc01: inc $01 lda $01 sta $03 rts The solution uses one cell thick border around square Petri dish as uninhabited dire land. Sample output contains 3 generations of the blinker and 5 of the glider: See Conway's Game of Life/ALGOL 68 APL2 (Dialog) Example in one line APL \ 1130 example (very old APL dialect via simulator) APL1130From: APL \ 1130 Samples The following APL \ 1130 code will need APL385 font installed to display correctly.

See Download APL TT Font ∇LIFE[⎕]∇[0] NG←LIFE CG; W[1] W←CG+(¯1⊖CG)+(1⊖CG)+(¯1⌽CG)+(1⌽CG)[2] W←W+(1⊖1⌽CG)+(¯1⊖1⌽CG)+(1⊖¯1⌽CG)+(¯1⊖¯1⌽CG)[3] NG←(3=W)+(CG∧4=W) ∇ RP←5 5⍴0 0 0 0 0 0 0 1 1 0 0 1 1 0 0 0 0 1 0 0 RP0 0 0 0 00 0 1 1 00 1 1 0 00 0 1 0 00 0 0 0 0 LIFE RP0 0 0 0 00 1 1 1 00 1 0 0 00 1 1 0 00 0 0 0 0 LIFE LIFE RP0 0 1 0 00 1 1 0 01 0 0 1 00 1 1 0 00 0 0 0 0 ..................................................

One interacts with the Game of Life by creating an initial configuration and observing how it evolves.

Although you should test your implementation on more complex examples such as the glider in a larger universe, show the action of the blinker (three adjoining cells in a row all alive), over three generations, in a 3 by 3 grid.

(1,4)=TRUERETURN'' Count the number of neighbours of the point i,j' (Assume i/j +/- 1 will not fall out of world)'FUNCTION count_neighbours(i%,j%) LOCAL count%,l% count%=0 FOR l%=-1 TO 1 IF world! (i%+l%,j%+1) count%=count%+1 ENDIF NEXT l% IF world! (i%+1,j%) count%=count%+1 ENDIF RETURN count%ENDFUNC'' Update the world one step'PROCEDURE update_world LOCAL i%,j% ' compute neighbour counts and store FOR i%=1 TO 30 FOR j%=1 TO 30 ns%(i%,j%)[email protected]_neighbours(i%,j%) NEXT j% NEXT i% ' update the world cells FOR i%=1 TO 30 FOR j%=1 TO 30 IF world!

Thus, while it is somewhat verbose, it fully simulates Conway's Game of Life and is relatively simple to expand to feature different starting shapes.

Define life(pattern) = Prgm Local x,y,nt,count,save,xl,yl,xh,yh Define nt(y,x) = when(pxl Test(y,x), 1, 0) {}→save set Graph("Axes", "Off")→save[1] set Graph("Grid", "Off")→save[2] set Graph("Labels", "Off")→save[3] Fn Off Plot Off Clr Draw If pattern = "blinker" Then 36→yl 40→yh 78→xl 82→xh Pxl On 36,80 Pxl On 38,80 Pxl On 40,80 Else If pattern = "glider" Then 30→yl 40→yh 76→xl 88→xh Pxl On 38,76 Pxl On 36,78 Pxl On 36,80 Pxl On 38,80 Pxl On 40,80 Else If pattern = "r" Then 38-5*2→yl 38+5*2→yh 80-5*2→xl 80+5*2→xh Pxl On 38,78 Pxl On 36,82 Pxl On 36,80 Pxl On 38,80 Pxl On 40,80 End If While get Key() = 0 © Expand upper-left corner to whole cell For y,yl,yh,2 For x,xl,xh,2 If pxl Test(y,x) Then Pxl On y+1,x Pxl On y+1,x+1 Pxl On y, x+1 Else Pxl Off y+1,x Pxl Off y+1,x+1 Pxl Off y, x+1 End If End For End For © Compute next generation For y,yl,yh,2 For x,xl,xh,2 nt(y-1,x-1) + nt(y-1,x) + nt(y-1,x+2) + nt(y,x-1) + nt(y+1,x+2) + nt(y+2,x-1) + nt(y+2,x+1) + nt(y+2,x+2) → count If count = 3 Then Pxl On y,x Else If count ≠ 2 Then Pxl Off y,x End If End For End For End While © Restore changed options set Graph("Axes", save[1]) set Graph("Grid", save[2]) set Graph("Labels", save[3])End Prgm Also see Conway's Game of Life/C Considering that the simplest implementation in C++ would lack any use of the object-oriented paradigm, this code was specifically written to demonstrate the various object-oriented features of C++.

;pixels on the sta (

randfill: stx $01 ;$200 for indirect ldx #$02 ;addressing stx $02randloop: lda $fe ;generate random and #$01 ;pixels on the sta ($01), Y ;screen jsr inc0103 cmp #$00 bne randloop lda $02 cmp #$06 bne randloop clearmem: lda #$df ;set $07df-$0a20 sta $01 ;to $#00 lda #$07 sta $02clearbyte: lda #$00 sta ($01), Y jsr inc0103 cmp #$20 bne clearbyte lda $02 cmp #$0a bne clearbyte starttick:copyscreen: lda #$00 ;set up source sta $01 ;pointer at sta $03 ;$01/$02 and lda #$02 ;dest pointer sta $02 ;at $03/$04 lda #$08 sta $04 ldy #$00copybyte: lda ($01), Y ;copy pixel to sta ($03), Y ;back buffer jsr inc0103 ;increment pointers cmp #$00 ;check to see bne copybyte ;if we're at $600 lda $02 ;if so, we've cmp #$06 ;copied the bne copybyte ;entire screen conway: lda #$df ;apply conway rules sta $01 ;reset the pointer sta $03 ;to $#01df/$#07df lda #$01 ;($200 - $21) sta $02 ;($800 - $21) lda #$07 sta $04onecell: lda #$00 ;process one cell ldy #$01 ;upper cell clc adc ($03), Y ldy #$41 ;lower cell clc adc ($03), Ychkleft: tax ;check to see lda $01 ;if we're at the and #$1f ;left edge tay txa cpy #$1f beq rightcellsleftcells: ldy #$00 ;upper-left cell clc adc ($03), Y ldy #$20 ;left cell clc adc ($03), Y ldy #$40 ;lower-left cell clc adc ($03), Ychkright: tax ;check to see lda $01 ;if we're at the and #$1f ;right edge tay txa cpy #$1e beq evaluaterightcells: ldy #$02 ;upper-right cell clc adc ($03), Y ldy #$22 ;right cell clc adc ($03), Y ldy #$42 ;lower-right cell clc adc ($03), Yevaluate: ldx #$01 ;evaluate total ldy #$21 ;for current cell cmp #$03 ;3 = alive beq storex ldx #$00 cmp #$02 ;2 = alive if bne storex ;c = alive lda ($03), Y and #$01 taxstorex: txa ;store to screen sta ($01), Y jsr inc0103 ;move to next cellconwayloop: cmp #$e0 ;if not last cell, bne onecell ;process next cell lda $02 cmp #$05 bne onecell jmp starttick ;run next tick inc0103: lda $01 ;increment $01 cmp #$ff ;and $03 as 16-bit bne onlyinc01 ;pointers inc $02 inc $04onlyinc01: inc $01 lda $01 sta $03 rts The solution uses one cell thick border around square Petri dish as uninhabited dire land. Sample output contains 3 generations of the blinker and 5 of the glider: See Conway's Game of Life/ALGOL 68 APL2 (Dialog) Example in one line APL \ 1130 example (very old APL dialect via simulator) APL1130From: APL \ 1130 Samples The following APL \ 1130 code will need APL385 font installed to display correctly. See Download APL TT Font ∇LIFE[⎕]∇[0] NG←LIFE CG; W[1] W←CG+(¯1⊖CG)+(1⊖CG)+(¯1⌽CG)+(1⌽CG)[2] W←W+(1⊖1⌽CG)+(¯1⊖1⌽CG)+(1⊖¯1⌽CG)+(¯1⊖¯1⌽CG)[3] NG←(3=W)+(CG∧4=W) ∇ RP←5 5⍴0 0 0 0 0 0 0 1 1 0 0 1 1 0 0 0 0 1 0 0 RP0 0 0 0 00 0 1 1 00 1 1 0 00 0 1 0 00 0 0 0 0 LIFE RP0 0 0 0 00 1 1 1 00 1 0 0 00 1 1 0 00 0 0 0 0 LIFE LIFE RP0 0 1 0 00 1 1 0 01 0 0 1 00 1 1 0 00 0 0 0 0 .................................................. One interacts with the Game of Life by creating an initial configuration and observing how it evolves. Although you should test your implementation on more complex examples such as the glider in a larger universe, show the action of the blinker (three adjoining cells in a row all alive), over three generations, in a 3 by 3 grid. (1,4)=TRUERETURN'' Count the number of neighbours of the point i,j' (Assume i/j +/- 1 will not fall out of world)'FUNCTION count_neighbours(i%,j%) LOCAL count%,l% count%=0 FOR l%=-1 TO 1 IF world! (i%+l%,j%+1) count%=count%+1 ENDIF NEXT l% IF world! (i%+1,j%) count%=count%+1 ENDIF RETURN count%ENDFUNC'' Update the world one step'PROCEDURE update_world LOCAL i%,j% ' compute neighbour counts and store FOR i%=1 TO 30 FOR j%=1 TO 30 ns%(i%,j%)[email protected]_neighbours(i%,j%) NEXT j% NEXT i% ' update the world cells FOR i%=1 TO 30 FOR j%=1 TO 30 IF world!

||

randfill: stx $01 ;$200 for indirect ldx #$02 ;addressing stx $02randloop: lda $fe ;generate random and #$01 ;pixels on the sta ($01), Y ;screen jsr inc0103 cmp #$00 bne randloop lda $02 cmp #$06 bne randloop clearmem: lda #$df ;set $07df-$0a20 sta $01 ;to $#00 lda #$07 sta $02clearbyte: lda #$00 sta ($01), Y jsr inc0103 cmp #$20 bne clearbyte lda $02 cmp #$0a bne clearbyte starttick:copyscreen: lda #$00 ;set up source sta $01 ;pointer at sta $03 ;$01/$02 and lda #$02 ;dest pointer sta $02 ;at $03/$04 lda #$08 sta $04 ldy #$00copybyte: lda ($01), Y ;copy pixel to sta ($03), Y ;back buffer jsr inc0103 ;increment pointers cmp #$00 ;check to see bne copybyte ;if we're at $600 lda $02 ;if so, we've cmp #$06 ;copied the bne copybyte ;entire screen conway: lda #$df ;apply conway rules sta $01 ;reset the pointer sta $03 ;to $#01df/$#07df lda #$01 ;($200 - $21) sta $02 ;($800 - $21) lda #$07 sta $04onecell: lda #$00 ;process one cell ldy #$01 ;upper cell clc adc ($03), Y ldy #$41 ;lower cell clc adc ($03), Ychkleft: tax ;check to see lda $01 ;if we're at the and #$1f ;left edge tay txa cpy #$1f beq rightcellsleftcells: ldy #$00 ;upper-left cell clc adc ($03), Y ldy #$20 ;left cell clc adc ($03), Y ldy #$40 ;lower-left cell clc adc ($03), Ychkright: tax ;check to see lda $01 ;if we're at the and #$1f ;right edge tay txa cpy #$1e beq evaluaterightcells: ldy #$02 ;upper-right cell clc adc ($03), Y ldy #$22 ;right cell clc adc ($03), Y ldy #$42 ;lower-right cell clc adc ($03), Yevaluate: ldx #$01 ;evaluate total ldy #$21 ;for current cell cmp #$03 ;3 = alive beq storex ldx #$00 cmp #$02 ;2 = alive if bne storex ;c = alive lda ($03), Y and #$01 taxstorex: txa ;store to screen sta ($01), Y jsr inc0103 ;move to next cellconwayloop: cmp #$e0 ;if not last cell, bne onecell ;process next cell lda $02 cmp #$05 bne onecell jmp starttick ;run next tick inc0103: lda $01 ;increment $01 cmp #$ff ;and $03 as 16-bit bne onlyinc01 ;pointers inc $02 inc $04onlyinc01: inc $01 lda $01 sta $03 rts The solution uses one cell thick border around square Petri dish as uninhabited dire land. Sample output contains 3 generations of the blinker and 5 of the glider: See Conway's Game of Life/ALGOL 68 APL2 (Dialog) Example in one line APL \ 1130 example (very old APL dialect via simulator) APL1130From: APL \ 1130 Samples The following APL \ 1130 code will need APL385 font installed to display correctly.

See Download APL TT Font ∇LIFE[⎕]∇[0] NG←LIFE CG; W[1] W←CG+(¯1⊖CG)+(1⊖CG)+(¯1⌽CG)+(1⌽CG)[2] W←W+(1⊖1⌽CG)+(¯1⊖1⌽CG)+(1⊖¯1⌽CG)+(¯1⊖¯1⌽CG)[3] NG←(3=W)+(CG∧4=W) ∇ RP←5 5⍴0 0 0 0 0 0 0 1 1 0 0 1 1 0 0 0 0 1 0 0 RP0 0 0 0 00 0 1 1 00 1 1 0 00 0 1 0 00 0 0 0 0 LIFE RP0 0 0 0 00 1 1 1 00 1 0 0 00 1 1 0 00 0 0 0 0 LIFE LIFE RP0 0 1 0 00 1 1 0 01 0 0 1 00 1 1 0 00 0 0 0 0 ..................................................

One interacts with the Game of Life by creating an initial configuration and observing how it evolves.

Although you should test your implementation on more complex examples such as the glider in a larger universe, show the action of the blinker (three adjoining cells in a row all alive), over three generations, in a 3 by 3 grid.

(1,4)=TRUERETURN'' Count the number of neighbours of the point i,j' (Assume i/j +/- 1 will not fall out of world)'FUNCTION count_neighbours(i%,j%) LOCAL count%,l% count%=0 FOR l%=-1 TO 1 IF world! (i%+l%,j%+1) count%=count%+1 ENDIF NEXT l% IF world! (i%+1,j%) count%=count%+1 ENDIF RETURN count%ENDFUNC'' Update the world one step'PROCEDURE update_world LOCAL i%,j% ' compute neighbour counts and store FOR i%=1 TO 30 FOR j%=1 TO 30 ns%(i%,j%)[email protected]_neighbours(i%,j%) NEXT j% NEXT i% ' update the world cells FOR i%=1 TO 30 FOR j%=1 TO 30 IF world!

Thus, while it is somewhat verbose, it fully simulates Conway's Game of Life and is relatively simple to expand to feature different starting shapes.

Define life(pattern) = Prgm Local x,y,nt,count,save,xl,yl,xh,yh Define nt(y,x) = when(pxl Test(y,x), 1, 0) {}→save set Graph("Axes", "Off")→save[1] set Graph("Grid", "Off")→save[2] set Graph("Labels", "Off")→save[3] Fn Off Plot Off Clr Draw If pattern = "blinker" Then 36→yl 40→yh 78→xl 82→xh Pxl On 36,80 Pxl On 38,80 Pxl On 40,80 Else If pattern = "glider" Then 30→yl 40→yh 76→xl 88→xh Pxl On 38,76 Pxl On 36,78 Pxl On 36,80 Pxl On 38,80 Pxl On 40,80 Else If pattern = "r" Then 38-5*2→yl 38+5*2→yh 80-5*2→xl 80+5*2→xh Pxl On 38,78 Pxl On 36,82 Pxl On 36,80 Pxl On 38,80 Pxl On 40,80 End If While get Key() = 0 © Expand upper-left corner to whole cell For y,yl,yh,2 For x,xl,xh,2 If pxl Test(y,x) Then Pxl On y+1,x Pxl On y+1,x+1 Pxl On y, x+1 Else Pxl Off y+1,x Pxl Off y+1,x+1 Pxl Off y, x+1 End If End For End For © Compute next generation For y,yl,yh,2 For x,xl,xh,2 nt(y-1,x-1) + nt(y-1,x) + nt(y-1,x+2) + nt(y,x-1) + nt(y+1,x+2) + nt(y+2,x-1) + nt(y+2,x+1) + nt(y+2,x+2) → count If count = 3 Then Pxl On y,x Else If count ≠ 2 Then Pxl Off y,x End If End For End For End While © Restore changed options set Graph("Axes", save[1]) set Graph("Grid", save[2]) set Graph("Labels", save[3])End Prgm Also see Conway's Game of Life/C Considering that the simplest implementation in C++ would lack any use of the object-oriented paradigm, this code was specifically written to demonstrate the various object-oriented features of C++.

), Y ;screen jsr inc0103 cmp #

randfill: stx

randfill: stx $01 ;$200 for indirect ldx #$02 ;addressing stx $02randloop: lda $fe ;generate random and #$01 ;pixels on the sta ($01), Y ;screen jsr inc0103 cmp #$00 bne randloop lda $02 cmp #$06 bne randloop clearmem: lda #$df ;set $07df-$0a20 sta $01 ;to $#00 lda #$07 sta $02clearbyte: lda #$00 sta ($01), Y jsr inc0103 cmp #$20 bne clearbyte lda $02 cmp #$0a bne clearbyte starttick:copyscreen: lda #$00 ;set up source sta $01 ;pointer at sta $03 ;$01/$02 and lda #$02 ;dest pointer sta $02 ;at $03/$04 lda #$08 sta $04 ldy #$00copybyte: lda ($01), Y ;copy pixel to sta ($03), Y ;back buffer jsr inc0103 ;increment pointers cmp #$00 ;check to see bne copybyte ;if we're at $600 lda $02 ;if so, we've cmp #$06 ;copied the bne copybyte ;entire screen conway: lda #$df ;apply conway rules sta $01 ;reset the pointer sta $03 ;to $#01df/$#07df lda #$01 ;($200 - $21) sta $02 ;($800 - $21) lda #$07 sta $04onecell: lda #$00 ;process one cell ldy #$01 ;upper cell clc adc ($03), Y ldy #$41 ;lower cell clc adc ($03), Ychkleft: tax ;check to see lda $01 ;if we're at the and #$1f ;left edge tay txa cpy #$1f beq rightcellsleftcells: ldy #$00 ;upper-left cell clc adc ($03), Y ldy #$20 ;left cell clc adc ($03), Y ldy #$40 ;lower-left cell clc adc ($03), Ychkright: tax ;check to see lda $01 ;if we're at the and #$1f ;right edge tay txa cpy #$1e beq evaluaterightcells: ldy #$02 ;upper-right cell clc adc ($03), Y ldy #$22 ;right cell clc adc ($03), Y ldy #$42 ;lower-right cell clc adc ($03), Yevaluate: ldx #$01 ;evaluate total ldy #$21 ;for current cell cmp #$03 ;3 = alive beq storex ldx #$00 cmp #$02 ;2 = alive if bne storex ;c = alive lda ($03), Y and #$01 taxstorex: txa ;store to screen sta ($01), Y jsr inc0103 ;move to next cellconwayloop: cmp #$e0 ;if not last cell, bne onecell ;process next cell lda $02 cmp #$05 bne onecell jmp starttick ;run next tick inc0103: lda $01 ;increment $01 cmp #$ff ;and $03 as 16-bit bne onlyinc01 ;pointers inc $02 inc $04onlyinc01: inc $01 lda $01 sta $03 rts The solution uses one cell thick border around square Petri dish as uninhabited dire land. Sample output contains 3 generations of the blinker and 5 of the glider: See Conway's Game of Life/ALGOL 68 APL2 (Dialog) Example in one line APL \ 1130 example (very old APL dialect via simulator) APL1130From: APL \ 1130 Samples The following APL \ 1130 code will need APL385 font installed to display correctly. See Download APL TT Font ∇LIFE[⎕]∇[0] NG←LIFE CG; W[1] W←CG+(¯1⊖CG)+(1⊖CG)+(¯1⌽CG)+(1⌽CG)[2] W←W+(1⊖1⌽CG)+(¯1⊖1⌽CG)+(1⊖¯1⌽CG)+(¯1⊖¯1⌽CG)[3] NG←(3=W)+(CG∧4=W) ∇ RP←5 5⍴0 0 0 0 0 0 0 1 1 0 0 1 1 0 0 0 0 1 0 0 RP0 0 0 0 00 0 1 1 00 1 1 0 00 0 1 0 00 0 0 0 0 LIFE RP0 0 0 0 00 1 1 1 00 1 0 0 00 1 1 0 00 0 0 0 0 LIFE LIFE RP0 0 1 0 00 1 1 0 01 0 0 1 00 1 1 0 00 0 0 0 0 .................................................. One interacts with the Game of Life by creating an initial configuration and observing how it evolves. Although you should test your implementation on more complex examples such as the glider in a larger universe, show the action of the blinker (three adjoining cells in a row all alive), over three generations, in a 3 by 3 grid. (1,4)=TRUERETURN'' Count the number of neighbours of the point i,j' (Assume i/j +/- 1 will not fall out of world)'FUNCTION count_neighbours(i%,j%) LOCAL count%,l% count%=0 FOR l%=-1 TO 1 IF world! (i%+l%,j%+1) count%=count%+1 ENDIF NEXT l% IF world! (i%+1,j%) count%=count%+1 ENDIF RETURN count%ENDFUNC'' Update the world one step'PROCEDURE update_world LOCAL i%,j% ' compute neighbour counts and store FOR i%=1 TO 30 FOR j%=1 TO 30 ns%(i%,j%)[email protected]_neighbours(i%,j%) NEXT j% NEXT i% ' update the world cells FOR i%=1 TO 30 FOR j%=1 TO 30 IF world!

||

randfill: stx $01 ;$200 for indirect ldx #$02 ;addressing stx $02randloop: lda $fe ;generate random and #$01 ;pixels on the sta ($01), Y ;screen jsr inc0103 cmp #$00 bne randloop lda $02 cmp #$06 bne randloop clearmem: lda #$df ;set $07df-$0a20 sta $01 ;to $#00 lda #$07 sta $02clearbyte: lda #$00 sta ($01), Y jsr inc0103 cmp #$20 bne clearbyte lda $02 cmp #$0a bne clearbyte starttick:copyscreen: lda #$00 ;set up source sta $01 ;pointer at sta $03 ;$01/$02 and lda #$02 ;dest pointer sta $02 ;at $03/$04 lda #$08 sta $04 ldy #$00copybyte: lda ($01), Y ;copy pixel to sta ($03), Y ;back buffer jsr inc0103 ;increment pointers cmp #$00 ;check to see bne copybyte ;if we're at $600 lda $02 ;if so, we've cmp #$06 ;copied the bne copybyte ;entire screen conway: lda #$df ;apply conway rules sta $01 ;reset the pointer sta $03 ;to $#01df/$#07df lda #$01 ;($200 - $21) sta $02 ;($800 - $21) lda #$07 sta $04onecell: lda #$00 ;process one cell ldy #$01 ;upper cell clc adc ($03), Y ldy #$41 ;lower cell clc adc ($03), Ychkleft: tax ;check to see lda $01 ;if we're at the and #$1f ;left edge tay txa cpy #$1f beq rightcellsleftcells: ldy #$00 ;upper-left cell clc adc ($03), Y ldy #$20 ;left cell clc adc ($03), Y ldy #$40 ;lower-left cell clc adc ($03), Ychkright: tax ;check to see lda $01 ;if we're at the and #$1f ;right edge tay txa cpy #$1e beq evaluaterightcells: ldy #$02 ;upper-right cell clc adc ($03), Y ldy #$22 ;right cell clc adc ($03), Y ldy #$42 ;lower-right cell clc adc ($03), Yevaluate: ldx #$01 ;evaluate total ldy #$21 ;for current cell cmp #$03 ;3 = alive beq storex ldx #$00 cmp #$02 ;2 = alive if bne storex ;c = alive lda ($03), Y and #$01 taxstorex: txa ;store to screen sta ($01), Y jsr inc0103 ;move to next cellconwayloop: cmp #$e0 ;if not last cell, bne onecell ;process next cell lda $02 cmp #$05 bne onecell jmp starttick ;run next tick inc0103: lda $01 ;increment $01 cmp #$ff ;and $03 as 16-bit bne onlyinc01 ;pointers inc $02 inc $04onlyinc01: inc $01 lda $01 sta $03 rts The solution uses one cell thick border around square Petri dish as uninhabited dire land. Sample output contains 3 generations of the blinker and 5 of the glider: See Conway's Game of Life/ALGOL 68 APL2 (Dialog) Example in one line APL \ 1130 example (very old APL dialect via simulator) APL1130From: APL \ 1130 Samples The following APL \ 1130 code will need APL385 font installed to display correctly.

See Download APL TT Font ∇LIFE[⎕]∇[0] NG←LIFE CG; W[1] W←CG+(¯1⊖CG)+(1⊖CG)+(¯1⌽CG)+(1⌽CG)[2] W←W+(1⊖1⌽CG)+(¯1⊖1⌽CG)+(1⊖¯1⌽CG)+(¯1⊖¯1⌽CG)[3] NG←(3=W)+(CG∧4=W) ∇ RP←5 5⍴0 0 0 0 0 0 0 1 1 0 0 1 1 0 0 0 0 1 0 0 RP0 0 0 0 00 0 1 1 00 1 1 0 00 0 1 0 00 0 0 0 0 LIFE RP0 0 0 0 00 1 1 1 00 1 0 0 00 1 1 0 00 0 0 0 0 LIFE LIFE RP0 0 1 0 00 1 1 0 01 0 0 1 00 1 1 0 00 0 0 0 0 ..................................................

One interacts with the Game of Life by creating an initial configuration and observing how it evolves.

Although you should test your implementation on more complex examples such as the glider in a larger universe, show the action of the blinker (three adjoining cells in a row all alive), over three generations, in a 3 by 3 grid.

(1,4)=TRUERETURN'' Count the number of neighbours of the point i,j' (Assume i/j +/- 1 will not fall out of world)'FUNCTION count_neighbours(i%,j%) LOCAL count%,l% count%=0 FOR l%=-1 TO 1 IF world! (i%+l%,j%+1) count%=count%+1 ENDIF NEXT l% IF world! (i%+1,j%) count%=count%+1 ENDIF RETURN count%ENDFUNC'' Update the world one step'PROCEDURE update_world LOCAL i%,j% ' compute neighbour counts and store FOR i%=1 TO 30 FOR j%=1 TO 30 ns%(i%,j%)[email protected]_neighbours(i%,j%) NEXT j% NEXT i% ' update the world cells FOR i%=1 TO 30 FOR j%=1 TO 30 IF world!

Thus, while it is somewhat verbose, it fully simulates Conway's Game of Life and is relatively simple to expand to feature different starting shapes.

Define life(pattern) = Prgm Local x,y,nt,count,save,xl,yl,xh,yh Define nt(y,x) = when(pxl Test(y,x), 1, 0) {}→save set Graph("Axes", "Off")→save[1] set Graph("Grid", "Off")→save[2] set Graph("Labels", "Off")→save[3] Fn Off Plot Off Clr Draw If pattern = "blinker" Then 36→yl 40→yh 78→xl 82→xh Pxl On 36,80 Pxl On 38,80 Pxl On 40,80 Else If pattern = "glider" Then 30→yl 40→yh 76→xl 88→xh Pxl On 38,76 Pxl On 36,78 Pxl On 36,80 Pxl On 38,80 Pxl On 40,80 Else If pattern = "r" Then 38-5*2→yl 38+5*2→yh 80-5*2→xl 80+5*2→xh Pxl On 38,78 Pxl On 36,82 Pxl On 36,80 Pxl On 38,80 Pxl On 40,80 End If While get Key() = 0 © Expand upper-left corner to whole cell For y,yl,yh,2 For x,xl,xh,2 If pxl Test(y,x) Then Pxl On y+1,x Pxl On y+1,x+1 Pxl On y, x+1 Else Pxl Off y+1,x Pxl Off y+1,x+1 Pxl Off y, x+1 End If End For End For © Compute next generation For y,yl,yh,2 For x,xl,xh,2 nt(y-1,x-1) + nt(y-1,x) + nt(y-1,x+2) + nt(y,x-1) + nt(y+1,x+2) + nt(y+2,x-1) + nt(y+2,x+1) + nt(y+2,x+2) → count If count = 3 Then Pxl On y,x Else If count ≠ 2 Then Pxl Off y,x End If End For End For End While © Restore changed options set Graph("Axes", save[1]) set Graph("Grid", save[2]) set Graph("Labels", save[3])End Prgm Also see Conway's Game of Life/C Considering that the simplest implementation in C++ would lack any use of the object-oriented paradigm, this code was specifically written to demonstrate the various object-oriented features of C++.

;0 for indirect ldx # ;addressing stx randloop: lda $fe ;generate random and #

randfill: stx $01 ;$200 for indirect ldx #$02 ;addressing stx $02randloop: lda $fe ;generate random and #$01 ;pixels on the sta ($01), Y ;screen jsr inc0103 cmp #$00 bne randloop lda $02 cmp #$06 bne randloop clearmem: lda #$df ;set $07df-$0a20 sta $01 ;to $#00 lda #$07 sta $02clearbyte: lda #$00 sta ($01), Y jsr inc0103 cmp #$20 bne clearbyte lda $02 cmp #$0a bne clearbyte starttick:copyscreen: lda #$00 ;set up source sta $01 ;pointer at sta $03 ;$01/$02 and lda #$02 ;dest pointer sta $02 ;at $03/$04 lda #$08 sta $04 ldy #$00copybyte: lda ($01), Y ;copy pixel to sta ($03), Y ;back buffer jsr inc0103 ;increment pointers cmp #$00 ;check to see bne copybyte ;if we're at $600 lda $02 ;if so, we've cmp #$06 ;copied the bne copybyte ;entire screen conway: lda #$df ;apply conway rules sta $01 ;reset the pointer sta $03 ;to $#01df/$#07df lda #$01 ;($200 - $21) sta $02 ;($800 - $21) lda #$07 sta $04onecell: lda #$00 ;process one cell ldy #$01 ;upper cell clc adc ($03), Y ldy #$41 ;lower cell clc adc ($03), Ychkleft: tax ;check to see lda $01 ;if we're at the and #$1f ;left edge tay txa cpy #$1f beq rightcellsleftcells: ldy #$00 ;upper-left cell clc adc ($03), Y ldy #$20 ;left cell clc adc ($03), Y ldy #$40 ;lower-left cell clc adc ($03), Ychkright: tax ;check to see lda $01 ;if we're at the and #$1f ;right edge tay txa cpy #$1e beq evaluaterightcells: ldy #$02 ;upper-right cell clc adc ($03), Y ldy #$22 ;right cell clc adc ($03), Y ldy #$42 ;lower-right cell clc adc ($03), Yevaluate: ldx #$01 ;evaluate total ldy #$21 ;for current cell cmp #$03 ;3 = alive beq storex ldx #$00 cmp #$02 ;2 = alive if bne storex ;c = alive lda ($03), Y and #$01 taxstorex: txa ;store to screen sta ($01), Y jsr inc0103 ;move to next cellconwayloop: cmp #$e0 ;if not last cell, bne onecell ;process next cell lda $02 cmp #$05 bne onecell jmp starttick ;run next tick inc0103: lda $01 ;increment $01 cmp #$ff ;and $03 as 16-bit bne onlyinc01 ;pointers inc $02 inc $04onlyinc01: inc $01 lda $01 sta $03 rts The solution uses one cell thick border around square Petri dish as uninhabited dire land. Sample output contains 3 generations of the blinker and 5 of the glider: See Conway's Game of Life/ALGOL 68 APL2 (Dialog) Example in one line APL \ 1130 example (very old APL dialect via simulator) APL1130From: APL \ 1130 Samples The following APL \ 1130 code will need APL385 font installed to display correctly. See Download APL TT Font ∇LIFE[⎕]∇[0] NG←LIFE CG; W[1] W←CG+(¯1⊖CG)+(1⊖CG)+(¯1⌽CG)+(1⌽CG)[2] W←W+(1⊖1⌽CG)+(¯1⊖1⌽CG)+(1⊖¯1⌽CG)+(¯1⊖¯1⌽CG)[3] NG←(3=W)+(CG∧4=W) ∇ RP←5 5⍴0 0 0 0 0 0 0 1 1 0 0 1 1 0 0 0 0 1 0 0 RP0 0 0 0 00 0 1 1 00 1 1 0 00 0 1 0 00 0 0 0 0 LIFE RP0 0 0 0 00 1 1 1 00 1 0 0 00 1 1 0 00 0 0 0 0 LIFE LIFE RP0 0 1 0 00 1 1 0 01 0 0 1 00 1 1 0 00 0 0 0 0 .................................................. One interacts with the Game of Life by creating an initial configuration and observing how it evolves. Although you should test your implementation on more complex examples such as the glider in a larger universe, show the action of the blinker (three adjoining cells in a row all alive), over three generations, in a 3 by 3 grid. (1,4)=TRUERETURN'' Count the number of neighbours of the point i,j' (Assume i/j +/- 1 will not fall out of world)'FUNCTION count_neighbours(i%,j%) LOCAL count%,l% count%=0 FOR l%=-1 TO 1 IF world! (i%+l%,j%+1) count%=count%+1 ENDIF NEXT l% IF world! (i%+1,j%) count%=count%+1 ENDIF RETURN count%ENDFUNC'' Update the world one step'PROCEDURE update_world LOCAL i%,j% ' compute neighbour counts and store FOR i%=1 TO 30 FOR j%=1 TO 30 ns%(i%,j%)[email protected]_neighbours(i%,j%) NEXT j% NEXT i% ' update the world cells FOR i%=1 TO 30 FOR j%=1 TO 30 IF world!

||

randfill: stx $01 ;$200 for indirect ldx #$02 ;addressing stx $02randloop: lda $fe ;generate random and #$01 ;pixels on the sta ($01), Y ;screen jsr inc0103 cmp #$00 bne randloop lda $02 cmp #$06 bne randloop clearmem: lda #$df ;set $07df-$0a20 sta $01 ;to $#00 lda #$07 sta $02clearbyte: lda #$00 sta ($01), Y jsr inc0103 cmp #$20 bne clearbyte lda $02 cmp #$0a bne clearbyte starttick:copyscreen: lda #$00 ;set up source sta $01 ;pointer at sta $03 ;$01/$02 and lda #$02 ;dest pointer sta $02 ;at $03/$04 lda #$08 sta $04 ldy #$00copybyte: lda ($01), Y ;copy pixel to sta ($03), Y ;back buffer jsr inc0103 ;increment pointers cmp #$00 ;check to see bne copybyte ;if we're at $600 lda $02 ;if so, we've cmp #$06 ;copied the bne copybyte ;entire screen conway: lda #$df ;apply conway rules sta $01 ;reset the pointer sta $03 ;to $#01df/$#07df lda #$01 ;($200 - $21) sta $02 ;($800 - $21) lda #$07 sta $04onecell: lda #$00 ;process one cell ldy #$01 ;upper cell clc adc ($03), Y ldy #$41 ;lower cell clc adc ($03), Ychkleft: tax ;check to see lda $01 ;if we're at the and #$1f ;left edge tay txa cpy #$1f beq rightcellsleftcells: ldy #$00 ;upper-left cell clc adc ($03), Y ldy #$20 ;left cell clc adc ($03), Y ldy #$40 ;lower-left cell clc adc ($03), Ychkright: tax ;check to see lda $01 ;if we're at the and #$1f ;right edge tay txa cpy #$1e beq evaluaterightcells: ldy #$02 ;upper-right cell clc adc ($03), Y ldy #$22 ;right cell clc adc ($03), Y ldy #$42 ;lower-right cell clc adc ($03), Yevaluate: ldx #$01 ;evaluate total ldy #$21 ;for current cell cmp #$03 ;3 = alive beq storex ldx #$00 cmp #$02 ;2 = alive if bne storex ;c = alive lda ($03), Y and #$01 taxstorex: txa ;store to screen sta ($01), Y jsr inc0103 ;move to next cellconwayloop: cmp #$e0 ;if not last cell, bne onecell ;process next cell lda $02 cmp #$05 bne onecell jmp starttick ;run next tick inc0103: lda $01 ;increment $01 cmp #$ff ;and $03 as 16-bit bne onlyinc01 ;pointers inc $02 inc $04onlyinc01: inc $01 lda $01 sta $03 rts The solution uses one cell thick border around square Petri dish as uninhabited dire land. Sample output contains 3 generations of the blinker and 5 of the glider: See Conway's Game of Life/ALGOL 68 APL2 (Dialog) Example in one line APL \ 1130 example (very old APL dialect via simulator) APL1130From: APL \ 1130 Samples The following APL \ 1130 code will need APL385 font installed to display correctly.

See Download APL TT Font ∇LIFE[⎕]∇[0] NG←LIFE CG; W[1] W←CG+(¯1⊖CG)+(1⊖CG)+(¯1⌽CG)+(1⌽CG)[2] W←W+(1⊖1⌽CG)+(¯1⊖1⌽CG)+(1⊖¯1⌽CG)+(¯1⊖¯1⌽CG)[3] NG←(3=W)+(CG∧4=W) ∇ RP←5 5⍴0 0 0 0 0 0 0 1 1 0 0 1 1 0 0 0 0 1 0 0 RP0 0 0 0 00 0 1 1 00 1 1 0 00 0 1 0 00 0 0 0 0 LIFE RP0 0 0 0 00 1 1 1 00 1 0 0 00 1 1 0 00 0 0 0 0 LIFE LIFE RP0 0 1 0 00 1 1 0 01 0 0 1 00 1 1 0 00 0 0 0 0 ..................................................

One interacts with the Game of Life by creating an initial configuration and observing how it evolves.

Although you should test your implementation on more complex examples such as the glider in a larger universe, show the action of the blinker (three adjoining cells in a row all alive), over three generations, in a 3 by 3 grid.

(1,4)=TRUERETURN'' Count the number of neighbours of the point i,j' (Assume i/j +/- 1 will not fall out of world)'FUNCTION count_neighbours(i%,j%) LOCAL count%,l% count%=0 FOR l%=-1 TO 1 IF world! (i%+l%,j%+1) count%=count%+1 ENDIF NEXT l% IF world! (i%+1,j%) count%=count%+1 ENDIF RETURN count%ENDFUNC'' Update the world one step'PROCEDURE update_world LOCAL i%,j% ' compute neighbour counts and store FOR i%=1 TO 30 FOR j%=1 TO 30 ns%(i%,j%)[email protected]_neighbours(i%,j%) NEXT j% NEXT i% ' update the world cells FOR i%=1 TO 30 FOR j%=1 TO 30 IF world!

Thus, while it is somewhat verbose, it fully simulates Conway's Game of Life and is relatively simple to expand to feature different starting shapes.

Define life(pattern) = Prgm Local x,y,nt,count,save,xl,yl,xh,yh Define nt(y,x) = when(pxl Test(y,x), 1, 0) {}→save set Graph("Axes", "Off")→save[1] set Graph("Grid", "Off")→save[2] set Graph("Labels", "Off")→save[3] Fn Off Plot Off Clr Draw If pattern = "blinker" Then 36→yl 40→yh 78→xl 82→xh Pxl On 36,80 Pxl On 38,80 Pxl On 40,80 Else If pattern = "glider" Then 30→yl 40→yh 76→xl 88→xh Pxl On 38,76 Pxl On 36,78 Pxl On 36,80 Pxl On 38,80 Pxl On 40,80 Else If pattern = "r" Then 38-5*2→yl 38+5*2→yh 80-5*2→xl 80+5*2→xh Pxl On 38,78 Pxl On 36,82 Pxl On 36,80 Pxl On 38,80 Pxl On 40,80 End If While get Key() = 0 © Expand upper-left corner to whole cell For y,yl,yh,2 For x,xl,xh,2 If pxl Test(y,x) Then Pxl On y+1,x Pxl On y+1,x+1 Pxl On y, x+1 Else Pxl Off y+1,x Pxl Off y+1,x+1 Pxl Off y, x+1 End If End For End For © Compute next generation For y,yl,yh,2 For x,xl,xh,2 nt(y-1,x-1) + nt(y-1,x) + nt(y-1,x+2) + nt(y,x-1) + nt(y+1,x+2) + nt(y+2,x-1) + nt(y+2,x+1) + nt(y+2,x+2) → count If count = 3 Then Pxl On y,x Else If count ≠ 2 Then Pxl Off y,x End If End For End For End While © Restore changed options set Graph("Axes", save[1]) set Graph("Grid", save[2]) set Graph("Labels", save[3])End Prgm Also see Conway's Game of Life/C Considering that the simplest implementation in C++ would lack any use of the object-oriented paradigm, this code was specifically written to demonstrate the various object-oriented features of C++.

;pixels on the sta (

randfill: stx $01 ;$200 for indirect ldx #$02 ;addressing stx $02randloop: lda $fe ;generate random and #$01 ;pixels on the sta ($01), Y ;screen jsr inc0103 cmp #$00 bne randloop lda $02 cmp #$06 bne randloop clearmem: lda #$df ;set $07df-$0a20 sta $01 ;to $#00 lda #$07 sta $02clearbyte: lda #$00 sta ($01), Y jsr inc0103 cmp #$20 bne clearbyte lda $02 cmp #$0a bne clearbyte starttick:copyscreen: lda #$00 ;set up source sta $01 ;pointer at sta $03 ;$01/$02 and lda #$02 ;dest pointer sta $02 ;at $03/$04 lda #$08 sta $04 ldy #$00copybyte: lda ($01), Y ;copy pixel to sta ($03), Y ;back buffer jsr inc0103 ;increment pointers cmp #$00 ;check to see bne copybyte ;if we're at $600 lda $02 ;if so, we've cmp #$06 ;copied the bne copybyte ;entire screen conway: lda #$df ;apply conway rules sta $01 ;reset the pointer sta $03 ;to $#01df/$#07df lda #$01 ;($200 - $21) sta $02 ;($800 - $21) lda #$07 sta $04onecell: lda #$00 ;process one cell ldy #$01 ;upper cell clc adc ($03), Y ldy #$41 ;lower cell clc adc ($03), Ychkleft: tax ;check to see lda $01 ;if we're at the and #$1f ;left edge tay txa cpy #$1f beq rightcellsleftcells: ldy #$00 ;upper-left cell clc adc ($03), Y ldy #$20 ;left cell clc adc ($03), Y ldy #$40 ;lower-left cell clc adc ($03), Ychkright: tax ;check to see lda $01 ;if we're at the and #$1f ;right edge tay txa cpy #$1e beq evaluaterightcells: ldy #$02 ;upper-right cell clc adc ($03), Y ldy #$22 ;right cell clc adc ($03), Y ldy #$42 ;lower-right cell clc adc ($03), Yevaluate: ldx #$01 ;evaluate total ldy #$21 ;for current cell cmp #$03 ;3 = alive beq storex ldx #$00 cmp #$02 ;2 = alive if bne storex ;c = alive lda ($03), Y and #$01 taxstorex: txa ;store to screen sta ($01), Y jsr inc0103 ;move to next cellconwayloop: cmp #$e0 ;if not last cell, bne onecell ;process next cell lda $02 cmp #$05 bne onecell jmp starttick ;run next tick inc0103: lda $01 ;increment $01 cmp #$ff ;and $03 as 16-bit bne onlyinc01 ;pointers inc $02 inc $04onlyinc01: inc $01 lda $01 sta $03 rts The solution uses one cell thick border around square Petri dish as uninhabited dire land. Sample output contains 3 generations of the blinker and 5 of the glider: See Conway's Game of Life/ALGOL 68 APL2 (Dialog) Example in one line APL \ 1130 example (very old APL dialect via simulator) APL1130From: APL \ 1130 Samples The following APL \ 1130 code will need APL385 font installed to display correctly. See Download APL TT Font ∇LIFE[⎕]∇[0] NG←LIFE CG; W[1] W←CG+(¯1⊖CG)+(1⊖CG)+(¯1⌽CG)+(1⌽CG)[2] W←W+(1⊖1⌽CG)+(¯1⊖1⌽CG)+(1⊖¯1⌽CG)+(¯1⊖¯1⌽CG)[3] NG←(3=W)+(CG∧4=W) ∇ RP←5 5⍴0 0 0 0 0 0 0 1 1 0 0 1 1 0 0 0 0 1 0 0 RP0 0 0 0 00 0 1 1 00 1 1 0 00 0 1 0 00 0 0 0 0 LIFE RP0 0 0 0 00 1 1 1 00 1 0 0 00 1 1 0 00 0 0 0 0 LIFE LIFE RP0 0 1 0 00 1 1 0 01 0 0 1 00 1 1 0 00 0 0 0 0 .................................................. One interacts with the Game of Life by creating an initial configuration and observing how it evolves. Although you should test your implementation on more complex examples such as the glider in a larger universe, show the action of the blinker (three adjoining cells in a row all alive), over three generations, in a 3 by 3 grid. (1,4)=TRUERETURN'' Count the number of neighbours of the point i,j' (Assume i/j +/- 1 will not fall out of world)'FUNCTION count_neighbours(i%,j%) LOCAL count%,l% count%=0 FOR l%=-1 TO 1 IF world! (i%+l%,j%+1) count%=count%+1 ENDIF NEXT l% IF world! (i%+1,j%) count%=count%+1 ENDIF RETURN count%ENDFUNC'' Update the world one step'PROCEDURE update_world LOCAL i%,j% ' compute neighbour counts and store FOR i%=1 TO 30 FOR j%=1 TO 30 ns%(i%,j%)[email protected]_neighbours(i%,j%) NEXT j% NEXT i% ' update the world cells FOR i%=1 TO 30 FOR j%=1 TO 30 IF world!

||

randfill: stx $01 ;$200 for indirect ldx #$02 ;addressing stx $02randloop: lda $fe ;generate random and #$01 ;pixels on the sta ($01), Y ;screen jsr inc0103 cmp #$00 bne randloop lda $02 cmp #$06 bne randloop clearmem: lda #$df ;set $07df-$0a20 sta $01 ;to $#00 lda #$07 sta $02clearbyte: lda #$00 sta ($01), Y jsr inc0103 cmp #$20 bne clearbyte lda $02 cmp #$0a bne clearbyte starttick:copyscreen: lda #$00 ;set up source sta $01 ;pointer at sta $03 ;$01/$02 and lda #$02 ;dest pointer sta $02 ;at $03/$04 lda #$08 sta $04 ldy #$00copybyte: lda ($01), Y ;copy pixel to sta ($03), Y ;back buffer jsr inc0103 ;increment pointers cmp #$00 ;check to see bne copybyte ;if we're at $600 lda $02 ;if so, we've cmp #$06 ;copied the bne copybyte ;entire screen conway: lda #$df ;apply conway rules sta $01 ;reset the pointer sta $03 ;to $#01df/$#07df lda #$01 ;($200 - $21) sta $02 ;($800 - $21) lda #$07 sta $04onecell: lda #$00 ;process one cell ldy #$01 ;upper cell clc adc ($03), Y ldy #$41 ;lower cell clc adc ($03), Ychkleft: tax ;check to see lda $01 ;if we're at the and #$1f ;left edge tay txa cpy #$1f beq rightcellsleftcells: ldy #$00 ;upper-left cell clc adc ($03), Y ldy #$20 ;left cell clc adc ($03), Y ldy #$40 ;lower-left cell clc adc ($03), Ychkright: tax ;check to see lda $01 ;if we're at the and #$1f ;right edge tay txa cpy #$1e beq evaluaterightcells: ldy #$02 ;upper-right cell clc adc ($03), Y ldy #$22 ;right cell clc adc ($03), Y ldy #$42 ;lower-right cell clc adc ($03), Yevaluate: ldx #$01 ;evaluate total ldy #$21 ;for current cell cmp #$03 ;3 = alive beq storex ldx #$00 cmp #$02 ;2 = alive if bne storex ;c = alive lda ($03), Y and #$01 taxstorex: txa ;store to screen sta ($01), Y jsr inc0103 ;move to next cellconwayloop: cmp #$e0 ;if not last cell, bne onecell ;process next cell lda $02 cmp #$05 bne onecell jmp starttick ;run next tick inc0103: lda $01 ;increment $01 cmp #$ff ;and $03 as 16-bit bne onlyinc01 ;pointers inc $02 inc $04onlyinc01: inc $01 lda $01 sta $03 rts The solution uses one cell thick border around square Petri dish as uninhabited dire land. Sample output contains 3 generations of the blinker and 5 of the glider: See Conway's Game of Life/ALGOL 68 APL2 (Dialog) Example in one line APL \ 1130 example (very old APL dialect via simulator) APL1130From: APL \ 1130 Samples The following APL \ 1130 code will need APL385 font installed to display correctly.

See Download APL TT Font ∇LIFE[⎕]∇[0] NG←LIFE CG; W[1] W←CG+(¯1⊖CG)+(1⊖CG)+(¯1⌽CG)+(1⌽CG)[2] W←W+(1⊖1⌽CG)+(¯1⊖1⌽CG)+(1⊖¯1⌽CG)+(¯1⊖¯1⌽CG)[3] NG←(3=W)+(CG∧4=W) ∇ RP←5 5⍴0 0 0 0 0 0 0 1 1 0 0 1 1 0 0 0 0 1 0 0 RP0 0 0 0 00 0 1 1 00 1 1 0 00 0 1 0 00 0 0 0 0 LIFE RP0 0 0 0 00 1 1 1 00 1 0 0 00 1 1 0 00 0 0 0 0 LIFE LIFE RP0 0 1 0 00 1 1 0 01 0 0 1 00 1 1 0 00 0 0 0 0 ..................................................

One interacts with the Game of Life by creating an initial configuration and observing how it evolves.

Although you should test your implementation on more complex examples such as the glider in a larger universe, show the action of the blinker (three adjoining cells in a row all alive), over three generations, in a 3 by 3 grid.

(1,4)=TRUERETURN'' Count the number of neighbours of the point i,j' (Assume i/j +/- 1 will not fall out of world)'FUNCTION count_neighbours(i%,j%) LOCAL count%,l% count%=0 FOR l%=-1 TO 1 IF world! (i%+l%,j%+1) count%=count%+1 ENDIF NEXT l% IF world! (i%+1,j%) count%=count%+1 ENDIF RETURN count%ENDFUNC'' Update the world one step'PROCEDURE update_world LOCAL i%,j% ' compute neighbour counts and store FOR i%=1 TO 30 FOR j%=1 TO 30 ns%(i%,j%)[email protected]_neighbours(i%,j%) NEXT j% NEXT i% ' update the world cells FOR i%=1 TO 30 FOR j%=1 TO 30 IF world!

Thus, while it is somewhat verbose, it fully simulates Conway's Game of Life and is relatively simple to expand to feature different starting shapes.

Define life(pattern) = Prgm Local x,y,nt,count,save,xl,yl,xh,yh Define nt(y,x) = when(pxl Test(y,x), 1, 0) {}→save set Graph("Axes", "Off")→save[1] set Graph("Grid", "Off")→save[2] set Graph("Labels", "Off")→save[3] Fn Off Plot Off Clr Draw If pattern = "blinker" Then 36→yl 40→yh 78→xl 82→xh Pxl On 36,80 Pxl On 38,80 Pxl On 40,80 Else If pattern = "glider" Then 30→yl 40→yh 76→xl 88→xh Pxl On 38,76 Pxl On 36,78 Pxl On 36,80 Pxl On 38,80 Pxl On 40,80 Else If pattern = "r" Then 38-5*2→yl 38+5*2→yh 80-5*2→xl 80+5*2→xh Pxl On 38,78 Pxl On 36,82 Pxl On 36,80 Pxl On 38,80 Pxl On 40,80 End If While get Key() = 0 © Expand upper-left corner to whole cell For y,yl,yh,2 For x,xl,xh,2 If pxl Test(y,x) Then Pxl On y+1,x Pxl On y+1,x+1 Pxl On y, x+1 Else Pxl Off y+1,x Pxl Off y+1,x+1 Pxl Off y, x+1 End If End For End For © Compute next generation For y,yl,yh,2 For x,xl,xh,2 nt(y-1,x-1) + nt(y-1,x) + nt(y-1,x+2) + nt(y,x-1) + nt(y+1,x+2) + nt(y+2,x-1) + nt(y+2,x+1) + nt(y+2,x+2) → count If count = 3 Then Pxl On y,x Else If count ≠ 2 Then Pxl Off y,x End If End For End For End While © Restore changed options set Graph("Axes", save[1]) set Graph("Grid", save[2]) set Graph("Labels", save[3])End Prgm Also see Conway's Game of Life/C Considering that the simplest implementation in C++ would lack any use of the object-oriented paradigm, this code was specifically written to demonstrate the various object-oriented features of C++.

), Y ;screen jsr inc0103 cmp #

randfill: stx

randfill: stx $01 ;$200 for indirect ldx #$02 ;addressing stx $02randloop: lda $fe ;generate random and #$01 ;pixels on the sta ($01), Y ;screen jsr inc0103 cmp #$00 bne randloop lda $02 cmp #$06 bne randloop clearmem: lda #$df ;set $07df-$0a20 sta $01 ;to $#00 lda #$07 sta $02clearbyte: lda #$00 sta ($01), Y jsr inc0103 cmp #$20 bne clearbyte lda $02 cmp #$0a bne clearbyte starttick:copyscreen: lda #$00 ;set up source sta $01 ;pointer at sta $03 ;$01/$02 and lda #$02 ;dest pointer sta $02 ;at $03/$04 lda #$08 sta $04 ldy #$00copybyte: lda ($01), Y ;copy pixel to sta ($03), Y ;back buffer jsr inc0103 ;increment pointers cmp #$00 ;check to see bne copybyte ;if we're at $600 lda $02 ;if so, we've cmp #$06 ;copied the bne copybyte ;entire screen conway: lda #$df ;apply conway rules sta $01 ;reset the pointer sta $03 ;to $#01df/$#07df lda #$01 ;($200 - $21) sta $02 ;($800 - $21) lda #$07 sta $04onecell: lda #$00 ;process one cell ldy #$01 ;upper cell clc adc ($03), Y ldy #$41 ;lower cell clc adc ($03), Ychkleft: tax ;check to see lda $01 ;if we're at the and #$1f ;left edge tay txa cpy #$1f beq rightcellsleftcells: ldy #$00 ;upper-left cell clc adc ($03), Y ldy #$20 ;left cell clc adc ($03), Y ldy #$40 ;lower-left cell clc adc ($03), Ychkright: tax ;check to see lda $01 ;if we're at the and #$1f ;right edge tay txa cpy #$1e beq evaluaterightcells: ldy #$02 ;upper-right cell clc adc ($03), Y ldy #$22 ;right cell clc adc ($03), Y ldy #$42 ;lower-right cell clc adc ($03), Yevaluate: ldx #$01 ;evaluate total ldy #$21 ;for current cell cmp #$03 ;3 = alive beq storex ldx #$00 cmp #$02 ;2 = alive if bne storex ;c = alive lda ($03), Y and #$01 taxstorex: txa ;store to screen sta ($01), Y jsr inc0103 ;move to next cellconwayloop: cmp #$e0 ;if not last cell, bne onecell ;process next cell lda $02 cmp #$05 bne onecell jmp starttick ;run next tick inc0103: lda $01 ;increment $01 cmp #$ff ;and $03 as 16-bit bne onlyinc01 ;pointers inc $02 inc $04onlyinc01: inc $01 lda $01 sta $03 rts The solution uses one cell thick border around square Petri dish as uninhabited dire land. Sample output contains 3 generations of the blinker and 5 of the glider: See Conway's Game of Life/ALGOL 68 APL2 (Dialog) Example in one line APL \ 1130 example (very old APL dialect via simulator) APL1130From: APL \ 1130 Samples The following APL \ 1130 code will need APL385 font installed to display correctly. See Download APL TT Font ∇LIFE[⎕]∇[0] NG←LIFE CG; W[1] W←CG+(¯1⊖CG)+(1⊖CG)+(¯1⌽CG)+(1⌽CG)[2] W←W+(1⊖1⌽CG)+(¯1⊖1⌽CG)+(1⊖¯1⌽CG)+(¯1⊖¯1⌽CG)[3] NG←(3=W)+(CG∧4=W) ∇ RP←5 5⍴0 0 0 0 0 0 0 1 1 0 0 1 1 0 0 0 0 1 0 0 RP0 0 0 0 00 0 1 1 00 1 1 0 00 0 1 0 00 0 0 0 0 LIFE RP0 0 0 0 00 1 1 1 00 1 0 0 00 1 1 0 00 0 0 0 0 LIFE LIFE RP0 0 1 0 00 1 1 0 01 0 0 1 00 1 1 0 00 0 0 0 0 .................................................. One interacts with the Game of Life by creating an initial configuration and observing how it evolves. Although you should test your implementation on more complex examples such as the glider in a larger universe, show the action of the blinker (three adjoining cells in a row all alive), over three generations, in a 3 by 3 grid. (1,4)=TRUERETURN'' Count the number of neighbours of the point i,j' (Assume i/j +/- 1 will not fall out of world)'FUNCTION count_neighbours(i%,j%) LOCAL count%,l% count%=0 FOR l%=-1 TO 1 IF world! (i%+l%,j%+1) count%=count%+1 ENDIF NEXT l% IF world! (i%+1,j%) count%=count%+1 ENDIF RETURN count%ENDFUNC'' Update the world one step'PROCEDURE update_world LOCAL i%,j% ' compute neighbour counts and store FOR i%=1 TO 30 FOR j%=1 TO 30 ns%(i%,j%)[email protected]_neighbours(i%,j%) NEXT j% NEXT i% ' update the world cells FOR i%=1 TO 30 FOR j%=1 TO 30 IF world!

||

randfill: stx $01 ;$200 for indirect ldx #$02 ;addressing stx $02randloop: lda $fe ;generate random and #$01 ;pixels on the sta ($01), Y ;screen jsr inc0103 cmp #$00 bne randloop lda $02 cmp #$06 bne randloop clearmem: lda #$df ;set $07df-$0a20 sta $01 ;to $#00 lda #$07 sta $02clearbyte: lda #$00 sta ($01), Y jsr inc0103 cmp #$20 bne clearbyte lda $02 cmp #$0a bne clearbyte starttick:copyscreen: lda #$00 ;set up source sta $01 ;pointer at sta $03 ;$01/$02 and lda #$02 ;dest pointer sta $02 ;at $03/$04 lda #$08 sta $04 ldy #$00copybyte: lda ($01), Y ;copy pixel to sta ($03), Y ;back buffer jsr inc0103 ;increment pointers cmp #$00 ;check to see bne copybyte ;if we're at $600 lda $02 ;if so, we've cmp #$06 ;copied the bne copybyte ;entire screen conway: lda #$df ;apply conway rules sta $01 ;reset the pointer sta $03 ;to $#01df/$#07df lda #$01 ;($200 - $21) sta $02 ;($800 - $21) lda #$07 sta $04onecell: lda #$00 ;process one cell ldy #$01 ;upper cell clc adc ($03), Y ldy #$41 ;lower cell clc adc ($03), Ychkleft: tax ;check to see lda $01 ;if we're at the and #$1f ;left edge tay txa cpy #$1f beq rightcellsleftcells: ldy #$00 ;upper-left cell clc adc ($03), Y ldy #$20 ;left cell clc adc ($03), Y ldy #$40 ;lower-left cell clc adc ($03), Ychkright: tax ;check to see lda $01 ;if we're at the and #$1f ;right edge tay txa cpy #$1e beq evaluaterightcells: ldy #$02 ;upper-right cell clc adc ($03), Y ldy #$22 ;right cell clc adc ($03), Y ldy #$42 ;lower-right cell clc adc ($03), Yevaluate: ldx #$01 ;evaluate total ldy #$21 ;for current cell cmp #$03 ;3 = alive beq storex ldx #$00 cmp #$02 ;2 = alive if bne storex ;c = alive lda ($03), Y and #$01 taxstorex: txa ;store to screen sta ($01), Y jsr inc0103 ;move to next cellconwayloop: cmp #$e0 ;if not last cell, bne onecell ;process next cell lda $02 cmp #$05 bne onecell jmp starttick ;run next tick inc0103: lda $01 ;increment $01 cmp #$ff ;and $03 as 16-bit bne onlyinc01 ;pointers inc $02 inc $04onlyinc01: inc $01 lda $01 sta $03 rts The solution uses one cell thick border around square Petri dish as uninhabited dire land. Sample output contains 3 generations of the blinker and 5 of the glider: See Conway's Game of Life/ALGOL 68 APL2 (Dialog) Example in one line APL \ 1130 example (very old APL dialect via simulator) APL1130From: APL \ 1130 Samples The following APL \ 1130 code will need APL385 font installed to display correctly.

See Download APL TT Font ∇LIFE[⎕]∇[0] NG←LIFE CG; W[1] W←CG+(¯1⊖CG)+(1⊖CG)+(¯1⌽CG)+(1⌽CG)[2] W←W+(1⊖1⌽CG)+(¯1⊖1⌽CG)+(1⊖¯1⌽CG)+(¯1⊖¯1⌽CG)[3] NG←(3=W)+(CG∧4=W) ∇ RP←5 5⍴0 0 0 0 0 0 0 1 1 0 0 1 1 0 0 0 0 1 0 0 RP0 0 0 0 00 0 1 1 00 1 1 0 00 0 1 0 00 0 0 0 0 LIFE RP0 0 0 0 00 1 1 1 00 1 0 0 00 1 1 0 00 0 0 0 0 LIFE LIFE RP0 0 1 0 00 1 1 0 01 0 0 1 00 1 1 0 00 0 0 0 0 ..................................................

One interacts with the Game of Life by creating an initial configuration and observing how it evolves.

Although you should test your implementation on more complex examples such as the glider in a larger universe, show the action of the blinker (three adjoining cells in a row all alive), over three generations, in a 3 by 3 grid.

(1,4)=TRUERETURN'' Count the number of neighbours of the point i,j' (Assume i/j +/- 1 will not fall out of world)'FUNCTION count_neighbours(i%,j%) LOCAL count%,l% count%=0 FOR l%=-1 TO 1 IF world! (i%+l%,j%+1) count%=count%+1 ENDIF NEXT l% IF world! (i%+1,j%) count%=count%+1 ENDIF RETURN count%ENDFUNC'' Update the world one step'PROCEDURE update_world LOCAL i%,j% ' compute neighbour counts and store FOR i%=1 TO 30 FOR j%=1 TO 30 ns%(i%,j%)[email protected]_neighbours(i%,j%) NEXT j% NEXT i% ' update the world cells FOR i%=1 TO 30 FOR j%=1 TO 30 IF world!

Thus, while it is somewhat verbose, it fully simulates Conway's Game of Life and is relatively simple to expand to feature different starting shapes.

Define life(pattern) = Prgm Local x,y,nt,count,save,xl,yl,xh,yh Define nt(y,x) = when(pxl Test(y,x), 1, 0) {}→save set Graph("Axes", "Off")→save[1] set Graph("Grid", "Off")→save[2] set Graph("Labels", "Off")→save[3] Fn Off Plot Off Clr Draw If pattern = "blinker" Then 36→yl 40→yh 78→xl 82→xh Pxl On 36,80 Pxl On 38,80 Pxl On 40,80 Else If pattern = "glider" Then 30→yl 40→yh 76→xl 88→xh Pxl On 38,76 Pxl On 36,78 Pxl On 36,80 Pxl On 38,80 Pxl On 40,80 Else If pattern = "r" Then 38-5*2→yl 38+5*2→yh 80-5*2→xl 80+5*2→xh Pxl On 38,78 Pxl On 36,82 Pxl On 36,80 Pxl On 38,80 Pxl On 40,80 End If While get Key() = 0 © Expand upper-left corner to whole cell For y,yl,yh,2 For x,xl,xh,2 If pxl Test(y,x) Then Pxl On y+1,x Pxl On y+1,x+1 Pxl On y, x+1 Else Pxl Off y+1,x Pxl Off y+1,x+1 Pxl Off y, x+1 End If End For End For © Compute next generation For y,yl,yh,2 For x,xl,xh,2 nt(y-1,x-1) + nt(y-1,x) + nt(y-1,x+2) + nt(y,x-1) + nt(y+1,x+2) + nt(y+2,x-1) + nt(y+2,x+1) + nt(y+2,x+2) → count If count = 3 Then Pxl On y,x Else If count ≠ 2 Then Pxl Off y,x End If End For End For End While © Restore changed options set Graph("Axes", save[1]) set Graph("Grid", save[2]) set Graph("Labels", save[3])End Prgm Also see Conway's Game of Life/C Considering that the simplest implementation in C++ would lack any use of the object-oriented paradigm, this code was specifically written to demonstrate the various object-oriented features of C++.

;0 for indirect ldx # ;addressing stx randloop: lda $fe ;generate random and #

randfill: stx $01 ;$200 for indirect ldx #$02 ;addressing stx $02randloop: lda $fe ;generate random and #$01 ;pixels on the sta ($01), Y ;screen jsr inc0103 cmp #$00 bne randloop lda $02 cmp #$06 bne randloop clearmem: lda #$df ;set $07df-$0a20 sta $01 ;to $#00 lda #$07 sta $02clearbyte: lda #$00 sta ($01), Y jsr inc0103 cmp #$20 bne clearbyte lda $02 cmp #$0a bne clearbyte starttick:copyscreen: lda #$00 ;set up source sta $01 ;pointer at sta $03 ;$01/$02 and lda #$02 ;dest pointer sta $02 ;at $03/$04 lda #$08 sta $04 ldy #$00copybyte: lda ($01), Y ;copy pixel to sta ($03), Y ;back buffer jsr inc0103 ;increment pointers cmp #$00 ;check to see bne copybyte ;if we're at $600 lda $02 ;if so, we've cmp #$06 ;copied the bne copybyte ;entire screen conway: lda #$df ;apply conway rules sta $01 ;reset the pointer sta $03 ;to $#01df/$#07df lda #$01 ;($200 - $21) sta $02 ;($800 - $21) lda #$07 sta $04onecell: lda #$00 ;process one cell ldy #$01 ;upper cell clc adc ($03), Y ldy #$41 ;lower cell clc adc ($03), Ychkleft: tax ;check to see lda $01 ;if we're at the and #$1f ;left edge tay txa cpy #$1f beq rightcellsleftcells: ldy #$00 ;upper-left cell clc adc ($03), Y ldy #$20 ;left cell clc adc ($03), Y ldy #$40 ;lower-left cell clc adc ($03), Ychkright: tax ;check to see lda $01 ;if we're at the and #$1f ;right edge tay txa cpy #$1e beq evaluaterightcells: ldy #$02 ;upper-right cell clc adc ($03), Y ldy #$22 ;right cell clc adc ($03), Y ldy #$42 ;lower-right cell clc adc ($03), Yevaluate: ldx #$01 ;evaluate total ldy #$21 ;for current cell cmp #$03 ;3 = alive beq storex ldx #$00 cmp #$02 ;2 = alive if bne storex ;c = alive lda ($03), Y and #$01 taxstorex: txa ;store to screen sta ($01), Y jsr inc0103 ;move to next cellconwayloop: cmp #$e0 ;if not last cell, bne onecell ;process next cell lda $02 cmp #$05 bne onecell jmp starttick ;run next tick inc0103: lda $01 ;increment $01 cmp #$ff ;and $03 as 16-bit bne onlyinc01 ;pointers inc $02 inc $04onlyinc01: inc $01 lda $01 sta $03 rts The solution uses one cell thick border around square Petri dish as uninhabited dire land. Sample output contains 3 generations of the blinker and 5 of the glider: See Conway's Game of Life/ALGOL 68 APL2 (Dialog) Example in one line APL \ 1130 example (very old APL dialect via simulator) APL1130From: APL \ 1130 Samples The following APL \ 1130 code will need APL385 font installed to display correctly. See Download APL TT Font ∇LIFE[⎕]∇[0] NG←LIFE CG; W[1] W←CG+(¯1⊖CG)+(1⊖CG)+(¯1⌽CG)+(1⌽CG)[2] W←W+(1⊖1⌽CG)+(¯1⊖1⌽CG)+(1⊖¯1⌽CG)+(¯1⊖¯1⌽CG)[3] NG←(3=W)+(CG∧4=W) ∇ RP←5 5⍴0 0 0 0 0 0 0 1 1 0 0 1 1 0 0 0 0 1 0 0 RP0 0 0 0 00 0 1 1 00 1 1 0 00 0 1 0 00 0 0 0 0 LIFE RP0 0 0 0 00 1 1 1 00 1 0 0 00 1 1 0 00 0 0 0 0 LIFE LIFE RP0 0 1 0 00 1 1 0 01 0 0 1 00 1 1 0 00 0 0 0 0 .................................................. One interacts with the Game of Life by creating an initial configuration and observing how it evolves. Although you should test your implementation on more complex examples such as the glider in a larger universe, show the action of the blinker (three adjoining cells in a row all alive), over three generations, in a 3 by 3 grid. (1,4)=TRUERETURN'' Count the number of neighbours of the point i,j' (Assume i/j +/- 1 will not fall out of world)'FUNCTION count_neighbours(i%,j%) LOCAL count%,l% count%=0 FOR l%=-1 TO 1 IF world! (i%+l%,j%+1) count%=count%+1 ENDIF NEXT l% IF world! (i%+1,j%) count%=count%+1 ENDIF RETURN count%ENDFUNC'' Update the world one step'PROCEDURE update_world LOCAL i%,j% ' compute neighbour counts and store FOR i%=1 TO 30 FOR j%=1 TO 30 ns%(i%,j%)[email protected]_neighbours(i%,j%) NEXT j% NEXT i% ' update the world cells FOR i%=1 TO 30 FOR j%=1 TO 30 IF world!

||

randfill: stx $01 ;$200 for indirect ldx #$02 ;addressing stx $02randloop: lda $fe ;generate random and #$01 ;pixels on the sta ($01), Y ;screen jsr inc0103 cmp #$00 bne randloop lda $02 cmp #$06 bne randloop clearmem: lda #$df ;set $07df-$0a20 sta $01 ;to $#00 lda #$07 sta $02clearbyte: lda #$00 sta ($01), Y jsr inc0103 cmp #$20 bne clearbyte lda $02 cmp #$0a bne clearbyte starttick:copyscreen: lda #$00 ;set up source sta $01 ;pointer at sta $03 ;$01/$02 and lda #$02 ;dest pointer sta $02 ;at $03/$04 lda #$08 sta $04 ldy #$00copybyte: lda ($01), Y ;copy pixel to sta ($03), Y ;back buffer jsr inc0103 ;increment pointers cmp #$00 ;check to see bne copybyte ;if we're at $600 lda $02 ;if so, we've cmp #$06 ;copied the bne copybyte ;entire screen conway: lda #$df ;apply conway rules sta $01 ;reset the pointer sta $03 ;to $#01df/$#07df lda #$01 ;($200 - $21) sta $02 ;($800 - $21) lda #$07 sta $04onecell: lda #$00 ;process one cell ldy #$01 ;upper cell clc adc ($03), Y ldy #$41 ;lower cell clc adc ($03), Ychkleft: tax ;check to see lda $01 ;if we're at the and #$1f ;left edge tay txa cpy #$1f beq rightcellsleftcells: ldy #$00 ;upper-left cell clc adc ($03), Y ldy #$20 ;left cell clc adc ($03), Y ldy #$40 ;lower-left cell clc adc ($03), Ychkright: tax ;check to see lda $01 ;if we're at the and #$1f ;right edge tay txa cpy #$1e beq evaluaterightcells: ldy #$02 ;upper-right cell clc adc ($03), Y ldy #$22 ;right cell clc adc ($03), Y ldy #$42 ;lower-right cell clc adc ($03), Yevaluate: ldx #$01 ;evaluate total ldy #$21 ;for current cell cmp #$03 ;3 = alive beq storex ldx #$00 cmp #$02 ;2 = alive if bne storex ;c = alive lda ($03), Y and #$01 taxstorex: txa ;store to screen sta ($01), Y jsr inc0103 ;move to next cellconwayloop: cmp #$e0 ;if not last cell, bne onecell ;process next cell lda $02 cmp #$05 bne onecell jmp starttick ;run next tick inc0103: lda $01 ;increment $01 cmp #$ff ;and $03 as 16-bit bne onlyinc01 ;pointers inc $02 inc $04onlyinc01: inc $01 lda $01 sta $03 rts The solution uses one cell thick border around square Petri dish as uninhabited dire land. Sample output contains 3 generations of the blinker and 5 of the glider: See Conway's Game of Life/ALGOL 68 APL2 (Dialog) Example in one line APL \ 1130 example (very old APL dialect via simulator) APL1130From: APL \ 1130 Samples The following APL \ 1130 code will need APL385 font installed to display correctly.

See Download APL TT Font ∇LIFE[⎕]∇[0] NG←LIFE CG; W[1] W←CG+(¯1⊖CG)+(1⊖CG)+(¯1⌽CG)+(1⌽CG)[2] W←W+(1⊖1⌽CG)+(¯1⊖1⌽CG)+(1⊖¯1⌽CG)+(¯1⊖¯1⌽CG)[3] NG←(3=W)+(CG∧4=W) ∇ RP←5 5⍴0 0 0 0 0 0 0 1 1 0 0 1 1 0 0 0 0 1 0 0 RP0 0 0 0 00 0 1 1 00 1 1 0 00 0 1 0 00 0 0 0 0 LIFE RP0 0 0 0 00 1 1 1 00 1 0 0 00 1 1 0 00 0 0 0 0 LIFE LIFE RP0 0 1 0 00 1 1 0 01 0 0 1 00 1 1 0 00 0 0 0 0 ..................................................

One interacts with the Game of Life by creating an initial configuration and observing how it evolves.

Although you should test your implementation on more complex examples such as the glider in a larger universe, show the action of the blinker (three adjoining cells in a row all alive), over three generations, in a 3 by 3 grid.

(1,4)=TRUERETURN'' Count the number of neighbours of the point i,j' (Assume i/j +/- 1 will not fall out of world)'FUNCTION count_neighbours(i%,j%) LOCAL count%,l% count%=0 FOR l%=-1 TO 1 IF world! (i%+l%,j%+1) count%=count%+1 ENDIF NEXT l% IF world! (i%+1,j%) count%=count%+1 ENDIF RETURN count%ENDFUNC'' Update the world one step'PROCEDURE update_world LOCAL i%,j% ' compute neighbour counts and store FOR i%=1 TO 30 FOR j%=1 TO 30 ns%(i%,j%)[email protected]_neighbours(i%,j%) NEXT j% NEXT i% ' update the world cells FOR i%=1 TO 30 FOR j%=1 TO 30 IF world!

Thus, while it is somewhat verbose, it fully simulates Conway's Game of Life and is relatively simple to expand to feature different starting shapes.

Define life(pattern) = Prgm Local x,y,nt,count,save,xl,yl,xh,yh Define nt(y,x) = when(pxl Test(y,x), 1, 0) {}→save set Graph("Axes", "Off")→save[1] set Graph("Grid", "Off")→save[2] set Graph("Labels", "Off")→save[3] Fn Off Plot Off Clr Draw If pattern = "blinker" Then 36→yl 40→yh 78→xl 82→xh Pxl On 36,80 Pxl On 38,80 Pxl On 40,80 Else If pattern = "glider" Then 30→yl 40→yh 76→xl 88→xh Pxl On 38,76 Pxl On 36,78 Pxl On 36,80 Pxl On 38,80 Pxl On 40,80 Else If pattern = "r" Then 38-5*2→yl 38+5*2→yh 80-5*2→xl 80+5*2→xh Pxl On 38,78 Pxl On 36,82 Pxl On 36,80 Pxl On 38,80 Pxl On 40,80 End If While get Key() = 0 © Expand upper-left corner to whole cell For y,yl,yh,2 For x,xl,xh,2 If pxl Test(y,x) Then Pxl On y+1,x Pxl On y+1,x+1 Pxl On y, x+1 Else Pxl Off y+1,x Pxl Off y+1,x+1 Pxl Off y, x+1 End If End For End For © Compute next generation For y,yl,yh,2 For x,xl,xh,2 nt(y-1,x-1) + nt(y-1,x) + nt(y-1,x+2) + nt(y,x-1) + nt(y+1,x+2) + nt(y+2,x-1) + nt(y+2,x+1) + nt(y+2,x+2) → count If count = 3 Then Pxl On y,x Else If count ≠ 2 Then Pxl Off y,x End If End For End For End While © Restore changed options set Graph("Axes", save[1]) set Graph("Grid", save[2]) set Graph("Labels", save[3])End Prgm Also see Conway's Game of Life/C Considering that the simplest implementation in C++ would lack any use of the object-oriented paradigm, this code was specifically written to demonstrate the various object-oriented features of C++.

;pixels on the sta (

randfill: stx $01 ;$200 for indirect ldx #$02 ;addressing stx $02randloop: lda $fe ;generate random and #$01 ;pixels on the sta ($01), Y ;screen jsr inc0103 cmp #$00 bne randloop lda $02 cmp #$06 bne randloop clearmem: lda #$df ;set $07df-$0a20 sta $01 ;to $#00 lda #$07 sta $02clearbyte: lda #$00 sta ($01), Y jsr inc0103 cmp #$20 bne clearbyte lda $02 cmp #$0a bne clearbyte starttick:copyscreen: lda #$00 ;set up source sta $01 ;pointer at sta $03 ;$01/$02 and lda #$02 ;dest pointer sta $02 ;at $03/$04 lda #$08 sta $04 ldy #$00copybyte: lda ($01), Y ;copy pixel to sta ($03), Y ;back buffer jsr inc0103 ;increment pointers cmp #$00 ;check to see bne copybyte ;if we're at $600 lda $02 ;if so, we've cmp #$06 ;copied the bne copybyte ;entire screen conway: lda #$df ;apply conway rules sta $01 ;reset the pointer sta $03 ;to $#01df/$#07df lda #$01 ;($200 - $21) sta $02 ;($800 - $21) lda #$07 sta $04onecell: lda #$00 ;process one cell ldy #$01 ;upper cell clc adc ($03), Y ldy #$41 ;lower cell clc adc ($03), Ychkleft: tax ;check to see lda $01 ;if we're at the and #$1f ;left edge tay txa cpy #$1f beq rightcellsleftcells: ldy #$00 ;upper-left cell clc adc ($03), Y ldy #$20 ;left cell clc adc ($03), Y ldy #$40 ;lower-left cell clc adc ($03), Ychkright: tax ;check to see lda $01 ;if we're at the and #$1f ;right edge tay txa cpy #$1e beq evaluaterightcells: ldy #$02 ;upper-right cell clc adc ($03), Y ldy #$22 ;right cell clc adc ($03), Y ldy #$42 ;lower-right cell clc adc ($03), Yevaluate: ldx #$01 ;evaluate total ldy #$21 ;for current cell cmp #$03 ;3 = alive beq storex ldx #$00 cmp #$02 ;2 = alive if bne storex ;c = alive lda ($03), Y and #$01 taxstorex: txa ;store to screen sta ($01), Y jsr inc0103 ;move to next cellconwayloop: cmp #$e0 ;if not last cell, bne onecell ;process next cell lda $02 cmp #$05 bne onecell jmp starttick ;run next tick inc0103: lda $01 ;increment $01 cmp #$ff ;and $03 as 16-bit bne onlyinc01 ;pointers inc $02 inc $04onlyinc01: inc $01 lda $01 sta $03 rts The solution uses one cell thick border around square Petri dish as uninhabited dire land. Sample output contains 3 generations of the blinker and 5 of the glider: See Conway's Game of Life/ALGOL 68 APL2 (Dialog) Example in one line APL \ 1130 example (very old APL dialect via simulator) APL1130From: APL \ 1130 Samples The following APL \ 1130 code will need APL385 font installed to display correctly. See Download APL TT Font ∇LIFE[⎕]∇[0] NG←LIFE CG; W[1] W←CG+(¯1⊖CG)+(1⊖CG)+(¯1⌽CG)+(1⌽CG)[2] W←W+(1⊖1⌽CG)+(¯1⊖1⌽CG)+(1⊖¯1⌽CG)+(¯1⊖¯1⌽CG)[3] NG←(3=W)+(CG∧4=W) ∇ RP←5 5⍴0 0 0 0 0 0 0 1 1 0 0 1 1 0 0 0 0 1 0 0 RP0 0 0 0 00 0 1 1 00 1 1 0 00 0 1 0 00 0 0 0 0 LIFE RP0 0 0 0 00 1 1 1 00 1 0 0 00 1 1 0 00 0 0 0 0 LIFE LIFE RP0 0 1 0 00 1 1 0 01 0 0 1 00 1 1 0 00 0 0 0 0 .................................................. One interacts with the Game of Life by creating an initial configuration and observing how it evolves. Although you should test your implementation on more complex examples such as the glider in a larger universe, show the action of the blinker (three adjoining cells in a row all alive), over three generations, in a 3 by 3 grid. (1,4)=TRUERETURN'' Count the number of neighbours of the point i,j' (Assume i/j +/- 1 will not fall out of world)'FUNCTION count_neighbours(i%,j%) LOCAL count%,l% count%=0 FOR l%=-1 TO 1 IF world! (i%+l%,j%+1) count%=count%+1 ENDIF NEXT l% IF world! (i%+1,j%) count%=count%+1 ENDIF RETURN count%ENDFUNC'' Update the world one step'PROCEDURE update_world LOCAL i%,j% ' compute neighbour counts and store FOR i%=1 TO 30 FOR j%=1 TO 30 ns%(i%,j%)[email protected]_neighbours(i%,j%) NEXT j% NEXT i% ' update the world cells FOR i%=1 TO 30 FOR j%=1 TO 30 IF world!

||

randfill: stx $01 ;$200 for indirect ldx #$02 ;addressing stx $02randloop: lda $fe ;generate random and #$01 ;pixels on the sta ($01), Y ;screen jsr inc0103 cmp #$00 bne randloop lda $02 cmp #$06 bne randloop clearmem: lda #$df ;set $07df-$0a20 sta $01 ;to $#00 lda #$07 sta $02clearbyte: lda #$00 sta ($01), Y jsr inc0103 cmp #$20 bne clearbyte lda $02 cmp #$0a bne clearbyte starttick:copyscreen: lda #$00 ;set up source sta $01 ;pointer at sta $03 ;$01/$02 and lda #$02 ;dest pointer sta $02 ;at $03/$04 lda #$08 sta $04 ldy #$00copybyte: lda ($01), Y ;copy pixel to sta ($03), Y ;back buffer jsr inc0103 ;increment pointers cmp #$00 ;check to see bne copybyte ;if we're at $600 lda $02 ;if so, we've cmp #$06 ;copied the bne copybyte ;entire screen conway: lda #$df ;apply conway rules sta $01 ;reset the pointer sta $03 ;to $#01df/$#07df lda #$01 ;($200 - $21) sta $02 ;($800 - $21) lda #$07 sta $04onecell: lda #$00 ;process one cell ldy #$01 ;upper cell clc adc ($03), Y ldy #$41 ;lower cell clc adc ($03), Ychkleft: tax ;check to see lda $01 ;if we're at the and #$1f ;left edge tay txa cpy #$1f beq rightcellsleftcells: ldy #$00 ;upper-left cell clc adc ($03), Y ldy #$20 ;left cell clc adc ($03), Y ldy #$40 ;lower-left cell clc adc ($03), Ychkright: tax ;check to see lda $01 ;if we're at the and #$1f ;right edge tay txa cpy #$1e beq evaluaterightcells: ldy #$02 ;upper-right cell clc adc ($03), Y ldy #$22 ;right cell clc adc ($03), Y ldy #$42 ;lower-right cell clc adc ($03), Yevaluate: ldx #$01 ;evaluate total ldy #$21 ;for current cell cmp #$03 ;3 = alive beq storex ldx #$00 cmp #$02 ;2 = alive if bne storex ;c = alive lda ($03), Y and #$01 taxstorex: txa ;store to screen sta ($01), Y jsr inc0103 ;move to next cellconwayloop: cmp #$e0 ;if not last cell, bne onecell ;process next cell lda $02 cmp #$05 bne onecell jmp starttick ;run next tick inc0103: lda $01 ;increment $01 cmp #$ff ;and $03 as 16-bit bne onlyinc01 ;pointers inc $02 inc $04onlyinc01: inc $01 lda $01 sta $03 rts The solution uses one cell thick border around square Petri dish as uninhabited dire land. Sample output contains 3 generations of the blinker and 5 of the glider: See Conway's Game of Life/ALGOL 68 APL2 (Dialog) Example in one line APL \ 1130 example (very old APL dialect via simulator) APL1130From: APL \ 1130 Samples The following APL \ 1130 code will need APL385 font installed to display correctly.

See Download APL TT Font ∇LIFE[⎕]∇[0] NG←LIFE CG; W[1] W←CG+(¯1⊖CG)+(1⊖CG)+(¯1⌽CG)+(1⌽CG)[2] W←W+(1⊖1⌽CG)+(¯1⊖1⌽CG)+(1⊖¯1⌽CG)+(¯1⊖¯1⌽CG)[3] NG←(3=W)+(CG∧4=W) ∇ RP←5 5⍴0 0 0 0 0 0 0 1 1 0 0 1 1 0 0 0 0 1 0 0 RP0 0 0 0 00 0 1 1 00 1 1 0 00 0 1 0 00 0 0 0 0 LIFE RP0 0 0 0 00 1 1 1 00 1 0 0 00 1 1 0 00 0 0 0 0 LIFE LIFE RP0 0 1 0 00 1 1 0 01 0 0 1 00 1 1 0 00 0 0 0 0 ..................................................

One interacts with the Game of Life by creating an initial configuration and observing how it evolves.

Although you should test your implementation on more complex examples such as the glider in a larger universe, show the action of the blinker (three adjoining cells in a row all alive), over three generations, in a 3 by 3 grid.

(1,4)=TRUERETURN'' Count the number of neighbours of the point i,j' (Assume i/j +/- 1 will not fall out of world)'FUNCTION count_neighbours(i%,j%) LOCAL count%,l% count%=0 FOR l%=-1 TO 1 IF world! (i%+l%,j%+1) count%=count%+1 ENDIF NEXT l% IF world! (i%+1,j%) count%=count%+1 ENDIF RETURN count%ENDFUNC'' Update the world one step'PROCEDURE update_world LOCAL i%,j% ' compute neighbour counts and store FOR i%=1 TO 30 FOR j%=1 TO 30 ns%(i%,j%)[email protected]_neighbours(i%,j%) NEXT j% NEXT i% ' update the world cells FOR i%=1 TO 30 FOR j%=1 TO 30 IF world!

Thus, while it is somewhat verbose, it fully simulates Conway's Game of Life and is relatively simple to expand to feature different starting shapes.

Define life(pattern) = Prgm Local x,y,nt,count,save,xl,yl,xh,yh Define nt(y,x) = when(pxl Test(y,x), 1, 0) {}→save set Graph("Axes", "Off")→save[1] set Graph("Grid", "Off")→save[2] set Graph("Labels", "Off")→save[3] Fn Off Plot Off Clr Draw If pattern = "blinker" Then 36→yl 40→yh 78→xl 82→xh Pxl On 36,80 Pxl On 38,80 Pxl On 40,80 Else If pattern = "glider" Then 30→yl 40→yh 76→xl 88→xh Pxl On 38,76 Pxl On 36,78 Pxl On 36,80 Pxl On 38,80 Pxl On 40,80 Else If pattern = "r" Then 38-5*2→yl 38+5*2→yh 80-5*2→xl 80+5*2→xh Pxl On 38,78 Pxl On 36,82 Pxl On 36,80 Pxl On 38,80 Pxl On 40,80 End If While get Key() = 0 © Expand upper-left corner to whole cell For y,yl,yh,2 For x,xl,xh,2 If pxl Test(y,x) Then Pxl On y+1,x Pxl On y+1,x+1 Pxl On y, x+1 Else Pxl Off y+1,x Pxl Off y+1,x+1 Pxl Off y, x+1 End If End For End For © Compute next generation For y,yl,yh,2 For x,xl,xh,2 nt(y-1,x-1) + nt(y-1,x) + nt(y-1,x+2) + nt(y,x-1) + nt(y+1,x+2) + nt(y+2,x-1) + nt(y+2,x+1) + nt(y+2,x+2) → count If count = 3 Then Pxl On y,x Else If count ≠ 2 Then Pxl Off y,x End If End For End For End While © Restore changed options set Graph("Axes", save[1]) set Graph("Grid", save[2]) set Graph("Labels", save[3])End Prgm Also see Conway's Game of Life/C Considering that the simplest implementation in C++ would lack any use of the object-oriented paradigm, this code was specifically written to demonstrate the various object-oriented features of C++.

), Y ;screen jsr inc0103 cmp #

randfill: stx

randfill: stx $01 ;$200 for indirect ldx #$02 ;addressing stx $02randloop: lda $fe ;generate random and #$01 ;pixels on the sta ($01), Y ;screen jsr inc0103 cmp #$00 bne randloop lda $02 cmp #$06 bne randloop clearmem: lda #$df ;set $07df-$0a20 sta $01 ;to $#00 lda #$07 sta $02clearbyte: lda #$00 sta ($01), Y jsr inc0103 cmp #$20 bne clearbyte lda $02 cmp #$0a bne clearbyte starttick:copyscreen: lda #$00 ;set up source sta $01 ;pointer at sta $03 ;$01/$02 and lda #$02 ;dest pointer sta $02 ;at $03/$04 lda #$08 sta $04 ldy #$00copybyte: lda ($01), Y ;copy pixel to sta ($03), Y ;back buffer jsr inc0103 ;increment pointers cmp #$00 ;check to see bne copybyte ;if we're at $600 lda $02 ;if so, we've cmp #$06 ;copied the bne copybyte ;entire screen conway: lda #$df ;apply conway rules sta $01 ;reset the pointer sta $03 ;to $#01df/$#07df lda #$01 ;($200 - $21) sta $02 ;($800 - $21) lda #$07 sta $04onecell: lda #$00 ;process one cell ldy #$01 ;upper cell clc adc ($03), Y ldy #$41 ;lower cell clc adc ($03), Ychkleft: tax ;check to see lda $01 ;if we're at the and #$1f ;left edge tay txa cpy #$1f beq rightcellsleftcells: ldy #$00 ;upper-left cell clc adc ($03), Y ldy #$20 ;left cell clc adc ($03), Y ldy #$40 ;lower-left cell clc adc ($03), Ychkright: tax ;check to see lda $01 ;if we're at the and #$1f ;right edge tay txa cpy #$1e beq evaluaterightcells: ldy #$02 ;upper-right cell clc adc ($03), Y ldy #$22 ;right cell clc adc ($03), Y ldy #$42 ;lower-right cell clc adc ($03), Yevaluate: ldx #$01 ;evaluate total ldy #$21 ;for current cell cmp #$03 ;3 = alive beq storex ldx #$00 cmp #$02 ;2 = alive if bne storex ;c = alive lda ($03), Y and #$01 taxstorex: txa ;store to screen sta ($01), Y jsr inc0103 ;move to next cellconwayloop: cmp #$e0 ;if not last cell, bne onecell ;process next cell lda $02 cmp #$05 bne onecell jmp starttick ;run next tick inc0103: lda $01 ;increment $01 cmp #$ff ;and $03 as 16-bit bne onlyinc01 ;pointers inc $02 inc $04onlyinc01: inc $01 lda $01 sta $03 rts The solution uses one cell thick border around square Petri dish as uninhabited dire land. Sample output contains 3 generations of the blinker and 5 of the glider: See Conway's Game of Life/ALGOL 68 APL2 (Dialog) Example in one line APL \ 1130 example (very old APL dialect via simulator) APL1130From: APL \ 1130 Samples The following APL \ 1130 code will need APL385 font installed to display correctly. See Download APL TT Font ∇LIFE[⎕]∇[0] NG←LIFE CG; W[1] W←CG+(¯1⊖CG)+(1⊖CG)+(¯1⌽CG)+(1⌽CG)[2] W←W+(1⊖1⌽CG)+(¯1⊖1⌽CG)+(1⊖¯1⌽CG)+(¯1⊖¯1⌽CG)[3] NG←(3=W)+(CG∧4=W) ∇ RP←5 5⍴0 0 0 0 0 0 0 1 1 0 0 1 1 0 0 0 0 1 0 0 RP0 0 0 0 00 0 1 1 00 1 1 0 00 0 1 0 00 0 0 0 0 LIFE RP0 0 0 0 00 1 1 1 00 1 0 0 00 1 1 0 00 0 0 0 0 LIFE LIFE RP0 0 1 0 00 1 1 0 01 0 0 1 00 1 1 0 00 0 0 0 0 .................................................. One interacts with the Game of Life by creating an initial configuration and observing how it evolves. Although you should test your implementation on more complex examples such as the glider in a larger universe, show the action of the blinker (three adjoining cells in a row all alive), over three generations, in a 3 by 3 grid. (1,4)=TRUERETURN'' Count the number of neighbours of the point i,j' (Assume i/j +/- 1 will not fall out of world)'FUNCTION count_neighbours(i%,j%) LOCAL count%,l% count%=0 FOR l%=-1 TO 1 IF world! (i%+l%,j%+1) count%=count%+1 ENDIF NEXT l% IF world! (i%+1,j%) count%=count%+1 ENDIF RETURN count%ENDFUNC'' Update the world one step'PROCEDURE update_world LOCAL i%,j% ' compute neighbour counts and store FOR i%=1 TO 30 FOR j%=1 TO 30 ns%(i%,j%)[email protected]_neighbours(i%,j%) NEXT j% NEXT i% ' update the world cells FOR i%=1 TO 30 FOR j%=1 TO 30 IF world!

||

randfill: stx $01 ;$200 for indirect ldx #$02 ;addressing stx $02randloop: lda $fe ;generate random and #$01 ;pixels on the sta ($01), Y ;screen jsr inc0103 cmp #$00 bne randloop lda $02 cmp #$06 bne randloop clearmem: lda #$df ;set $07df-$0a20 sta $01 ;to $#00 lda #$07 sta $02clearbyte: lda #$00 sta ($01), Y jsr inc0103 cmp #$20 bne clearbyte lda $02 cmp #$0a bne clearbyte starttick:copyscreen: lda #$00 ;set up source sta $01 ;pointer at sta $03 ;$01/$02 and lda #$02 ;dest pointer sta $02 ;at $03/$04 lda #$08 sta $04 ldy #$00copybyte: lda ($01), Y ;copy pixel to sta ($03), Y ;back buffer jsr inc0103 ;increment pointers cmp #$00 ;check to see bne copybyte ;if we're at $600 lda $02 ;if so, we've cmp #$06 ;copied the bne copybyte ;entire screen conway: lda #$df ;apply conway rules sta $01 ;reset the pointer sta $03 ;to $#01df/$#07df lda #$01 ;($200 - $21) sta $02 ;($800 - $21) lda #$07 sta $04onecell: lda #$00 ;process one cell ldy #$01 ;upper cell clc adc ($03), Y ldy #$41 ;lower cell clc adc ($03), Ychkleft: tax ;check to see lda $01 ;if we're at the and #$1f ;left edge tay txa cpy #$1f beq rightcellsleftcells: ldy #$00 ;upper-left cell clc adc ($03), Y ldy #$20 ;left cell clc adc ($03), Y ldy #$40 ;lower-left cell clc adc ($03), Ychkright: tax ;check to see lda $01 ;if we're at the and #$1f ;right edge tay txa cpy #$1e beq evaluaterightcells: ldy #$02 ;upper-right cell clc adc ($03), Y ldy #$22 ;right cell clc adc ($03), Y ldy #$42 ;lower-right cell clc adc ($03), Yevaluate: ldx #$01 ;evaluate total ldy #$21 ;for current cell cmp #$03 ;3 = alive beq storex ldx #$00 cmp #$02 ;2 = alive if bne storex ;c = alive lda ($03), Y and #$01 taxstorex: txa ;store to screen sta ($01), Y jsr inc0103 ;move to next cellconwayloop: cmp #$e0 ;if not last cell, bne onecell ;process next cell lda $02 cmp #$05 bne onecell jmp starttick ;run next tick inc0103: lda $01 ;increment $01 cmp #$ff ;and $03 as 16-bit bne onlyinc01 ;pointers inc $02 inc $04onlyinc01: inc $01 lda $01 sta $03 rts The solution uses one cell thick border around square Petri dish as uninhabited dire land. Sample output contains 3 generations of the blinker and 5 of the glider: See Conway's Game of Life/ALGOL 68 APL2 (Dialog) Example in one line APL \ 1130 example (very old APL dialect via simulator) APL1130From: APL \ 1130 Samples The following APL \ 1130 code will need APL385 font installed to display correctly.

See Download APL TT Font ∇LIFE[⎕]∇[0] NG←LIFE CG; W[1] W←CG+(¯1⊖CG)+(1⊖CG)+(¯1⌽CG)+(1⌽CG)[2] W←W+(1⊖1⌽CG)+(¯1⊖1⌽CG)+(1⊖¯1⌽CG)+(¯1⊖¯1⌽CG)[3] NG←(3=W)+(CG∧4=W) ∇ RP←5 5⍴0 0 0 0 0 0 0 1 1 0 0 1 1 0 0 0 0 1 0 0 RP0 0 0 0 00 0 1 1 00 1 1 0 00 0 1 0 00 0 0 0 0 LIFE RP0 0 0 0 00 1 1 1 00 1 0 0 00 1 1 0 00 0 0 0 0 LIFE LIFE RP0 0 1 0 00 1 1 0 01 0 0 1 00 1 1 0 00 0 0 0 0 ..................................................

One interacts with the Game of Life by creating an initial configuration and observing how it evolves.

Although you should test your implementation on more complex examples such as the glider in a larger universe, show the action of the blinker (three adjoining cells in a row all alive), over three generations, in a 3 by 3 grid.

(1,4)=TRUERETURN'' Count the number of neighbours of the point i,j' (Assume i/j +/- 1 will not fall out of world)'FUNCTION count_neighbours(i%,j%) LOCAL count%,l% count%=0 FOR l%=-1 TO 1 IF world! (i%+l%,j%+1) count%=count%+1 ENDIF NEXT l% IF world! (i%+1,j%) count%=count%+1 ENDIF RETURN count%ENDFUNC'' Update the world one step'PROCEDURE update_world LOCAL i%,j% ' compute neighbour counts and store FOR i%=1 TO 30 FOR j%=1 TO 30 ns%(i%,j%)[email protected]_neighbours(i%,j%) NEXT j% NEXT i% ' update the world cells FOR i%=1 TO 30 FOR j%=1 TO 30 IF world!

Thus, while it is somewhat verbose, it fully simulates Conway's Game of Life and is relatively simple to expand to feature different starting shapes.

Define life(pattern) = Prgm Local x,y,nt,count,save,xl,yl,xh,yh Define nt(y,x) = when(pxl Test(y,x), 1, 0) {}→save set Graph("Axes", "Off")→save[1] set Graph("Grid", "Off")→save[2] set Graph("Labels", "Off")→save[3] Fn Off Plot Off Clr Draw If pattern = "blinker" Then 36→yl 40→yh 78→xl 82→xh Pxl On 36,80 Pxl On 38,80 Pxl On 40,80 Else If pattern = "glider" Then 30→yl 40→yh 76→xl 88→xh Pxl On 38,76 Pxl On 36,78 Pxl On 36,80 Pxl On 38,80 Pxl On 40,80 Else If pattern = "r" Then 38-5*2→yl 38+5*2→yh 80-5*2→xl 80+5*2→xh Pxl On 38,78 Pxl On 36,82 Pxl On 36,80 Pxl On 38,80 Pxl On 40,80 End If While get Key() = 0 © Expand upper-left corner to whole cell For y,yl,yh,2 For x,xl,xh,2 If pxl Test(y,x) Then Pxl On y+1,x Pxl On y+1,x+1 Pxl On y, x+1 Else Pxl Off y+1,x Pxl Off y+1,x+1 Pxl Off y, x+1 End If End For End For © Compute next generation For y,yl,yh,2 For x,xl,xh,2 nt(y-1,x-1) + nt(y-1,x) + nt(y-1,x+2) + nt(y,x-1) + nt(y+1,x+2) + nt(y+2,x-1) + nt(y+2,x+1) + nt(y+2,x+2) → count If count = 3 Then Pxl On y,x Else If count ≠ 2 Then Pxl Off y,x End If End For End For End While © Restore changed options set Graph("Axes", save[1]) set Graph("Grid", save[2]) set Graph("Labels", save[3])End Prgm Also see Conway's Game of Life/C Considering that the simplest implementation in C++ would lack any use of the object-oriented paradigm, this code was specifically written to demonstrate the various object-oriented features of C++.

;0 for indirect ldx # ;addressing stx randloop: lda $fe ;generate random and #

randfill: stx $01 ;$200 for indirect ldx #$02 ;addressing stx $02randloop: lda $fe ;generate random and #$01 ;pixels on the sta ($01), Y ;screen jsr inc0103 cmp #$00 bne randloop lda $02 cmp #$06 bne randloop clearmem: lda #$df ;set $07df-$0a20 sta $01 ;to $#00 lda #$07 sta $02clearbyte: lda #$00 sta ($01), Y jsr inc0103 cmp #$20 bne clearbyte lda $02 cmp #$0a bne clearbyte starttick:copyscreen: lda #$00 ;set up source sta $01 ;pointer at sta $03 ;$01/$02 and lda #$02 ;dest pointer sta $02 ;at $03/$04 lda #$08 sta $04 ldy #$00copybyte: lda ($01), Y ;copy pixel to sta ($03), Y ;back buffer jsr inc0103 ;increment pointers cmp #$00 ;check to see bne copybyte ;if we're at $600 lda $02 ;if so, we've cmp #$06 ;copied the bne copybyte ;entire screen conway: lda #$df ;apply conway rules sta $01 ;reset the pointer sta $03 ;to $#01df/$#07df lda #$01 ;($200 - $21) sta $02 ;($800 - $21) lda #$07 sta $04onecell: lda #$00 ;process one cell ldy #$01 ;upper cell clc adc ($03), Y ldy #$41 ;lower cell clc adc ($03), Ychkleft: tax ;check to see lda $01 ;if we're at the and #$1f ;left edge tay txa cpy #$1f beq rightcellsleftcells: ldy #$00 ;upper-left cell clc adc ($03), Y ldy #$20 ;left cell clc adc ($03), Y ldy #$40 ;lower-left cell clc adc ($03), Ychkright: tax ;check to see lda $01 ;if we're at the and #$1f ;right edge tay txa cpy #$1e beq evaluaterightcells: ldy #$02 ;upper-right cell clc adc ($03), Y ldy #$22 ;right cell clc adc ($03), Y ldy #$42 ;lower-right cell clc adc ($03), Yevaluate: ldx #$01 ;evaluate total ldy #$21 ;for current cell cmp #$03 ;3 = alive beq storex ldx #$00 cmp #$02 ;2 = alive if bne storex ;c = alive lda ($03), Y and #$01 taxstorex: txa ;store to screen sta ($01), Y jsr inc0103 ;move to next cellconwayloop: cmp #$e0 ;if not last cell, bne onecell ;process next cell lda $02 cmp #$05 bne onecell jmp starttick ;run next tick inc0103: lda $01 ;increment $01 cmp #$ff ;and $03 as 16-bit bne onlyinc01 ;pointers inc $02 inc $04onlyinc01: inc $01 lda $01 sta $03 rts The solution uses one cell thick border around square Petri dish as uninhabited dire land. Sample output contains 3 generations of the blinker and 5 of the glider: See Conway's Game of Life/ALGOL 68 APL2 (Dialog) Example in one line APL \ 1130 example (very old APL dialect via simulator) APL1130From: APL \ 1130 Samples The following APL \ 1130 code will need APL385 font installed to display correctly. See Download APL TT Font ∇LIFE[⎕]∇[0] NG←LIFE CG; W[1] W←CG+(¯1⊖CG)+(1⊖CG)+(¯1⌽CG)+(1⌽CG)[2] W←W+(1⊖1⌽CG)+(¯1⊖1⌽CG)+(1⊖¯1⌽CG)+(¯1⊖¯1⌽CG)[3] NG←(3=W)+(CG∧4=W) ∇ RP←5 5⍴0 0 0 0 0 0 0 1 1 0 0 1 1 0 0 0 0 1 0 0 RP0 0 0 0 00 0 1 1 00 1 1 0 00 0 1 0 00 0 0 0 0 LIFE RP0 0 0 0 00 1 1 1 00 1 0 0 00 1 1 0 00 0 0 0 0 LIFE LIFE RP0 0 1 0 00 1 1 0 01 0 0 1 00 1 1 0 00 0 0 0 0 .................................................. One interacts with the Game of Life by creating an initial configuration and observing how it evolves. Although you should test your implementation on more complex examples such as the glider in a larger universe, show the action of the blinker (three adjoining cells in a row all alive), over three generations, in a 3 by 3 grid. (1,4)=TRUERETURN'' Count the number of neighbours of the point i,j' (Assume i/j +/- 1 will not fall out of world)'FUNCTION count_neighbours(i%,j%) LOCAL count%,l% count%=0 FOR l%=-1 TO 1 IF world! (i%+l%,j%+1) count%=count%+1 ENDIF NEXT l% IF world! (i%+1,j%) count%=count%+1 ENDIF RETURN count%ENDFUNC'' Update the world one step'PROCEDURE update_world LOCAL i%,j% ' compute neighbour counts and store FOR i%=1 TO 30 FOR j%=1 TO 30 ns%(i%,j%)[email protected]_neighbours(i%,j%) NEXT j% NEXT i% ' update the world cells FOR i%=1 TO 30 FOR j%=1 TO 30 IF world!

||

randfill: stx $01 ;$200 for indirect ldx #$02 ;addressing stx $02randloop: lda $fe ;generate random and #$01 ;pixels on the sta ($01), Y ;screen jsr inc0103 cmp #$00 bne randloop lda $02 cmp #$06 bne randloop clearmem: lda #$df ;set $07df-$0a20 sta $01 ;to $#00 lda #$07 sta $02clearbyte: lda #$00 sta ($01), Y jsr inc0103 cmp #$20 bne clearbyte lda $02 cmp #$0a bne clearbyte starttick:copyscreen: lda #$00 ;set up source sta $01 ;pointer at sta $03 ;$01/$02 and lda #$02 ;dest pointer sta $02 ;at $03/$04 lda #$08 sta $04 ldy #$00copybyte: lda ($01), Y ;copy pixel to sta ($03), Y ;back buffer jsr inc0103 ;increment pointers cmp #$00 ;check to see bne copybyte ;if we're at $600 lda $02 ;if so, we've cmp #$06 ;copied the bne copybyte ;entire screen conway: lda #$df ;apply conway rules sta $01 ;reset the pointer sta $03 ;to $#01df/$#07df lda #$01 ;($200 - $21) sta $02 ;($800 - $21) lda #$07 sta $04onecell: lda #$00 ;process one cell ldy #$01 ;upper cell clc adc ($03), Y ldy #$41 ;lower cell clc adc ($03), Ychkleft: tax ;check to see lda $01 ;if we're at the and #$1f ;left edge tay txa cpy #$1f beq rightcellsleftcells: ldy #$00 ;upper-left cell clc adc ($03), Y ldy #$20 ;left cell clc adc ($03), Y ldy #$40 ;lower-left cell clc adc ($03), Ychkright: tax ;check to see lda $01 ;if we're at the and #$1f ;right edge tay txa cpy #$1e beq evaluaterightcells: ldy #$02 ;upper-right cell clc adc ($03), Y ldy #$22 ;right cell clc adc ($03), Y ldy #$42 ;lower-right cell clc adc ($03), Yevaluate: ldx #$01 ;evaluate total ldy #$21 ;for current cell cmp #$03 ;3 = alive beq storex ldx #$00 cmp #$02 ;2 = alive if bne storex ;c = alive lda ($03), Y and #$01 taxstorex: txa ;store to screen sta ($01), Y jsr inc0103 ;move to next cellconwayloop: cmp #$e0 ;if not last cell, bne onecell ;process next cell lda $02 cmp #$05 bne onecell jmp starttick ;run next tick inc0103: lda $01 ;increment $01 cmp #$ff ;and $03 as 16-bit bne onlyinc01 ;pointers inc $02 inc $04onlyinc01: inc $01 lda $01 sta $03 rts The solution uses one cell thick border around square Petri dish as uninhabited dire land. Sample output contains 3 generations of the blinker and 5 of the glider: See Conway's Game of Life/ALGOL 68 APL2 (Dialog) Example in one line APL \ 1130 example (very old APL dialect via simulator) APL1130From: APL \ 1130 Samples The following APL \ 1130 code will need APL385 font installed to display correctly.

See Download APL TT Font ∇LIFE[⎕]∇[0] NG←LIFE CG; W[1] W←CG+(¯1⊖CG)+(1⊖CG)+(¯1⌽CG)+(1⌽CG)[2] W←W+(1⊖1⌽CG)+(¯1⊖1⌽CG)+(1⊖¯1⌽CG)+(¯1⊖¯1⌽CG)[3] NG←(3=W)+(CG∧4=W) ∇ RP←5 5⍴0 0 0 0 0 0 0 1 1 0 0 1 1 0 0 0 0 1 0 0 RP0 0 0 0 00 0 1 1 00 1 1 0 00 0 1 0 00 0 0 0 0 LIFE RP0 0 0 0 00 1 1 1 00 1 0 0 00 1 1 0 00 0 0 0 0 LIFE LIFE RP0 0 1 0 00 1 1 0 01 0 0 1 00 1 1 0 00 0 0 0 0 ..................................................

One interacts with the Game of Life by creating an initial configuration and observing how it evolves.

Although you should test your implementation on more complex examples such as the glider in a larger universe, show the action of the blinker (three adjoining cells in a row all alive), over three generations, in a 3 by 3 grid.

(1,4)=TRUERETURN'' Count the number of neighbours of the point i,j' (Assume i/j +/- 1 will not fall out of world)'FUNCTION count_neighbours(i%,j%) LOCAL count%,l% count%=0 FOR l%=-1 TO 1 IF world! (i%+l%,j%+1) count%=count%+1 ENDIF NEXT l% IF world! (i%+1,j%) count%=count%+1 ENDIF RETURN count%ENDFUNC'' Update the world one step'PROCEDURE update_world LOCAL i%,j% ' compute neighbour counts and store FOR i%=1 TO 30 FOR j%=1 TO 30 ns%(i%,j%)[email protected]_neighbours(i%,j%) NEXT j% NEXT i% ' update the world cells FOR i%=1 TO 30 FOR j%=1 TO 30 IF world!

Thus, while it is somewhat verbose, it fully simulates Conway's Game of Life and is relatively simple to expand to feature different starting shapes.

Define life(pattern) = Prgm Local x,y,nt,count,save,xl,yl,xh,yh Define nt(y,x) = when(pxl Test(y,x), 1, 0) {}→save set Graph("Axes", "Off")→save[1] set Graph("Grid", "Off")→save[2] set Graph("Labels", "Off")→save[3] Fn Off Plot Off Clr Draw If pattern = "blinker" Then 36→yl 40→yh 78→xl 82→xh Pxl On 36,80 Pxl On 38,80 Pxl On 40,80 Else If pattern = "glider" Then 30→yl 40→yh 76→xl 88→xh Pxl On 38,76 Pxl On 36,78 Pxl On 36,80 Pxl On 38,80 Pxl On 40,80 Else If pattern = "r" Then 38-5*2→yl 38+5*2→yh 80-5*2→xl 80+5*2→xh Pxl On 38,78 Pxl On 36,82 Pxl On 36,80 Pxl On 38,80 Pxl On 40,80 End If While get Key() = 0 © Expand upper-left corner to whole cell For y,yl,yh,2 For x,xl,xh,2 If pxl Test(y,x) Then Pxl On y+1,x Pxl On y+1,x+1 Pxl On y, x+1 Else Pxl Off y+1,x Pxl Off y+1,x+1 Pxl Off y, x+1 End If End For End For © Compute next generation For y,yl,yh,2 For x,xl,xh,2 nt(y-1,x-1) + nt(y-1,x) + nt(y-1,x+2) + nt(y,x-1) + nt(y+1,x+2) + nt(y+2,x-1) + nt(y+2,x+1) + nt(y+2,x+2) → count If count = 3 Then Pxl On y,x Else If count ≠ 2 Then Pxl Off y,x End If End For End For End While © Restore changed options set Graph("Axes", save[1]) set Graph("Grid", save[2]) set Graph("Labels", save[3])End Prgm Also see Conway's Game of Life/C Considering that the simplest implementation in C++ would lack any use of the object-oriented paradigm, this code was specifically written to demonstrate the various object-oriented features of C++.

;pixels on the sta (

randfill: stx $01 ;$200 for indirect ldx #$02 ;addressing stx $02randloop: lda $fe ;generate random and #$01 ;pixels on the sta ($01), Y ;screen jsr inc0103 cmp #$00 bne randloop lda $02 cmp #$06 bne randloop clearmem: lda #$df ;set $07df-$0a20 sta $01 ;to $#00 lda #$07 sta $02clearbyte: lda #$00 sta ($01), Y jsr inc0103 cmp #$20 bne clearbyte lda $02 cmp #$0a bne clearbyte starttick:copyscreen: lda #$00 ;set up source sta $01 ;pointer at sta $03 ;$01/$02 and lda #$02 ;dest pointer sta $02 ;at $03/$04 lda #$08 sta $04 ldy #$00copybyte: lda ($01), Y ;copy pixel to sta ($03), Y ;back buffer jsr inc0103 ;increment pointers cmp #$00 ;check to see bne copybyte ;if we're at $600 lda $02 ;if so, we've cmp #$06 ;copied the bne copybyte ;entire screen conway: lda #$df ;apply conway rules sta $01 ;reset the pointer sta $03 ;to $#01df/$#07df lda #$01 ;($200 - $21) sta $02 ;($800 - $21) lda #$07 sta $04onecell: lda #$00 ;process one cell ldy #$01 ;upper cell clc adc ($03), Y ldy #$41 ;lower cell clc adc ($03), Ychkleft: tax ;check to see lda $01 ;if we're at the and #$1f ;left edge tay txa cpy #$1f beq rightcellsleftcells: ldy #$00 ;upper-left cell clc adc ($03), Y ldy #$20 ;left cell clc adc ($03), Y ldy #$40 ;lower-left cell clc adc ($03), Ychkright: tax ;check to see lda $01 ;if we're at the and #$1f ;right edge tay txa cpy #$1e beq evaluaterightcells: ldy #$02 ;upper-right cell clc adc ($03), Y ldy #$22 ;right cell clc adc ($03), Y ldy #$42 ;lower-right cell clc adc ($03), Yevaluate: ldx #$01 ;evaluate total ldy #$21 ;for current cell cmp #$03 ;3 = alive beq storex ldx #$00 cmp #$02 ;2 = alive if bne storex ;c = alive lda ($03), Y and #$01 taxstorex: txa ;store to screen sta ($01), Y jsr inc0103 ;move to next cellconwayloop: cmp #$e0 ;if not last cell, bne onecell ;process next cell lda $02 cmp #$05 bne onecell jmp starttick ;run next tick inc0103: lda $01 ;increment $01 cmp #$ff ;and $03 as 16-bit bne onlyinc01 ;pointers inc $02 inc $04onlyinc01: inc $01 lda $01 sta $03 rts The solution uses one cell thick border around square Petri dish as uninhabited dire land. Sample output contains 3 generations of the blinker and 5 of the glider: See Conway's Game of Life/ALGOL 68 APL2 (Dialog) Example in one line APL \ 1130 example (very old APL dialect via simulator) APL1130From: APL \ 1130 Samples The following APL \ 1130 code will need APL385 font installed to display correctly. See Download APL TT Font ∇LIFE[⎕]∇[0] NG←LIFE CG; W[1] W←CG+(¯1⊖CG)+(1⊖CG)+(¯1⌽CG)+(1⌽CG)[2] W←W+(1⊖1⌽CG)+(¯1⊖1⌽CG)+(1⊖¯1⌽CG)+(¯1⊖¯1⌽CG)[3] NG←(3=W)+(CG∧4=W) ∇ RP←5 5⍴0 0 0 0 0 0 0 1 1 0 0 1 1 0 0 0 0 1 0 0 RP0 0 0 0 00 0 1 1 00 1 1 0 00 0 1 0 00 0 0 0 0 LIFE RP0 0 0 0 00 1 1 1 00 1 0 0 00 1 1 0 00 0 0 0 0 LIFE LIFE RP0 0 1 0 00 1 1 0 01 0 0 1 00 1 1 0 00 0 0 0 0 .................................................. One interacts with the Game of Life by creating an initial configuration and observing how it evolves. Although you should test your implementation on more complex examples such as the glider in a larger universe, show the action of the blinker (three adjoining cells in a row all alive), over three generations, in a 3 by 3 grid. (1,4)=TRUERETURN'' Count the number of neighbours of the point i,j' (Assume i/j +/- 1 will not fall out of world)'FUNCTION count_neighbours(i%,j%) LOCAL count%,l% count%=0 FOR l%=-1 TO 1 IF world! (i%+l%,j%+1) count%=count%+1 ENDIF NEXT l% IF world! (i%+1,j%) count%=count%+1 ENDIF RETURN count%ENDFUNC'' Update the world one step'PROCEDURE update_world LOCAL i%,j% ' compute neighbour counts and store FOR i%=1 TO 30 FOR j%=1 TO 30 ns%(i%,j%)[email protected]_neighbours(i%,j%) NEXT j% NEXT i% ' update the world cells FOR i%=1 TO 30 FOR j%=1 TO 30 IF world!

||

randfill: stx $01 ;$200 for indirect ldx #$02 ;addressing stx $02randloop: lda $fe ;generate random and #$01 ;pixels on the sta ($01), Y ;screen jsr inc0103 cmp #$00 bne randloop lda $02 cmp #$06 bne randloop clearmem: lda #$df ;set $07df-$0a20 sta $01 ;to $#00 lda #$07 sta $02clearbyte: lda #$00 sta ($01), Y jsr inc0103 cmp #$20 bne clearbyte lda $02 cmp #$0a bne clearbyte starttick:copyscreen: lda #$00 ;set up source sta $01 ;pointer at sta $03 ;$01/$02 and lda #$02 ;dest pointer sta $02 ;at $03/$04 lda #$08 sta $04 ldy #$00copybyte: lda ($01), Y ;copy pixel to sta ($03), Y ;back buffer jsr inc0103 ;increment pointers cmp #$00 ;check to see bne copybyte ;if we're at $600 lda $02 ;if so, we've cmp #$06 ;copied the bne copybyte ;entire screen conway: lda #$df ;apply conway rules sta $01 ;reset the pointer sta $03 ;to $#01df/$#07df lda #$01 ;($200 - $21) sta $02 ;($800 - $21) lda #$07 sta $04onecell: lda #$00 ;process one cell ldy #$01 ;upper cell clc adc ($03), Y ldy #$41 ;lower cell clc adc ($03), Ychkleft: tax ;check to see lda $01 ;if we're at the and #$1f ;left edge tay txa cpy #$1f beq rightcellsleftcells: ldy #$00 ;upper-left cell clc adc ($03), Y ldy #$20 ;left cell clc adc ($03), Y ldy #$40 ;lower-left cell clc adc ($03), Ychkright: tax ;check to see lda $01 ;if we're at the and #$1f ;right edge tay txa cpy #$1e beq evaluaterightcells: ldy #$02 ;upper-right cell clc adc ($03), Y ldy #$22 ;right cell clc adc ($03), Y ldy #$42 ;lower-right cell clc adc ($03), Yevaluate: ldx #$01 ;evaluate total ldy #$21 ;for current cell cmp #$03 ;3 = alive beq storex ldx #$00 cmp #$02 ;2 = alive if bne storex ;c = alive lda ($03), Y and #$01 taxstorex: txa ;store to screen sta ($01), Y jsr inc0103 ;move to next cellconwayloop: cmp #$e0 ;if not last cell, bne onecell ;process next cell lda $02 cmp #$05 bne onecell jmp starttick ;run next tick inc0103: lda $01 ;increment $01 cmp #$ff ;and $03 as 16-bit bne onlyinc01 ;pointers inc $02 inc $04onlyinc01: inc $01 lda $01 sta $03 rts The solution uses one cell thick border around square Petri dish as uninhabited dire land. Sample output contains 3 generations of the blinker and 5 of the glider: See Conway's Game of Life/ALGOL 68 APL2 (Dialog) Example in one line APL \ 1130 example (very old APL dialect via simulator) APL1130From: APL \ 1130 Samples The following APL \ 1130 code will need APL385 font installed to display correctly.

See Download APL TT Font ∇LIFE[⎕]∇[0] NG←LIFE CG; W[1] W←CG+(¯1⊖CG)+(1⊖CG)+(¯1⌽CG)+(1⌽CG)[2] W←W+(1⊖1⌽CG)+(¯1⊖1⌽CG)+(1⊖¯1⌽CG)+(¯1⊖¯1⌽CG)[3] NG←(3=W)+(CG∧4=W) ∇ RP←5 5⍴0 0 0 0 0 0 0 1 1 0 0 1 1 0 0 0 0 1 0 0 RP0 0 0 0 00 0 1 1 00 1 1 0 00 0 1 0 00 0 0 0 0 LIFE RP0 0 0 0 00 1 1 1 00 1 0 0 00 1 1 0 00 0 0 0 0 LIFE LIFE RP0 0 1 0 00 1 1 0 01 0 0 1 00 1 1 0 00 0 0 0 0 ..................................................

One interacts with the Game of Life by creating an initial configuration and observing how it evolves.

Although you should test your implementation on more complex examples such as the glider in a larger universe, show the action of the blinker (three adjoining cells in a row all alive), over three generations, in a 3 by 3 grid.

(1,4)=TRUERETURN'' Count the number of neighbours of the point i,j' (Assume i/j +/- 1 will not fall out of world)'FUNCTION count_neighbours(i%,j%) LOCAL count%,l% count%=0 FOR l%=-1 TO 1 IF world! (i%+l%,j%+1) count%=count%+1 ENDIF NEXT l% IF world! (i%+1,j%) count%=count%+1 ENDIF RETURN count%ENDFUNC'' Update the world one step'PROCEDURE update_world LOCAL i%,j% ' compute neighbour counts and store FOR i%=1 TO 30 FOR j%=1 TO 30 ns%(i%,j%)[email protected]_neighbours(i%,j%) NEXT j% NEXT i% ' update the world cells FOR i%=1 TO 30 FOR j%=1 TO 30 IF world!

Thus, while it is somewhat verbose, it fully simulates Conway's Game of Life and is relatively simple to expand to feature different starting shapes.

Define life(pattern) = Prgm Local x,y,nt,count,save,xl,yl,xh,yh Define nt(y,x) = when(pxl Test(y,x), 1, 0) {}→save set Graph("Axes", "Off")→save[1] set Graph("Grid", "Off")→save[2] set Graph("Labels", "Off")→save[3] Fn Off Plot Off Clr Draw If pattern = "blinker" Then 36→yl 40→yh 78→xl 82→xh Pxl On 36,80 Pxl On 38,80 Pxl On 40,80 Else If pattern = "glider" Then 30→yl 40→yh 76→xl 88→xh Pxl On 38,76 Pxl On 36,78 Pxl On 36,80 Pxl On 38,80 Pxl On 40,80 Else If pattern = "r" Then 38-5*2→yl 38+5*2→yh 80-5*2→xl 80+5*2→xh Pxl On 38,78 Pxl On 36,82 Pxl On 36,80 Pxl On 38,80 Pxl On 40,80 End If While get Key() = 0 © Expand upper-left corner to whole cell For y,yl,yh,2 For x,xl,xh,2 If pxl Test(y,x) Then Pxl On y+1,x Pxl On y+1,x+1 Pxl On y, x+1 Else Pxl Off y+1,x Pxl Off y+1,x+1 Pxl Off y, x+1 End If End For End For © Compute next generation For y,yl,yh,2 For x,xl,xh,2 nt(y-1,x-1) + nt(y-1,x) + nt(y-1,x+2) + nt(y,x-1) + nt(y+1,x+2) + nt(y+2,x-1) + nt(y+2,x+1) + nt(y+2,x+2) → count If count = 3 Then Pxl On y,x Else If count ≠ 2 Then Pxl Off y,x End If End For End For End While © Restore changed options set Graph("Axes", save[1]) set Graph("Grid", save[2]) set Graph("Labels", save[3])End Prgm Also see Conway's Game of Life/C Considering that the simplest implementation in C++ would lack any use of the object-oriented paradigm, this code was specifically written to demonstrate the various object-oriented features of C++.

), Y ;screen jsr inc0103 cmp #

randfill: stx

randfill: stx $01 ;$200 for indirect ldx #$02 ;addressing stx $02randloop: lda $fe ;generate random and #$01 ;pixels on the sta ($01), Y ;screen jsr inc0103 cmp #$00 bne randloop lda $02 cmp #$06 bne randloop clearmem: lda #$df ;set $07df-$0a20 sta $01 ;to $#00 lda #$07 sta $02clearbyte: lda #$00 sta ($01), Y jsr inc0103 cmp #$20 bne clearbyte lda $02 cmp #$0a bne clearbyte starttick:copyscreen: lda #$00 ;set up source sta $01 ;pointer at sta $03 ;$01/$02 and lda #$02 ;dest pointer sta $02 ;at $03/$04 lda #$08 sta $04 ldy #$00copybyte: lda ($01), Y ;copy pixel to sta ($03), Y ;back buffer jsr inc0103 ;increment pointers cmp #$00 ;check to see bne copybyte ;if we're at $600 lda $02 ;if so, we've cmp #$06 ;copied the bne copybyte ;entire screen conway: lda #$df ;apply conway rules sta $01 ;reset the pointer sta $03 ;to $#01df/$#07df lda #$01 ;($200 - $21) sta $02 ;($800 - $21) lda #$07 sta $04onecell: lda #$00 ;process one cell ldy #$01 ;upper cell clc adc ($03), Y ldy #$41 ;lower cell clc adc ($03), Ychkleft: tax ;check to see lda $01 ;if we're at the and #$1f ;left edge tay txa cpy #$1f beq rightcellsleftcells: ldy #$00 ;upper-left cell clc adc ($03), Y ldy #$20 ;left cell clc adc ($03), Y ldy #$40 ;lower-left cell clc adc ($03), Ychkright: tax ;check to see lda $01 ;if we're at the and #$1f ;right edge tay txa cpy #$1e beq evaluaterightcells: ldy #$02 ;upper-right cell clc adc ($03), Y ldy #$22 ;right cell clc adc ($03), Y ldy #$42 ;lower-right cell clc adc ($03), Yevaluate: ldx #$01 ;evaluate total ldy #$21 ;for current cell cmp #$03 ;3 = alive beq storex ldx #$00 cmp #$02 ;2 = alive if bne storex ;c = alive lda ($03), Y and #$01 taxstorex: txa ;store to screen sta ($01), Y jsr inc0103 ;move to next cellconwayloop: cmp #$e0 ;if not last cell, bne onecell ;process next cell lda $02 cmp #$05 bne onecell jmp starttick ;run next tick inc0103: lda $01 ;increment $01 cmp #$ff ;and $03 as 16-bit bne onlyinc01 ;pointers inc $02 inc $04onlyinc01: inc $01 lda $01 sta $03 rts The solution uses one cell thick border around square Petri dish as uninhabited dire land. Sample output contains 3 generations of the blinker and 5 of the glider: See Conway's Game of Life/ALGOL 68 APL2 (Dialog) Example in one line APL \ 1130 example (very old APL dialect via simulator) APL1130From: APL \ 1130 Samples The following APL \ 1130 code will need APL385 font installed to display correctly. See Download APL TT Font ∇LIFE[⎕]∇[0] NG←LIFE CG; W[1] W←CG+(¯1⊖CG)+(1⊖CG)+(¯1⌽CG)+(1⌽CG)[2] W←W+(1⊖1⌽CG)+(¯1⊖1⌽CG)+(1⊖¯1⌽CG)+(¯1⊖¯1⌽CG)[3] NG←(3=W)+(CG∧4=W) ∇ RP←5 5⍴0 0 0 0 0 0 0 1 1 0 0 1 1 0 0 0 0 1 0 0 RP0 0 0 0 00 0 1 1 00 1 1 0 00 0 1 0 00 0 0 0 0 LIFE RP0 0 0 0 00 1 1 1 00 1 0 0 00 1 1 0 00 0 0 0 0 LIFE LIFE RP0 0 1 0 00 1 1 0 01 0 0 1 00 1 1 0 00 0 0 0 0 .................................................. One interacts with the Game of Life by creating an initial configuration and observing how it evolves. Although you should test your implementation on more complex examples such as the glider in a larger universe, show the action of the blinker (three adjoining cells in a row all alive), over three generations, in a 3 by 3 grid. (1,4)=TRUERETURN'' Count the number of neighbours of the point i,j' (Assume i/j +/- 1 will not fall out of world)'FUNCTION count_neighbours(i%,j%) LOCAL count%,l% count%=0 FOR l%=-1 TO 1 IF world! (i%+l%,j%+1) count%=count%+1 ENDIF NEXT l% IF world! (i%+1,j%) count%=count%+1 ENDIF RETURN count%ENDFUNC'' Update the world one step'PROCEDURE update_world LOCAL i%,j% ' compute neighbour counts and store FOR i%=1 TO 30 FOR j%=1 TO 30 ns%(i%,j%)[email protected]_neighbours(i%,j%) NEXT j% NEXT i% ' update the world cells FOR i%=1 TO 30 FOR j%=1 TO 30 IF world!

||

randfill: stx $01 ;$200 for indirect ldx #$02 ;addressing stx $02randloop: lda $fe ;generate random and #$01 ;pixels on the sta ($01), Y ;screen jsr inc0103 cmp #$00 bne randloop lda $02 cmp #$06 bne randloop clearmem: lda #$df ;set $07df-$0a20 sta $01 ;to $#00 lda #$07 sta $02clearbyte: lda #$00 sta ($01), Y jsr inc0103 cmp #$20 bne clearbyte lda $02 cmp #$0a bne clearbyte starttick:copyscreen: lda #$00 ;set up source sta $01 ;pointer at sta $03 ;$01/$02 and lda #$02 ;dest pointer sta $02 ;at $03/$04 lda #$08 sta $04 ldy #$00copybyte: lda ($01), Y ;copy pixel to sta ($03), Y ;back buffer jsr inc0103 ;increment pointers cmp #$00 ;check to see bne copybyte ;if we're at $600 lda $02 ;if so, we've cmp #$06 ;copied the bne copybyte ;entire screen conway: lda #$df ;apply conway rules sta $01 ;reset the pointer sta $03 ;to $#01df/$#07df lda #$01 ;($200 - $21) sta $02 ;($800 - $21) lda #$07 sta $04onecell: lda #$00 ;process one cell ldy #$01 ;upper cell clc adc ($03), Y ldy #$41 ;lower cell clc adc ($03), Ychkleft: tax ;check to see lda $01 ;if we're at the and #$1f ;left edge tay txa cpy #$1f beq rightcellsleftcells: ldy #$00 ;upper-left cell clc adc ($03), Y ldy #$20 ;left cell clc adc ($03), Y ldy #$40 ;lower-left cell clc adc ($03), Ychkright: tax ;check to see lda $01 ;if we're at the and #$1f ;right edge tay txa cpy #$1e beq evaluaterightcells: ldy #$02 ;upper-right cell clc adc ($03), Y ldy #$22 ;right cell clc adc ($03), Y ldy #$42 ;lower-right cell clc adc ($03), Yevaluate: ldx #$01 ;evaluate total ldy #$21 ;for current cell cmp #$03 ;3 = alive beq storex ldx #$00 cmp #$02 ;2 = alive if bne storex ;c = alive lda ($03), Y and #$01 taxstorex: txa ;store to screen sta ($01), Y jsr inc0103 ;move to next cellconwayloop: cmp #$e0 ;if not last cell, bne onecell ;process next cell lda $02 cmp #$05 bne onecell jmp starttick ;run next tick inc0103: lda $01 ;increment $01 cmp #$ff ;and $03 as 16-bit bne onlyinc01 ;pointers inc $02 inc $04onlyinc01: inc $01 lda $01 sta $03 rts The solution uses one cell thick border around square Petri dish as uninhabited dire land. Sample output contains 3 generations of the blinker and 5 of the glider: See Conway's Game of Life/ALGOL 68 APL2 (Dialog) Example in one line APL \ 1130 example (very old APL dialect via simulator) APL1130From: APL \ 1130 Samples The following APL \ 1130 code will need APL385 font installed to display correctly.

See Download APL TT Font ∇LIFE[⎕]∇[0] NG←LIFE CG; W[1] W←CG+(¯1⊖CG)+(1⊖CG)+(¯1⌽CG)+(1⌽CG)[2] W←W+(1⊖1⌽CG)+(¯1⊖1⌽CG)+(1⊖¯1⌽CG)+(¯1⊖¯1⌽CG)[3] NG←(3=W)+(CG∧4=W) ∇ RP←5 5⍴0 0 0 0 0 0 0 1 1 0 0 1 1 0 0 0 0 1 0 0 RP0 0 0 0 00 0 1 1 00 1 1 0 00 0 1 0 00 0 0 0 0 LIFE RP0 0 0 0 00 1 1 1 00 1 0 0 00 1 1 0 00 0 0 0 0 LIFE LIFE RP0 0 1 0 00 1 1 0 01 0 0 1 00 1 1 0 00 0 0 0 0 ..................................................

One interacts with the Game of Life by creating an initial configuration and observing how it evolves.

Although you should test your implementation on more complex examples such as the glider in a larger universe, show the action of the blinker (three adjoining cells in a row all alive), over three generations, in a 3 by 3 grid.

(1,4)=TRUERETURN'' Count the number of neighbours of the point i,j' (Assume i/j +/- 1 will not fall out of world)'FUNCTION count_neighbours(i%,j%) LOCAL count%,l% count%=0 FOR l%=-1 TO 1 IF world! (i%+l%,j%+1) count%=count%+1 ENDIF NEXT l% IF world! (i%+1,j%) count%=count%+1 ENDIF RETURN count%ENDFUNC'' Update the world one step'PROCEDURE update_world LOCAL i%,j% ' compute neighbour counts and store FOR i%=1 TO 30 FOR j%=1 TO 30 ns%(i%,j%)[email protected]_neighbours(i%,j%) NEXT j% NEXT i% ' update the world cells FOR i%=1 TO 30 FOR j%=1 TO 30 IF world!

Thus, while it is somewhat verbose, it fully simulates Conway's Game of Life and is relatively simple to expand to feature different starting shapes.

Define life(pattern) = Prgm Local x,y,nt,count,save,xl,yl,xh,yh Define nt(y,x) = when(pxl Test(y,x), 1, 0) {}→save set Graph("Axes", "Off")→save[1] set Graph("Grid", "Off")→save[2] set Graph("Labels", "Off")→save[3] Fn Off Plot Off Clr Draw If pattern = "blinker" Then 36→yl 40→yh 78→xl 82→xh Pxl On 36,80 Pxl On 38,80 Pxl On 40,80 Else If pattern = "glider" Then 30→yl 40→yh 76→xl 88→xh Pxl On 38,76 Pxl On 36,78 Pxl On 36,80 Pxl On 38,80 Pxl On 40,80 Else If pattern = "r" Then 38-5*2→yl 38+5*2→yh 80-5*2→xl 80+5*2→xh Pxl On 38,78 Pxl On 36,82 Pxl On 36,80 Pxl On 38,80 Pxl On 40,80 End If While get Key() = 0 © Expand upper-left corner to whole cell For y,yl,yh,2 For x,xl,xh,2 If pxl Test(y,x) Then Pxl On y+1,x Pxl On y+1,x+1 Pxl On y, x+1 Else Pxl Off y+1,x Pxl Off y+1,x+1 Pxl Off y, x+1 End If End For End For © Compute next generation For y,yl,yh,2 For x,xl,xh,2 nt(y-1,x-1) + nt(y-1,x) + nt(y-1,x+2) + nt(y,x-1) + nt(y+1,x+2) + nt(y+2,x-1) + nt(y+2,x+1) + nt(y+2,x+2) → count If count = 3 Then Pxl On y,x Else If count ≠ 2 Then Pxl Off y,x End If End For End For End While © Restore changed options set Graph("Axes", save[1]) set Graph("Grid", save[2]) set Graph("Labels", save[3])End Prgm Also see Conway's Game of Life/C Considering that the simplest implementation in C++ would lack any use of the object-oriented paradigm, this code was specifically written to demonstrate the various object-oriented features of C++.

;0 for indirect ldx # ;addressing stx randloop: lda $fe ;generate random and #

randfill: stx $01 ;$200 for indirect ldx #$02 ;addressing stx $02randloop: lda $fe ;generate random and #$01 ;pixels on the sta ($01), Y ;screen jsr inc0103 cmp #$00 bne randloop lda $02 cmp #$06 bne randloop clearmem: lda #$df ;set $07df-$0a20 sta $01 ;to $#00 lda #$07 sta $02clearbyte: lda #$00 sta ($01), Y jsr inc0103 cmp #$20 bne clearbyte lda $02 cmp #$0a bne clearbyte starttick:copyscreen: lda #$00 ;set up source sta $01 ;pointer at sta $03 ;$01/$02 and lda #$02 ;dest pointer sta $02 ;at $03/$04 lda #$08 sta $04 ldy #$00copybyte: lda ($01), Y ;copy pixel to sta ($03), Y ;back buffer jsr inc0103 ;increment pointers cmp #$00 ;check to see bne copybyte ;if we're at $600 lda $02 ;if so, we've cmp #$06 ;copied the bne copybyte ;entire screen conway: lda #$df ;apply conway rules sta $01 ;reset the pointer sta $03 ;to $#01df/$#07df lda #$01 ;($200 - $21) sta $02 ;($800 - $21) lda #$07 sta $04onecell: lda #$00 ;process one cell ldy #$01 ;upper cell clc adc ($03), Y ldy #$41 ;lower cell clc adc ($03), Ychkleft: tax ;check to see lda $01 ;if we're at the and #$1f ;left edge tay txa cpy #$1f beq rightcellsleftcells: ldy #$00 ;upper-left cell clc adc ($03), Y ldy #$20 ;left cell clc adc ($03), Y ldy #$40 ;lower-left cell clc adc ($03), Ychkright: tax ;check to see lda $01 ;if we're at the and #$1f ;right edge tay txa cpy #$1e beq evaluaterightcells: ldy #$02 ;upper-right cell clc adc ($03), Y ldy #$22 ;right cell clc adc ($03), Y ldy #$42 ;lower-right cell clc adc ($03), Yevaluate: ldx #$01 ;evaluate total ldy #$21 ;for current cell cmp #$03 ;3 = alive beq storex ldx #$00 cmp #$02 ;2 = alive if bne storex ;c = alive lda ($03), Y and #$01 taxstorex: txa ;store to screen sta ($01), Y jsr inc0103 ;move to next cellconwayloop: cmp #$e0 ;if not last cell, bne onecell ;process next cell lda $02 cmp #$05 bne onecell jmp starttick ;run next tick inc0103: lda $01 ;increment $01 cmp #$ff ;and $03 as 16-bit bne onlyinc01 ;pointers inc $02 inc $04onlyinc01: inc $01 lda $01 sta $03 rts The solution uses one cell thick border around square Petri dish as uninhabited dire land. Sample output contains 3 generations of the blinker and 5 of the glider: See Conway's Game of Life/ALGOL 68 APL2 (Dialog) Example in one line APL \ 1130 example (very old APL dialect via simulator) APL1130From: APL \ 1130 Samples The following APL \ 1130 code will need APL385 font installed to display correctly. See Download APL TT Font ∇LIFE[⎕]∇[0] NG←LIFE CG; W[1] W←CG+(¯1⊖CG)+(1⊖CG)+(¯1⌽CG)+(1⌽CG)[2] W←W+(1⊖1⌽CG)+(¯1⊖1⌽CG)+(1⊖¯1⌽CG)+(¯1⊖¯1⌽CG)[3] NG←(3=W)+(CG∧4=W) ∇ RP←5 5⍴0 0 0 0 0 0 0 1 1 0 0 1 1 0 0 0 0 1 0 0 RP0 0 0 0 00 0 1 1 00 1 1 0 00 0 1 0 00 0 0 0 0 LIFE RP0 0 0 0 00 1 1 1 00 1 0 0 00 1 1 0 00 0 0 0 0 LIFE LIFE RP0 0 1 0 00 1 1 0 01 0 0 1 00 1 1 0 00 0 0 0 0 .................................................. One interacts with the Game of Life by creating an initial configuration and observing how it evolves. Although you should test your implementation on more complex examples such as the glider in a larger universe, show the action of the blinker (three adjoining cells in a row all alive), over three generations, in a 3 by 3 grid. (1,4)=TRUERETURN'' Count the number of neighbours of the point i,j' (Assume i/j +/- 1 will not fall out of world)'FUNCTION count_neighbours(i%,j%) LOCAL count%,l% count%=0 FOR l%=-1 TO 1 IF world! (i%+l%,j%+1) count%=count%+1 ENDIF NEXT l% IF world! (i%+1,j%) count%=count%+1 ENDIF RETURN count%ENDFUNC'' Update the world one step'PROCEDURE update_world LOCAL i%,j% ' compute neighbour counts and store FOR i%=1 TO 30 FOR j%=1 TO 30 ns%(i%,j%)[email protected]_neighbours(i%,j%) NEXT j% NEXT i% ' update the world cells FOR i%=1 TO 30 FOR j%=1 TO 30 IF world!

||

randfill: stx $01 ;$200 for indirect ldx #$02 ;addressing stx $02randloop: lda $fe ;generate random and #$01 ;pixels on the sta ($01), Y ;screen jsr inc0103 cmp #$00 bne randloop lda $02 cmp #$06 bne randloop clearmem: lda #$df ;set $07df-$0a20 sta $01 ;to $#00 lda #$07 sta $02clearbyte: lda #$00 sta ($01), Y jsr inc0103 cmp #$20 bne clearbyte lda $02 cmp #$0a bne clearbyte starttick:copyscreen: lda #$00 ;set up source sta $01 ;pointer at sta $03 ;$01/$02 and lda #$02 ;dest pointer sta $02 ;at $03/$04 lda #$08 sta $04 ldy #$00copybyte: lda ($01), Y ;copy pixel to sta ($03), Y ;back buffer jsr inc0103 ;increment pointers cmp #$00 ;check to see bne copybyte ;if we're at $600 lda $02 ;if so, we've cmp #$06 ;copied the bne copybyte ;entire screen conway: lda #$df ;apply conway rules sta $01 ;reset the pointer sta $03 ;to $#01df/$#07df lda #$01 ;($200 - $21) sta $02 ;($800 - $21) lda #$07 sta $04onecell: lda #$00 ;process one cell ldy #$01 ;upper cell clc adc ($03), Y ldy #$41 ;lower cell clc adc ($03), Ychkleft: tax ;check to see lda $01 ;if we're at the and #$1f ;left edge tay txa cpy #$1f beq rightcellsleftcells: ldy #$00 ;upper-left cell clc adc ($03), Y ldy #$20 ;left cell clc adc ($03), Y ldy #$40 ;lower-left cell clc adc ($03), Ychkright: tax ;check to see lda $01 ;if we're at the and #$1f ;right edge tay txa cpy #$1e beq evaluaterightcells: ldy #$02 ;upper-right cell clc adc ($03), Y ldy #$22 ;right cell clc adc ($03), Y ldy #$42 ;lower-right cell clc adc ($03), Yevaluate: ldx #$01 ;evaluate total ldy #$21 ;for current cell cmp #$03 ;3 = alive beq storex ldx #$00 cmp #$02 ;2 = alive if bne storex ;c = alive lda ($03), Y and #$01 taxstorex: txa ;store to screen sta ($01), Y jsr inc0103 ;move to next cellconwayloop: cmp #$e0 ;if not last cell, bne onecell ;process next cell lda $02 cmp #$05 bne onecell jmp starttick ;run next tick inc0103: lda $01 ;increment $01 cmp #$ff ;and $03 as 16-bit bne onlyinc01 ;pointers inc $02 inc $04onlyinc01: inc $01 lda $01 sta $03 rts The solution uses one cell thick border around square Petri dish as uninhabited dire land. Sample output contains 3 generations of the blinker and 5 of the glider: See Conway's Game of Life/ALGOL 68 APL2 (Dialog) Example in one line APL \ 1130 example (very old APL dialect via simulator) APL1130From: APL \ 1130 Samples The following APL \ 1130 code will need APL385 font installed to display correctly.

See Download APL TT Font ∇LIFE[⎕]∇[0] NG←LIFE CG; W[1] W←CG+(¯1⊖CG)+(1⊖CG)+(¯1⌽CG)+(1⌽CG)[2] W←W+(1⊖1⌽CG)+(¯1⊖1⌽CG)+(1⊖¯1⌽CG)+(¯1⊖¯1⌽CG)[3] NG←(3=W)+(CG∧4=W) ∇ RP←5 5⍴0 0 0 0 0 0 0 1 1 0 0 1 1 0 0 0 0 1 0 0 RP0 0 0 0 00 0 1 1 00 1 1 0 00 0 1 0 00 0 0 0 0 LIFE RP0 0 0 0 00 1 1 1 00 1 0 0 00 1 1 0 00 0 0 0 0 LIFE LIFE RP0 0 1 0 00 1 1 0 01 0 0 1 00 1 1 0 00 0 0 0 0 ..................................................

One interacts with the Game of Life by creating an initial configuration and observing how it evolves.

Although you should test your implementation on more complex examples such as the glider in a larger universe, show the action of the blinker (three adjoining cells in a row all alive), over three generations, in a 3 by 3 grid.

(1,4)=TRUERETURN'' Count the number of neighbours of the point i,j' (Assume i/j +/- 1 will not fall out of world)'FUNCTION count_neighbours(i%,j%) LOCAL count%,l% count%=0 FOR l%=-1 TO 1 IF world! (i%+l%,j%+1) count%=count%+1 ENDIF NEXT l% IF world! (i%+1,j%) count%=count%+1 ENDIF RETURN count%ENDFUNC'' Update the world one step'PROCEDURE update_world LOCAL i%,j% ' compute neighbour counts and store FOR i%=1 TO 30 FOR j%=1 TO 30 ns%(i%,j%)[email protected]_neighbours(i%,j%) NEXT j% NEXT i% ' update the world cells FOR i%=1 TO 30 FOR j%=1 TO 30 IF world!

Thus, while it is somewhat verbose, it fully simulates Conway's Game of Life and is relatively simple to expand to feature different starting shapes.

Define life(pattern) = Prgm Local x,y,nt,count,save,xl,yl,xh,yh Define nt(y,x) = when(pxl Test(y,x), 1, 0) {}→save set Graph("Axes", "Off")→save[1] set Graph("Grid", "Off")→save[2] set Graph("Labels", "Off")→save[3] Fn Off Plot Off Clr Draw If pattern = "blinker" Then 36→yl 40→yh 78→xl 82→xh Pxl On 36,80 Pxl On 38,80 Pxl On 40,80 Else If pattern = "glider" Then 30→yl 40→yh 76→xl 88→xh Pxl On 38,76 Pxl On 36,78 Pxl On 36,80 Pxl On 38,80 Pxl On 40,80 Else If pattern = "r" Then 38-5*2→yl 38+5*2→yh 80-5*2→xl 80+5*2→xh Pxl On 38,78 Pxl On 36,82 Pxl On 36,80 Pxl On 38,80 Pxl On 40,80 End If While get Key() = 0 © Expand upper-left corner to whole cell For y,yl,yh,2 For x,xl,xh,2 If pxl Test(y,x) Then Pxl On y+1,x Pxl On y+1,x+1 Pxl On y, x+1 Else Pxl Off y+1,x Pxl Off y+1,x+1 Pxl Off y, x+1 End If End For End For © Compute next generation For y,yl,yh,2 For x,xl,xh,2 nt(y-1,x-1) + nt(y-1,x) + nt(y-1,x+2) + nt(y,x-1) + nt(y+1,x+2) + nt(y+2,x-1) + nt(y+2,x+1) + nt(y+2,x+2) → count If count = 3 Then Pxl On y,x Else If count ≠ 2 Then Pxl Off y,x End If End For End For End While © Restore changed options set Graph("Axes", save[1]) set Graph("Grid", save[2]) set Graph("Labels", save[3])End Prgm Also see Conway's Game of Life/C Considering that the simplest implementation in C++ would lack any use of the object-oriented paradigm, this code was specifically written to demonstrate the various object-oriented features of C++.

;pixels on the sta (

randfill: stx $01 ;$200 for indirect ldx #$02 ;addressing stx $02randloop: lda $fe ;generate random and #$01 ;pixels on the sta ($01), Y ;screen jsr inc0103 cmp #$00 bne randloop lda $02 cmp #$06 bne randloop clearmem: lda #$df ;set $07df-$0a20 sta $01 ;to $#00 lda #$07 sta $02clearbyte: lda #$00 sta ($01), Y jsr inc0103 cmp #$20 bne clearbyte lda $02 cmp #$0a bne clearbyte starttick:copyscreen: lda #$00 ;set up source sta $01 ;pointer at sta $03 ;$01/$02 and lda #$02 ;dest pointer sta $02 ;at $03/$04 lda #$08 sta $04 ldy #$00copybyte: lda ($01), Y ;copy pixel to sta ($03), Y ;back buffer jsr inc0103 ;increment pointers cmp #$00 ;check to see bne copybyte ;if we're at $600 lda $02 ;if so, we've cmp #$06 ;copied the bne copybyte ;entire screen conway: lda #$df ;apply conway rules sta $01 ;reset the pointer sta $03 ;to $#01df/$#07df lda #$01 ;($200 - $21) sta $02 ;($800 - $21) lda #$07 sta $04onecell: lda #$00 ;process one cell ldy #$01 ;upper cell clc adc ($03), Y ldy #$41 ;lower cell clc adc ($03), Ychkleft: tax ;check to see lda $01 ;if we're at the and #$1f ;left edge tay txa cpy #$1f beq rightcellsleftcells: ldy #$00 ;upper-left cell clc adc ($03), Y ldy #$20 ;left cell clc adc ($03), Y ldy #$40 ;lower-left cell clc adc ($03), Ychkright: tax ;check to see lda $01 ;if we're at the and #$1f ;right edge tay txa cpy #$1e beq evaluaterightcells: ldy #$02 ;upper-right cell clc adc ($03), Y ldy #$22 ;right cell clc adc ($03), Y ldy #$42 ;lower-right cell clc adc ($03), Yevaluate: ldx #$01 ;evaluate total ldy #$21 ;for current cell cmp #$03 ;3 = alive beq storex ldx #$00 cmp #$02 ;2 = alive if bne storex ;c = alive lda ($03), Y and #$01 taxstorex: txa ;store to screen sta ($01), Y jsr inc0103 ;move to next cellconwayloop: cmp #$e0 ;if not last cell, bne onecell ;process next cell lda $02 cmp #$05 bne onecell jmp starttick ;run next tick inc0103: lda $01 ;increment $01 cmp #$ff ;and $03 as 16-bit bne onlyinc01 ;pointers inc $02 inc $04onlyinc01: inc $01 lda $01 sta $03 rts The solution uses one cell thick border around square Petri dish as uninhabited dire land. Sample output contains 3 generations of the blinker and 5 of the glider: See Conway's Game of Life/ALGOL 68 APL2 (Dialog) Example in one line APL \ 1130 example (very old APL dialect via simulator) APL1130From: APL \ 1130 Samples The following APL \ 1130 code will need APL385 font installed to display correctly. See Download APL TT Font ∇LIFE[⎕]∇[0] NG←LIFE CG; W[1] W←CG+(¯1⊖CG)+(1⊖CG)+(¯1⌽CG)+(1⌽CG)[2] W←W+(1⊖1⌽CG)+(¯1⊖1⌽CG)+(1⊖¯1⌽CG)+(¯1⊖¯1⌽CG)[3] NG←(3=W)+(CG∧4=W) ∇ RP←5 5⍴0 0 0 0 0 0 0 1 1 0 0 1 1 0 0 0 0 1 0 0 RP0 0 0 0 00 0 1 1 00 1 1 0 00 0 1 0 00 0 0 0 0 LIFE RP0 0 0 0 00 1 1 1 00 1 0 0 00 1 1 0 00 0 0 0 0 LIFE LIFE RP0 0 1 0 00 1 1 0 01 0 0 1 00 1 1 0 00 0 0 0 0 .................................................. One interacts with the Game of Life by creating an initial configuration and observing how it evolves. Although you should test your implementation on more complex examples such as the glider in a larger universe, show the action of the blinker (three adjoining cells in a row all alive), over three generations, in a 3 by 3 grid. (1,4)=TRUERETURN'' Count the number of neighbours of the point i,j' (Assume i/j +/- 1 will not fall out of world)'FUNCTION count_neighbours(i%,j%) LOCAL count%,l% count%=0 FOR l%=-1 TO 1 IF world! (i%+l%,j%+1) count%=count%+1 ENDIF NEXT l% IF world! (i%+1,j%) count%=count%+1 ENDIF RETURN count%ENDFUNC'' Update the world one step'PROCEDURE update_world LOCAL i%,j% ' compute neighbour counts and store FOR i%=1 TO 30 FOR j%=1 TO 30 ns%(i%,j%)[email protected]_neighbours(i%,j%) NEXT j% NEXT i% ' update the world cells FOR i%=1 TO 30 FOR j%=1 TO 30 IF world!

||

randfill: stx $01 ;$200 for indirect ldx #$02 ;addressing stx $02randloop: lda $fe ;generate random and #$01 ;pixels on the sta ($01), Y ;screen jsr inc0103 cmp #$00 bne randloop lda $02 cmp #$06 bne randloop clearmem: lda #$df ;set $07df-$0a20 sta $01 ;to $#00 lda #$07 sta $02clearbyte: lda #$00 sta ($01), Y jsr inc0103 cmp #$20 bne clearbyte lda $02 cmp #$0a bne clearbyte starttick:copyscreen: lda #$00 ;set up source sta $01 ;pointer at sta $03 ;$01/$02 and lda #$02 ;dest pointer sta $02 ;at $03/$04 lda #$08 sta $04 ldy #$00copybyte: lda ($01), Y ;copy pixel to sta ($03), Y ;back buffer jsr inc0103 ;increment pointers cmp #$00 ;check to see bne copybyte ;if we're at $600 lda $02 ;if so, we've cmp #$06 ;copied the bne copybyte ;entire screen conway: lda #$df ;apply conway rules sta $01 ;reset the pointer sta $03 ;to $#01df/$#07df lda #$01 ;($200 - $21) sta $02 ;($800 - $21) lda #$07 sta $04onecell: lda #$00 ;process one cell ldy #$01 ;upper cell clc adc ($03), Y ldy #$41 ;lower cell clc adc ($03), Ychkleft: tax ;check to see lda $01 ;if we're at the and #$1f ;left edge tay txa cpy #$1f beq rightcellsleftcells: ldy #$00 ;upper-left cell clc adc ($03), Y ldy #$20 ;left cell clc adc ($03), Y ldy #$40 ;lower-left cell clc adc ($03), Ychkright: tax ;check to see lda $01 ;if we're at the and #$1f ;right edge tay txa cpy #$1e beq evaluaterightcells: ldy #$02 ;upper-right cell clc adc ($03), Y ldy #$22 ;right cell clc adc ($03), Y ldy #$42 ;lower-right cell clc adc ($03), Yevaluate: ldx #$01 ;evaluate total ldy #$21 ;for current cell cmp #$03 ;3 = alive beq storex ldx #$00 cmp #$02 ;2 = alive if bne storex ;c = alive lda ($03), Y and #$01 taxstorex: txa ;store to screen sta ($01), Y jsr inc0103 ;move to next cellconwayloop: cmp #$e0 ;if not last cell, bne onecell ;process next cell lda $02 cmp #$05 bne onecell jmp starttick ;run next tick inc0103: lda $01 ;increment $01 cmp #$ff ;and $03 as 16-bit bne onlyinc01 ;pointers inc $02 inc $04onlyinc01: inc $01 lda $01 sta $03 rts The solution uses one cell thick border around square Petri dish as uninhabited dire land. Sample output contains 3 generations of the blinker and 5 of the glider: See Conway's Game of Life/ALGOL 68 APL2 (Dialog) Example in one line APL \ 1130 example (very old APL dialect via simulator) APL1130From: APL \ 1130 Samples The following APL \ 1130 code will need APL385 font installed to display correctly.

See Download APL TT Font ∇LIFE[⎕]∇[0] NG←LIFE CG; W[1] W←CG+(¯1⊖CG)+(1⊖CG)+(¯1⌽CG)+(1⌽CG)[2] W←W+(1⊖1⌽CG)+(¯1⊖1⌽CG)+(1⊖¯1⌽CG)+(¯1⊖¯1⌽CG)[3] NG←(3=W)+(CG∧4=W) ∇ RP←5 5⍴0 0 0 0 0 0 0 1 1 0 0 1 1 0 0 0 0 1 0 0 RP0 0 0 0 00 0 1 1 00 1 1 0 00 0 1 0 00 0 0 0 0 LIFE RP0 0 0 0 00 1 1 1 00 1 0 0 00 1 1 0 00 0 0 0 0 LIFE LIFE RP0 0 1 0 00 1 1 0 01 0 0 1 00 1 1 0 00 0 0 0 0 ..................................................

One interacts with the Game of Life by creating an initial configuration and observing how it evolves.

Although you should test your implementation on more complex examples such as the glider in a larger universe, show the action of the blinker (three adjoining cells in a row all alive), over three generations, in a 3 by 3 grid.

(1,4)=TRUERETURN'' Count the number of neighbours of the point i,j' (Assume i/j +/- 1 will not fall out of world)'FUNCTION count_neighbours(i%,j%) LOCAL count%,l% count%=0 FOR l%=-1 TO 1 IF world! (i%+l%,j%+1) count%=count%+1 ENDIF NEXT l% IF world! (i%+1,j%) count%=count%+1 ENDIF RETURN count%ENDFUNC'' Update the world one step'PROCEDURE update_world LOCAL i%,j% ' compute neighbour counts and store FOR i%=1 TO 30 FOR j%=1 TO 30 ns%(i%,j%)[email protected]_neighbours(i%,j%) NEXT j% NEXT i% ' update the world cells FOR i%=1 TO 30 FOR j%=1 TO 30 IF world!

Thus, while it is somewhat verbose, it fully simulates Conway's Game of Life and is relatively simple to expand to feature different starting shapes.

Define life(pattern) = Prgm Local x,y,nt,count,save,xl,yl,xh,yh Define nt(y,x) = when(pxl Test(y,x), 1, 0) {}→save set Graph("Axes", "Off")→save[1] set Graph("Grid", "Off")→save[2] set Graph("Labels", "Off")→save[3] Fn Off Plot Off Clr Draw If pattern = "blinker" Then 36→yl 40→yh 78→xl 82→xh Pxl On 36,80 Pxl On 38,80 Pxl On 40,80 Else If pattern = "glider" Then 30→yl 40→yh 76→xl 88→xh Pxl On 38,76 Pxl On 36,78 Pxl On 36,80 Pxl On 38,80 Pxl On 40,80 Else If pattern = "r" Then 38-5*2→yl 38+5*2→yh 80-5*2→xl 80+5*2→xh Pxl On 38,78 Pxl On 36,82 Pxl On 36,80 Pxl On 38,80 Pxl On 40,80 End If While get Key() = 0 © Expand upper-left corner to whole cell For y,yl,yh,2 For x,xl,xh,2 If pxl Test(y,x) Then Pxl On y+1,x Pxl On y+1,x+1 Pxl On y, x+1 Else Pxl Off y+1,x Pxl Off y+1,x+1 Pxl Off y, x+1 End If End For End For © Compute next generation For y,yl,yh,2 For x,xl,xh,2 nt(y-1,x-1) + nt(y-1,x) + nt(y-1,x+2) + nt(y,x-1) + nt(y+1,x+2) + nt(y+2,x-1) + nt(y+2,x+1) + nt(y+2,x+2) → count If count = 3 Then Pxl On y,x Else If count ≠ 2 Then Pxl Off y,x End If End For End For End While © Restore changed options set Graph("Axes", save[1]) set Graph("Grid", save[2]) set Graph("Labels", save[3])End Prgm Also see Conway's Game of Life/C Considering that the simplest implementation in C++ would lack any use of the object-oriented paradigm, this code was specifically written to demonstrate the various object-oriented features of C++.

), Y ;screen jsr inc0103 cmp #

randfill: stx

randfill: stx $01 ;$200 for indirect ldx #$02 ;addressing stx $02randloop: lda $fe ;generate random and #$01 ;pixels on the sta ($01), Y ;screen jsr inc0103 cmp #$00 bne randloop lda $02 cmp #$06 bne randloop clearmem: lda #$df ;set $07df-$0a20 sta $01 ;to $#00 lda #$07 sta $02clearbyte: lda #$00 sta ($01), Y jsr inc0103 cmp #$20 bne clearbyte lda $02 cmp #$0a bne clearbyte starttick:copyscreen: lda #$00 ;set up source sta $01 ;pointer at sta $03 ;$01/$02 and lda #$02 ;dest pointer sta $02 ;at $03/$04 lda #$08 sta $04 ldy #$00copybyte: lda ($01), Y ;copy pixel to sta ($03), Y ;back buffer jsr inc0103 ;increment pointers cmp #$00 ;check to see bne copybyte ;if we're at $600 lda $02 ;if so, we've cmp #$06 ;copied the bne copybyte ;entire screen conway: lda #$df ;apply conway rules sta $01 ;reset the pointer sta $03 ;to $#01df/$#07df lda #$01 ;($200 - $21) sta $02 ;($800 - $21) lda #$07 sta $04onecell: lda #$00 ;process one cell ldy #$01 ;upper cell clc adc ($03), Y ldy #$41 ;lower cell clc adc ($03), Ychkleft: tax ;check to see lda $01 ;if we're at the and #$1f ;left edge tay txa cpy #$1f beq rightcellsleftcells: ldy #$00 ;upper-left cell clc adc ($03), Y ldy #$20 ;left cell clc adc ($03), Y ldy #$40 ;lower-left cell clc adc ($03), Ychkright: tax ;check to see lda $01 ;if we're at the and #$1f ;right edge tay txa cpy #$1e beq evaluaterightcells: ldy #$02 ;upper-right cell clc adc ($03), Y ldy #$22 ;right cell clc adc ($03), Y ldy #$42 ;lower-right cell clc adc ($03), Yevaluate: ldx #$01 ;evaluate total ldy #$21 ;for current cell cmp #$03 ;3 = alive beq storex ldx #$00 cmp #$02 ;2 = alive if bne storex ;c = alive lda ($03), Y and #$01 taxstorex: txa ;store to screen sta ($01), Y jsr inc0103 ;move to next cellconwayloop: cmp #$e0 ;if not last cell, bne onecell ;process next cell lda $02 cmp #$05 bne onecell jmp starttick ;run next tick inc0103: lda $01 ;increment $01 cmp #$ff ;and $03 as 16-bit bne onlyinc01 ;pointers inc $02 inc $04onlyinc01: inc $01 lda $01 sta $03 rts The solution uses one cell thick border around square Petri dish as uninhabited dire land. Sample output contains 3 generations of the blinker and 5 of the glider: See Conway's Game of Life/ALGOL 68 APL2 (Dialog) Example in one line APL \ 1130 example (very old APL dialect via simulator) APL1130From: APL \ 1130 Samples The following APL \ 1130 code will need APL385 font installed to display correctly. See Download APL TT Font ∇LIFE[⎕]∇[0] NG←LIFE CG; W[1] W←CG+(¯1⊖CG)+(1⊖CG)+(¯1⌽CG)+(1⌽CG)[2] W←W+(1⊖1⌽CG)+(¯1⊖1⌽CG)+(1⊖¯1⌽CG)+(¯1⊖¯1⌽CG)[3] NG←(3=W)+(CG∧4=W) ∇ RP←5 5⍴0 0 0 0 0 0 0 1 1 0 0 1 1 0 0 0 0 1 0 0 RP0 0 0 0 00 0 1 1 00 1 1 0 00 0 1 0 00 0 0 0 0 LIFE RP0 0 0 0 00 1 1 1 00 1 0 0 00 1 1 0 00 0 0 0 0 LIFE LIFE RP0 0 1 0 00 1 1 0 01 0 0 1 00 1 1 0 00 0 0 0 0 .................................................. One interacts with the Game of Life by creating an initial configuration and observing how it evolves. Although you should test your implementation on more complex examples such as the glider in a larger universe, show the action of the blinker (three adjoining cells in a row all alive), over three generations, in a 3 by 3 grid. (1,4)=TRUERETURN'' Count the number of neighbours of the point i,j' (Assume i/j +/- 1 will not fall out of world)'FUNCTION count_neighbours(i%,j%) LOCAL count%,l% count%=0 FOR l%=-1 TO 1 IF world! (i%+l%,j%+1) count%=count%+1 ENDIF NEXT l% IF world! (i%+1,j%) count%=count%+1 ENDIF RETURN count%ENDFUNC'' Update the world one step'PROCEDURE update_world LOCAL i%,j% ' compute neighbour counts and store FOR i%=1 TO 30 FOR j%=1 TO 30 ns%(i%,j%)[email protected]_neighbours(i%,j%) NEXT j% NEXT i% ' update the world cells FOR i%=1 TO 30 FOR j%=1 TO 30 IF world!

||

randfill: stx $01 ;$200 for indirect ldx #$02 ;addressing stx $02randloop: lda $fe ;generate random and #$01 ;pixels on the sta ($01), Y ;screen jsr inc0103 cmp #$00 bne randloop lda $02 cmp #$06 bne randloop clearmem: lda #$df ;set $07df-$0a20 sta $01 ;to $#00 lda #$07 sta $02clearbyte: lda #$00 sta ($01), Y jsr inc0103 cmp #$20 bne clearbyte lda $02 cmp #$0a bne clearbyte starttick:copyscreen: lda #$00 ;set up source sta $01 ;pointer at sta $03 ;$01/$02 and lda #$02 ;dest pointer sta $02 ;at $03/$04 lda #$08 sta $04 ldy #$00copybyte: lda ($01), Y ;copy pixel to sta ($03), Y ;back buffer jsr inc0103 ;increment pointers cmp #$00 ;check to see bne copybyte ;if we're at $600 lda $02 ;if so, we've cmp #$06 ;copied the bne copybyte ;entire screen conway: lda #$df ;apply conway rules sta $01 ;reset the pointer sta $03 ;to $#01df/$#07df lda #$01 ;($200 - $21) sta $02 ;($800 - $21) lda #$07 sta $04onecell: lda #$00 ;process one cell ldy #$01 ;upper cell clc adc ($03), Y ldy #$41 ;lower cell clc adc ($03), Ychkleft: tax ;check to see lda $01 ;if we're at the and #$1f ;left edge tay txa cpy #$1f beq rightcellsleftcells: ldy #$00 ;upper-left cell clc adc ($03), Y ldy #$20 ;left cell clc adc ($03), Y ldy #$40 ;lower-left cell clc adc ($03), Ychkright: tax ;check to see lda $01 ;if we're at the and #$1f ;right edge tay txa cpy #$1e beq evaluaterightcells: ldy #$02 ;upper-right cell clc adc ($03), Y ldy #$22 ;right cell clc adc ($03), Y ldy #$42 ;lower-right cell clc adc ($03), Yevaluate: ldx #$01 ;evaluate total ldy #$21 ;for current cell cmp #$03 ;3 = alive beq storex ldx #$00 cmp #$02 ;2 = alive if bne storex ;c = alive lda ($03), Y and #$01 taxstorex: txa ;store to screen sta ($01), Y jsr inc0103 ;move to next cellconwayloop: cmp #$e0 ;if not last cell, bne onecell ;process next cell lda $02 cmp #$05 bne onecell jmp starttick ;run next tick inc0103: lda $01 ;increment $01 cmp #$ff ;and $03 as 16-bit bne onlyinc01 ;pointers inc $02 inc $04onlyinc01: inc $01 lda $01 sta $03 rts The solution uses one cell thick border around square Petri dish as uninhabited dire land. Sample output contains 3 generations of the blinker and 5 of the glider: See Conway's Game of Life/ALGOL 68 APL2 (Dialog) Example in one line APL \ 1130 example (very old APL dialect via simulator) APL1130From: APL \ 1130 Samples The following APL \ 1130 code will need APL385 font installed to display correctly.

See Download APL TT Font ∇LIFE[⎕]∇[0] NG←LIFE CG; W[1] W←CG+(¯1⊖CG)+(1⊖CG)+(¯1⌽CG)+(1⌽CG)[2] W←W+(1⊖1⌽CG)+(¯1⊖1⌽CG)+(1⊖¯1⌽CG)+(¯1⊖¯1⌽CG)[3] NG←(3=W)+(CG∧4=W) ∇ RP←5 5⍴0 0 0 0 0 0 0 1 1 0 0 1 1 0 0 0 0 1 0 0 RP0 0 0 0 00 0 1 1 00 1 1 0 00 0 1 0 00 0 0 0 0 LIFE RP0 0 0 0 00 1 1 1 00 1 0 0 00 1 1 0 00 0 0 0 0 LIFE LIFE RP0 0 1 0 00 1 1 0 01 0 0 1 00 1 1 0 00 0 0 0 0 ..................................................

One interacts with the Game of Life by creating an initial configuration and observing how it evolves.

Although you should test your implementation on more complex examples such as the glider in a larger universe, show the action of the blinker (three adjoining cells in a row all alive), over three generations, in a 3 by 3 grid.

(1,4)=TRUERETURN'' Count the number of neighbours of the point i,j' (Assume i/j +/- 1 will not fall out of world)'FUNCTION count_neighbours(i%,j%) LOCAL count%,l% count%=0 FOR l%=-1 TO 1 IF world! (i%+l%,j%+1) count%=count%+1 ENDIF NEXT l% IF world! (i%+1,j%) count%=count%+1 ENDIF RETURN count%ENDFUNC'' Update the world one step'PROCEDURE update_world LOCAL i%,j% ' compute neighbour counts and store FOR i%=1 TO 30 FOR j%=1 TO 30 ns%(i%,j%)[email protected]_neighbours(i%,j%) NEXT j% NEXT i% ' update the world cells FOR i%=1 TO 30 FOR j%=1 TO 30 IF world!

Thus, while it is somewhat verbose, it fully simulates Conway's Game of Life and is relatively simple to expand to feature different starting shapes.

Define life(pattern) = Prgm Local x,y,nt,count,save,xl,yl,xh,yh Define nt(y,x) = when(pxl Test(y,x), 1, 0) {}→save set Graph("Axes", "Off")→save[1] set Graph("Grid", "Off")→save[2] set Graph("Labels", "Off")→save[3] Fn Off Plot Off Clr Draw If pattern = "blinker" Then 36→yl 40→yh 78→xl 82→xh Pxl On 36,80 Pxl On 38,80 Pxl On 40,80 Else If pattern = "glider" Then 30→yl 40→yh 76→xl 88→xh Pxl On 38,76 Pxl On 36,78 Pxl On 36,80 Pxl On 38,80 Pxl On 40,80 Else If pattern = "r" Then 38-5*2→yl 38+5*2→yh 80-5*2→xl 80+5*2→xh Pxl On 38,78 Pxl On 36,82 Pxl On 36,80 Pxl On 38,80 Pxl On 40,80 End If While get Key() = 0 © Expand upper-left corner to whole cell For y,yl,yh,2 For x,xl,xh,2 If pxl Test(y,x) Then Pxl On y+1,x Pxl On y+1,x+1 Pxl On y, x+1 Else Pxl Off y+1,x Pxl Off y+1,x+1 Pxl Off y, x+1 End If End For End For © Compute next generation For y,yl,yh,2 For x,xl,xh,2 nt(y-1,x-1) + nt(y-1,x) + nt(y-1,x+2) + nt(y,x-1) + nt(y+1,x+2) + nt(y+2,x-1) + nt(y+2,x+1) + nt(y+2,x+2) → count If count = 3 Then Pxl On y,x Else If count ≠ 2 Then Pxl Off y,x End If End For End For End While © Restore changed options set Graph("Axes", save[1]) set Graph("Grid", save[2]) set Graph("Labels", save[3])End Prgm Also see Conway's Game of Life/C Considering that the simplest implementation in C++ would lack any use of the object-oriented paradigm, this code was specifically written to demonstrate the various object-oriented features of C++.

;0 for indirect ldx # ;addressing stx randloop: lda $fe ;generate random and #

randfill: stx $01 ;$200 for indirect ldx #$02 ;addressing stx $02randloop: lda $fe ;generate random and #$01 ;pixels on the sta ($01), Y ;screen jsr inc0103 cmp #$00 bne randloop lda $02 cmp #$06 bne randloop clearmem: lda #$df ;set $07df-$0a20 sta $01 ;to $#00 lda #$07 sta $02clearbyte: lda #$00 sta ($01), Y jsr inc0103 cmp #$20 bne clearbyte lda $02 cmp #$0a bne clearbyte starttick:copyscreen: lda #$00 ;set up source sta $01 ;pointer at sta $03 ;$01/$02 and lda #$02 ;dest pointer sta $02 ;at $03/$04 lda #$08 sta $04 ldy #$00copybyte: lda ($01), Y ;copy pixel to sta ($03), Y ;back buffer jsr inc0103 ;increment pointers cmp #$00 ;check to see bne copybyte ;if we're at $600 lda $02 ;if so, we've cmp #$06 ;copied the bne copybyte ;entire screen conway: lda #$df ;apply conway rules sta $01 ;reset the pointer sta $03 ;to $#01df/$#07df lda #$01 ;($200 - $21) sta $02 ;($800 - $21) lda #$07 sta $04onecell: lda #$00 ;process one cell ldy #$01 ;upper cell clc adc ($03), Y ldy #$41 ;lower cell clc adc ($03), Ychkleft: tax ;check to see lda $01 ;if we're at the and #$1f ;left edge tay txa cpy #$1f beq rightcellsleftcells: ldy #$00 ;upper-left cell clc adc ($03), Y ldy #$20 ;left cell clc adc ($03), Y ldy #$40 ;lower-left cell clc adc ($03), Ychkright: tax ;check to see lda $01 ;if we're at the and #$1f ;right edge tay txa cpy #$1e beq evaluaterightcells: ldy #$02 ;upper-right cell clc adc ($03), Y ldy #$22 ;right cell clc adc ($03), Y ldy #$42 ;lower-right cell clc adc ($03), Yevaluate: ldx #$01 ;evaluate total ldy #$21 ;for current cell cmp #$03 ;3 = alive beq storex ldx #$00 cmp #$02 ;2 = alive if bne storex ;c = alive lda ($03), Y and #$01 taxstorex: txa ;store to screen sta ($01), Y jsr inc0103 ;move to next cellconwayloop: cmp #$e0 ;if not last cell, bne onecell ;process next cell lda $02 cmp #$05 bne onecell jmp starttick ;run next tick inc0103: lda $01 ;increment $01 cmp #$ff ;and $03 as 16-bit bne onlyinc01 ;pointers inc $02 inc $04onlyinc01: inc $01 lda $01 sta $03 rts The solution uses one cell thick border around square Petri dish as uninhabited dire land. Sample output contains 3 generations of the blinker and 5 of the glider: See Conway's Game of Life/ALGOL 68 APL2 (Dialog) Example in one line APL \ 1130 example (very old APL dialect via simulator) APL1130From: APL \ 1130 Samples The following APL \ 1130 code will need APL385 font installed to display correctly. See Download APL TT Font ∇LIFE[⎕]∇[0] NG←LIFE CG; W[1] W←CG+(¯1⊖CG)+(1⊖CG)+(¯1⌽CG)+(1⌽CG)[2] W←W+(1⊖1⌽CG)+(¯1⊖1⌽CG)+(1⊖¯1⌽CG)+(¯1⊖¯1⌽CG)[3] NG←(3=W)+(CG∧4=W) ∇ RP←5 5⍴0 0 0 0 0 0 0 1 1 0 0 1 1 0 0 0 0 1 0 0 RP0 0 0 0 00 0 1 1 00 1 1 0 00 0 1 0 00 0 0 0 0 LIFE RP0 0 0 0 00 1 1 1 00 1 0 0 00 1 1 0 00 0 0 0 0 LIFE LIFE RP0 0 1 0 00 1 1 0 01 0 0 1 00 1 1 0 00 0 0 0 0 .................................................. One interacts with the Game of Life by creating an initial configuration and observing how it evolves. Although you should test your implementation on more complex examples such as the glider in a larger universe, show the action of the blinker (three adjoining cells in a row all alive), over three generations, in a 3 by 3 grid. (1,4)=TRUERETURN'' Count the number of neighbours of the point i,j' (Assume i/j +/- 1 will not fall out of world)'FUNCTION count_neighbours(i%,j%) LOCAL count%,l% count%=0 FOR l%=-1 TO 1 IF world! (i%+l%,j%+1) count%=count%+1 ENDIF NEXT l% IF world! (i%+1,j%) count%=count%+1 ENDIF RETURN count%ENDFUNC'' Update the world one step'PROCEDURE update_world LOCAL i%,j% ' compute neighbour counts and store FOR i%=1 TO 30 FOR j%=1 TO 30 ns%(i%,j%)[email protected]_neighbours(i%,j%) NEXT j% NEXT i% ' update the world cells FOR i%=1 TO 30 FOR j%=1 TO 30 IF world!

||

randfill: stx $01 ;$200 for indirect ldx #$02 ;addressing stx $02randloop: lda $fe ;generate random and #$01 ;pixels on the sta ($01), Y ;screen jsr inc0103 cmp #$00 bne randloop lda $02 cmp #$06 bne randloop clearmem: lda #$df ;set $07df-$0a20 sta $01 ;to $#00 lda #$07 sta $02clearbyte: lda #$00 sta ($01), Y jsr inc0103 cmp #$20 bne clearbyte lda $02 cmp #$0a bne clearbyte starttick:copyscreen: lda #$00 ;set up source sta $01 ;pointer at sta $03 ;$01/$02 and lda #$02 ;dest pointer sta $02 ;at $03/$04 lda #$08 sta $04 ldy #$00copybyte: lda ($01), Y ;copy pixel to sta ($03), Y ;back buffer jsr inc0103 ;increment pointers cmp #$00 ;check to see bne copybyte ;if we're at $600 lda $02 ;if so, we've cmp #$06 ;copied the bne copybyte ;entire screen conway: lda #$df ;apply conway rules sta $01 ;reset the pointer sta $03 ;to $#01df/$#07df lda #$01 ;($200 - $21) sta $02 ;($800 - $21) lda #$07 sta $04onecell: lda #$00 ;process one cell ldy #$01 ;upper cell clc adc ($03), Y ldy #$41 ;lower cell clc adc ($03), Ychkleft: tax ;check to see lda $01 ;if we're at the and #$1f ;left edge tay txa cpy #$1f beq rightcellsleftcells: ldy #$00 ;upper-left cell clc adc ($03), Y ldy #$20 ;left cell clc adc ($03), Y ldy #$40 ;lower-left cell clc adc ($03), Ychkright: tax ;check to see lda $01 ;if we're at the and #$1f ;right edge tay txa cpy #$1e beq evaluaterightcells: ldy #$02 ;upper-right cell clc adc ($03), Y ldy #$22 ;right cell clc adc ($03), Y ldy #$42 ;lower-right cell clc adc ($03), Yevaluate: ldx #$01 ;evaluate total ldy #$21 ;for current cell cmp #$03 ;3 = alive beq storex ldx #$00 cmp #$02 ;2 = alive if bne storex ;c = alive lda ($03), Y and #$01 taxstorex: txa ;store to screen sta ($01), Y jsr inc0103 ;move to next cellconwayloop: cmp #$e0 ;if not last cell, bne onecell ;process next cell lda $02 cmp #$05 bne onecell jmp starttick ;run next tick inc0103: lda $01 ;increment $01 cmp #$ff ;and $03 as 16-bit bne onlyinc01 ;pointers inc $02 inc $04onlyinc01: inc $01 lda $01 sta $03 rts The solution uses one cell thick border around square Petri dish as uninhabited dire land. Sample output contains 3 generations of the blinker and 5 of the glider: See Conway's Game of Life/ALGOL 68 APL2 (Dialog) Example in one line APL \ 1130 example (very old APL dialect via simulator) APL1130From: APL \ 1130 Samples The following APL \ 1130 code will need APL385 font installed to display correctly.

See Download APL TT Font ∇LIFE[⎕]∇[0] NG←LIFE CG; W[1] W←CG+(¯1⊖CG)+(1⊖CG)+(¯1⌽CG)+(1⌽CG)[2] W←W+(1⊖1⌽CG)+(¯1⊖1⌽CG)+(1⊖¯1⌽CG)+(¯1⊖¯1⌽CG)[3] NG←(3=W)+(CG∧4=W) ∇ RP←5 5⍴0 0 0 0 0 0 0 1 1 0 0 1 1 0 0 0 0 1 0 0 RP0 0 0 0 00 0 1 1 00 1 1 0 00 0 1 0 00 0 0 0 0 LIFE RP0 0 0 0 00 1 1 1 00 1 0 0 00 1 1 0 00 0 0 0 0 LIFE LIFE RP0 0 1 0 00 1 1 0 01 0 0 1 00 1 1 0 00 0 0 0 0 ..................................................

One interacts with the Game of Life by creating an initial configuration and observing how it evolves.

Although you should test your implementation on more complex examples such as the glider in a larger universe, show the action of the blinker (three adjoining cells in a row all alive), over three generations, in a 3 by 3 grid.

(1,4)=TRUERETURN'' Count the number of neighbours of the point i,j' (Assume i/j +/- 1 will not fall out of world)'FUNCTION count_neighbours(i%,j%) LOCAL count%,l% count%=0 FOR l%=-1 TO 1 IF world! (i%+l%,j%+1) count%=count%+1 ENDIF NEXT l% IF world! (i%+1,j%) count%=count%+1 ENDIF RETURN count%ENDFUNC'' Update the world one step'PROCEDURE update_world LOCAL i%,j% ' compute neighbour counts and store FOR i%=1 TO 30 FOR j%=1 TO 30 ns%(i%,j%)[email protected]_neighbours(i%,j%) NEXT j% NEXT i% ' update the world cells FOR i%=1 TO 30 FOR j%=1 TO 30 IF world!

Thus, while it is somewhat verbose, it fully simulates Conway's Game of Life and is relatively simple to expand to feature different starting shapes.

Define life(pattern) = Prgm Local x,y,nt,count,save,xl,yl,xh,yh Define nt(y,x) = when(pxl Test(y,x), 1, 0) {}→save set Graph("Axes", "Off")→save[1] set Graph("Grid", "Off")→save[2] set Graph("Labels", "Off")→save[3] Fn Off Plot Off Clr Draw If pattern = "blinker" Then 36→yl 40→yh 78→xl 82→xh Pxl On 36,80 Pxl On 38,80 Pxl On 40,80 Else If pattern = "glider" Then 30→yl 40→yh 76→xl 88→xh Pxl On 38,76 Pxl On 36,78 Pxl On 36,80 Pxl On 38,80 Pxl On 40,80 Else If pattern = "r" Then 38-5*2→yl 38+5*2→yh 80-5*2→xl 80+5*2→xh Pxl On 38,78 Pxl On 36,82 Pxl On 36,80 Pxl On 38,80 Pxl On 40,80 End If While get Key() = 0 © Expand upper-left corner to whole cell For y,yl,yh,2 For x,xl,xh,2 If pxl Test(y,x) Then Pxl On y+1,x Pxl On y+1,x+1 Pxl On y, x+1 Else Pxl Off y+1,x Pxl Off y+1,x+1 Pxl Off y, x+1 End If End For End For © Compute next generation For y,yl,yh,2 For x,xl,xh,2 nt(y-1,x-1) + nt(y-1,x) + nt(y-1,x+2) + nt(y,x-1) + nt(y+1,x+2) + nt(y+2,x-1) + nt(y+2,x+1) + nt(y+2,x+2) → count If count = 3 Then Pxl On y,x Else If count ≠ 2 Then Pxl Off y,x End If End For End For End While © Restore changed options set Graph("Axes", save[1]) set Graph("Grid", save[2]) set Graph("Labels", save[3])End Prgm Also see Conway's Game of Life/C Considering that the simplest implementation in C++ would lack any use of the object-oriented paradigm, this code was specifically written to demonstrate the various object-oriented features of C++.

;pixels on the sta (

randfill: stx $01 ;$200 for indirect ldx #$02 ;addressing stx $02randloop: lda $fe ;generate random and #$01 ;pixels on the sta ($01), Y ;screen jsr inc0103 cmp #$00 bne randloop lda $02 cmp #$06 bne randloop clearmem: lda #$df ;set $07df-$0a20 sta $01 ;to $#00 lda #$07 sta $02clearbyte: lda #$00 sta ($01), Y jsr inc0103 cmp #$20 bne clearbyte lda $02 cmp #$0a bne clearbyte starttick:copyscreen: lda #$00 ;set up source sta $01 ;pointer at sta $03 ;$01/$02 and lda #$02 ;dest pointer sta $02 ;at $03/$04 lda #$08 sta $04 ldy #$00copybyte: lda ($01), Y ;copy pixel to sta ($03), Y ;back buffer jsr inc0103 ;increment pointers cmp #$00 ;check to see bne copybyte ;if we're at $600 lda $02 ;if so, we've cmp #$06 ;copied the bne copybyte ;entire screen conway: lda #$df ;apply conway rules sta $01 ;reset the pointer sta $03 ;to $#01df/$#07df lda #$01 ;($200 - $21) sta $02 ;($800 - $21) lda #$07 sta $04onecell: lda #$00 ;process one cell ldy #$01 ;upper cell clc adc ($03), Y ldy #$41 ;lower cell clc adc ($03), Ychkleft: tax ;check to see lda $01 ;if we're at the and #$1f ;left edge tay txa cpy #$1f beq rightcellsleftcells: ldy #$00 ;upper-left cell clc adc ($03), Y ldy #$20 ;left cell clc adc ($03), Y ldy #$40 ;lower-left cell clc adc ($03), Ychkright: tax ;check to see lda $01 ;if we're at the and #$1f ;right edge tay txa cpy #$1e beq evaluaterightcells: ldy #$02 ;upper-right cell clc adc ($03), Y ldy #$22 ;right cell clc adc ($03), Y ldy #$42 ;lower-right cell clc adc ($03), Yevaluate: ldx #$01 ;evaluate total ldy #$21 ;for current cell cmp #$03 ;3 = alive beq storex ldx #$00 cmp #$02 ;2 = alive if bne storex ;c = alive lda ($03), Y and #$01 taxstorex: txa ;store to screen sta ($01), Y jsr inc0103 ;move to next cellconwayloop: cmp #$e0 ;if not last cell, bne onecell ;process next cell lda $02 cmp #$05 bne onecell jmp starttick ;run next tick inc0103: lda $01 ;increment $01 cmp #$ff ;and $03 as 16-bit bne onlyinc01 ;pointers inc $02 inc $04onlyinc01: inc $01 lda $01 sta $03 rts The solution uses one cell thick border around square Petri dish as uninhabited dire land. Sample output contains 3 generations of the blinker and 5 of the glider: See Conway's Game of Life/ALGOL 68 APL2 (Dialog) Example in one line APL \ 1130 example (very old APL dialect via simulator) APL1130From: APL \ 1130 Samples The following APL \ 1130 code will need APL385 font installed to display correctly. See Download APL TT Font ∇LIFE[⎕]∇[0] NG←LIFE CG; W[1] W←CG+(¯1⊖CG)+(1⊖CG)+(¯1⌽CG)+(1⌽CG)[2] W←W+(1⊖1⌽CG)+(¯1⊖1⌽CG)+(1⊖¯1⌽CG)+(¯1⊖¯1⌽CG)[3] NG←(3=W)+(CG∧4=W) ∇ RP←5 5⍴0 0 0 0 0 0 0 1 1 0 0 1 1 0 0 0 0 1 0 0 RP0 0 0 0 00 0 1 1 00 1 1 0 00 0 1 0 00 0 0 0 0 LIFE RP0 0 0 0 00 1 1 1 00 1 0 0 00 1 1 0 00 0 0 0 0 LIFE LIFE RP0 0 1 0 00 1 1 0 01 0 0 1 00 1 1 0 00 0 0 0 0 .................................................. One interacts with the Game of Life by creating an initial configuration and observing how it evolves. Although you should test your implementation on more complex examples such as the glider in a larger universe, show the action of the blinker (three adjoining cells in a row all alive), over three generations, in a 3 by 3 grid. (1,4)=TRUERETURN'' Count the number of neighbours of the point i,j' (Assume i/j +/- 1 will not fall out of world)'FUNCTION count_neighbours(i%,j%) LOCAL count%,l% count%=0 FOR l%=-1 TO 1 IF world! (i%+l%,j%+1) count%=count%+1 ENDIF NEXT l% IF world! (i%+1,j%) count%=count%+1 ENDIF RETURN count%ENDFUNC'' Update the world one step'PROCEDURE update_world LOCAL i%,j% ' compute neighbour counts and store FOR i%=1 TO 30 FOR j%=1 TO 30 ns%(i%,j%)[email protected]_neighbours(i%,j%) NEXT j% NEXT i% ' update the world cells FOR i%=1 TO 30 FOR j%=1 TO 30 IF world!

||

randfill: stx $01 ;$200 for indirect ldx #$02 ;addressing stx $02randloop: lda $fe ;generate random and #$01 ;pixels on the sta ($01), Y ;screen jsr inc0103 cmp #$00 bne randloop lda $02 cmp #$06 bne randloop clearmem: lda #$df ;set $07df-$0a20 sta $01 ;to $#00 lda #$07 sta $02clearbyte: lda #$00 sta ($01), Y jsr inc0103 cmp #$20 bne clearbyte lda $02 cmp #$0a bne clearbyte starttick:copyscreen: lda #$00 ;set up source sta $01 ;pointer at sta $03 ;$01/$02 and lda #$02 ;dest pointer sta $02 ;at $03/$04 lda #$08 sta $04 ldy #$00copybyte: lda ($01), Y ;copy pixel to sta ($03), Y ;back buffer jsr inc0103 ;increment pointers cmp #$00 ;check to see bne copybyte ;if we're at $600 lda $02 ;if so, we've cmp #$06 ;copied the bne copybyte ;entire screen conway: lda #$df ;apply conway rules sta $01 ;reset the pointer sta $03 ;to $#01df/$#07df lda #$01 ;($200 - $21) sta $02 ;($800 - $21) lda #$07 sta $04onecell: lda #$00 ;process one cell ldy #$01 ;upper cell clc adc ($03), Y ldy #$41 ;lower cell clc adc ($03), Ychkleft: tax ;check to see lda $01 ;if we're at the and #$1f ;left edge tay txa cpy #$1f beq rightcellsleftcells: ldy #$00 ;upper-left cell clc adc ($03), Y ldy #$20 ;left cell clc adc ($03), Y ldy #$40 ;lower-left cell clc adc ($03), Ychkright: tax ;check to see lda $01 ;if we're at the and #$1f ;right edge tay txa cpy #$1e beq evaluaterightcells: ldy #$02 ;upper-right cell clc adc ($03), Y ldy #$22 ;right cell clc adc ($03), Y ldy #$42 ;lower-right cell clc adc ($03), Yevaluate: ldx #$01 ;evaluate total ldy #$21 ;for current cell cmp #$03 ;3 = alive beq storex ldx #$00 cmp #$02 ;2 = alive if bne storex ;c = alive lda ($03), Y and #$01 taxstorex: txa ;store to screen sta ($01), Y jsr inc0103 ;move to next cellconwayloop: cmp #$e0 ;if not last cell, bne onecell ;process next cell lda $02 cmp #$05 bne onecell jmp starttick ;run next tick inc0103: lda $01 ;increment $01 cmp #$ff ;and $03 as 16-bit bne onlyinc01 ;pointers inc $02 inc $04onlyinc01: inc $01 lda $01 sta $03 rts The solution uses one cell thick border around square Petri dish as uninhabited dire land. Sample output contains 3 generations of the blinker and 5 of the glider: See Conway's Game of Life/ALGOL 68 APL2 (Dialog) Example in one line APL \ 1130 example (very old APL dialect via simulator) APL1130From: APL \ 1130 Samples The following APL \ 1130 code will need APL385 font installed to display correctly.

See Download APL TT Font ∇LIFE[⎕]∇[0] NG←LIFE CG; W[1] W←CG+(¯1⊖CG)+(1⊖CG)+(¯1⌽CG)+(1⌽CG)[2] W←W+(1⊖1⌽CG)+(¯1⊖1⌽CG)+(1⊖¯1⌽CG)+(¯1⊖¯1⌽CG)[3] NG←(3=W)+(CG∧4=W) ∇ RP←5 5⍴0 0 0 0 0 0 0 1 1 0 0 1 1 0 0 0 0 1 0 0 RP0 0 0 0 00 0 1 1 00 1 1 0 00 0 1 0 00 0 0 0 0 LIFE RP0 0 0 0 00 1 1 1 00 1 0 0 00 1 1 0 00 0 0 0 0 LIFE LIFE RP0 0 1 0 00 1 1 0 01 0 0 1 00 1 1 0 00 0 0 0 0 ..................................................

One interacts with the Game of Life by creating an initial configuration and observing how it evolves.

Although you should test your implementation on more complex examples such as the glider in a larger universe, show the action of the blinker (three adjoining cells in a row all alive), over three generations, in a 3 by 3 grid.

(1,4)=TRUERETURN'' Count the number of neighbours of the point i,j' (Assume i/j +/- 1 will not fall out of world)'FUNCTION count_neighbours(i%,j%) LOCAL count%,l% count%=0 FOR l%=-1 TO 1 IF world! (i%+l%,j%+1) count%=count%+1 ENDIF NEXT l% IF world! (i%+1,j%) count%=count%+1 ENDIF RETURN count%ENDFUNC'' Update the world one step'PROCEDURE update_world LOCAL i%,j% ' compute neighbour counts and store FOR i%=1 TO 30 FOR j%=1 TO 30 ns%(i%,j%)[email protected]_neighbours(i%,j%) NEXT j% NEXT i% ' update the world cells FOR i%=1 TO 30 FOR j%=1 TO 30 IF world!

Thus, while it is somewhat verbose, it fully simulates Conway's Game of Life and is relatively simple to expand to feature different starting shapes.

Define life(pattern) = Prgm Local x,y,nt,count,save,xl,yl,xh,yh Define nt(y,x) = when(pxl Test(y,x), 1, 0) {}→save set Graph("Axes", "Off")→save[1] set Graph("Grid", "Off")→save[2] set Graph("Labels", "Off")→save[3] Fn Off Plot Off Clr Draw If pattern = "blinker" Then 36→yl 40→yh 78→xl 82→xh Pxl On 36,80 Pxl On 38,80 Pxl On 40,80 Else If pattern = "glider" Then 30→yl 40→yh 76→xl 88→xh Pxl On 38,76 Pxl On 36,78 Pxl On 36,80 Pxl On 38,80 Pxl On 40,80 Else If pattern = "r" Then 38-5*2→yl 38+5*2→yh 80-5*2→xl 80+5*2→xh Pxl On 38,78 Pxl On 36,82 Pxl On 36,80 Pxl On 38,80 Pxl On 40,80 End If While get Key() = 0 © Expand upper-left corner to whole cell For y,yl,yh,2 For x,xl,xh,2 If pxl Test(y,x) Then Pxl On y+1,x Pxl On y+1,x+1 Pxl On y, x+1 Else Pxl Off y+1,x Pxl Off y+1,x+1 Pxl Off y, x+1 End If End For End For © Compute next generation For y,yl,yh,2 For x,xl,xh,2 nt(y-1,x-1) + nt(y-1,x) + nt(y-1,x+2) + nt(y,x-1) + nt(y+1,x+2) + nt(y+2,x-1) + nt(y+2,x+1) + nt(y+2,x+2) → count If count = 3 Then Pxl On y,x Else If count ≠ 2 Then Pxl Off y,x End If End For End For End While © Restore changed options set Graph("Axes", save[1]) set Graph("Grid", save[2]) set Graph("Labels", save[3])End Prgm Also see Conway's Game of Life/C Considering that the simplest implementation in C++ would lack any use of the object-oriented paradigm, this code was specifically written to demonstrate the various object-oriented features of C++.

), Y ;screen jsr inc0103 cmp #

randfill: stx

randfill: stx $01 ;$200 for indirect ldx #$02 ;addressing stx $02randloop: lda $fe ;generate random and #$01 ;pixels on the sta ($01), Y ;screen jsr inc0103 cmp #$00 bne randloop lda $02 cmp #$06 bne randloop clearmem: lda #$df ;set $07df-$0a20 sta $01 ;to $#00 lda #$07 sta $02clearbyte: lda #$00 sta ($01), Y jsr inc0103 cmp #$20 bne clearbyte lda $02 cmp #$0a bne clearbyte starttick:copyscreen: lda #$00 ;set up source sta $01 ;pointer at sta $03 ;$01/$02 and lda #$02 ;dest pointer sta $02 ;at $03/$04 lda #$08 sta $04 ldy #$00copybyte: lda ($01), Y ;copy pixel to sta ($03), Y ;back buffer jsr inc0103 ;increment pointers cmp #$00 ;check to see bne copybyte ;if we're at $600 lda $02 ;if so, we've cmp #$06 ;copied the bne copybyte ;entire screen conway: lda #$df ;apply conway rules sta $01 ;reset the pointer sta $03 ;to $#01df/$#07df lda #$01 ;($200 - $21) sta $02 ;($800 - $21) lda #$07 sta $04onecell: lda #$00 ;process one cell ldy #$01 ;upper cell clc adc ($03), Y ldy #$41 ;lower cell clc adc ($03), Ychkleft: tax ;check to see lda $01 ;if we're at the and #$1f ;left edge tay txa cpy #$1f beq rightcellsleftcells: ldy #$00 ;upper-left cell clc adc ($03), Y ldy #$20 ;left cell clc adc ($03), Y ldy #$40 ;lower-left cell clc adc ($03), Ychkright: tax ;check to see lda $01 ;if we're at the and #$1f ;right edge tay txa cpy #$1e beq evaluaterightcells: ldy #$02 ;upper-right cell clc adc ($03), Y ldy #$22 ;right cell clc adc ($03), Y ldy #$42 ;lower-right cell clc adc ($03), Yevaluate: ldx #$01 ;evaluate total ldy #$21 ;for current cell cmp #$03 ;3 = alive beq storex ldx #$00 cmp #$02 ;2 = alive if bne storex ;c = alive lda ($03), Y and #$01 taxstorex: txa ;store to screen sta ($01), Y jsr inc0103 ;move to next cellconwayloop: cmp #$e0 ;if not last cell, bne onecell ;process next cell lda $02 cmp #$05 bne onecell jmp starttick ;run next tick inc0103: lda $01 ;increment $01 cmp #$ff ;and $03 as 16-bit bne onlyinc01 ;pointers inc $02 inc $04onlyinc01: inc $01 lda $01 sta $03 rts The solution uses one cell thick border around square Petri dish as uninhabited dire land. Sample output contains 3 generations of the blinker and 5 of the glider: See Conway's Game of Life/ALGOL 68 APL2 (Dialog) Example in one line APL \ 1130 example (very old APL dialect via simulator) APL1130From: APL \ 1130 Samples The following APL \ 1130 code will need APL385 font installed to display correctly. See Download APL TT Font ∇LIFE[⎕]∇[0] NG←LIFE CG; W[1] W←CG+(¯1⊖CG)+(1⊖CG)+(¯1⌽CG)+(1⌽CG)[2] W←W+(1⊖1⌽CG)+(¯1⊖1⌽CG)+(1⊖¯1⌽CG)+(¯1⊖¯1⌽CG)[3] NG←(3=W)+(CG∧4=W) ∇ RP←5 5⍴0 0 0 0 0 0 0 1 1 0 0 1 1 0 0 0 0 1 0 0 RP0 0 0 0 00 0 1 1 00 1 1 0 00 0 1 0 00 0 0 0 0 LIFE RP0 0 0 0 00 1 1 1 00 1 0 0 00 1 1 0 00 0 0 0 0 LIFE LIFE RP0 0 1 0 00 1 1 0 01 0 0 1 00 1 1 0 00 0 0 0 0 .................................................. One interacts with the Game of Life by creating an initial configuration and observing how it evolves. Although you should test your implementation on more complex examples such as the glider in a larger universe, show the action of the blinker (three adjoining cells in a row all alive), over three generations, in a 3 by 3 grid. (1,4)=TRUERETURN'' Count the number of neighbours of the point i,j' (Assume i/j +/- 1 will not fall out of world)'FUNCTION count_neighbours(i%,j%) LOCAL count%,l% count%=0 FOR l%=-1 TO 1 IF world! (i%+l%,j%+1) count%=count%+1 ENDIF NEXT l% IF world! (i%+1,j%) count%=count%+1 ENDIF RETURN count%ENDFUNC'' Update the world one step'PROCEDURE update_world LOCAL i%,j% ' compute neighbour counts and store FOR i%=1 TO 30 FOR j%=1 TO 30 ns%(i%,j%)[email protected]_neighbours(i%,j%) NEXT j% NEXT i% ' update the world cells FOR i%=1 TO 30 FOR j%=1 TO 30 IF world!

||

randfill: stx $01 ;$200 for indirect ldx #$02 ;addressing stx $02randloop: lda $fe ;generate random and #$01 ;pixels on the sta ($01), Y ;screen jsr inc0103 cmp #$00 bne randloop lda $02 cmp #$06 bne randloop clearmem: lda #$df ;set $07df-$0a20 sta $01 ;to $#00 lda #$07 sta $02clearbyte: lda #$00 sta ($01), Y jsr inc0103 cmp #$20 bne clearbyte lda $02 cmp #$0a bne clearbyte starttick:copyscreen: lda #$00 ;set up source sta $01 ;pointer at sta $03 ;$01/$02 and lda #$02 ;dest pointer sta $02 ;at $03/$04 lda #$08 sta $04 ldy #$00copybyte: lda ($01), Y ;copy pixel to sta ($03), Y ;back buffer jsr inc0103 ;increment pointers cmp #$00 ;check to see bne copybyte ;if we're at $600 lda $02 ;if so, we've cmp #$06 ;copied the bne copybyte ;entire screen conway: lda #$df ;apply conway rules sta $01 ;reset the pointer sta $03 ;to $#01df/$#07df lda #$01 ;($200 - $21) sta $02 ;($800 - $21) lda #$07 sta $04onecell: lda #$00 ;process one cell ldy #$01 ;upper cell clc adc ($03), Y ldy #$41 ;lower cell clc adc ($03), Ychkleft: tax ;check to see lda $01 ;if we're at the and #$1f ;left edge tay txa cpy #$1f beq rightcellsleftcells: ldy #$00 ;upper-left cell clc adc ($03), Y ldy #$20 ;left cell clc adc ($03), Y ldy #$40 ;lower-left cell clc adc ($03), Ychkright: tax ;check to see lda $01 ;if we're at the and #$1f ;right edge tay txa cpy #$1e beq evaluaterightcells: ldy #$02 ;upper-right cell clc adc ($03), Y ldy #$22 ;right cell clc adc ($03), Y ldy #$42 ;lower-right cell clc adc ($03), Yevaluate: ldx #$01 ;evaluate total ldy #$21 ;for current cell cmp #$03 ;3 = alive beq storex ldx #$00 cmp #$02 ;2 = alive if bne storex ;c = alive lda ($03), Y and #$01 taxstorex: txa ;store to screen sta ($01), Y jsr inc0103 ;move to next cellconwayloop: cmp #$e0 ;if not last cell, bne onecell ;process next cell lda $02 cmp #$05 bne onecell jmp starttick ;run next tick inc0103: lda $01 ;increment $01 cmp #$ff ;and $03 as 16-bit bne onlyinc01 ;pointers inc $02 inc $04onlyinc01: inc $01 lda $01 sta $03 rts The solution uses one cell thick border around square Petri dish as uninhabited dire land. Sample output contains 3 generations of the blinker and 5 of the glider: See Conway's Game of Life/ALGOL 68 APL2 (Dialog) Example in one line APL \ 1130 example (very old APL dialect via simulator) APL1130From: APL \ 1130 Samples The following APL \ 1130 code will need APL385 font installed to display correctly.

See Download APL TT Font ∇LIFE[⎕]∇[0] NG←LIFE CG; W[1] W←CG+(¯1⊖CG)+(1⊖CG)+(¯1⌽CG)+(1⌽CG)[2] W←W+(1⊖1⌽CG)+(¯1⊖1⌽CG)+(1⊖¯1⌽CG)+(¯1⊖¯1⌽CG)[3] NG←(3=W)+(CG∧4=W) ∇ RP←5 5⍴0 0 0 0 0 0 0 1 1 0 0 1 1 0 0 0 0 1 0 0 RP0 0 0 0 00 0 1 1 00 1 1 0 00 0 1 0 00 0 0 0 0 LIFE RP0 0 0 0 00 1 1 1 00 1 0 0 00 1 1 0 00 0 0 0 0 LIFE LIFE RP0 0 1 0 00 1 1 0 01 0 0 1 00 1 1 0 00 0 0 0 0 ..................................................

One interacts with the Game of Life by creating an initial configuration and observing how it evolves.

Although you should test your implementation on more complex examples such as the glider in a larger universe, show the action of the blinker (three adjoining cells in a row all alive), over three generations, in a 3 by 3 grid.

(1,4)=TRUERETURN'' Count the number of neighbours of the point i,j' (Assume i/j +/- 1 will not fall out of world)'FUNCTION count_neighbours(i%,j%) LOCAL count%,l% count%=0 FOR l%=-1 TO 1 IF world! (i%+l%,j%+1) count%=count%+1 ENDIF NEXT l% IF world! (i%+1,j%) count%=count%+1 ENDIF RETURN count%ENDFUNC'' Update the world one step'PROCEDURE update_world LOCAL i%,j% ' compute neighbour counts and store FOR i%=1 TO 30 FOR j%=1 TO 30 ns%(i%,j%)[email protected]_neighbours(i%,j%) NEXT j% NEXT i% ' update the world cells FOR i%=1 TO 30 FOR j%=1 TO 30 IF world!

Thus, while it is somewhat verbose, it fully simulates Conway's Game of Life and is relatively simple to expand to feature different starting shapes.

Define life(pattern) = Prgm Local x,y,nt,count,save,xl,yl,xh,yh Define nt(y,x) = when(pxl Test(y,x), 1, 0) {}→save set Graph("Axes", "Off")→save[1] set Graph("Grid", "Off")→save[2] set Graph("Labels", "Off")→save[3] Fn Off Plot Off Clr Draw If pattern = "blinker" Then 36→yl 40→yh 78→xl 82→xh Pxl On 36,80 Pxl On 38,80 Pxl On 40,80 Else If pattern = "glider" Then 30→yl 40→yh 76→xl 88→xh Pxl On 38,76 Pxl On 36,78 Pxl On 36,80 Pxl On 38,80 Pxl On 40,80 Else If pattern = "r" Then 38-5*2→yl 38+5*2→yh 80-5*2→xl 80+5*2→xh Pxl On 38,78 Pxl On 36,82 Pxl On 36,80 Pxl On 38,80 Pxl On 40,80 End If While get Key() = 0 © Expand upper-left corner to whole cell For y,yl,yh,2 For x,xl,xh,2 If pxl Test(y,x) Then Pxl On y+1,x Pxl On y+1,x+1 Pxl On y, x+1 Else Pxl Off y+1,x Pxl Off y+1,x+1 Pxl Off y, x+1 End If End For End For © Compute next generation For y,yl,yh,2 For x,xl,xh,2 nt(y-1,x-1) + nt(y-1,x) + nt(y-1,x+2) + nt(y,x-1) + nt(y+1,x+2) + nt(y+2,x-1) + nt(y+2,x+1) + nt(y+2,x+2) → count If count = 3 Then Pxl On y,x Else If count ≠ 2 Then Pxl Off y,x End If End For End For End While © Restore changed options set Graph("Axes", save[1]) set Graph("Grid", save[2]) set Graph("Labels", save[3])End Prgm Also see Conway's Game of Life/C Considering that the simplest implementation in C++ would lack any use of the object-oriented paradigm, this code was specifically written to demonstrate the various object-oriented features of C++.

;0 for indirect ldx # ;addressing stx randloop: lda $fe ;generate random and #

randfill: stx $01 ;$200 for indirect ldx #$02 ;addressing stx $02randloop: lda $fe ;generate random and #$01 ;pixels on the sta ($01), Y ;screen jsr inc0103 cmp #$00 bne randloop lda $02 cmp #$06 bne randloop clearmem: lda #$df ;set $07df-$0a20 sta $01 ;to $#00 lda #$07 sta $02clearbyte: lda #$00 sta ($01), Y jsr inc0103 cmp #$20 bne clearbyte lda $02 cmp #$0a bne clearbyte starttick:copyscreen: lda #$00 ;set up source sta $01 ;pointer at sta $03 ;$01/$02 and lda #$02 ;dest pointer sta $02 ;at $03/$04 lda #$08 sta $04 ldy #$00copybyte: lda ($01), Y ;copy pixel to sta ($03), Y ;back buffer jsr inc0103 ;increment pointers cmp #$00 ;check to see bne copybyte ;if we're at $600 lda $02 ;if so, we've cmp #$06 ;copied the bne copybyte ;entire screen conway: lda #$df ;apply conway rules sta $01 ;reset the pointer sta $03 ;to $#01df/$#07df lda #$01 ;($200 - $21) sta $02 ;($800 - $21) lda #$07 sta $04onecell: lda #$00 ;process one cell ldy #$01 ;upper cell clc adc ($03), Y ldy #$41 ;lower cell clc adc ($03), Ychkleft: tax ;check to see lda $01 ;if we're at the and #$1f ;left edge tay txa cpy #$1f beq rightcellsleftcells: ldy #$00 ;upper-left cell clc adc ($03), Y ldy #$20 ;left cell clc adc ($03), Y ldy #$40 ;lower-left cell clc adc ($03), Ychkright: tax ;check to see lda $01 ;if we're at the and #$1f ;right edge tay txa cpy #$1e beq evaluaterightcells: ldy #$02 ;upper-right cell clc adc ($03), Y ldy #$22 ;right cell clc adc ($03), Y ldy #$42 ;lower-right cell clc adc ($03), Yevaluate: ldx #$01 ;evaluate total ldy #$21 ;for current cell cmp #$03 ;3 = alive beq storex ldx #$00 cmp #$02 ;2 = alive if bne storex ;c = alive lda ($03), Y and #$01 taxstorex: txa ;store to screen sta ($01), Y jsr inc0103 ;move to next cellconwayloop: cmp #$e0 ;if not last cell, bne onecell ;process next cell lda $02 cmp #$05 bne onecell jmp starttick ;run next tick inc0103: lda $01 ;increment $01 cmp #$ff ;and $03 as 16-bit bne onlyinc01 ;pointers inc $02 inc $04onlyinc01: inc $01 lda $01 sta $03 rts The solution uses one cell thick border around square Petri dish as uninhabited dire land. Sample output contains 3 generations of the blinker and 5 of the glider: See Conway's Game of Life/ALGOL 68 APL2 (Dialog) Example in one line APL \ 1130 example (very old APL dialect via simulator) APL1130From: APL \ 1130 Samples The following APL \ 1130 code will need APL385 font installed to display correctly. See Download APL TT Font ∇LIFE[⎕]∇[0] NG←LIFE CG; W[1] W←CG+(¯1⊖CG)+(1⊖CG)+(¯1⌽CG)+(1⌽CG)[2] W←W+(1⊖1⌽CG)+(¯1⊖1⌽CG)+(1⊖¯1⌽CG)+(¯1⊖¯1⌽CG)[3] NG←(3=W)+(CG∧4=W) ∇ RP←5 5⍴0 0 0 0 0 0 0 1 1 0 0 1 1 0 0 0 0 1 0 0 RP0 0 0 0 00 0 1 1 00 1 1 0 00 0 1 0 00 0 0 0 0 LIFE RP0 0 0 0 00 1 1 1 00 1 0 0 00 1 1 0 00 0 0 0 0 LIFE LIFE RP0 0 1 0 00 1 1 0 01 0 0 1 00 1 1 0 00 0 0 0 0 .................................................. One interacts with the Game of Life by creating an initial configuration and observing how it evolves. Although you should test your implementation on more complex examples such as the glider in a larger universe, show the action of the blinker (three adjoining cells in a row all alive), over three generations, in a 3 by 3 grid. (1,4)=TRUERETURN'' Count the number of neighbours of the point i,j' (Assume i/j +/- 1 will not fall out of world)'FUNCTION count_neighbours(i%,j%) LOCAL count%,l% count%=0 FOR l%=-1 TO 1 IF world! (i%+l%,j%+1) count%=count%+1 ENDIF NEXT l% IF world! (i%+1,j%) count%=count%+1 ENDIF RETURN count%ENDFUNC'' Update the world one step'PROCEDURE update_world LOCAL i%,j% ' compute neighbour counts and store FOR i%=1 TO 30 FOR j%=1 TO 30 ns%(i%,j%)[email protected]_neighbours(i%,j%) NEXT j% NEXT i% ' update the world cells FOR i%=1 TO 30 FOR j%=1 TO 30 IF world!

||

randfill: stx $01 ;$200 for indirect ldx #$02 ;addressing stx $02randloop: lda $fe ;generate random and #$01 ;pixels on the sta ($01), Y ;screen jsr inc0103 cmp #$00 bne randloop lda $02 cmp #$06 bne randloop clearmem: lda #$df ;set $07df-$0a20 sta $01 ;to $#00 lda #$07 sta $02clearbyte: lda #$00 sta ($01), Y jsr inc0103 cmp #$20 bne clearbyte lda $02 cmp #$0a bne clearbyte starttick:copyscreen: lda #$00 ;set up source sta $01 ;pointer at sta $03 ;$01/$02 and lda #$02 ;dest pointer sta $02 ;at $03/$04 lda #$08 sta $04 ldy #$00copybyte: lda ($01), Y ;copy pixel to sta ($03), Y ;back buffer jsr inc0103 ;increment pointers cmp #$00 ;check to see bne copybyte ;if we're at $600 lda $02 ;if so, we've cmp #$06 ;copied the bne copybyte ;entire screen conway: lda #$df ;apply conway rules sta $01 ;reset the pointer sta $03 ;to $#01df/$#07df lda #$01 ;($200 - $21) sta $02 ;($800 - $21) lda #$07 sta $04onecell: lda #$00 ;process one cell ldy #$01 ;upper cell clc adc ($03), Y ldy #$41 ;lower cell clc adc ($03), Ychkleft: tax ;check to see lda $01 ;if we're at the and #$1f ;left edge tay txa cpy #$1f beq rightcellsleftcells: ldy #$00 ;upper-left cell clc adc ($03), Y ldy #$20 ;left cell clc adc ($03), Y ldy #$40 ;lower-left cell clc adc ($03), Ychkright: tax ;check to see lda $01 ;if we're at the and #$1f ;right edge tay txa cpy #$1e beq evaluaterightcells: ldy #$02 ;upper-right cell clc adc ($03), Y ldy #$22 ;right cell clc adc ($03), Y ldy #$42 ;lower-right cell clc adc ($03), Yevaluate: ldx #$01 ;evaluate total ldy #$21 ;for current cell cmp #$03 ;3 = alive beq storex ldx #$00 cmp #$02 ;2 = alive if bne storex ;c = alive lda ($03), Y and #$01 taxstorex: txa ;store to screen sta ($01), Y jsr inc0103 ;move to next cellconwayloop: cmp #$e0 ;if not last cell, bne onecell ;process next cell lda $02 cmp #$05 bne onecell jmp starttick ;run next tick inc0103: lda $01 ;increment $01 cmp #$ff ;and $03 as 16-bit bne onlyinc01 ;pointers inc $02 inc $04onlyinc01: inc $01 lda $01 sta $03 rts The solution uses one cell thick border around square Petri dish as uninhabited dire land. Sample output contains 3 generations of the blinker and 5 of the glider: See Conway's Game of Life/ALGOL 68 APL2 (Dialog) Example in one line APL \ 1130 example (very old APL dialect via simulator) APL1130From: APL \ 1130 Samples The following APL \ 1130 code will need APL385 font installed to display correctly.

See Download APL TT Font ∇LIFE[⎕]∇[0] NG←LIFE CG; W[1] W←CG+(¯1⊖CG)+(1⊖CG)+(¯1⌽CG)+(1⌽CG)[2] W←W+(1⊖1⌽CG)+(¯1⊖1⌽CG)+(1⊖¯1⌽CG)+(¯1⊖¯1⌽CG)[3] NG←(3=W)+(CG∧4=W) ∇ RP←5 5⍴0 0 0 0 0 0 0 1 1 0 0 1 1 0 0 0 0 1 0 0 RP0 0 0 0 00 0 1 1 00 1 1 0 00 0 1 0 00 0 0 0 0 LIFE RP0 0 0 0 00 1 1 1 00 1 0 0 00 1 1 0 00 0 0 0 0 LIFE LIFE RP0 0 1 0 00 1 1 0 01 0 0 1 00 1 1 0 00 0 0 0 0 ..................................................

One interacts with the Game of Life by creating an initial configuration and observing how it evolves.

Although you should test your implementation on more complex examples such as the glider in a larger universe, show the action of the blinker (three adjoining cells in a row all alive), over three generations, in a 3 by 3 grid.

(1,4)=TRUERETURN'' Count the number of neighbours of the point i,j' (Assume i/j +/- 1 will not fall out of world)'FUNCTION count_neighbours(i%,j%) LOCAL count%,l% count%=0 FOR l%=-1 TO 1 IF world! (i%+l%,j%+1) count%=count%+1 ENDIF NEXT l% IF world! (i%+1,j%) count%=count%+1 ENDIF RETURN count%ENDFUNC'' Update the world one step'PROCEDURE update_world LOCAL i%,j% ' compute neighbour counts and store FOR i%=1 TO 30 FOR j%=1 TO 30 ns%(i%,j%)[email protected]_neighbours(i%,j%) NEXT j% NEXT i% ' update the world cells FOR i%=1 TO 30 FOR j%=1 TO 30 IF world!

Thus, while it is somewhat verbose, it fully simulates Conway's Game of Life and is relatively simple to expand to feature different starting shapes.

Define life(pattern) = Prgm Local x,y,nt,count,save,xl,yl,xh,yh Define nt(y,x) = when(pxl Test(y,x), 1, 0) {}→save set Graph("Axes", "Off")→save[1] set Graph("Grid", "Off")→save[2] set Graph("Labels", "Off")→save[3] Fn Off Plot Off Clr Draw If pattern = "blinker" Then 36→yl 40→yh 78→xl 82→xh Pxl On 36,80 Pxl On 38,80 Pxl On 40,80 Else If pattern = "glider" Then 30→yl 40→yh 76→xl 88→xh Pxl On 38,76 Pxl On 36,78 Pxl On 36,80 Pxl On 38,80 Pxl On 40,80 Else If pattern = "r" Then 38-5*2→yl 38+5*2→yh 80-5*2→xl 80+5*2→xh Pxl On 38,78 Pxl On 36,82 Pxl On 36,80 Pxl On 38,80 Pxl On 40,80 End If While get Key() = 0 © Expand upper-left corner to whole cell For y,yl,yh,2 For x,xl,xh,2 If pxl Test(y,x) Then Pxl On y+1,x Pxl On y+1,x+1 Pxl On y, x+1 Else Pxl Off y+1,x Pxl Off y+1,x+1 Pxl Off y, x+1 End If End For End For © Compute next generation For y,yl,yh,2 For x,xl,xh,2 nt(y-1,x-1) + nt(y-1,x) + nt(y-1,x+2) + nt(y,x-1) + nt(y+1,x+2) + nt(y+2,x-1) + nt(y+2,x+1) + nt(y+2,x+2) → count If count = 3 Then Pxl On y,x Else If count ≠ 2 Then Pxl Off y,x End If End For End For End While © Restore changed options set Graph("Axes", save[1]) set Graph("Grid", save[2]) set Graph("Labels", save[3])End Prgm Also see Conway's Game of Life/C Considering that the simplest implementation in C++ would lack any use of the object-oriented paradigm, this code was specifically written to demonstrate the various object-oriented features of C++.

;pixels on the sta (

randfill: stx $01 ;$200 for indirect ldx #$02 ;addressing stx $02randloop: lda $fe ;generate random and #$01 ;pixels on the sta ($01), Y ;screen jsr inc0103 cmp #$00 bne randloop lda $02 cmp #$06 bne randloop clearmem: lda #$df ;set $07df-$0a20 sta $01 ;to $#00 lda #$07 sta $02clearbyte: lda #$00 sta ($01), Y jsr inc0103 cmp #$20 bne clearbyte lda $02 cmp #$0a bne clearbyte starttick:copyscreen: lda #$00 ;set up source sta $01 ;pointer at sta $03 ;$01/$02 and lda #$02 ;dest pointer sta $02 ;at $03/$04 lda #$08 sta $04 ldy #$00copybyte: lda ($01), Y ;copy pixel to sta ($03), Y ;back buffer jsr inc0103 ;increment pointers cmp #$00 ;check to see bne copybyte ;if we're at $600 lda $02 ;if so, we've cmp #$06 ;copied the bne copybyte ;entire screen conway: lda #$df ;apply conway rules sta $01 ;reset the pointer sta $03 ;to $#01df/$#07df lda #$01 ;($200 - $21) sta $02 ;($800 - $21) lda #$07 sta $04onecell: lda #$00 ;process one cell ldy #$01 ;upper cell clc adc ($03), Y ldy #$41 ;lower cell clc adc ($03), Ychkleft: tax ;check to see lda $01 ;if we're at the and #$1f ;left edge tay txa cpy #$1f beq rightcellsleftcells: ldy #$00 ;upper-left cell clc adc ($03), Y ldy #$20 ;left cell clc adc ($03), Y ldy #$40 ;lower-left cell clc adc ($03), Ychkright: tax ;check to see lda $01 ;if we're at the and #$1f ;right edge tay txa cpy #$1e beq evaluaterightcells: ldy #$02 ;upper-right cell clc adc ($03), Y ldy #$22 ;right cell clc adc ($03), Y ldy #$42 ;lower-right cell clc adc ($03), Yevaluate: ldx #$01 ;evaluate total ldy #$21 ;for current cell cmp #$03 ;3 = alive beq storex ldx #$00 cmp #$02 ;2 = alive if bne storex ;c = alive lda ($03), Y and #$01 taxstorex: txa ;store to screen sta ($01), Y jsr inc0103 ;move to next cellconwayloop: cmp #$e0 ;if not last cell, bne onecell ;process next cell lda $02 cmp #$05 bne onecell jmp starttick ;run next tick inc0103: lda $01 ;increment $01 cmp #$ff ;and $03 as 16-bit bne onlyinc01 ;pointers inc $02 inc $04onlyinc01: inc $01 lda $01 sta $03 rts The solution uses one cell thick border around square Petri dish as uninhabited dire land. Sample output contains 3 generations of the blinker and 5 of the glider: See Conway's Game of Life/ALGOL 68 APL2 (Dialog) Example in one line APL \ 1130 example (very old APL dialect via simulator) APL1130From: APL \ 1130 Samples The following APL \ 1130 code will need APL385 font installed to display correctly. See Download APL TT Font ∇LIFE[⎕]∇[0] NG←LIFE CG; W[1] W←CG+(¯1⊖CG)+(1⊖CG)+(¯1⌽CG)+(1⌽CG)[2] W←W+(1⊖1⌽CG)+(¯1⊖1⌽CG)+(1⊖¯1⌽CG)+(¯1⊖¯1⌽CG)[3] NG←(3=W)+(CG∧4=W) ∇ RP←5 5⍴0 0 0 0 0 0 0 1 1 0 0 1 1 0 0 0 0 1 0 0 RP0 0 0 0 00 0 1 1 00 1 1 0 00 0 1 0 00 0 0 0 0 LIFE RP0 0 0 0 00 1 1 1 00 1 0 0 00 1 1 0 00 0 0 0 0 LIFE LIFE RP0 0 1 0 00 1 1 0 01 0 0 1 00 1 1 0 00 0 0 0 0 .................................................. One interacts with the Game of Life by creating an initial configuration and observing how it evolves. Although you should test your implementation on more complex examples such as the glider in a larger universe, show the action of the blinker (three adjoining cells in a row all alive), over three generations, in a 3 by 3 grid. (1,4)=TRUERETURN'' Count the number of neighbours of the point i,j' (Assume i/j +/- 1 will not fall out of world)'FUNCTION count_neighbours(i%,j%) LOCAL count%,l% count%=0 FOR l%=-1 TO 1 IF world! (i%+l%,j%+1) count%=count%+1 ENDIF NEXT l% IF world! (i%+1,j%) count%=count%+1 ENDIF RETURN count%ENDFUNC'' Update the world one step'PROCEDURE update_world LOCAL i%,j% ' compute neighbour counts and store FOR i%=1 TO 30 FOR j%=1 TO 30 ns%(i%,j%)[email protected]_neighbours(i%,j%) NEXT j% NEXT i% ' update the world cells FOR i%=1 TO 30 FOR j%=1 TO 30 IF world!

||

randfill: stx $01 ;$200 for indirect ldx #$02 ;addressing stx $02randloop: lda $fe ;generate random and #$01 ;pixels on the sta ($01), Y ;screen jsr inc0103 cmp #$00 bne randloop lda $02 cmp #$06 bne randloop clearmem: lda #$df ;set $07df-$0a20 sta $01 ;to $#00 lda #$07 sta $02clearbyte: lda #$00 sta ($01), Y jsr inc0103 cmp #$20 bne clearbyte lda $02 cmp #$0a bne clearbyte starttick:copyscreen: lda #$00 ;set up source sta $01 ;pointer at sta $03 ;$01/$02 and lda #$02 ;dest pointer sta $02 ;at $03/$04 lda #$08 sta $04 ldy #$00copybyte: lda ($01), Y ;copy pixel to sta ($03), Y ;back buffer jsr inc0103 ;increment pointers cmp #$00 ;check to see bne copybyte ;if we're at $600 lda $02 ;if so, we've cmp #$06 ;copied the bne copybyte ;entire screen conway: lda #$df ;apply conway rules sta $01 ;reset the pointer sta $03 ;to $#01df/$#07df lda #$01 ;($200 - $21) sta $02 ;($800 - $21) lda #$07 sta $04onecell: lda #$00 ;process one cell ldy #$01 ;upper cell clc adc ($03), Y ldy #$41 ;lower cell clc adc ($03), Ychkleft: tax ;check to see lda $01 ;if we're at the and #$1f ;left edge tay txa cpy #$1f beq rightcellsleftcells: ldy #$00 ;upper-left cell clc adc ($03), Y ldy #$20 ;left cell clc adc ($03), Y ldy #$40 ;lower-left cell clc adc ($03), Ychkright: tax ;check to see lda $01 ;if we're at the and #$1f ;right edge tay txa cpy #$1e beq evaluaterightcells: ldy #$02 ;upper-right cell clc adc ($03), Y ldy #$22 ;right cell clc adc ($03), Y ldy #$42 ;lower-right cell clc adc ($03), Yevaluate: ldx #$01 ;evaluate total ldy #$21 ;for current cell cmp #$03 ;3 = alive beq storex ldx #$00 cmp #$02 ;2 = alive if bne storex ;c = alive lda ($03), Y and #$01 taxstorex: txa ;store to screen sta ($01), Y jsr inc0103 ;move to next cellconwayloop: cmp #$e0 ;if not last cell, bne onecell ;process next cell lda $02 cmp #$05 bne onecell jmp starttick ;run next tick inc0103: lda $01 ;increment $01 cmp #$ff ;and $03 as 16-bit bne onlyinc01 ;pointers inc $02 inc $04onlyinc01: inc $01 lda $01 sta $03 rts The solution uses one cell thick border around square Petri dish as uninhabited dire land. Sample output contains 3 generations of the blinker and 5 of the glider: See Conway's Game of Life/ALGOL 68 APL2 (Dialog) Example in one line APL \ 1130 example (very old APL dialect via simulator) APL1130From: APL \ 1130 Samples The following APL \ 1130 code will need APL385 font installed to display correctly.

See Download APL TT Font ∇LIFE[⎕]∇[0] NG←LIFE CG; W[1] W←CG+(¯1⊖CG)+(1⊖CG)+(¯1⌽CG)+(1⌽CG)[2] W←W+(1⊖1⌽CG)+(¯1⊖1⌽CG)+(1⊖¯1⌽CG)+(¯1⊖¯1⌽CG)[3] NG←(3=W)+(CG∧4=W) ∇ RP←5 5⍴0 0 0 0 0 0 0 1 1 0 0 1 1 0 0 0 0 1 0 0 RP0 0 0 0 00 0 1 1 00 1 1 0 00 0 1 0 00 0 0 0 0 LIFE RP0 0 0 0 00 1 1 1 00 1 0 0 00 1 1 0 00 0 0 0 0 LIFE LIFE RP0 0 1 0 00 1 1 0 01 0 0 1 00 1 1 0 00 0 0 0 0 ..................................................

One interacts with the Game of Life by creating an initial configuration and observing how it evolves.

Although you should test your implementation on more complex examples such as the glider in a larger universe, show the action of the blinker (three adjoining cells in a row all alive), over three generations, in a 3 by 3 grid.

(1,4)=TRUERETURN'' Count the number of neighbours of the point i,j' (Assume i/j +/- 1 will not fall out of world)'FUNCTION count_neighbours(i%,j%) LOCAL count%,l% count%=0 FOR l%=-1 TO 1 IF world! (i%+l%,j%+1) count%=count%+1 ENDIF NEXT l% IF world! (i%+1,j%) count%=count%+1 ENDIF RETURN count%ENDFUNC'' Update the world one step'PROCEDURE update_world LOCAL i%,j% ' compute neighbour counts and store FOR i%=1 TO 30 FOR j%=1 TO 30 ns%(i%,j%)[email protected]_neighbours(i%,j%) NEXT j% NEXT i% ' update the world cells FOR i%=1 TO 30 FOR j%=1 TO 30 IF world!

Thus, while it is somewhat verbose, it fully simulates Conway's Game of Life and is relatively simple to expand to feature different starting shapes.

Define life(pattern) = Prgm Local x,y,nt,count,save,xl,yl,xh,yh Define nt(y,x) = when(pxl Test(y,x), 1, 0) {}→save set Graph("Axes", "Off")→save[1] set Graph("Grid", "Off")→save[2] set Graph("Labels", "Off")→save[3] Fn Off Plot Off Clr Draw If pattern = "blinker" Then 36→yl 40→yh 78→xl 82→xh Pxl On 36,80 Pxl On 38,80 Pxl On 40,80 Else If pattern = "glider" Then 30→yl 40→yh 76→xl 88→xh Pxl On 38,76 Pxl On 36,78 Pxl On 36,80 Pxl On 38,80 Pxl On 40,80 Else If pattern = "r" Then 38-5*2→yl 38+5*2→yh 80-5*2→xl 80+5*2→xh Pxl On 38,78 Pxl On 36,82 Pxl On 36,80 Pxl On 38,80 Pxl On 40,80 End If While get Key() = 0 © Expand upper-left corner to whole cell For y,yl,yh,2 For x,xl,xh,2 If pxl Test(y,x) Then Pxl On y+1,x Pxl On y+1,x+1 Pxl On y, x+1 Else Pxl Off y+1,x Pxl Off y+1,x+1 Pxl Off y, x+1 End If End For End For © Compute next generation For y,yl,yh,2 For x,xl,xh,2 nt(y-1,x-1) + nt(y-1,x) + nt(y-1,x+2) + nt(y,x-1) + nt(y+1,x+2) + nt(y+2,x-1) + nt(y+2,x+1) + nt(y+2,x+2) → count If count = 3 Then Pxl On y,x Else If count ≠ 2 Then Pxl Off y,x End If End For End For End While © Restore changed options set Graph("Axes", save[1]) set Graph("Grid", save[2]) set Graph("Labels", save[3])End Prgm Also see Conway's Game of Life/C Considering that the simplest implementation in C++ would lack any use of the object-oriented paradigm, this code was specifically written to demonstrate the various object-oriented features of C++.

), Y ;screen jsr inc0103 cmp #

randfill: stx

randfill: stx $01 ;$200 for indirect ldx #$02 ;addressing stx $02randloop: lda $fe ;generate random and #$01 ;pixels on the sta ($01), Y ;screen jsr inc0103 cmp #$00 bne randloop lda $02 cmp #$06 bne randloop clearmem: lda #$df ;set $07df-$0a20 sta $01 ;to $#00 lda #$07 sta $02clearbyte: lda #$00 sta ($01), Y jsr inc0103 cmp #$20 bne clearbyte lda $02 cmp #$0a bne clearbyte starttick:copyscreen: lda #$00 ;set up source sta $01 ;pointer at sta $03 ;$01/$02 and lda #$02 ;dest pointer sta $02 ;at $03/$04 lda #$08 sta $04 ldy #$00copybyte: lda ($01), Y ;copy pixel to sta ($03), Y ;back buffer jsr inc0103 ;increment pointers cmp #$00 ;check to see bne copybyte ;if we're at $600 lda $02 ;if so, we've cmp #$06 ;copied the bne copybyte ;entire screen conway: lda #$df ;apply conway rules sta $01 ;reset the pointer sta $03 ;to $#01df/$#07df lda #$01 ;($200 - $21) sta $02 ;($800 - $21) lda #$07 sta $04onecell: lda #$00 ;process one cell ldy #$01 ;upper cell clc adc ($03), Y ldy #$41 ;lower cell clc adc ($03), Ychkleft: tax ;check to see lda $01 ;if we're at the and #$1f ;left edge tay txa cpy #$1f beq rightcellsleftcells: ldy #$00 ;upper-left cell clc adc ($03), Y ldy #$20 ;left cell clc adc ($03), Y ldy #$40 ;lower-left cell clc adc ($03), Ychkright: tax ;check to see lda $01 ;if we're at the and #$1f ;right edge tay txa cpy #$1e beq evaluaterightcells: ldy #$02 ;upper-right cell clc adc ($03), Y ldy #$22 ;right cell clc adc ($03), Y ldy #$42 ;lower-right cell clc adc ($03), Yevaluate: ldx #$01 ;evaluate total ldy #$21 ;for current cell cmp #$03 ;3 = alive beq storex ldx #$00 cmp #$02 ;2 = alive if bne storex ;c = alive lda ($03), Y and #$01 taxstorex: txa ;store to screen sta ($01), Y jsr inc0103 ;move to next cellconwayloop: cmp #$e0 ;if not last cell, bne onecell ;process next cell lda $02 cmp #$05 bne onecell jmp starttick ;run next tick inc0103: lda $01 ;increment $01 cmp #$ff ;and $03 as 16-bit bne onlyinc01 ;pointers inc $02 inc $04onlyinc01: inc $01 lda $01 sta $03 rts The solution uses one cell thick border around square Petri dish as uninhabited dire land. Sample output contains 3 generations of the blinker and 5 of the glider: See Conway's Game of Life/ALGOL 68 APL2 (Dialog) Example in one line APL \ 1130 example (very old APL dialect via simulator) APL1130From: APL \ 1130 Samples The following APL \ 1130 code will need APL385 font installed to display correctly. See Download APL TT Font ∇LIFE[⎕]∇[0] NG←LIFE CG; W[1] W←CG+(¯1⊖CG)+(1⊖CG)+(¯1⌽CG)+(1⌽CG)[2] W←W+(1⊖1⌽CG)+(¯1⊖1⌽CG)+(1⊖¯1⌽CG)+(¯1⊖¯1⌽CG)[3] NG←(3=W)+(CG∧4=W) ∇ RP←5 5⍴0 0 0 0 0 0 0 1 1 0 0 1 1 0 0 0 0 1 0 0 RP0 0 0 0 00 0 1 1 00 1 1 0 00 0 1 0 00 0 0 0 0 LIFE RP0 0 0 0 00 1 1 1 00 1 0 0 00 1 1 0 00 0 0 0 0 LIFE LIFE RP0 0 1 0 00 1 1 0 01 0 0 1 00 1 1 0 00 0 0 0 0 .................................................. One interacts with the Game of Life by creating an initial configuration and observing how it evolves. Although you should test your implementation on more complex examples such as the glider in a larger universe, show the action of the blinker (three adjoining cells in a row all alive), over three generations, in a 3 by 3 grid. (1,4)=TRUERETURN'' Count the number of neighbours of the point i,j' (Assume i/j +/- 1 will not fall out of world)'FUNCTION count_neighbours(i%,j%) LOCAL count%,l% count%=0 FOR l%=-1 TO 1 IF world! (i%+l%,j%+1) count%=count%+1 ENDIF NEXT l% IF world! (i%+1,j%) count%=count%+1 ENDIF RETURN count%ENDFUNC'' Update the world one step'PROCEDURE update_world LOCAL i%,j% ' compute neighbour counts and store FOR i%=1 TO 30 FOR j%=1 TO 30 ns%(i%,j%)[email protected]_neighbours(i%,j%) NEXT j% NEXT i% ' update the world cells FOR i%=1 TO 30 FOR j%=1 TO 30 IF world!

||

randfill: stx $01 ;$200 for indirect ldx #$02 ;addressing stx $02randloop: lda $fe ;generate random and #$01 ;pixels on the sta ($01), Y ;screen jsr inc0103 cmp #$00 bne randloop lda $02 cmp #$06 bne randloop clearmem: lda #$df ;set $07df-$0a20 sta $01 ;to $#00 lda #$07 sta $02clearbyte: lda #$00 sta ($01), Y jsr inc0103 cmp #$20 bne clearbyte lda $02 cmp #$0a bne clearbyte starttick:copyscreen: lda #$00 ;set up source sta $01 ;pointer at sta $03 ;$01/$02 and lda #$02 ;dest pointer sta $02 ;at $03/$04 lda #$08 sta $04 ldy #$00copybyte: lda ($01), Y ;copy pixel to sta ($03), Y ;back buffer jsr inc0103 ;increment pointers cmp #$00 ;check to see bne copybyte ;if we're at $600 lda $02 ;if so, we've cmp #$06 ;copied the bne copybyte ;entire screen conway: lda #$df ;apply conway rules sta $01 ;reset the pointer sta $03 ;to $#01df/$#07df lda #$01 ;($200 - $21) sta $02 ;($800 - $21) lda #$07 sta $04onecell: lda #$00 ;process one cell ldy #$01 ;upper cell clc adc ($03), Y ldy #$41 ;lower cell clc adc ($03), Ychkleft: tax ;check to see lda $01 ;if we're at the and #$1f ;left edge tay txa cpy #$1f beq rightcellsleftcells: ldy #$00 ;upper-left cell clc adc ($03), Y ldy #$20 ;left cell clc adc ($03), Y ldy #$40 ;lower-left cell clc adc ($03), Ychkright: tax ;check to see lda $01 ;if we're at the and #$1f ;right edge tay txa cpy #$1e beq evaluaterightcells: ldy #$02 ;upper-right cell clc adc ($03), Y ldy #$22 ;right cell clc adc ($03), Y ldy #$42 ;lower-right cell clc adc ($03), Yevaluate: ldx #$01 ;evaluate total ldy #$21 ;for current cell cmp #$03 ;3 = alive beq storex ldx #$00 cmp #$02 ;2 = alive if bne storex ;c = alive lda ($03), Y and #$01 taxstorex: txa ;store to screen sta ($01), Y jsr inc0103 ;move to next cellconwayloop: cmp #$e0 ;if not last cell, bne onecell ;process next cell lda $02 cmp #$05 bne onecell jmp starttick ;run next tick inc0103: lda $01 ;increment $01 cmp #$ff ;and $03 as 16-bit bne onlyinc01 ;pointers inc $02 inc $04onlyinc01: inc $01 lda $01 sta $03 rts The solution uses one cell thick border around square Petri dish as uninhabited dire land. Sample output contains 3 generations of the blinker and 5 of the glider: See Conway's Game of Life/ALGOL 68 APL2 (Dialog) Example in one line APL \ 1130 example (very old APL dialect via simulator) APL1130From: APL \ 1130 Samples The following APL \ 1130 code will need APL385 font installed to display correctly.

See Download APL TT Font ∇LIFE[⎕]∇[0] NG←LIFE CG; W[1] W←CG+(¯1⊖CG)+(1⊖CG)+(¯1⌽CG)+(1⌽CG)[2] W←W+(1⊖1⌽CG)+(¯1⊖1⌽CG)+(1⊖¯1⌽CG)+(¯1⊖¯1⌽CG)[3] NG←(3=W)+(CG∧4=W) ∇ RP←5 5⍴0 0 0 0 0 0 0 1 1 0 0 1 1 0 0 0 0 1 0 0 RP0 0 0 0 00 0 1 1 00 1 1 0 00 0 1 0 00 0 0 0 0 LIFE RP0 0 0 0 00 1 1 1 00 1 0 0 00 1 1 0 00 0 0 0 0 LIFE LIFE RP0 0 1 0 00 1 1 0 01 0 0 1 00 1 1 0 00 0 0 0 0 ..................................................

One interacts with the Game of Life by creating an initial configuration and observing how it evolves.

Although you should test your implementation on more complex examples such as the glider in a larger universe, show the action of the blinker (three adjoining cells in a row all alive), over three generations, in a 3 by 3 grid.

(1,4)=TRUERETURN'' Count the number of neighbours of the point i,j' (Assume i/j +/- 1 will not fall out of world)'FUNCTION count_neighbours(i%,j%) LOCAL count%,l% count%=0 FOR l%=-1 TO 1 IF world! (i%+l%,j%+1) count%=count%+1 ENDIF NEXT l% IF world! (i%+1,j%) count%=count%+1 ENDIF RETURN count%ENDFUNC'' Update the world one step'PROCEDURE update_world LOCAL i%,j% ' compute neighbour counts and store FOR i%=1 TO 30 FOR j%=1 TO 30 ns%(i%,j%)[email protected]_neighbours(i%,j%) NEXT j% NEXT i% ' update the world cells FOR i%=1 TO 30 FOR j%=1 TO 30 IF world!

Thus, while it is somewhat verbose, it fully simulates Conway's Game of Life and is relatively simple to expand to feature different starting shapes.

Define life(pattern) = Prgm Local x,y,nt,count,save,xl,yl,xh,yh Define nt(y,x) = when(pxl Test(y,x), 1, 0) {}→save set Graph("Axes", "Off")→save[1] set Graph("Grid", "Off")→save[2] set Graph("Labels", "Off")→save[3] Fn Off Plot Off Clr Draw If pattern = "blinker" Then 36→yl 40→yh 78→xl 82→xh Pxl On 36,80 Pxl On 38,80 Pxl On 40,80 Else If pattern = "glider" Then 30→yl 40→yh 76→xl 88→xh Pxl On 38,76 Pxl On 36,78 Pxl On 36,80 Pxl On 38,80 Pxl On 40,80 Else If pattern = "r" Then 38-5*2→yl 38+5*2→yh 80-5*2→xl 80+5*2→xh Pxl On 38,78 Pxl On 36,82 Pxl On 36,80 Pxl On 38,80 Pxl On 40,80 End If While get Key() = 0 © Expand upper-left corner to whole cell For y,yl,yh,2 For x,xl,xh,2 If pxl Test(y,x) Then Pxl On y+1,x Pxl On y+1,x+1 Pxl On y, x+1 Else Pxl Off y+1,x Pxl Off y+1,x+1 Pxl Off y, x+1 End If End For End For © Compute next generation For y,yl,yh,2 For x,xl,xh,2 nt(y-1,x-1) + nt(y-1,x) + nt(y-1,x+2) + nt(y,x-1) + nt(y+1,x+2) + nt(y+2,x-1) + nt(y+2,x+1) + nt(y+2,x+2) → count If count = 3 Then Pxl On y,x Else If count ≠ 2 Then Pxl Off y,x End If End For End For End While © Restore changed options set Graph("Axes", save[1]) set Graph("Grid", save[2]) set Graph("Labels", save[3])End Prgm Also see Conway's Game of Life/C Considering that the simplest implementation in C++ would lack any use of the object-oriented paradigm, this code was specifically written to demonstrate the various object-oriented features of C++.

;0 for indirect ldx # ;addressing stx randloop: lda $fe ;generate random and #

randfill: stx $01 ;$200 for indirect ldx #$02 ;addressing stx $02randloop: lda $fe ;generate random and #$01 ;pixels on the sta ($01), Y ;screen jsr inc0103 cmp #$00 bne randloop lda $02 cmp #$06 bne randloop clearmem: lda #$df ;set $07df-$0a20 sta $01 ;to $#00 lda #$07 sta $02clearbyte: lda #$00 sta ($01), Y jsr inc0103 cmp #$20 bne clearbyte lda $02 cmp #$0a bne clearbyte starttick:copyscreen: lda #$00 ;set up source sta $01 ;pointer at sta $03 ;$01/$02 and lda #$02 ;dest pointer sta $02 ;at $03/$04 lda #$08 sta $04 ldy #$00copybyte: lda ($01), Y ;copy pixel to sta ($03), Y ;back buffer jsr inc0103 ;increment pointers cmp #$00 ;check to see bne copybyte ;if we're at $600 lda $02 ;if so, we've cmp #$06 ;copied the bne copybyte ;entire screen conway: lda #$df ;apply conway rules sta $01 ;reset the pointer sta $03 ;to $#01df/$#07df lda #$01 ;($200 - $21) sta $02 ;($800 - $21) lda #$07 sta $04onecell: lda #$00 ;process one cell ldy #$01 ;upper cell clc adc ($03), Y ldy #$41 ;lower cell clc adc ($03), Ychkleft: tax ;check to see lda $01 ;if we're at the and #$1f ;left edge tay txa cpy #$1f beq rightcellsleftcells: ldy #$00 ;upper-left cell clc adc ($03), Y ldy #$20 ;left cell clc adc ($03), Y ldy #$40 ;lower-left cell clc adc ($03), Ychkright: tax ;check to see lda $01 ;if we're at the and #$1f ;right edge tay txa cpy #$1e beq evaluaterightcells: ldy #$02 ;upper-right cell clc adc ($03), Y ldy #$22 ;right cell clc adc ($03), Y ldy #$42 ;lower-right cell clc adc ($03), Yevaluate: ldx #$01 ;evaluate total ldy #$21 ;for current cell cmp #$03 ;3 = alive beq storex ldx #$00 cmp #$02 ;2 = alive if bne storex ;c = alive lda ($03), Y and #$01 taxstorex: txa ;store to screen sta ($01), Y jsr inc0103 ;move to next cellconwayloop: cmp #$e0 ;if not last cell, bne onecell ;process next cell lda $02 cmp #$05 bne onecell jmp starttick ;run next tick inc0103: lda $01 ;increment $01 cmp #$ff ;and $03 as 16-bit bne onlyinc01 ;pointers inc $02 inc $04onlyinc01: inc $01 lda $01 sta $03 rts The solution uses one cell thick border around square Petri dish as uninhabited dire land. Sample output contains 3 generations of the blinker and 5 of the glider: See Conway's Game of Life/ALGOL 68 APL2 (Dialog) Example in one line APL \ 1130 example (very old APL dialect via simulator) APL1130From: APL \ 1130 Samples The following APL \ 1130 code will need APL385 font installed to display correctly. See Download APL TT Font ∇LIFE[⎕]∇[0] NG←LIFE CG; W[1] W←CG+(¯1⊖CG)+(1⊖CG)+(¯1⌽CG)+(1⌽CG)[2] W←W+(1⊖1⌽CG)+(¯1⊖1⌽CG)+(1⊖¯1⌽CG)+(¯1⊖¯1⌽CG)[3] NG←(3=W)+(CG∧4=W) ∇ RP←5 5⍴0 0 0 0 0 0 0 1 1 0 0 1 1 0 0 0 0 1 0 0 RP0 0 0 0 00 0 1 1 00 1 1 0 00 0 1 0 00 0 0 0 0 LIFE RP0 0 0 0 00 1 1 1 00 1 0 0 00 1 1 0 00 0 0 0 0 LIFE LIFE RP0 0 1 0 00 1 1 0 01 0 0 1 00 1 1 0 00 0 0 0 0 .................................................. One interacts with the Game of Life by creating an initial configuration and observing how it evolves. Although you should test your implementation on more complex examples such as the glider in a larger universe, show the action of the blinker (three adjoining cells in a row all alive), over three generations, in a 3 by 3 grid. (1,4)=TRUERETURN'' Count the number of neighbours of the point i,j' (Assume i/j +/- 1 will not fall out of world)'FUNCTION count_neighbours(i%,j%) LOCAL count%,l% count%=0 FOR l%=-1 TO 1 IF world! (i%+l%,j%+1) count%=count%+1 ENDIF NEXT l% IF world! (i%+1,j%) count%=count%+1 ENDIF RETURN count%ENDFUNC'' Update the world one step'PROCEDURE update_world LOCAL i%,j% ' compute neighbour counts and store FOR i%=1 TO 30 FOR j%=1 TO 30 ns%(i%,j%)[email protected]_neighbours(i%,j%) NEXT j% NEXT i% ' update the world cells FOR i%=1 TO 30 FOR j%=1 TO 30 IF world!

||

randfill: stx $01 ;$200 for indirect ldx #$02 ;addressing stx $02randloop: lda $fe ;generate random and #$01 ;pixels on the sta ($01), Y ;screen jsr inc0103 cmp #$00 bne randloop lda $02 cmp #$06 bne randloop clearmem: lda #$df ;set $07df-$0a20 sta $01 ;to $#00 lda #$07 sta $02clearbyte: lda #$00 sta ($01), Y jsr inc0103 cmp #$20 bne clearbyte lda $02 cmp #$0a bne clearbyte starttick:copyscreen: lda #$00 ;set up source sta $01 ;pointer at sta $03 ;$01/$02 and lda #$02 ;dest pointer sta $02 ;at $03/$04 lda #$08 sta $04 ldy #$00copybyte: lda ($01), Y ;copy pixel to sta ($03), Y ;back buffer jsr inc0103 ;increment pointers cmp #$00 ;check to see bne copybyte ;if we're at $600 lda $02 ;if so, we've cmp #$06 ;copied the bne copybyte ;entire screen conway: lda #$df ;apply conway rules sta $01 ;reset the pointer sta $03 ;to $#01df/$#07df lda #$01 ;($200 - $21) sta $02 ;($800 - $21) lda #$07 sta $04onecell: lda #$00 ;process one cell ldy #$01 ;upper cell clc adc ($03), Y ldy #$41 ;lower cell clc adc ($03), Ychkleft: tax ;check to see lda $01 ;if we're at the and #$1f ;left edge tay txa cpy #$1f beq rightcellsleftcells: ldy #$00 ;upper-left cell clc adc ($03), Y ldy #$20 ;left cell clc adc ($03), Y ldy #$40 ;lower-left cell clc adc ($03), Ychkright: tax ;check to see lda $01 ;if we're at the and #$1f ;right edge tay txa cpy #$1e beq evaluaterightcells: ldy #$02 ;upper-right cell clc adc ($03), Y ldy #$22 ;right cell clc adc ($03), Y ldy #$42 ;lower-right cell clc adc ($03), Yevaluate: ldx #$01 ;evaluate total ldy #$21 ;for current cell cmp #$03 ;3 = alive beq storex ldx #$00 cmp #$02 ;2 = alive if bne storex ;c = alive lda ($03), Y and #$01 taxstorex: txa ;store to screen sta ($01), Y jsr inc0103 ;move to next cellconwayloop: cmp #$e0 ;if not last cell, bne onecell ;process next cell lda $02 cmp #$05 bne onecell jmp starttick ;run next tick inc0103: lda $01 ;increment $01 cmp #$ff ;and $03 as 16-bit bne onlyinc01 ;pointers inc $02 inc $04onlyinc01: inc $01 lda $01 sta $03 rts The solution uses one cell thick border around square Petri dish as uninhabited dire land. Sample output contains 3 generations of the blinker and 5 of the glider: See Conway's Game of Life/ALGOL 68 APL2 (Dialog) Example in one line APL \ 1130 example (very old APL dialect via simulator) APL1130From: APL \ 1130 Samples The following APL \ 1130 code will need APL385 font installed to display correctly.

See Download APL TT Font ∇LIFE[⎕]∇[0] NG←LIFE CG; W[1] W←CG+(¯1⊖CG)+(1⊖CG)+(¯1⌽CG)+(1⌽CG)[2] W←W+(1⊖1⌽CG)+(¯1⊖1⌽CG)+(1⊖¯1⌽CG)+(¯1⊖¯1⌽CG)[3] NG←(3=W)+(CG∧4=W) ∇ RP←5 5⍴0 0 0 0 0 0 0 1 1 0 0 1 1 0 0 0 0 1 0 0 RP0 0 0 0 00 0 1 1 00 1 1 0 00 0 1 0 00 0 0 0 0 LIFE RP0 0 0 0 00 1 1 1 00 1 0 0 00 1 1 0 00 0 0 0 0 LIFE LIFE RP0 0 1 0 00 1 1 0 01 0 0 1 00 1 1 0 00 0 0 0 0 ..................................................

One interacts with the Game of Life by creating an initial configuration and observing how it evolves.

Although you should test your implementation on more complex examples such as the glider in a larger universe, show the action of the blinker (three adjoining cells in a row all alive), over three generations, in a 3 by 3 grid.

(1,4)=TRUERETURN'' Count the number of neighbours of the point i,j' (Assume i/j +/- 1 will not fall out of world)'FUNCTION count_neighbours(i%,j%) LOCAL count%,l% count%=0 FOR l%=-1 TO 1 IF world! (i%+l%,j%+1) count%=count%+1 ENDIF NEXT l% IF world! (i%+1,j%) count%=count%+1 ENDIF RETURN count%ENDFUNC'' Update the world one step'PROCEDURE update_world LOCAL i%,j% ' compute neighbour counts and store FOR i%=1 TO 30 FOR j%=1 TO 30 ns%(i%,j%)[email protected]_neighbours(i%,j%) NEXT j% NEXT i% ' update the world cells FOR i%=1 TO 30 FOR j%=1 TO 30 IF world!

Thus, while it is somewhat verbose, it fully simulates Conway's Game of Life and is relatively simple to expand to feature different starting shapes.

Define life(pattern) = Prgm Local x,y,nt,count,save,xl,yl,xh,yh Define nt(y,x) = when(pxl Test(y,x), 1, 0) {}→save set Graph("Axes", "Off")→save[1] set Graph("Grid", "Off")→save[2] set Graph("Labels", "Off")→save[3] Fn Off Plot Off Clr Draw If pattern = "blinker" Then 36→yl 40→yh 78→xl 82→xh Pxl On 36,80 Pxl On 38,80 Pxl On 40,80 Else If pattern = "glider" Then 30→yl 40→yh 76→xl 88→xh Pxl On 38,76 Pxl On 36,78 Pxl On 36,80 Pxl On 38,80 Pxl On 40,80 Else If pattern = "r" Then 38-5*2→yl 38+5*2→yh 80-5*2→xl 80+5*2→xh Pxl On 38,78 Pxl On 36,82 Pxl On 36,80 Pxl On 38,80 Pxl On 40,80 End If While get Key() = 0 © Expand upper-left corner to whole cell For y,yl,yh,2 For x,xl,xh,2 If pxl Test(y,x) Then Pxl On y+1,x Pxl On y+1,x+1 Pxl On y, x+1 Else Pxl Off y+1,x Pxl Off y+1,x+1 Pxl Off y, x+1 End If End For End For © Compute next generation For y,yl,yh,2 For x,xl,xh,2 nt(y-1,x-1) + nt(y-1,x) + nt(y-1,x+2) + nt(y,x-1) + nt(y+1,x+2) + nt(y+2,x-1) + nt(y+2,x+1) + nt(y+2,x+2) → count If count = 3 Then Pxl On y,x Else If count ≠ 2 Then Pxl Off y,x End If End For End For End While © Restore changed options set Graph("Axes", save[1]) set Graph("Grid", save[2]) set Graph("Labels", save[3])End Prgm Also see Conway's Game of Life/C Considering that the simplest implementation in C++ would lack any use of the object-oriented paradigm, this code was specifically written to demonstrate the various object-oriented features of C++.

;pixels on the sta (

randfill: stx $01 ;$200 for indirect ldx #$02 ;addressing stx $02randloop: lda $fe ;generate random and #$01 ;pixels on the sta ($01), Y ;screen jsr inc0103 cmp #$00 bne randloop lda $02 cmp #$06 bne randloop clearmem: lda #$df ;set $07df-$0a20 sta $01 ;to $#00 lda #$07 sta $02clearbyte: lda #$00 sta ($01), Y jsr inc0103 cmp #$20 bne clearbyte lda $02 cmp #$0a bne clearbyte starttick:copyscreen: lda #$00 ;set up source sta $01 ;pointer at sta $03 ;$01/$02 and lda #$02 ;dest pointer sta $02 ;at $03/$04 lda #$08 sta $04 ldy #$00copybyte: lda ($01), Y ;copy pixel to sta ($03), Y ;back buffer jsr inc0103 ;increment pointers cmp #$00 ;check to see bne copybyte ;if we're at $600 lda $02 ;if so, we've cmp #$06 ;copied the bne copybyte ;entire screen conway: lda #$df ;apply conway rules sta $01 ;reset the pointer sta $03 ;to $#01df/$#07df lda #$01 ;($200 - $21) sta $02 ;($800 - $21) lda #$07 sta $04onecell: lda #$00 ;process one cell ldy #$01 ;upper cell clc adc ($03), Y ldy #$41 ;lower cell clc adc ($03), Ychkleft: tax ;check to see lda $01 ;if we're at the and #$1f ;left edge tay txa cpy #$1f beq rightcellsleftcells: ldy #$00 ;upper-left cell clc adc ($03), Y ldy #$20 ;left cell clc adc ($03), Y ldy #$40 ;lower-left cell clc adc ($03), Ychkright: tax ;check to see lda $01 ;if we're at the and #$1f ;right edge tay txa cpy #$1e beq evaluaterightcells: ldy #$02 ;upper-right cell clc adc ($03), Y ldy #$22 ;right cell clc adc ($03), Y ldy #$42 ;lower-right cell clc adc ($03), Yevaluate: ldx #$01 ;evaluate total ldy #$21 ;for current cell cmp #$03 ;3 = alive beq storex ldx #$00 cmp #$02 ;2 = alive if bne storex ;c = alive lda ($03), Y and #$01 taxstorex: txa ;store to screen sta ($01), Y jsr inc0103 ;move to next cellconwayloop: cmp #$e0 ;if not last cell, bne onecell ;process next cell lda $02 cmp #$05 bne onecell jmp starttick ;run next tick inc0103: lda $01 ;increment $01 cmp #$ff ;and $03 as 16-bit bne onlyinc01 ;pointers inc $02 inc $04onlyinc01: inc $01 lda $01 sta $03 rts The solution uses one cell thick border around square Petri dish as uninhabited dire land. Sample output contains 3 generations of the blinker and 5 of the glider: See Conway's Game of Life/ALGOL 68 APL2 (Dialog) Example in one line APL \ 1130 example (very old APL dialect via simulator) APL1130From: APL \ 1130 Samples The following APL \ 1130 code will need APL385 font installed to display correctly. See Download APL TT Font ∇LIFE[⎕]∇[0] NG←LIFE CG; W[1] W←CG+(¯1⊖CG)+(1⊖CG)+(¯1⌽CG)+(1⌽CG)[2] W←W+(1⊖1⌽CG)+(¯1⊖1⌽CG)+(1⊖¯1⌽CG)+(¯1⊖¯1⌽CG)[3] NG←(3=W)+(CG∧4=W) ∇ RP←5 5⍴0 0 0 0 0 0 0 1 1 0 0 1 1 0 0 0 0 1 0 0 RP0 0 0 0 00 0 1 1 00 1 1 0 00 0 1 0 00 0 0 0 0 LIFE RP0 0 0 0 00 1 1 1 00 1 0 0 00 1 1 0 00 0 0 0 0 LIFE LIFE RP0 0 1 0 00 1 1 0 01 0 0 1 00 1 1 0 00 0 0 0 0 .................................................. One interacts with the Game of Life by creating an initial configuration and observing how it evolves. Although you should test your implementation on more complex examples such as the glider in a larger universe, show the action of the blinker (three adjoining cells in a row all alive), over three generations, in a 3 by 3 grid. (1,4)=TRUERETURN'' Count the number of neighbours of the point i,j' (Assume i/j +/- 1 will not fall out of world)'FUNCTION count_neighbours(i%,j%) LOCAL count%,l% count%=0 FOR l%=-1 TO 1 IF world! (i%+l%,j%+1) count%=count%+1 ENDIF NEXT l% IF world! (i%+1,j%) count%=count%+1 ENDIF RETURN count%ENDFUNC'' Update the world one step'PROCEDURE update_world LOCAL i%,j% ' compute neighbour counts and store FOR i%=1 TO 30 FOR j%=1 TO 30 ns%(i%,j%)[email protected]_neighbours(i%,j%) NEXT j% NEXT i% ' update the world cells FOR i%=1 TO 30 FOR j%=1 TO 30 IF world!

||

randfill: stx $01 ;$200 for indirect ldx #$02 ;addressing stx $02randloop: lda $fe ;generate random and #$01 ;pixels on the sta ($01), Y ;screen jsr inc0103 cmp #$00 bne randloop lda $02 cmp #$06 bne randloop clearmem: lda #$df ;set $07df-$0a20 sta $01 ;to $#00 lda #$07 sta $02clearbyte: lda #$00 sta ($01), Y jsr inc0103 cmp #$20 bne clearbyte lda $02 cmp #$0a bne clearbyte starttick:copyscreen: lda #$00 ;set up source sta $01 ;pointer at sta $03 ;$01/$02 and lda #$02 ;dest pointer sta $02 ;at $03/$04 lda #$08 sta $04 ldy #$00copybyte: lda ($01), Y ;copy pixel to sta ($03), Y ;back buffer jsr inc0103 ;increment pointers cmp #$00 ;check to see bne copybyte ;if we're at $600 lda $02 ;if so, we've cmp #$06 ;copied the bne copybyte ;entire screen conway: lda #$df ;apply conway rules sta $01 ;reset the pointer sta $03 ;to $#01df/$#07df lda #$01 ;($200 - $21) sta $02 ;($800 - $21) lda #$07 sta $04onecell: lda #$00 ;process one cell ldy #$01 ;upper cell clc adc ($03), Y ldy #$41 ;lower cell clc adc ($03), Ychkleft: tax ;check to see lda $01 ;if we're at the and #$1f ;left edge tay txa cpy #$1f beq rightcellsleftcells: ldy #$00 ;upper-left cell clc adc ($03), Y ldy #$20 ;left cell clc adc ($03), Y ldy #$40 ;lower-left cell clc adc ($03), Ychkright: tax ;check to see lda $01 ;if we're at the and #$1f ;right edge tay txa cpy #$1e beq evaluaterightcells: ldy #$02 ;upper-right cell clc adc ($03), Y ldy #$22 ;right cell clc adc ($03), Y ldy #$42 ;lower-right cell clc adc ($03), Yevaluate: ldx #$01 ;evaluate total ldy #$21 ;for current cell cmp #$03 ;3 = alive beq storex ldx #$00 cmp #$02 ;2 = alive if bne storex ;c = alive lda ($03), Y and #$01 taxstorex: txa ;store to screen sta ($01), Y jsr inc0103 ;move to next cellconwayloop: cmp #$e0 ;if not last cell, bne onecell ;process next cell lda $02 cmp #$05 bne onecell jmp starttick ;run next tick inc0103: lda $01 ;increment $01 cmp #$ff ;and $03 as 16-bit bne onlyinc01 ;pointers inc $02 inc $04onlyinc01: inc $01 lda $01 sta $03 rts The solution uses one cell thick border around square Petri dish as uninhabited dire land. Sample output contains 3 generations of the blinker and 5 of the glider: See Conway's Game of Life/ALGOL 68 APL2 (Dialog) Example in one line APL \ 1130 example (very old APL dialect via simulator) APL1130From: APL \ 1130 Samples The following APL \ 1130 code will need APL385 font installed to display correctly.

See Download APL TT Font ∇LIFE[⎕]∇[0] NG←LIFE CG; W[1] W←CG+(¯1⊖CG)+(1⊖CG)+(¯1⌽CG)+(1⌽CG)[2] W←W+(1⊖1⌽CG)+(¯1⊖1⌽CG)+(1⊖¯1⌽CG)+(¯1⊖¯1⌽CG)[3] NG←(3=W)+(CG∧4=W) ∇ RP←5 5⍴0 0 0 0 0 0 0 1 1 0 0 1 1 0 0 0 0 1 0 0 RP0 0 0 0 00 0 1 1 00 1 1 0 00 0 1 0 00 0 0 0 0 LIFE RP0 0 0 0 00 1 1 1 00 1 0 0 00 1 1 0 00 0 0 0 0 LIFE LIFE RP0 0 1 0 00 1 1 0 01 0 0 1 00 1 1 0 00 0 0 0 0 ..................................................

One interacts with the Game of Life by creating an initial configuration and observing how it evolves.

Although you should test your implementation on more complex examples such as the glider in a larger universe, show the action of the blinker (three adjoining cells in a row all alive), over three generations, in a 3 by 3 grid.

(1,4)=TRUERETURN'' Count the number of neighbours of the point i,j' (Assume i/j +/- 1 will not fall out of world)'FUNCTION count_neighbours(i%,j%) LOCAL count%,l% count%=0 FOR l%=-1 TO 1 IF world! (i%+l%,j%+1) count%=count%+1 ENDIF NEXT l% IF world! (i%+1,j%) count%=count%+1 ENDIF RETURN count%ENDFUNC'' Update the world one step'PROCEDURE update_world LOCAL i%,j% ' compute neighbour counts and store FOR i%=1 TO 30 FOR j%=1 TO 30 ns%(i%,j%)[email protected]_neighbours(i%,j%) NEXT j% NEXT i% ' update the world cells FOR i%=1 TO 30 FOR j%=1 TO 30 IF world!

Thus, while it is somewhat verbose, it fully simulates Conway's Game of Life and is relatively simple to expand to feature different starting shapes.

Define life(pattern) = Prgm Local x,y,nt,count,save,xl,yl,xh,yh Define nt(y,x) = when(pxl Test(y,x), 1, 0) {}→save set Graph("Axes", "Off")→save[1] set Graph("Grid", "Off")→save[2] set Graph("Labels", "Off")→save[3] Fn Off Plot Off Clr Draw If pattern = "blinker" Then 36→yl 40→yh 78→xl 82→xh Pxl On 36,80 Pxl On 38,80 Pxl On 40,80 Else If pattern = "glider" Then 30→yl 40→yh 76→xl 88→xh Pxl On 38,76 Pxl On 36,78 Pxl On 36,80 Pxl On 38,80 Pxl On 40,80 Else If pattern = "r" Then 38-5*2→yl 38+5*2→yh 80-5*2→xl 80+5*2→xh Pxl On 38,78 Pxl On 36,82 Pxl On 36,80 Pxl On 38,80 Pxl On 40,80 End If While get Key() = 0 © Expand upper-left corner to whole cell For y,yl,yh,2 For x,xl,xh,2 If pxl Test(y,x) Then Pxl On y+1,x Pxl On y+1,x+1 Pxl On y, x+1 Else Pxl Off y+1,x Pxl Off y+1,x+1 Pxl Off y, x+1 End If End For End For © Compute next generation For y,yl,yh,2 For x,xl,xh,2 nt(y-1,x-1) + nt(y-1,x) + nt(y-1,x+2) + nt(y,x-1) + nt(y+1,x+2) + nt(y+2,x-1) + nt(y+2,x+1) + nt(y+2,x+2) → count If count = 3 Then Pxl On y,x Else If count ≠ 2 Then Pxl Off y,x End If End For End For End While © Restore changed options set Graph("Axes", save[1]) set Graph("Grid", save[2]) set Graph("Labels", save[3])End Prgm Also see Conway's Game of Life/C Considering that the simplest implementation in C++ would lack any use of the object-oriented paradigm, this code was specifically written to demonstrate the various object-oriented features of C++.

), Y ;screen jsr inc0103 cmp #

randfill: stx

randfill: stx $01 ;$200 for indirect ldx #$02 ;addressing stx $02randloop: lda $fe ;generate random and #$01 ;pixels on the sta ($01), Y ;screen jsr inc0103 cmp #$00 bne randloop lda $02 cmp #$06 bne randloop clearmem: lda #$df ;set $07df-$0a20 sta $01 ;to $#00 lda #$07 sta $02clearbyte: lda #$00 sta ($01), Y jsr inc0103 cmp #$20 bne clearbyte lda $02 cmp #$0a bne clearbyte starttick:copyscreen: lda #$00 ;set up source sta $01 ;pointer at sta $03 ;$01/$02 and lda #$02 ;dest pointer sta $02 ;at $03/$04 lda #$08 sta $04 ldy #$00copybyte: lda ($01), Y ;copy pixel to sta ($03), Y ;back buffer jsr inc0103 ;increment pointers cmp #$00 ;check to see bne copybyte ;if we're at $600 lda $02 ;if so, we've cmp #$06 ;copied the bne copybyte ;entire screen conway: lda #$df ;apply conway rules sta $01 ;reset the pointer sta $03 ;to $#01df/$#07df lda #$01 ;($200 - $21) sta $02 ;($800 - $21) lda #$07 sta $04onecell: lda #$00 ;process one cell ldy #$01 ;upper cell clc adc ($03), Y ldy #$41 ;lower cell clc adc ($03), Ychkleft: tax ;check to see lda $01 ;if we're at the and #$1f ;left edge tay txa cpy #$1f beq rightcellsleftcells: ldy #$00 ;upper-left cell clc adc ($03), Y ldy #$20 ;left cell clc adc ($03), Y ldy #$40 ;lower-left cell clc adc ($03), Ychkright: tax ;check to see lda $01 ;if we're at the and #$1f ;right edge tay txa cpy #$1e beq evaluaterightcells: ldy #$02 ;upper-right cell clc adc ($03), Y ldy #$22 ;right cell clc adc ($03), Y ldy #$42 ;lower-right cell clc adc ($03), Yevaluate: ldx #$01 ;evaluate total ldy #$21 ;for current cell cmp #$03 ;3 = alive beq storex ldx #$00 cmp #$02 ;2 = alive if bne storex ;c = alive lda ($03), Y and #$01 taxstorex: txa ;store to screen sta ($01), Y jsr inc0103 ;move to next cellconwayloop: cmp #$e0 ;if not last cell, bne onecell ;process next cell lda $02 cmp #$05 bne onecell jmp starttick ;run next tick inc0103: lda $01 ;increment $01 cmp #$ff ;and $03 as 16-bit bne onlyinc01 ;pointers inc $02 inc $04onlyinc01: inc $01 lda $01 sta $03 rts The solution uses one cell thick border around square Petri dish as uninhabited dire land. Sample output contains 3 generations of the blinker and 5 of the glider: See Conway's Game of Life/ALGOL 68 APL2 (Dialog) Example in one line APL \ 1130 example (very old APL dialect via simulator) APL1130From: APL \ 1130 Samples The following APL \ 1130 code will need APL385 font installed to display correctly. See Download APL TT Font ∇LIFE[⎕]∇[0] NG←LIFE CG; W[1] W←CG+(¯1⊖CG)+(1⊖CG)+(¯1⌽CG)+(1⌽CG)[2] W←W+(1⊖1⌽CG)+(¯1⊖1⌽CG)+(1⊖¯1⌽CG)+(¯1⊖¯1⌽CG)[3] NG←(3=W)+(CG∧4=W) ∇ RP←5 5⍴0 0 0 0 0 0 0 1 1 0 0 1 1 0 0 0 0 1 0 0 RP0 0 0 0 00 0 1 1 00 1 1 0 00 0 1 0 00 0 0 0 0 LIFE RP0 0 0 0 00 1 1 1 00 1 0 0 00 1 1 0 00 0 0 0 0 LIFE LIFE RP0 0 1 0 00 1 1 0 01 0 0 1 00 1 1 0 00 0 0 0 0 .................................................. One interacts with the Game of Life by creating an initial configuration and observing how it evolves. Although you should test your implementation on more complex examples such as the glider in a larger universe, show the action of the blinker (three adjoining cells in a row all alive), over three generations, in a 3 by 3 grid. (1,4)=TRUERETURN'' Count the number of neighbours of the point i,j' (Assume i/j +/- 1 will not fall out of world)'FUNCTION count_neighbours(i%,j%) LOCAL count%,l% count%=0 FOR l%=-1 TO 1 IF world! (i%+l%,j%+1) count%=count%+1 ENDIF NEXT l% IF world! (i%+1,j%) count%=count%+1 ENDIF RETURN count%ENDFUNC'' Update the world one step'PROCEDURE update_world LOCAL i%,j% ' compute neighbour counts and store FOR i%=1 TO 30 FOR j%=1 TO 30 ns%(i%,j%)[email protected]_neighbours(i%,j%) NEXT j% NEXT i% ' update the world cells FOR i%=1 TO 30 FOR j%=1 TO 30 IF world!

||

randfill: stx $01 ;$200 for indirect ldx #$02 ;addressing stx $02randloop: lda $fe ;generate random and #$01 ;pixels on the sta ($01), Y ;screen jsr inc0103 cmp #$00 bne randloop lda $02 cmp #$06 bne randloop clearmem: lda #$df ;set $07df-$0a20 sta $01 ;to $#00 lda #$07 sta $02clearbyte: lda #$00 sta ($01), Y jsr inc0103 cmp #$20 bne clearbyte lda $02 cmp #$0a bne clearbyte starttick:copyscreen: lda #$00 ;set up source sta $01 ;pointer at sta $03 ;$01/$02 and lda #$02 ;dest pointer sta $02 ;at $03/$04 lda #$08 sta $04 ldy #$00copybyte: lda ($01), Y ;copy pixel to sta ($03), Y ;back buffer jsr inc0103 ;increment pointers cmp #$00 ;check to see bne copybyte ;if we're at $600 lda $02 ;if so, we've cmp #$06 ;copied the bne copybyte ;entire screen conway: lda #$df ;apply conway rules sta $01 ;reset the pointer sta $03 ;to $#01df/$#07df lda #$01 ;($200 - $21) sta $02 ;($800 - $21) lda #$07 sta $04onecell: lda #$00 ;process one cell ldy #$01 ;upper cell clc adc ($03), Y ldy #$41 ;lower cell clc adc ($03), Ychkleft: tax ;check to see lda $01 ;if we're at the and #$1f ;left edge tay txa cpy #$1f beq rightcellsleftcells: ldy #$00 ;upper-left cell clc adc ($03), Y ldy #$20 ;left cell clc adc ($03), Y ldy #$40 ;lower-left cell clc adc ($03), Ychkright: tax ;check to see lda $01 ;if we're at the and #$1f ;right edge tay txa cpy #$1e beq evaluaterightcells: ldy #$02 ;upper-right cell clc adc ($03), Y ldy #$22 ;right cell clc adc ($03), Y ldy #$42 ;lower-right cell clc adc ($03), Yevaluate: ldx #$01 ;evaluate total ldy #$21 ;for current cell cmp #$03 ;3 = alive beq storex ldx #$00 cmp #$02 ;2 = alive if bne storex ;c = alive lda ($03), Y and #$01 taxstorex: txa ;store to screen sta ($01), Y jsr inc0103 ;move to next cellconwayloop: cmp #$e0 ;if not last cell, bne onecell ;process next cell lda $02 cmp #$05 bne onecell jmp starttick ;run next tick inc0103: lda $01 ;increment $01 cmp #$ff ;and $03 as 16-bit bne onlyinc01 ;pointers inc $02 inc $04onlyinc01: inc $01 lda $01 sta $03 rts The solution uses one cell thick border around square Petri dish as uninhabited dire land. Sample output contains 3 generations of the blinker and 5 of the glider: See Conway's Game of Life/ALGOL 68 APL2 (Dialog) Example in one line APL \ 1130 example (very old APL dialect via simulator) APL1130From: APL \ 1130 Samples The following APL \ 1130 code will need APL385 font installed to display correctly.

See Download APL TT Font ∇LIFE[⎕]∇[0] NG←LIFE CG; W[1] W←CG+(¯1⊖CG)+(1⊖CG)+(¯1⌽CG)+(1⌽CG)[2] W←W+(1⊖1⌽CG)+(¯1⊖1⌽CG)+(1⊖¯1⌽CG)+(¯1⊖¯1⌽CG)[3] NG←(3=W)+(CG∧4=W) ∇ RP←5 5⍴0 0 0 0 0 0 0 1 1 0 0 1 1 0 0 0 0 1 0 0 RP0 0 0 0 00 0 1 1 00 1 1 0 00 0 1 0 00 0 0 0 0 LIFE RP0 0 0 0 00 1 1 1 00 1 0 0 00 1 1 0 00 0 0 0 0 LIFE LIFE RP0 0 1 0 00 1 1 0 01 0 0 1 00 1 1 0 00 0 0 0 0 ..................................................

One interacts with the Game of Life by creating an initial configuration and observing how it evolves.

Although you should test your implementation on more complex examples such as the glider in a larger universe, show the action of the blinker (three adjoining cells in a row all alive), over three generations, in a 3 by 3 grid.

(1,4)=TRUERETURN'' Count the number of neighbours of the point i,j' (Assume i/j +/- 1 will not fall out of world)'FUNCTION count_neighbours(i%,j%) LOCAL count%,l% count%=0 FOR l%=-1 TO 1 IF world! (i%+l%,j%+1) count%=count%+1 ENDIF NEXT l% IF world! (i%+1,j%) count%=count%+1 ENDIF RETURN count%ENDFUNC'' Update the world one step'PROCEDURE update_world LOCAL i%,j% ' compute neighbour counts and store FOR i%=1 TO 30 FOR j%=1 TO 30 ns%(i%,j%)[email protected]_neighbours(i%,j%) NEXT j% NEXT i% ' update the world cells FOR i%=1 TO 30 FOR j%=1 TO 30 IF world!

Thus, while it is somewhat verbose, it fully simulates Conway's Game of Life and is relatively simple to expand to feature different starting shapes.

Define life(pattern) = Prgm Local x,y,nt,count,save,xl,yl,xh,yh Define nt(y,x) = when(pxl Test(y,x), 1, 0) {}→save set Graph("Axes", "Off")→save[1] set Graph("Grid", "Off")→save[2] set Graph("Labels", "Off")→save[3] Fn Off Plot Off Clr Draw If pattern = "blinker" Then 36→yl 40→yh 78→xl 82→xh Pxl On 36,80 Pxl On 38,80 Pxl On 40,80 Else If pattern = "glider" Then 30→yl 40→yh 76→xl 88→xh Pxl On 38,76 Pxl On 36,78 Pxl On 36,80 Pxl On 38,80 Pxl On 40,80 Else If pattern = "r" Then 38-5*2→yl 38+5*2→yh 80-5*2→xl 80+5*2→xh Pxl On 38,78 Pxl On 36,82 Pxl On 36,80 Pxl On 38,80 Pxl On 40,80 End If While get Key() = 0 © Expand upper-left corner to whole cell For y,yl,yh,2 For x,xl,xh,2 If pxl Test(y,x) Then Pxl On y+1,x Pxl On y+1,x+1 Pxl On y, x+1 Else Pxl Off y+1,x Pxl Off y+1,x+1 Pxl Off y, x+1 End If End For End For © Compute next generation For y,yl,yh,2 For x,xl,xh,2 nt(y-1,x-1) + nt(y-1,x) + nt(y-1,x+2) + nt(y,x-1) + nt(y+1,x+2) + nt(y+2,x-1) + nt(y+2,x+1) + nt(y+2,x+2) → count If count = 3 Then Pxl On y,x Else If count ≠ 2 Then Pxl Off y,x End If End For End For End While © Restore changed options set Graph("Axes", save[1]) set Graph("Grid", save[2]) set Graph("Labels", save[3])End Prgm Also see Conway's Game of Life/C Considering that the simplest implementation in C++ would lack any use of the object-oriented paradigm, this code was specifically written to demonstrate the various object-oriented features of C++.

;0 for indirect ldx # ;addressing stx randloop: lda $fe ;generate random and #

randfill: stx $01 ;$200 for indirect ldx #$02 ;addressing stx $02randloop: lda $fe ;generate random and #$01 ;pixels on the sta ($01), Y ;screen jsr inc0103 cmp #$00 bne randloop lda $02 cmp #$06 bne randloop clearmem: lda #$df ;set $07df-$0a20 sta $01 ;to $#00 lda #$07 sta $02clearbyte: lda #$00 sta ($01), Y jsr inc0103 cmp #$20 bne clearbyte lda $02 cmp #$0a bne clearbyte starttick:copyscreen: lda #$00 ;set up source sta $01 ;pointer at sta $03 ;$01/$02 and lda #$02 ;dest pointer sta $02 ;at $03/$04 lda #$08 sta $04 ldy #$00copybyte: lda ($01), Y ;copy pixel to sta ($03), Y ;back buffer jsr inc0103 ;increment pointers cmp #$00 ;check to see bne copybyte ;if we're at $600 lda $02 ;if so, we've cmp #$06 ;copied the bne copybyte ;entire screen conway: lda #$df ;apply conway rules sta $01 ;reset the pointer sta $03 ;to $#01df/$#07df lda #$01 ;($200 - $21) sta $02 ;($800 - $21) lda #$07 sta $04onecell: lda #$00 ;process one cell ldy #$01 ;upper cell clc adc ($03), Y ldy #$41 ;lower cell clc adc ($03), Ychkleft: tax ;check to see lda $01 ;if we're at the and #$1f ;left edge tay txa cpy #$1f beq rightcellsleftcells: ldy #$00 ;upper-left cell clc adc ($03), Y ldy #$20 ;left cell clc adc ($03), Y ldy #$40 ;lower-left cell clc adc ($03), Ychkright: tax ;check to see lda $01 ;if we're at the and #$1f ;right edge tay txa cpy #$1e beq evaluaterightcells: ldy #$02 ;upper-right cell clc adc ($03), Y ldy #$22 ;right cell clc adc ($03), Y ldy #$42 ;lower-right cell clc adc ($03), Yevaluate: ldx #$01 ;evaluate total ldy #$21 ;for current cell cmp #$03 ;3 = alive beq storex ldx #$00 cmp #$02 ;2 = alive if bne storex ;c = alive lda ($03), Y and #$01 taxstorex: txa ;store to screen sta ($01), Y jsr inc0103 ;move to next cellconwayloop: cmp #$e0 ;if not last cell, bne onecell ;process next cell lda $02 cmp #$05 bne onecell jmp starttick ;run next tick inc0103: lda $01 ;increment $01 cmp #$ff ;and $03 as 16-bit bne onlyinc01 ;pointers inc $02 inc $04onlyinc01: inc $01 lda $01 sta $03 rts The solution uses one cell thick border around square Petri dish as uninhabited dire land. Sample output contains 3 generations of the blinker and 5 of the glider: See Conway's Game of Life/ALGOL 68 APL2 (Dialog) Example in one line APL \ 1130 example (very old APL dialect via simulator) APL1130From: APL \ 1130 Samples The following APL \ 1130 code will need APL385 font installed to display correctly. See Download APL TT Font ∇LIFE[⎕]∇[0] NG←LIFE CG; W[1] W←CG+(¯1⊖CG)+(1⊖CG)+(¯1⌽CG)+(1⌽CG)[2] W←W+(1⊖1⌽CG)+(¯1⊖1⌽CG)+(1⊖¯1⌽CG)+(¯1⊖¯1⌽CG)[3] NG←(3=W)+(CG∧4=W) ∇ RP←5 5⍴0 0 0 0 0 0 0 1 1 0 0 1 1 0 0 0 0 1 0 0 RP0 0 0 0 00 0 1 1 00 1 1 0 00 0 1 0 00 0 0 0 0 LIFE RP0 0 0 0 00 1 1 1 00 1 0 0 00 1 1 0 00 0 0 0 0 LIFE LIFE RP0 0 1 0 00 1 1 0 01 0 0 1 00 1 1 0 00 0 0 0 0 .................................................. One interacts with the Game of Life by creating an initial configuration and observing how it evolves. Although you should test your implementation on more complex examples such as the glider in a larger universe, show the action of the blinker (three adjoining cells in a row all alive), over three generations, in a 3 by 3 grid. (1,4)=TRUERETURN'' Count the number of neighbours of the point i,j' (Assume i/j +/- 1 will not fall out of world)'FUNCTION count_neighbours(i%,j%) LOCAL count%,l% count%=0 FOR l%=-1 TO 1 IF world! (i%+l%,j%+1) count%=count%+1 ENDIF NEXT l% IF world! (i%+1,j%) count%=count%+1 ENDIF RETURN count%ENDFUNC'' Update the world one step'PROCEDURE update_world LOCAL i%,j% ' compute neighbour counts and store FOR i%=1 TO 30 FOR j%=1 TO 30 ns%(i%,j%)[email protected]_neighbours(i%,j%) NEXT j% NEXT i% ' update the world cells FOR i%=1 TO 30 FOR j%=1 TO 30 IF world!

||

randfill: stx $01 ;$200 for indirect ldx #$02 ;addressing stx $02randloop: lda $fe ;generate random and #$01 ;pixels on the sta ($01), Y ;screen jsr inc0103 cmp #$00 bne randloop lda $02 cmp #$06 bne randloop clearmem: lda #$df ;set $07df-$0a20 sta $01 ;to $#00 lda #$07 sta $02clearbyte: lda #$00 sta ($01), Y jsr inc0103 cmp #$20 bne clearbyte lda $02 cmp #$0a bne clearbyte starttick:copyscreen: lda #$00 ;set up source sta $01 ;pointer at sta $03 ;$01/$02 and lda #$02 ;dest pointer sta $02 ;at $03/$04 lda #$08 sta $04 ldy #$00copybyte: lda ($01), Y ;copy pixel to sta ($03), Y ;back buffer jsr inc0103 ;increment pointers cmp #$00 ;check to see bne copybyte ;if we're at $600 lda $02 ;if so, we've cmp #$06 ;copied the bne copybyte ;entire screen conway: lda #$df ;apply conway rules sta $01 ;reset the pointer sta $03 ;to $#01df/$#07df lda #$01 ;($200 - $21) sta $02 ;($800 - $21) lda #$07 sta $04onecell: lda #$00 ;process one cell ldy #$01 ;upper cell clc adc ($03), Y ldy #$41 ;lower cell clc adc ($03), Ychkleft: tax ;check to see lda $01 ;if we're at the and #$1f ;left edge tay txa cpy #$1f beq rightcellsleftcells: ldy #$00 ;upper-left cell clc adc ($03), Y ldy #$20 ;left cell clc adc ($03), Y ldy #$40 ;lower-left cell clc adc ($03), Ychkright: tax ;check to see lda $01 ;if we're at the and #$1f ;right edge tay txa cpy #$1e beq evaluaterightcells: ldy #$02 ;upper-right cell clc adc ($03), Y ldy #$22 ;right cell clc adc ($03), Y ldy #$42 ;lower-right cell clc adc ($03), Yevaluate: ldx #$01 ;evaluate total ldy #$21 ;for current cell cmp #$03 ;3 = alive beq storex ldx #$00 cmp #$02 ;2 = alive if bne storex ;c = alive lda ($03), Y and #$01 taxstorex: txa ;store to screen sta ($01), Y jsr inc0103 ;move to next cellconwayloop: cmp #$e0 ;if not last cell, bne onecell ;process next cell lda $02 cmp #$05 bne onecell jmp starttick ;run next tick inc0103: lda $01 ;increment $01 cmp #$ff ;and $03 as 16-bit bne onlyinc01 ;pointers inc $02 inc $04onlyinc01: inc $01 lda $01 sta $03 rts The solution uses one cell thick border around square Petri dish as uninhabited dire land. Sample output contains 3 generations of the blinker and 5 of the glider: See Conway's Game of Life/ALGOL 68 APL2 (Dialog) Example in one line APL \ 1130 example (very old APL dialect via simulator) APL1130From: APL \ 1130 Samples The following APL \ 1130 code will need APL385 font installed to display correctly.

See Download APL TT Font ∇LIFE[⎕]∇[0] NG←LIFE CG; W[1] W←CG+(¯1⊖CG)+(1⊖CG)+(¯1⌽CG)+(1⌽CG)[2] W←W+(1⊖1⌽CG)+(¯1⊖1⌽CG)+(1⊖¯1⌽CG)+(¯1⊖¯1⌽CG)[3] NG←(3=W)+(CG∧4=W) ∇ RP←5 5⍴0 0 0 0 0 0 0 1 1 0 0 1 1 0 0 0 0 1 0 0 RP0 0 0 0 00 0 1 1 00 1 1 0 00 0 1 0 00 0 0 0 0 LIFE RP0 0 0 0 00 1 1 1 00 1 0 0 00 1 1 0 00 0 0 0 0 LIFE LIFE RP0 0 1 0 00 1 1 0 01 0 0 1 00 1 1 0 00 0 0 0 0 ..................................................

One interacts with the Game of Life by creating an initial configuration and observing how it evolves.

Although you should test your implementation on more complex examples such as the glider in a larger universe, show the action of the blinker (three adjoining cells in a row all alive), over three generations, in a 3 by 3 grid.

(1,4)=TRUERETURN'' Count the number of neighbours of the point i,j' (Assume i/j +/- 1 will not fall out of world)'FUNCTION count_neighbours(i%,j%) LOCAL count%,l% count%=0 FOR l%=-1 TO 1 IF world! (i%+l%,j%+1) count%=count%+1 ENDIF NEXT l% IF world! (i%+1,j%) count%=count%+1 ENDIF RETURN count%ENDFUNC'' Update the world one step'PROCEDURE update_world LOCAL i%,j% ' compute neighbour counts and store FOR i%=1 TO 30 FOR j%=1 TO 30 ns%(i%,j%)[email protected]_neighbours(i%,j%) NEXT j% NEXT i% ' update the world cells FOR i%=1 TO 30 FOR j%=1 TO 30 IF world!

Thus, while it is somewhat verbose, it fully simulates Conway's Game of Life and is relatively simple to expand to feature different starting shapes.

Define life(pattern) = Prgm Local x,y,nt,count,save,xl,yl,xh,yh Define nt(y,x) = when(pxl Test(y,x), 1, 0) {}→save set Graph("Axes", "Off")→save[1] set Graph("Grid", "Off")→save[2] set Graph("Labels", "Off")→save[3] Fn Off Plot Off Clr Draw If pattern = "blinker" Then 36→yl 40→yh 78→xl 82→xh Pxl On 36,80 Pxl On 38,80 Pxl On 40,80 Else If pattern = "glider" Then 30→yl 40→yh 76→xl 88→xh Pxl On 38,76 Pxl On 36,78 Pxl On 36,80 Pxl On 38,80 Pxl On 40,80 Else If pattern = "r" Then 38-5*2→yl 38+5*2→yh 80-5*2→xl 80+5*2→xh Pxl On 38,78 Pxl On 36,82 Pxl On 36,80 Pxl On 38,80 Pxl On 40,80 End If While get Key() = 0 © Expand upper-left corner to whole cell For y,yl,yh,2 For x,xl,xh,2 If pxl Test(y,x) Then Pxl On y+1,x Pxl On y+1,x+1 Pxl On y, x+1 Else Pxl Off y+1,x Pxl Off y+1,x+1 Pxl Off y, x+1 End If End For End For © Compute next generation For y,yl,yh,2 For x,xl,xh,2 nt(y-1,x-1) + nt(y-1,x) + nt(y-1,x+2) + nt(y,x-1) + nt(y+1,x+2) + nt(y+2,x-1) + nt(y+2,x+1) + nt(y+2,x+2) → count If count = 3 Then Pxl On y,x Else If count ≠ 2 Then Pxl Off y,x End If End For End For End While © Restore changed options set Graph("Axes", save[1]) set Graph("Grid", save[2]) set Graph("Labels", save[3])End Prgm Also see Conway's Game of Life/C Considering that the simplest implementation in C++ would lack any use of the object-oriented paradigm, this code was specifically written to demonstrate the various object-oriented features of C++.

;pixels on the sta (

randfill: stx $01 ;$200 for indirect ldx #$02 ;addressing stx $02randloop: lda $fe ;generate random and #$01 ;pixels on the sta ($01), Y ;screen jsr inc0103 cmp #$00 bne randloop lda $02 cmp #$06 bne randloop clearmem: lda #$df ;set $07df-$0a20 sta $01 ;to $#00 lda #$07 sta $02clearbyte: lda #$00 sta ($01), Y jsr inc0103 cmp #$20 bne clearbyte lda $02 cmp #$0a bne clearbyte starttick:copyscreen: lda #$00 ;set up source sta $01 ;pointer at sta $03 ;$01/$02 and lda #$02 ;dest pointer sta $02 ;at $03/$04 lda #$08 sta $04 ldy #$00copybyte: lda ($01), Y ;copy pixel to sta ($03), Y ;back buffer jsr inc0103 ;increment pointers cmp #$00 ;check to see bne copybyte ;if we're at $600 lda $02 ;if so, we've cmp #$06 ;copied the bne copybyte ;entire screen conway: lda #$df ;apply conway rules sta $01 ;reset the pointer sta $03 ;to $#01df/$#07df lda #$01 ;($200 - $21) sta $02 ;($800 - $21) lda #$07 sta $04onecell: lda #$00 ;process one cell ldy #$01 ;upper cell clc adc ($03), Y ldy #$41 ;lower cell clc adc ($03), Ychkleft: tax ;check to see lda $01 ;if we're at the and #$1f ;left edge tay txa cpy #$1f beq rightcellsleftcells: ldy #$00 ;upper-left cell clc adc ($03), Y ldy #$20 ;left cell clc adc ($03), Y ldy #$40 ;lower-left cell clc adc ($03), Ychkright: tax ;check to see lda $01 ;if we're at the and #$1f ;right edge tay txa cpy #$1e beq evaluaterightcells: ldy #$02 ;upper-right cell clc adc ($03), Y ldy #$22 ;right cell clc adc ($03), Y ldy #$42 ;lower-right cell clc adc ($03), Yevaluate: ldx #$01 ;evaluate total ldy #$21 ;for current cell cmp #$03 ;3 = alive beq storex ldx #$00 cmp #$02 ;2 = alive if bne storex ;c = alive lda ($03), Y and #$01 taxstorex: txa ;store to screen sta ($01), Y jsr inc0103 ;move to next cellconwayloop: cmp #$e0 ;if not last cell, bne onecell ;process next cell lda $02 cmp #$05 bne onecell jmp starttick ;run next tick inc0103: lda $01 ;increment $01 cmp #$ff ;and $03 as 16-bit bne onlyinc01 ;pointers inc $02 inc $04onlyinc01: inc $01 lda $01 sta $03 rts The solution uses one cell thick border around square Petri dish as uninhabited dire land. Sample output contains 3 generations of the blinker and 5 of the glider: See Conway's Game of Life/ALGOL 68 APL2 (Dialog) Example in one line APL \ 1130 example (very old APL dialect via simulator) APL1130From: APL \ 1130 Samples The following APL \ 1130 code will need APL385 font installed to display correctly. See Download APL TT Font ∇LIFE[⎕]∇[0] NG←LIFE CG; W[1] W←CG+(¯1⊖CG)+(1⊖CG)+(¯1⌽CG)+(1⌽CG)[2] W←W+(1⊖1⌽CG)+(¯1⊖1⌽CG)+(1⊖¯1⌽CG)+(¯1⊖¯1⌽CG)[3] NG←(3=W)+(CG∧4=W) ∇ RP←5 5⍴0 0 0 0 0 0 0 1 1 0 0 1 1 0 0 0 0 1 0 0 RP0 0 0 0 00 0 1 1 00 1 1 0 00 0 1 0 00 0 0 0 0 LIFE RP0 0 0 0 00 1 1 1 00 1 0 0 00 1 1 0 00 0 0 0 0 LIFE LIFE RP0 0 1 0 00 1 1 0 01 0 0 1 00 1 1 0 00 0 0 0 0 .................................................. One interacts with the Game of Life by creating an initial configuration and observing how it evolves. Although you should test your implementation on more complex examples such as the glider in a larger universe, show the action of the blinker (three adjoining cells in a row all alive), over three generations, in a 3 by 3 grid. (1,4)=TRUERETURN'' Count the number of neighbours of the point i,j' (Assume i/j +/- 1 will not fall out of world)'FUNCTION count_neighbours(i%,j%) LOCAL count%,l% count%=0 FOR l%=-1 TO 1 IF world! (i%+l%,j%+1) count%=count%+1 ENDIF NEXT l% IF world! (i%+1,j%) count%=count%+1 ENDIF RETURN count%ENDFUNC'' Update the world one step'PROCEDURE update_world LOCAL i%,j% ' compute neighbour counts and store FOR i%=1 TO 30 FOR j%=1 TO 30 ns%(i%,j%)[email protected]_neighbours(i%,j%) NEXT j% NEXT i% ' update the world cells FOR i%=1 TO 30 FOR j%=1 TO 30 IF world!

||

randfill: stx $01 ;$200 for indirect ldx #$02 ;addressing stx $02randloop: lda $fe ;generate random and #$01 ;pixels on the sta ($01), Y ;screen jsr inc0103 cmp #$00 bne randloop lda $02 cmp #$06 bne randloop clearmem: lda #$df ;set $07df-$0a20 sta $01 ;to $#00 lda #$07 sta $02clearbyte: lda #$00 sta ($01), Y jsr inc0103 cmp #$20 bne clearbyte lda $02 cmp #$0a bne clearbyte starttick:copyscreen: lda #$00 ;set up source sta $01 ;pointer at sta $03 ;$01/$02 and lda #$02 ;dest pointer sta $02 ;at $03/$04 lda #$08 sta $04 ldy #$00copybyte: lda ($01), Y ;copy pixel to sta ($03), Y ;back buffer jsr inc0103 ;increment pointers cmp #$00 ;check to see bne copybyte ;if we're at $600 lda $02 ;if so, we've cmp #$06 ;copied the bne copybyte ;entire screen conway: lda #$df ;apply conway rules sta $01 ;reset the pointer sta $03 ;to $#01df/$#07df lda #$01 ;($200 - $21) sta $02 ;($800 - $21) lda #$07 sta $04onecell: lda #$00 ;process one cell ldy #$01 ;upper cell clc adc ($03), Y ldy #$41 ;lower cell clc adc ($03), Ychkleft: tax ;check to see lda $01 ;if we're at the and #$1f ;left edge tay txa cpy #$1f beq rightcellsleftcells: ldy #$00 ;upper-left cell clc adc ($03), Y ldy #$20 ;left cell clc adc ($03), Y ldy #$40 ;lower-left cell clc adc ($03), Ychkright: tax ;check to see lda $01 ;if we're at the and #$1f ;right edge tay txa cpy #$1e beq evaluaterightcells: ldy #$02 ;upper-right cell clc adc ($03), Y ldy #$22 ;right cell clc adc ($03), Y ldy #$42 ;lower-right cell clc adc ($03), Yevaluate: ldx #$01 ;evaluate total ldy #$21 ;for current cell cmp #$03 ;3 = alive beq storex ldx #$00 cmp #$02 ;2 = alive if bne storex ;c = alive lda ($03), Y and #$01 taxstorex: txa ;store to screen sta ($01), Y jsr inc0103 ;move to next cellconwayloop: cmp #$e0 ;if not last cell, bne onecell ;process next cell lda $02 cmp #$05 bne onecell jmp starttick ;run next tick inc0103: lda $01 ;increment $01 cmp #$ff ;and $03 as 16-bit bne onlyinc01 ;pointers inc $02 inc $04onlyinc01: inc $01 lda $01 sta $03 rts The solution uses one cell thick border around square Petri dish as uninhabited dire land. Sample output contains 3 generations of the blinker and 5 of the glider: See Conway's Game of Life/ALGOL 68 APL2 (Dialog) Example in one line APL \ 1130 example (very old APL dialect via simulator) APL1130From: APL \ 1130 Samples The following APL \ 1130 code will need APL385 font installed to display correctly.

See Download APL TT Font ∇LIFE[⎕]∇[0] NG←LIFE CG; W[1] W←CG+(¯1⊖CG)+(1⊖CG)+(¯1⌽CG)+(1⌽CG)[2] W←W+(1⊖1⌽CG)+(¯1⊖1⌽CG)+(1⊖¯1⌽CG)+(¯1⊖¯1⌽CG)[3] NG←(3=W)+(CG∧4=W) ∇ RP←5 5⍴0 0 0 0 0 0 0 1 1 0 0 1 1 0 0 0 0 1 0 0 RP0 0 0 0 00 0 1 1 00 1 1 0 00 0 1 0 00 0 0 0 0 LIFE RP0 0 0 0 00 1 1 1 00 1 0 0 00 1 1 0 00 0 0 0 0 LIFE LIFE RP0 0 1 0 00 1 1 0 01 0 0 1 00 1 1 0 00 0 0 0 0 ..................................................

One interacts with the Game of Life by creating an initial configuration and observing how it evolves.

Although you should test your implementation on more complex examples such as the glider in a larger universe, show the action of the blinker (three adjoining cells in a row all alive), over three generations, in a 3 by 3 grid.

(1,4)=TRUERETURN'' Count the number of neighbours of the point i,j' (Assume i/j +/- 1 will not fall out of world)'FUNCTION count_neighbours(i%,j%) LOCAL count%,l% count%=0 FOR l%=-1 TO 1 IF world! (i%+l%,j%+1) count%=count%+1 ENDIF NEXT l% IF world! (i%+1,j%) count%=count%+1 ENDIF RETURN count%ENDFUNC'' Update the world one step'PROCEDURE update_world LOCAL i%,j% ' compute neighbour counts and store FOR i%=1 TO 30 FOR j%=1 TO 30 ns%(i%,j%)[email protected]_neighbours(i%,j%) NEXT j% NEXT i% ' update the world cells FOR i%=1 TO 30 FOR j%=1 TO 30 IF world!

Thus, while it is somewhat verbose, it fully simulates Conway's Game of Life and is relatively simple to expand to feature different starting shapes.

Define life(pattern) = Prgm Local x,y,nt,count,save,xl,yl,xh,yh Define nt(y,x) = when(pxl Test(y,x), 1, 0) {}→save set Graph("Axes", "Off")→save[1] set Graph("Grid", "Off")→save[2] set Graph("Labels", "Off")→save[3] Fn Off Plot Off Clr Draw If pattern = "blinker" Then 36→yl 40→yh 78→xl 82→xh Pxl On 36,80 Pxl On 38,80 Pxl On 40,80 Else If pattern = "glider" Then 30→yl 40→yh 76→xl 88→xh Pxl On 38,76 Pxl On 36,78 Pxl On 36,80 Pxl On 38,80 Pxl On 40,80 Else If pattern = "r" Then 38-5*2→yl 38+5*2→yh 80-5*2→xl 80+5*2→xh Pxl On 38,78 Pxl On 36,82 Pxl On 36,80 Pxl On 38,80 Pxl On 40,80 End If While get Key() = 0 © Expand upper-left corner to whole cell For y,yl,yh,2 For x,xl,xh,2 If pxl Test(y,x) Then Pxl On y+1,x Pxl On y+1,x+1 Pxl On y, x+1 Else Pxl Off y+1,x Pxl Off y+1,x+1 Pxl Off y, x+1 End If End For End For © Compute next generation For y,yl,yh,2 For x,xl,xh,2 nt(y-1,x-1) + nt(y-1,x) + nt(y-1,x+2) + nt(y,x-1) + nt(y+1,x+2) + nt(y+2,x-1) + nt(y+2,x+1) + nt(y+2,x+2) → count If count = 3 Then Pxl On y,x Else If count ≠ 2 Then Pxl Off y,x End If End For End For End While © Restore changed options set Graph("Axes", save[1]) set Graph("Grid", save[2]) set Graph("Labels", save[3])End Prgm Also see Conway's Game of Life/C Considering that the simplest implementation in C++ would lack any use of the object-oriented paradigm, this code was specifically written to demonstrate the various object-oriented features of C++.

), Y ;screen jsr inc0103 cmp #[[

randfill: stx $01 ;$200 for indirect ldx #$02 ;addressing stx $02randloop: lda $fe ;generate random and #$01 ;pixels on the sta ($01), Y ;screen jsr inc0103 cmp #$00 bne randloop lda $02 cmp #$06 bne randloop clearmem: lda #$df ;set $07df-$0a20 sta $01 ;to $#00 lda #$07 sta $02clearbyte: lda #$00 sta ($01), Y jsr inc0103 cmp #$20 bne clearbyte lda $02 cmp #$0a bne clearbyte starttick:copyscreen: lda #$00 ;set up source sta $01 ;pointer at sta $03 ;$01/$02 and lda #$02 ;dest pointer sta $02 ;at $03/$04 lda #$08 sta $04 ldy #$00copybyte: lda ($01), Y ;copy pixel to sta ($03), Y ;back buffer jsr inc0103 ;increment pointers cmp #$00 ;check to see bne copybyte ;if we're at $600 lda $02 ;if so, we've cmp #$06 ;copied the bne copybyte ;entire screen conway: lda #$df ;apply conway rules sta $01 ;reset the pointer sta $03 ;to $#01df/$#07df lda #$01 ;($200 - $21) sta $02 ;($800 - $21) lda #$07 sta $04onecell: lda #$00 ;process one cell ldy #$01 ;upper cell clc adc ($03), Y ldy #$41 ;lower cell clc adc ($03), Ychkleft: tax ;check to see lda $01 ;if we're at the and #$1f ;left edge tay txa cpy #$1f beq rightcellsleftcells: ldy #$00 ;upper-left cell clc adc ($03), Y ldy #$20 ;left cell clc adc ($03), Y ldy #$40 ;lower-left cell clc adc ($03), Ychkright: tax ;check to see lda $01 ;if we're at the and #$1f ;right edge tay txa cpy #$1e beq evaluaterightcells: ldy #$02 ;upper-right cell clc adc ($03), Y ldy #$22 ;right cell clc adc ($03), Y ldy #$42 ;lower-right cell clc adc ($03), Yevaluate: ldx #$01 ;evaluate total ldy #$21 ;for current cell cmp #$03 ;3 = alive beq storex ldx #$00 cmp #$02 ;2 = alive if bne storex ;c = alive lda ($03), Y and #$01 taxstorex: txa ;store to screen sta ($01), Y jsr inc0103 ;move to next cellconwayloop: cmp #$e0 ;if not last cell, bne onecell ;process next cell lda $02 cmp #$05 bne onecell jmp starttick ;run next tick inc0103: lda $01 ;increment $01 cmp #$ff ;and $03 as 16-bit bne onlyinc01 ;pointers inc $02 inc $04onlyinc01: inc $01 lda $01 sta $03 rts The solution uses one cell thick border around square Petri dish as uninhabited dire land. Sample output contains 3 generations of the blinker and 5 of the glider: See Conway's Game of Life/ALGOL 68 APL2 (Dialog) Example in one line APL \ 1130 example (very old APL dialect via simulator) APL1130From: APL \ 1130 Samples The following APL \ 1130 code will need APL385 font installed to display correctly. See Download APL TT Font ∇LIFE[⎕]∇[0] NG←LIFE CG; W[1] W←CG+(¯1⊖CG)+(1⊖CG)+(¯1⌽CG)+(1⌽CG)[2] W←W+(1⊖1⌽CG)+(¯1⊖1⌽CG)+(1⊖¯1⌽CG)+(¯1⊖¯1⌽CG)[3] NG←(3=W)+(CG∧4=W) ∇ RP←5 5⍴0 0 0 0 0 0 0 1 1 0 0 1 1 0 0 0 0 1 0 0 RP0 0 0 0 00 0 1 1 00 1 1 0 00 0 1 0 00 0 0 0 0 LIFE RP0 0 0 0 00 1 1 1 00 1 0 0 00 1 1 0 00 0 0 0 0 LIFE LIFE RP0 0 1 0 00 1 1 0 01 0 0 1 00 1 1 0 00 0 0 0 0 .................................................. One interacts with the Game of Life by creating an initial configuration and observing how it evolves. Although you should test your implementation on more complex examples such as the glider in a larger universe, show the action of the blinker (three adjoining cells in a row all alive), over three generations, in a 3 by 3 grid. (1,4)=TRUERETURN'' Count the number of neighbours of the point i,j' (Assume i/j +/- 1 will not fall out of world)'FUNCTION count_neighbours(i%,j%) LOCAL count%,l% count%=0 FOR l%=-1 TO 1 IF world! (i%+l%,j%+1) count%=count%+1 ENDIF NEXT l% IF world! (i%+1,j%) count%=count%+1 ENDIF RETURN count%ENDFUNC'' Update the world one step'PROCEDURE update_world LOCAL i%,j% ' compute neighbour counts and store FOR i%=1 TO 30 FOR j%=1 TO 30 ns%(i%,j%)[email protected]_neighbours(i%,j%) NEXT j% NEXT i% ' update the world cells FOR i%=1 TO 30 FOR j%=1 TO 30 IF world!

||

randfill: stx $01 ;$200 for indirect ldx #$02 ;addressing stx $02randloop: lda $fe ;generate random and #$01 ;pixels on the sta ($01), Y ;screen jsr inc0103 cmp #$00 bne randloop lda $02 cmp #$06 bne randloop clearmem: lda #$df ;set $07df-$0a20 sta $01 ;to $#00 lda #$07 sta $02clearbyte: lda #$00 sta ($01), Y jsr inc0103 cmp #$20 bne clearbyte lda $02 cmp #$0a bne clearbyte starttick:copyscreen: lda #$00 ;set up source sta $01 ;pointer at sta $03 ;$01/$02 and lda #$02 ;dest pointer sta $02 ;at $03/$04 lda #$08 sta $04 ldy #$00copybyte: lda ($01), Y ;copy pixel to sta ($03), Y ;back buffer jsr inc0103 ;increment pointers cmp #$00 ;check to see bne copybyte ;if we're at $600 lda $02 ;if so, we've cmp #$06 ;copied the bne copybyte ;entire screen conway: lda #$df ;apply conway rules sta $01 ;reset the pointer sta $03 ;to $#01df/$#07df lda #$01 ;($200 - $21) sta $02 ;($800 - $21) lda #$07 sta $04onecell: lda #$00 ;process one cell ldy #$01 ;upper cell clc adc ($03), Y ldy #$41 ;lower cell clc adc ($03), Ychkleft: tax ;check to see lda $01 ;if we're at the and #$1f ;left edge tay txa cpy #$1f beq rightcellsleftcells: ldy #$00 ;upper-left cell clc adc ($03), Y ldy #$20 ;left cell clc adc ($03), Y ldy #$40 ;lower-left cell clc adc ($03), Ychkright: tax ;check to see lda $01 ;if we're at the and #$1f ;right edge tay txa cpy #$1e beq evaluaterightcells: ldy #$02 ;upper-right cell clc adc ($03), Y ldy #$22 ;right cell clc adc ($03), Y ldy #$42 ;lower-right cell clc adc ($03), Yevaluate: ldx #$01 ;evaluate total ldy #$21 ;for current cell cmp #$03 ;3 = alive beq storex ldx #$00 cmp #$02 ;2 = alive if bne storex ;c = alive lda ($03), Y and #$01 taxstorex: txa ;store to screen sta ($01), Y jsr inc0103 ;move to next cellconwayloop: cmp #$e0 ;if not last cell, bne onecell ;process next cell lda $02 cmp #$05 bne onecell jmp starttick ;run next tick inc0103: lda $01 ;increment $01 cmp #$ff ;and $03 as 16-bit bne onlyinc01 ;pointers inc $02 inc $04onlyinc01: inc $01 lda $01 sta $03 rts The solution uses one cell thick border around square Petri dish as uninhabited dire land. Sample output contains 3 generations of the blinker and 5 of the glider: See Conway's Game of Life/ALGOL 68 APL2 (Dialog) Example in one line APL \ 1130 example (very old APL dialect via simulator) APL1130From: APL \ 1130 Samples The following APL \ 1130 code will need APL385 font installed to display correctly.

See Download APL TT Font ∇LIFE[⎕]∇[0] NG←LIFE CG; W[1] W←CG+(¯1⊖CG)+(1⊖CG)+(¯1⌽CG)+(1⌽CG)[2] W←W+(1⊖1⌽CG)+(¯1⊖1⌽CG)+(1⊖¯1⌽CG)+(¯1⊖¯1⌽CG)[3] NG←(3=W)+(CG∧4=W) ∇ RP←5 5⍴0 0 0 0 0 0 0 1 1 0 0 1 1 0 0 0 0 1 0 0 RP0 0 0 0 00 0 1 1 00 1 1 0 00 0 1 0 00 0 0 0 0 LIFE RP0 0 0 0 00 1 1 1 00 1 0 0 00 1 1 0 00 0 0 0 0 LIFE LIFE RP0 0 1 0 00 1 1 0 01 0 0 1 00 1 1 0 00 0 0 0 0 ..................................................

One interacts with the Game of Life by creating an initial configuration and observing how it evolves.

Although you should test your implementation on more complex examples such as the glider in a larger universe, show the action of the blinker (three adjoining cells in a row all alive), over three generations, in a 3 by 3 grid.

(1,4)=TRUERETURN'' Count the number of neighbours of the point i,j' (Assume i/j +/- 1 will not fall out of world)'FUNCTION count_neighbours(i%,j%) LOCAL count%,l% count%=0 FOR l%=-1 TO 1 IF world! (i%+l%,j%+1) count%=count%+1 ENDIF NEXT l% IF world! (i%+1,j%) count%=count%+1 ENDIF RETURN count%ENDFUNC'' Update the world one step'PROCEDURE update_world LOCAL i%,j% ' compute neighbour counts and store FOR i%=1 TO 30 FOR j%=1 TO 30 ns%(i%,j%)[email protected]_neighbours(i%,j%) NEXT j% NEXT i% ' update the world cells FOR i%=1 TO 30 FOR j%=1 TO 30 IF world!

Thus, while it is somewhat verbose, it fully simulates Conway's Game of Life and is relatively simple to expand to feature different starting shapes.

Define life(pattern) = Prgm Local x,y,nt,count,save,xl,yl,xh,yh Define nt(y,x) = when(pxl Test(y,x), 1, 0) {}→save set Graph("Axes", "Off")→save[1] set Graph("Grid", "Off")→save[2] set Graph("Labels", "Off")→save[3] Fn Off Plot Off Clr Draw If pattern = "blinker" Then 36→yl 40→yh 78→xl 82→xh Pxl On 36,80 Pxl On 38,80 Pxl On 40,80 Else If pattern = "glider" Then 30→yl 40→yh 76→xl 88→xh Pxl On 38,76 Pxl On 36,78 Pxl On 36,80 Pxl On 38,80 Pxl On 40,80 Else If pattern = "r" Then 38-5*2→yl 38+5*2→yh 80-5*2→xl 80+5*2→xh Pxl On 38,78 Pxl On 36,82 Pxl On 36,80 Pxl On 38,80 Pxl On 40,80 End If While get Key() = 0 © Expand upper-left corner to whole cell For y,yl,yh,2 For x,xl,xh,2 If pxl Test(y,x) Then Pxl On y+1,x Pxl On y+1,x+1 Pxl On y, x+1 Else Pxl Off y+1,x Pxl Off y+1,x+1 Pxl Off y, x+1 End If End For End For © Compute next generation For y,yl,yh,2 For x,xl,xh,2 nt(y-1,x-1) + nt(y-1,x) + nt(y-1,x+2) + nt(y,x-1) + nt(y+1,x+2) + nt(y+2,x-1) + nt(y+2,x+1) + nt(y+2,x+2) → count If count = 3 Then Pxl On y,x Else If count ≠ 2 Then Pxl Off y,x End If End For End For End While © Restore changed options set Graph("Axes", save[1]) set Graph("Grid", save[2]) set Graph("Labels", save[3])End Prgm Also see Conway's Game of Life/C Considering that the simplest implementation in C++ would lack any use of the object-oriented paradigm, this code was specifically written to demonstrate the various object-oriented features of C++.

]] bne randloop lda cmp # bne randloop clearmem: lda #$df ;set df-[[

randfill: stx $01 ;$200 for indirect ldx #$02 ;addressing stx $02randloop: lda $fe ;generate random and #$01 ;pixels on the sta ($01), Y ;screen jsr inc0103 cmp #$00 bne randloop lda $02 cmp #$06 bne randloop clearmem: lda #$df ;set $07df-$0a20 sta $01 ;to $#00 lda #$07 sta $02clearbyte: lda #$00 sta ($01), Y jsr inc0103 cmp #$20 bne clearbyte lda $02 cmp #$0a bne clearbyte starttick:copyscreen: lda #$00 ;set up source sta $01 ;pointer at sta $03 ;$01/$02 and lda #$02 ;dest pointer sta $02 ;at $03/$04 lda #$08 sta $04 ldy #$00copybyte: lda ($01), Y ;copy pixel to sta ($03), Y ;back buffer jsr inc0103 ;increment pointers cmp #$00 ;check to see bne copybyte ;if we're at $600 lda $02 ;if so, we've cmp #$06 ;copied the bne copybyte ;entire screen conway: lda #$df ;apply conway rules sta $01 ;reset the pointer sta $03 ;to $#01df/$#07df lda #$01 ;($200 - $21) sta $02 ;($800 - $21) lda #$07 sta $04onecell: lda #$00 ;process one cell ldy #$01 ;upper cell clc adc ($03), Y ldy #$41 ;lower cell clc adc ($03), Ychkleft: tax ;check to see lda $01 ;if we're at the and #$1f ;left edge tay txa cpy #$1f beq rightcellsleftcells: ldy #$00 ;upper-left cell clc adc ($03), Y ldy #$20 ;left cell clc adc ($03), Y ldy #$40 ;lower-left cell clc adc ($03), Ychkright: tax ;check to see lda $01 ;if we're at the and #$1f ;right edge tay txa cpy #$1e beq evaluaterightcells: ldy #$02 ;upper-right cell clc adc ($03), Y ldy #$22 ;right cell clc adc ($03), Y ldy #$42 ;lower-right cell clc adc ($03), Yevaluate: ldx #$01 ;evaluate total ldy #$21 ;for current cell cmp #$03 ;3 = alive beq storex ldx #$00 cmp #$02 ;2 = alive if bne storex ;c = alive lda ($03), Y and #$01 taxstorex: txa ;store to screen sta ($01), Y jsr inc0103 ;move to next cellconwayloop: cmp #$e0 ;if not last cell, bne onecell ;process next cell lda $02 cmp #$05 bne onecell jmp starttick ;run next tick inc0103: lda $01 ;increment $01 cmp #$ff ;and $03 as 16-bit bne onlyinc01 ;pointers inc $02 inc $04onlyinc01: inc $01 lda $01 sta $03 rts The solution uses one cell thick border around square Petri dish as uninhabited dire land. Sample output contains 3 generations of the blinker and 5 of the glider: See Conway's Game of Life/ALGOL 68 APL2 (Dialog) Example in one line APL \ 1130 example (very old APL dialect via simulator) APL1130From: APL \ 1130 Samples The following APL \ 1130 code will need APL385 font installed to display correctly. See Download APL TT Font ∇LIFE[⎕]∇[0] NG←LIFE CG; W[1] W←CG+(¯1⊖CG)+(1⊖CG)+(¯1⌽CG)+(1⌽CG)[2] W←W+(1⊖1⌽CG)+(¯1⊖1⌽CG)+(1⊖¯1⌽CG)+(¯1⊖¯1⌽CG)[3] NG←(3=W)+(CG∧4=W) ∇ RP←5 5⍴0 0 0 0 0 0 0 1 1 0 0 1 1 0 0 0 0 1 0 0 RP0 0 0 0 00 0 1 1 00 1 1 0 00 0 1 0 00 0 0 0 0 LIFE RP0 0 0 0 00 1 1 1 00 1 0 0 00 1 1 0 00 0 0 0 0 LIFE LIFE RP0 0 1 0 00 1 1 0 01 0 0 1 00 1 1 0 00 0 0 0 0 .................................................. One interacts with the Game of Life by creating an initial configuration and observing how it evolves. Although you should test your implementation on more complex examples such as the glider in a larger universe, show the action of the blinker (three adjoining cells in a row all alive), over three generations, in a 3 by 3 grid. (1,4)=TRUERETURN'' Count the number of neighbours of the point i,j' (Assume i/j +/- 1 will not fall out of world)'FUNCTION count_neighbours(i%,j%) LOCAL count%,l% count%=0 FOR l%=-1 TO 1 IF world! (i%+l%,j%+1) count%=count%+1 ENDIF NEXT l% IF world! (i%+1,j%) count%=count%+1 ENDIF RETURN count%ENDFUNC'' Update the world one step'PROCEDURE update_world LOCAL i%,j% ' compute neighbour counts and store FOR i%=1 TO 30 FOR j%=1 TO 30 ns%(i%,j%)[email protected]_neighbours(i%,j%) NEXT j% NEXT i% ' update the world cells FOR i%=1 TO 30 FOR j%=1 TO 30 IF world!

||

randfill: stx $01 ;$200 for indirect ldx #$02 ;addressing stx $02randloop: lda $fe ;generate random and #$01 ;pixels on the sta ($01), Y ;screen jsr inc0103 cmp #$00 bne randloop lda $02 cmp #$06 bne randloop clearmem: lda #$df ;set $07df-$0a20 sta $01 ;to $#00 lda #$07 sta $02clearbyte: lda #$00 sta ($01), Y jsr inc0103 cmp #$20 bne clearbyte lda $02 cmp #$0a bne clearbyte starttick:copyscreen: lda #$00 ;set up source sta $01 ;pointer at sta $03 ;$01/$02 and lda #$02 ;dest pointer sta $02 ;at $03/$04 lda #$08 sta $04 ldy #$00copybyte: lda ($01), Y ;copy pixel to sta ($03), Y ;back buffer jsr inc0103 ;increment pointers cmp #$00 ;check to see bne copybyte ;if we're at $600 lda $02 ;if so, we've cmp #$06 ;copied the bne copybyte ;entire screen conway: lda #$df ;apply conway rules sta $01 ;reset the pointer sta $03 ;to $#01df/$#07df lda #$01 ;($200 - $21) sta $02 ;($800 - $21) lda #$07 sta $04onecell: lda #$00 ;process one cell ldy #$01 ;upper cell clc adc ($03), Y ldy #$41 ;lower cell clc adc ($03), Ychkleft: tax ;check to see lda $01 ;if we're at the and #$1f ;left edge tay txa cpy #$1f beq rightcellsleftcells: ldy #$00 ;upper-left cell clc adc ($03), Y ldy #$20 ;left cell clc adc ($03), Y ldy #$40 ;lower-left cell clc adc ($03), Ychkright: tax ;check to see lda $01 ;if we're at the and #$1f ;right edge tay txa cpy #$1e beq evaluaterightcells: ldy #$02 ;upper-right cell clc adc ($03), Y ldy #$22 ;right cell clc adc ($03), Y ldy #$42 ;lower-right cell clc adc ($03), Yevaluate: ldx #$01 ;evaluate total ldy #$21 ;for current cell cmp #$03 ;3 = alive beq storex ldx #$00 cmp #$02 ;2 = alive if bne storex ;c = alive lda ($03), Y and #$01 taxstorex: txa ;store to screen sta ($01), Y jsr inc0103 ;move to next cellconwayloop: cmp #$e0 ;if not last cell, bne onecell ;process next cell lda $02 cmp #$05 bne onecell jmp starttick ;run next tick inc0103: lda $01 ;increment $01 cmp #$ff ;and $03 as 16-bit bne onlyinc01 ;pointers inc $02 inc $04onlyinc01: inc $01 lda $01 sta $03 rts The solution uses one cell thick border around square Petri dish as uninhabited dire land. Sample output contains 3 generations of the blinker and 5 of the glider: See Conway's Game of Life/ALGOL 68 APL2 (Dialog) Example in one line APL \ 1130 example (very old APL dialect via simulator) APL1130From: APL \ 1130 Samples The following APL \ 1130 code will need APL385 font installed to display correctly.

See Download APL TT Font ∇LIFE[⎕]∇[0] NG←LIFE CG; W[1] W←CG+(¯1⊖CG)+(1⊖CG)+(¯1⌽CG)+(1⌽CG)[2] W←W+(1⊖1⌽CG)+(¯1⊖1⌽CG)+(1⊖¯1⌽CG)+(¯1⊖¯1⌽CG)[3] NG←(3=W)+(CG∧4=W) ∇ RP←5 5⍴0 0 0 0 0 0 0 1 1 0 0 1 1 0 0 0 0 1 0 0 RP0 0 0 0 00 0 1 1 00 1 1 0 00 0 1 0 00 0 0 0 0 LIFE RP0 0 0 0 00 1 1 1 00 1 0 0 00 1 1 0 00 0 0 0 0 LIFE LIFE RP0 0 1 0 00 1 1 0 01 0 0 1 00 1 1 0 00 0 0 0 0 ..................................................

One interacts with the Game of Life by creating an initial configuration and observing how it evolves.

Although you should test your implementation on more complex examples such as the glider in a larger universe, show the action of the blinker (three adjoining cells in a row all alive), over three generations, in a 3 by 3 grid.

(1,4)=TRUERETURN'' Count the number of neighbours of the point i,j' (Assume i/j +/- 1 will not fall out of world)'FUNCTION count_neighbours(i%,j%) LOCAL count%,l% count%=0 FOR l%=-1 TO 1 IF world! (i%+l%,j%+1) count%=count%+1 ENDIF NEXT l% IF world! (i%+1,j%) count%=count%+1 ENDIF RETURN count%ENDFUNC'' Update the world one step'PROCEDURE update_world LOCAL i%,j% ' compute neighbour counts and store FOR i%=1 TO 30 FOR j%=1 TO 30 ns%(i%,j%)[email protected]_neighbours(i%,j%) NEXT j% NEXT i% ' update the world cells FOR i%=1 TO 30 FOR j%=1 TO 30 IF world!

Thus, while it is somewhat verbose, it fully simulates Conway's Game of Life and is relatively simple to expand to feature different starting shapes.

Define life(pattern) = Prgm Local x,y,nt,count,save,xl,yl,xh,yh Define nt(y,x) = when(pxl Test(y,x), 1, 0) {}→save set Graph("Axes", "Off")→save[1] set Graph("Grid", "Off")→save[2] set Graph("Labels", "Off")→save[3] Fn Off Plot Off Clr Draw If pattern = "blinker" Then 36→yl 40→yh 78→xl 82→xh Pxl On 36,80 Pxl On 38,80 Pxl On 40,80 Else If pattern = "glider" Then 30→yl 40→yh 76→xl 88→xh Pxl On 38,76 Pxl On 36,78 Pxl On 36,80 Pxl On 38,80 Pxl On 40,80 Else If pattern = "r" Then 38-5*2→yl 38+5*2→yh 80-5*2→xl 80+5*2→xh Pxl On 38,78 Pxl On 36,82 Pxl On 36,80 Pxl On 38,80 Pxl On 40,80 End If While get Key() = 0 © Expand upper-left corner to whole cell For y,yl,yh,2 For x,xl,xh,2 If pxl Test(y,x) Then Pxl On y+1,x Pxl On y+1,x+1 Pxl On y, x+1 Else Pxl Off y+1,x Pxl Off y+1,x+1 Pxl Off y, x+1 End If End For End For © Compute next generation For y,yl,yh,2 For x,xl,xh,2 nt(y-1,x-1) + nt(y-1,x) + nt(y-1,x+2) + nt(y,x-1) + nt(y+1,x+2) + nt(y+2,x-1) + nt(y+2,x+1) + nt(y+2,x+2) → count If count = 3 Then Pxl On y,x Else If count ≠ 2 Then Pxl Off y,x End If End For End For End While © Restore changed options set Graph("Axes", save[1]) set Graph("Grid", save[2]) set Graph("Labels", save[3])End Prgm Also see Conway's Game of Life/C Considering that the simplest implementation in C++ would lack any use of the object-oriented paradigm, this code was specifically written to demonstrate the various object-oriented features of C++.

]]a20 sta

randfill: stx $01 ;$200 for indirect ldx #$02 ;addressing stx $02randloop: lda $fe ;generate random and #$01 ;pixels on the sta ($01), Y ;screen jsr inc0103 cmp #$00 bne randloop lda $02 cmp #$06 bne randloop clearmem: lda #$df ;set $07df-$0a20 sta $01 ;to $#00 lda #$07 sta $02clearbyte: lda #$00 sta ($01), Y jsr inc0103 cmp #$20 bne clearbyte lda $02 cmp #$0a bne clearbyte starttick:copyscreen: lda #$00 ;set up source sta $01 ;pointer at sta $03 ;$01/$02 and lda #$02 ;dest pointer sta $02 ;at $03/$04 lda #$08 sta $04 ldy #$00copybyte: lda ($01), Y ;copy pixel to sta ($03), Y ;back buffer jsr inc0103 ;increment pointers cmp #$00 ;check to see bne copybyte ;if we're at $600 lda $02 ;if so, we've cmp #$06 ;copied the bne copybyte ;entire screen conway: lda #$df ;apply conway rules sta $01 ;reset the pointer sta $03 ;to $#01df/$#07df lda #$01 ;($200 - $21) sta $02 ;($800 - $21) lda #$07 sta $04onecell: lda #$00 ;process one cell ldy #$01 ;upper cell clc adc ($03), Y ldy #$41 ;lower cell clc adc ($03), Ychkleft: tax ;check to see lda $01 ;if we're at the and #$1f ;left edge tay txa cpy #$1f beq rightcellsleftcells: ldy #$00 ;upper-left cell clc adc ($03), Y ldy #$20 ;left cell clc adc ($03), Y ldy #$40 ;lower-left cell clc adc ($03), Ychkright: tax ;check to see lda $01 ;if we're at the and #$1f ;right edge tay txa cpy #$1e beq evaluaterightcells: ldy #$02 ;upper-right cell clc adc ($03), Y ldy #$22 ;right cell clc adc ($03), Y ldy #$42 ;lower-right cell clc adc ($03), Yevaluate: ldx #$01 ;evaluate total ldy #$21 ;for current cell cmp #$03 ;3 = alive beq storex ldx #$00 cmp #$02 ;2 = alive if bne storex ;c = alive lda ($03), Y and #$01 taxstorex: txa ;store to screen sta ($01), Y jsr inc0103 ;move to next cellconwayloop: cmp #$e0 ;if not last cell, bne onecell ;process next cell lda $02 cmp #$05 bne onecell jmp starttick ;run next tick inc0103: lda $01 ;increment $01 cmp #$ff ;and $03 as 16-bit bne onlyinc01 ;pointers inc $02 inc $04onlyinc01: inc $01 lda $01 sta $03 rts The solution uses one cell thick border around square Petri dish as uninhabited dire land. Sample output contains 3 generations of the blinker and 5 of the glider: See Conway's Game of Life/ALGOL 68 APL2 (Dialog) Example in one line APL \ 1130 example (very old APL dialect via simulator) APL1130From: APL \ 1130 Samples The following APL \ 1130 code will need APL385 font installed to display correctly. See Download APL TT Font ∇LIFE[⎕]∇[0] NG←LIFE CG; W[1] W←CG+(¯1⊖CG)+(1⊖CG)+(¯1⌽CG)+(1⌽CG)[2] W←W+(1⊖1⌽CG)+(¯1⊖1⌽CG)+(1⊖¯1⌽CG)+(¯1⊖¯1⌽CG)[3] NG←(3=W)+(CG∧4=W) ∇ RP←5 5⍴0 0 0 0 0 0 0 1 1 0 0 1 1 0 0 0 0 1 0 0 RP0 0 0 0 00 0 1 1 00 1 1 0 00 0 1 0 00 0 0 0 0 LIFE RP0 0 0 0 00 1 1 1 00 1 0 0 00 1 1 0 00 0 0 0 0 LIFE LIFE RP0 0 1 0 00 1 1 0 01 0 0 1 00 1 1 0 00 0 0 0 0 .................................................. One interacts with the Game of Life by creating an initial configuration and observing how it evolves. Although you should test your implementation on more complex examples such as the glider in a larger universe, show the action of the blinker (three adjoining cells in a row all alive), over three generations, in a 3 by 3 grid. (1,4)=TRUERETURN'' Count the number of neighbours of the point i,j' (Assume i/j +/- 1 will not fall out of world)'FUNCTION count_neighbours(i%,j%) LOCAL count%,l% count%=0 FOR l%=-1 TO 1 IF world! (i%+l%,j%+1) count%=count%+1 ENDIF NEXT l% IF world! (i%+1,j%) count%=count%+1 ENDIF RETURN count%ENDFUNC'' Update the world one step'PROCEDURE update_world LOCAL i%,j% ' compute neighbour counts and store FOR i%=1 TO 30 FOR j%=1 TO 30 ns%(i%,j%)[email protected]_neighbours(i%,j%) NEXT j% NEXT i% ' update the world cells FOR i%=1 TO 30 FOR j%=1 TO 30 IF world!

||

randfill: stx $01 ;$200 for indirect ldx #$02 ;addressing stx $02randloop: lda $fe ;generate random and #$01 ;pixels on the sta ($01), Y ;screen jsr inc0103 cmp #$00 bne randloop lda $02 cmp #$06 bne randloop clearmem: lda #$df ;set $07df-$0a20 sta $01 ;to $#00 lda #$07 sta $02clearbyte: lda #$00 sta ($01), Y jsr inc0103 cmp #$20 bne clearbyte lda $02 cmp #$0a bne clearbyte starttick:copyscreen: lda #$00 ;set up source sta $01 ;pointer at sta $03 ;$01/$02 and lda #$02 ;dest pointer sta $02 ;at $03/$04 lda #$08 sta $04 ldy #$00copybyte: lda ($01), Y ;copy pixel to sta ($03), Y ;back buffer jsr inc0103 ;increment pointers cmp #$00 ;check to see bne copybyte ;if we're at $600 lda $02 ;if so, we've cmp #$06 ;copied the bne copybyte ;entire screen conway: lda #$df ;apply conway rules sta $01 ;reset the pointer sta $03 ;to $#01df/$#07df lda #$01 ;($200 - $21) sta $02 ;($800 - $21) lda #$07 sta $04onecell: lda #$00 ;process one cell ldy #$01 ;upper cell clc adc ($03), Y ldy #$41 ;lower cell clc adc ($03), Ychkleft: tax ;check to see lda $01 ;if we're at the and #$1f ;left edge tay txa cpy #$1f beq rightcellsleftcells: ldy #$00 ;upper-left cell clc adc ($03), Y ldy #$20 ;left cell clc adc ($03), Y ldy #$40 ;lower-left cell clc adc ($03), Ychkright: tax ;check to see lda $01 ;if we're at the and #$1f ;right edge tay txa cpy #$1e beq evaluaterightcells: ldy #$02 ;upper-right cell clc adc ($03), Y ldy #$22 ;right cell clc adc ($03), Y ldy #$42 ;lower-right cell clc adc ($03), Yevaluate: ldx #$01 ;evaluate total ldy #$21 ;for current cell cmp #$03 ;3 = alive beq storex ldx #$00 cmp #$02 ;2 = alive if bne storex ;c = alive lda ($03), Y and #$01 taxstorex: txa ;store to screen sta ($01), Y jsr inc0103 ;move to next cellconwayloop: cmp #$e0 ;if not last cell, bne onecell ;process next cell lda $02 cmp #$05 bne onecell jmp starttick ;run next tick inc0103: lda $01 ;increment $01 cmp #$ff ;and $03 as 16-bit bne onlyinc01 ;pointers inc $02 inc $04onlyinc01: inc $01 lda $01 sta $03 rts The solution uses one cell thick border around square Petri dish as uninhabited dire land. Sample output contains 3 generations of the blinker and 5 of the glider: See Conway's Game of Life/ALGOL 68 APL2 (Dialog) Example in one line APL \ 1130 example (very old APL dialect via simulator) APL1130From: APL \ 1130 Samples The following APL \ 1130 code will need APL385 font installed to display correctly.

See Download APL TT Font ∇LIFE[⎕]∇[0] NG←LIFE CG; W[1] W←CG+(¯1⊖CG)+(1⊖CG)+(¯1⌽CG)+(1⌽CG)[2] W←W+(1⊖1⌽CG)+(¯1⊖1⌽CG)+(1⊖¯1⌽CG)+(¯1⊖¯1⌽CG)[3] NG←(3=W)+(CG∧4=W) ∇ RP←5 5⍴0 0 0 0 0 0 0 1 1 0 0 1 1 0 0 0 0 1 0 0 RP0 0 0 0 00 0 1 1 00 1 1 0 00 0 1 0 00 0 0 0 0 LIFE RP0 0 0 0 00 1 1 1 00 1 0 0 00 1 1 0 00 0 0 0 0 LIFE LIFE RP0 0 1 0 00 1 1 0 01 0 0 1 00 1 1 0 00 0 0 0 0 ..................................................

One interacts with the Game of Life by creating an initial configuration and observing how it evolves.

Although you should test your implementation on more complex examples such as the glider in a larger universe, show the action of the blinker (three adjoining cells in a row all alive), over three generations, in a 3 by 3 grid.

(1,4)=TRUERETURN'' Count the number of neighbours of the point i,j' (Assume i/j +/- 1 will not fall out of world)'FUNCTION count_neighbours(i%,j%) LOCAL count%,l% count%=0 FOR l%=-1 TO 1 IF world! (i%+l%,j%+1) count%=count%+1 ENDIF NEXT l% IF world! (i%+1,j%) count%=count%+1 ENDIF RETURN count%ENDFUNC'' Update the world one step'PROCEDURE update_world LOCAL i%,j% ' compute neighbour counts and store FOR i%=1 TO 30 FOR j%=1 TO 30 ns%(i%,j%)[email protected]_neighbours(i%,j%) NEXT j% NEXT i% ' update the world cells FOR i%=1 TO 30 FOR j%=1 TO 30 IF world!

Thus, while it is somewhat verbose, it fully simulates Conway's Game of Life and is relatively simple to expand to feature different starting shapes.

Define life(pattern) = Prgm Local x,y,nt,count,save,xl,yl,xh,yh Define nt(y,x) = when(pxl Test(y,x), 1, 0) {}→save set Graph("Axes", "Off")→save[1] set Graph("Grid", "Off")→save[2] set Graph("Labels", "Off")→save[3] Fn Off Plot Off Clr Draw If pattern = "blinker" Then 36→yl 40→yh 78→xl 82→xh Pxl On 36,80 Pxl On 38,80 Pxl On 40,80 Else If pattern = "glider" Then 30→yl 40→yh 76→xl 88→xh Pxl On 38,76 Pxl On 36,78 Pxl On 36,80 Pxl On 38,80 Pxl On 40,80 Else If pattern = "r" Then 38-5*2→yl 38+5*2→yh 80-5*2→xl 80+5*2→xh Pxl On 38,78 Pxl On 36,82 Pxl On 36,80 Pxl On 38,80 Pxl On 40,80 End If While get Key() = 0 © Expand upper-left corner to whole cell For y,yl,yh,2 For x,xl,xh,2 If pxl Test(y,x) Then Pxl On y+1,x Pxl On y+1,x+1 Pxl On y, x+1 Else Pxl Off y+1,x Pxl Off y+1,x+1 Pxl Off y, x+1 End If End For End For © Compute next generation For y,yl,yh,2 For x,xl,xh,2 nt(y-1,x-1) + nt(y-1,x) + nt(y-1,x+2) + nt(y,x-1) + nt(y+1,x+2) + nt(y+2,x-1) + nt(y+2,x+1) + nt(y+2,x+2) → count If count = 3 Then Pxl On y,x Else If count ≠ 2 Then Pxl Off y,x End If End For End For End While © Restore changed options set Graph("Axes", save[1]) set Graph("Grid", save[2]) set Graph("Labels", save[3])End Prgm Also see Conway's Game of Life/C Considering that the simplest implementation in C++ would lack any use of the object-oriented paradigm, this code was specifically written to demonstrate the various object-oriented features of C++.

;to $#00 lda # sta clearbyte: lda #[[

randfill: stx $01 ;$200 for indirect ldx #$02 ;addressing stx $02randloop: lda $fe ;generate random and #$01 ;pixels on the sta ($01), Y ;screen jsr inc0103 cmp #$00 bne randloop lda $02 cmp #$06 bne randloop clearmem: lda #$df ;set $07df-$0a20 sta $01 ;to $#00 lda #$07 sta $02clearbyte: lda #$00 sta ($01), Y jsr inc0103 cmp #$20 bne clearbyte lda $02 cmp #$0a bne clearbyte starttick:copyscreen: lda #$00 ;set up source sta $01 ;pointer at sta $03 ;$01/$02 and lda #$02 ;dest pointer sta $02 ;at $03/$04 lda #$08 sta $04 ldy #$00copybyte: lda ($01), Y ;copy pixel to sta ($03), Y ;back buffer jsr inc0103 ;increment pointers cmp #$00 ;check to see bne copybyte ;if we're at $600 lda $02 ;if so, we've cmp #$06 ;copied the bne copybyte ;entire screen conway: lda #$df ;apply conway rules sta $01 ;reset the pointer sta $03 ;to $#01df/$#07df lda #$01 ;($200 - $21) sta $02 ;($800 - $21) lda #$07 sta $04onecell: lda #$00 ;process one cell ldy #$01 ;upper cell clc adc ($03), Y ldy #$41 ;lower cell clc adc ($03), Ychkleft: tax ;check to see lda $01 ;if we're at the and #$1f ;left edge tay txa cpy #$1f beq rightcellsleftcells: ldy #$00 ;upper-left cell clc adc ($03), Y ldy #$20 ;left cell clc adc ($03), Y ldy #$40 ;lower-left cell clc adc ($03), Ychkright: tax ;check to see lda $01 ;if we're at the and #$1f ;right edge tay txa cpy #$1e beq evaluaterightcells: ldy #$02 ;upper-right cell clc adc ($03), Y ldy #$22 ;right cell clc adc ($03), Y ldy #$42 ;lower-right cell clc adc ($03), Yevaluate: ldx #$01 ;evaluate total ldy #$21 ;for current cell cmp #$03 ;3 = alive beq storex ldx #$00 cmp #$02 ;2 = alive if bne storex ;c = alive lda ($03), Y and #$01 taxstorex: txa ;store to screen sta ($01), Y jsr inc0103 ;move to next cellconwayloop: cmp #$e0 ;if not last cell, bne onecell ;process next cell lda $02 cmp #$05 bne onecell jmp starttick ;run next tick inc0103: lda $01 ;increment $01 cmp #$ff ;and $03 as 16-bit bne onlyinc01 ;pointers inc $02 inc $04onlyinc01: inc $01 lda $01 sta $03 rts The solution uses one cell thick border around square Petri dish as uninhabited dire land. Sample output contains 3 generations of the blinker and 5 of the glider: See Conway's Game of Life/ALGOL 68 APL2 (Dialog) Example in one line APL \ 1130 example (very old APL dialect via simulator) APL1130From: APL \ 1130 Samples The following APL \ 1130 code will need APL385 font installed to display correctly. See Download APL TT Font ∇LIFE[⎕]∇[0] NG←LIFE CG; W[1] W←CG+(¯1⊖CG)+(1⊖CG)+(¯1⌽CG)+(1⌽CG)[2] W←W+(1⊖1⌽CG)+(¯1⊖1⌽CG)+(1⊖¯1⌽CG)+(¯1⊖¯1⌽CG)[3] NG←(3=W)+(CG∧4=W) ∇ RP←5 5⍴0 0 0 0 0 0 0 1 1 0 0 1 1 0 0 0 0 1 0 0 RP0 0 0 0 00 0 1 1 00 1 1 0 00 0 1 0 00 0 0 0 0 LIFE RP0 0 0 0 00 1 1 1 00 1 0 0 00 1 1 0 00 0 0 0 0 LIFE LIFE RP0 0 1 0 00 1 1 0 01 0 0 1 00 1 1 0 00 0 0 0 0 .................................................. One interacts with the Game of Life by creating an initial configuration and observing how it evolves. Although you should test your implementation on more complex examples such as the glider in a larger universe, show the action of the blinker (three adjoining cells in a row all alive), over three generations, in a 3 by 3 grid. (1,4)=TRUERETURN'' Count the number of neighbours of the point i,j' (Assume i/j +/- 1 will not fall out of world)'FUNCTION count_neighbours(i%,j%) LOCAL count%,l% count%=0 FOR l%=-1 TO 1 IF world! (i%+l%,j%+1) count%=count%+1 ENDIF NEXT l% IF world! (i%+1,j%) count%=count%+1 ENDIF RETURN count%ENDFUNC'' Update the world one step'PROCEDURE update_world LOCAL i%,j% ' compute neighbour counts and store FOR i%=1 TO 30 FOR j%=1 TO 30 ns%(i%,j%)[email protected]_neighbours(i%,j%) NEXT j% NEXT i% ' update the world cells FOR i%=1 TO 30 FOR j%=1 TO 30 IF world!

||

randfill: stx $01 ;$200 for indirect ldx #$02 ;addressing stx $02randloop: lda $fe ;generate random and #$01 ;pixels on the sta ($01), Y ;screen jsr inc0103 cmp #$00 bne randloop lda $02 cmp #$06 bne randloop clearmem: lda #$df ;set $07df-$0a20 sta $01 ;to $#00 lda #$07 sta $02clearbyte: lda #$00 sta ($01), Y jsr inc0103 cmp #$20 bne clearbyte lda $02 cmp #$0a bne clearbyte starttick:copyscreen: lda #$00 ;set up source sta $01 ;pointer at sta $03 ;$01/$02 and lda #$02 ;dest pointer sta $02 ;at $03/$04 lda #$08 sta $04 ldy #$00copybyte: lda ($01), Y ;copy pixel to sta ($03), Y ;back buffer jsr inc0103 ;increment pointers cmp #$00 ;check to see bne copybyte ;if we're at $600 lda $02 ;if so, we've cmp #$06 ;copied the bne copybyte ;entire screen conway: lda #$df ;apply conway rules sta $01 ;reset the pointer sta $03 ;to $#01df/$#07df lda #$01 ;($200 - $21) sta $02 ;($800 - $21) lda #$07 sta $04onecell: lda #$00 ;process one cell ldy #$01 ;upper cell clc adc ($03), Y ldy #$41 ;lower cell clc adc ($03), Ychkleft: tax ;check to see lda $01 ;if we're at the and #$1f ;left edge tay txa cpy #$1f beq rightcellsleftcells: ldy #$00 ;upper-left cell clc adc ($03), Y ldy #$20 ;left cell clc adc ($03), Y ldy #$40 ;lower-left cell clc adc ($03), Ychkright: tax ;check to see lda $01 ;if we're at the and #$1f ;right edge tay txa cpy #$1e beq evaluaterightcells: ldy #$02 ;upper-right cell clc adc ($03), Y ldy #$22 ;right cell clc adc ($03), Y ldy #$42 ;lower-right cell clc adc ($03), Yevaluate: ldx #$01 ;evaluate total ldy #$21 ;for current cell cmp #$03 ;3 = alive beq storex ldx #$00 cmp #$02 ;2 = alive if bne storex ;c = alive lda ($03), Y and #$01 taxstorex: txa ;store to screen sta ($01), Y jsr inc0103 ;move to next cellconwayloop: cmp #$e0 ;if not last cell, bne onecell ;process next cell lda $02 cmp #$05 bne onecell jmp starttick ;run next tick inc0103: lda $01 ;increment $01 cmp #$ff ;and $03 as 16-bit bne onlyinc01 ;pointers inc $02 inc $04onlyinc01: inc $01 lda $01 sta $03 rts The solution uses one cell thick border around square Petri dish as uninhabited dire land. Sample output contains 3 generations of the blinker and 5 of the glider: See Conway's Game of Life/ALGOL 68 APL2 (Dialog) Example in one line APL \ 1130 example (very old APL dialect via simulator) APL1130From: APL \ 1130 Samples The following APL \ 1130 code will need APL385 font installed to display correctly.

See Download APL TT Font ∇LIFE[⎕]∇[0] NG←LIFE CG; W[1] W←CG+(¯1⊖CG)+(1⊖CG)+(¯1⌽CG)+(1⌽CG)[2] W←W+(1⊖1⌽CG)+(¯1⊖1⌽CG)+(1⊖¯1⌽CG)+(¯1⊖¯1⌽CG)[3] NG←(3=W)+(CG∧4=W) ∇ RP←5 5⍴0 0 0 0 0 0 0 1 1 0 0 1 1 0 0 0 0 1 0 0 RP0 0 0 0 00 0 1 1 00 1 1 0 00 0 1 0 00 0 0 0 0 LIFE RP0 0 0 0 00 1 1 1 00 1 0 0 00 1 1 0 00 0 0 0 0 LIFE LIFE RP0 0 1 0 00 1 1 0 01 0 0 1 00 1 1 0 00 0 0 0 0 ..................................................

One interacts with the Game of Life by creating an initial configuration and observing how it evolves.

Although you should test your implementation on more complex examples such as the glider in a larger universe, show the action of the blinker (three adjoining cells in a row all alive), over three generations, in a 3 by 3 grid.

(1,4)=TRUERETURN'' Count the number of neighbours of the point i,j' (Assume i/j +/- 1 will not fall out of world)'FUNCTION count_neighbours(i%,j%) LOCAL count%,l% count%=0 FOR l%=-1 TO 1 IF world! (i%+l%,j%+1) count%=count%+1 ENDIF NEXT l% IF world! (i%+1,j%) count%=count%+1 ENDIF RETURN count%ENDFUNC'' Update the world one step'PROCEDURE update_world LOCAL i%,j% ' compute neighbour counts and store FOR i%=1 TO 30 FOR j%=1 TO 30 ns%(i%,j%)[email protected]_neighbours(i%,j%) NEXT j% NEXT i% ' update the world cells FOR i%=1 TO 30 FOR j%=1 TO 30 IF world!

Thus, while it is somewhat verbose, it fully simulates Conway's Game of Life and is relatively simple to expand to feature different starting shapes.

Define life(pattern) = Prgm Local x,y,nt,count,save,xl,yl,xh,yh Define nt(y,x) = when(pxl Test(y,x), 1, 0) {}→save set Graph("Axes", "Off")→save[1] set Graph("Grid", "Off")→save[2] set Graph("Labels", "Off")→save[3] Fn Off Plot Off Clr Draw If pattern = "blinker" Then 36→yl 40→yh 78→xl 82→xh Pxl On 36,80 Pxl On 38,80 Pxl On 40,80 Else If pattern = "glider" Then 30→yl 40→yh 76→xl 88→xh Pxl On 38,76 Pxl On 36,78 Pxl On 36,80 Pxl On 38,80 Pxl On 40,80 Else If pattern = "r" Then 38-5*2→yl 38+5*2→yh 80-5*2→xl 80+5*2→xh Pxl On 38,78 Pxl On 36,82 Pxl On 36,80 Pxl On 38,80 Pxl On 40,80 End If While get Key() = 0 © Expand upper-left corner to whole cell For y,yl,yh,2 For x,xl,xh,2 If pxl Test(y,x) Then Pxl On y+1,x Pxl On y+1,x+1 Pxl On y, x+1 Else Pxl Off y+1,x Pxl Off y+1,x+1 Pxl Off y, x+1 End If End For End For © Compute next generation For y,yl,yh,2 For x,xl,xh,2 nt(y-1,x-1) + nt(y-1,x) + nt(y-1,x+2) + nt(y,x-1) + nt(y+1,x+2) + nt(y+2,x-1) + nt(y+2,x+1) + nt(y+2,x+2) → count If count = 3 Then Pxl On y,x Else If count ≠ 2 Then Pxl Off y,x End If End For End For End While © Restore changed options set Graph("Axes", save[1]) set Graph("Grid", save[2]) set Graph("Labels", save[3])End Prgm Also see Conway's Game of Life/C Considering that the simplest implementation in C++ would lack any use of the object-oriented paradigm, this code was specifically written to demonstrate the various object-oriented features of C++.

]] sta (

randfill: stx $01 ;$200 for indirect ldx #$02 ;addressing stx $02randloop: lda $fe ;generate random and #$01 ;pixels on the sta ($01), Y ;screen jsr inc0103 cmp #$00 bne randloop lda $02 cmp #$06 bne randloop clearmem: lda #$df ;set $07df-$0a20 sta $01 ;to $#00 lda #$07 sta $02clearbyte: lda #$00 sta ($01), Y jsr inc0103 cmp #$20 bne clearbyte lda $02 cmp #$0a bne clearbyte starttick:copyscreen: lda #$00 ;set up source sta $01 ;pointer at sta $03 ;$01/$02 and lda #$02 ;dest pointer sta $02 ;at $03/$04 lda #$08 sta $04 ldy #$00copybyte: lda ($01), Y ;copy pixel to sta ($03), Y ;back buffer jsr inc0103 ;increment pointers cmp #$00 ;check to see bne copybyte ;if we're at $600 lda $02 ;if so, we've cmp #$06 ;copied the bne copybyte ;entire screen conway: lda #$df ;apply conway rules sta $01 ;reset the pointer sta $03 ;to $#01df/$#07df lda #$01 ;($200 - $21) sta $02 ;($800 - $21) lda #$07 sta $04onecell: lda #$00 ;process one cell ldy #$01 ;upper cell clc adc ($03), Y ldy #$41 ;lower cell clc adc ($03), Ychkleft: tax ;check to see lda $01 ;if we're at the and #$1f ;left edge tay txa cpy #$1f beq rightcellsleftcells: ldy #$00 ;upper-left cell clc adc ($03), Y ldy #$20 ;left cell clc adc ($03), Y ldy #$40 ;lower-left cell clc adc ($03), Ychkright: tax ;check to see lda $01 ;if we're at the and #$1f ;right edge tay txa cpy #$1e beq evaluaterightcells: ldy #$02 ;upper-right cell clc adc ($03), Y ldy #$22 ;right cell clc adc ($03), Y ldy #$42 ;lower-right cell clc adc ($03), Yevaluate: ldx #$01 ;evaluate total ldy #$21 ;for current cell cmp #$03 ;3 = alive beq storex ldx #$00 cmp #$02 ;2 = alive if bne storex ;c = alive lda ($03), Y and #$01 taxstorex: txa ;store to screen sta ($01), Y jsr inc0103 ;move to next cellconwayloop: cmp #$e0 ;if not last cell, bne onecell ;process next cell lda $02 cmp #$05 bne onecell jmp starttick ;run next tick inc0103: lda $01 ;increment $01 cmp #$ff ;and $03 as 16-bit bne onlyinc01 ;pointers inc $02 inc $04onlyinc01: inc $01 lda $01 sta $03 rts The solution uses one cell thick border around square Petri dish as uninhabited dire land. Sample output contains 3 generations of the blinker and 5 of the glider: See Conway's Game of Life/ALGOL 68 APL2 (Dialog) Example in one line APL \ 1130 example (very old APL dialect via simulator) APL1130From: APL \ 1130 Samples The following APL \ 1130 code will need APL385 font installed to display correctly. See Download APL TT Font ∇LIFE[⎕]∇[0] NG←LIFE CG; W[1] W←CG+(¯1⊖CG)+(1⊖CG)+(¯1⌽CG)+(1⌽CG)[2] W←W+(1⊖1⌽CG)+(¯1⊖1⌽CG)+(1⊖¯1⌽CG)+(¯1⊖¯1⌽CG)[3] NG←(3=W)+(CG∧4=W) ∇ RP←5 5⍴0 0 0 0 0 0 0 1 1 0 0 1 1 0 0 0 0 1 0 0 RP0 0 0 0 00 0 1 1 00 1 1 0 00 0 1 0 00 0 0 0 0 LIFE RP0 0 0 0 00 1 1 1 00 1 0 0 00 1 1 0 00 0 0 0 0 LIFE LIFE RP0 0 1 0 00 1 1 0 01 0 0 1 00 1 1 0 00 0 0 0 0 .................................................. One interacts with the Game of Life by creating an initial configuration and observing how it evolves. Although you should test your implementation on more complex examples such as the glider in a larger universe, show the action of the blinker (three adjoining cells in a row all alive), over three generations, in a 3 by 3 grid. (1,4)=TRUERETURN'' Count the number of neighbours of the point i,j' (Assume i/j +/- 1 will not fall out of world)'FUNCTION count_neighbours(i%,j%) LOCAL count%,l% count%=0 FOR l%=-1 TO 1 IF world! (i%+l%,j%+1) count%=count%+1 ENDIF NEXT l% IF world! (i%+1,j%) count%=count%+1 ENDIF RETURN count%ENDFUNC'' Update the world one step'PROCEDURE update_world LOCAL i%,j% ' compute neighbour counts and store FOR i%=1 TO 30 FOR j%=1 TO 30 ns%(i%,j%)[email protected]_neighbours(i%,j%) NEXT j% NEXT i% ' update the world cells FOR i%=1 TO 30 FOR j%=1 TO 30 IF world!

||

randfill: stx $01 ;$200 for indirect ldx #$02 ;addressing stx $02randloop: lda $fe ;generate random and #$01 ;pixels on the sta ($01), Y ;screen jsr inc0103 cmp #$00 bne randloop lda $02 cmp #$06 bne randloop clearmem: lda #$df ;set $07df-$0a20 sta $01 ;to $#00 lda #$07 sta $02clearbyte: lda #$00 sta ($01), Y jsr inc0103 cmp #$20 bne clearbyte lda $02 cmp #$0a bne clearbyte starttick:copyscreen: lda #$00 ;set up source sta $01 ;pointer at sta $03 ;$01/$02 and lda #$02 ;dest pointer sta $02 ;at $03/$04 lda #$08 sta $04 ldy #$00copybyte: lda ($01), Y ;copy pixel to sta ($03), Y ;back buffer jsr inc0103 ;increment pointers cmp #$00 ;check to see bne copybyte ;if we're at $600 lda $02 ;if so, we've cmp #$06 ;copied the bne copybyte ;entire screen conway: lda #$df ;apply conway rules sta $01 ;reset the pointer sta $03 ;to $#01df/$#07df lda #$01 ;($200 - $21) sta $02 ;($800 - $21) lda #$07 sta $04onecell: lda #$00 ;process one cell ldy #$01 ;upper cell clc adc ($03), Y ldy #$41 ;lower cell clc adc ($03), Ychkleft: tax ;check to see lda $01 ;if we're at the and #$1f ;left edge tay txa cpy #$1f beq rightcellsleftcells: ldy #$00 ;upper-left cell clc adc ($03), Y ldy #$20 ;left cell clc adc ($03), Y ldy #$40 ;lower-left cell clc adc ($03), Ychkright: tax ;check to see lda $01 ;if we're at the and #$1f ;right edge tay txa cpy #$1e beq evaluaterightcells: ldy #$02 ;upper-right cell clc adc ($03), Y ldy #$22 ;right cell clc adc ($03), Y ldy #$42 ;lower-right cell clc adc ($03), Yevaluate: ldx #$01 ;evaluate total ldy #$21 ;for current cell cmp #$03 ;3 = alive beq storex ldx #$00 cmp #$02 ;2 = alive if bne storex ;c = alive lda ($03), Y and #$01 taxstorex: txa ;store to screen sta ($01), Y jsr inc0103 ;move to next cellconwayloop: cmp #$e0 ;if not last cell, bne onecell ;process next cell lda $02 cmp #$05 bne onecell jmp starttick ;run next tick inc0103: lda $01 ;increment $01 cmp #$ff ;and $03 as 16-bit bne onlyinc01 ;pointers inc $02 inc $04onlyinc01: inc $01 lda $01 sta $03 rts The solution uses one cell thick border around square Petri dish as uninhabited dire land. Sample output contains 3 generations of the blinker and 5 of the glider: See Conway's Game of Life/ALGOL 68 APL2 (Dialog) Example in one line APL \ 1130 example (very old APL dialect via simulator) APL1130From: APL \ 1130 Samples The following APL \ 1130 code will need APL385 font installed to display correctly.

See Download APL TT Font ∇LIFE[⎕]∇[0] NG←LIFE CG; W[1] W←CG+(¯1⊖CG)+(1⊖CG)+(¯1⌽CG)+(1⌽CG)[2] W←W+(1⊖1⌽CG)+(¯1⊖1⌽CG)+(1⊖¯1⌽CG)+(¯1⊖¯1⌽CG)[3] NG←(3=W)+(CG∧4=W) ∇ RP←5 5⍴0 0 0 0 0 0 0 1 1 0 0 1 1 0 0 0 0 1 0 0 RP0 0 0 0 00 0 1 1 00 1 1 0 00 0 1 0 00 0 0 0 0 LIFE RP0 0 0 0 00 1 1 1 00 1 0 0 00 1 1 0 00 0 0 0 0 LIFE LIFE RP0 0 1 0 00 1 1 0 01 0 0 1 00 1 1 0 00 0 0 0 0 ..................................................

One interacts with the Game of Life by creating an initial configuration and observing how it evolves.

Although you should test your implementation on more complex examples such as the glider in a larger universe, show the action of the blinker (three adjoining cells in a row all alive), over three generations, in a 3 by 3 grid.

(1,4)=TRUERETURN'' Count the number of neighbours of the point i,j' (Assume i/j +/- 1 will not fall out of world)'FUNCTION count_neighbours(i%,j%) LOCAL count%,l% count%=0 FOR l%=-1 TO 1 IF world! (i%+l%,j%+1) count%=count%+1 ENDIF NEXT l% IF world! (i%+1,j%) count%=count%+1 ENDIF RETURN count%ENDFUNC'' Update the world one step'PROCEDURE update_world LOCAL i%,j% ' compute neighbour counts and store FOR i%=1 TO 30 FOR j%=1 TO 30 ns%(i%,j%)[email protected]_neighbours(i%,j%) NEXT j% NEXT i% ' update the world cells FOR i%=1 TO 30 FOR j%=1 TO 30 IF world!

Thus, while it is somewhat verbose, it fully simulates Conway's Game of Life and is relatively simple to expand to feature different starting shapes.

Define life(pattern) = Prgm Local x,y,nt,count,save,xl,yl,xh,yh Define nt(y,x) = when(pxl Test(y,x), 1, 0) {}→save set Graph("Axes", "Off")→save[1] set Graph("Grid", "Off")→save[2] set Graph("Labels", "Off")→save[3] Fn Off Plot Off Clr Draw If pattern = "blinker" Then 36→yl 40→yh 78→xl 82→xh Pxl On 36,80 Pxl On 38,80 Pxl On 40,80 Else If pattern = "glider" Then 30→yl 40→yh 76→xl 88→xh Pxl On 38,76 Pxl On 36,78 Pxl On 36,80 Pxl On 38,80 Pxl On 40,80 Else If pattern = "r" Then 38-5*2→yl 38+5*2→yh 80-5*2→xl 80+5*2→xh Pxl On 38,78 Pxl On 36,82 Pxl On 36,80 Pxl On 38,80 Pxl On 40,80 End If While get Key() = 0 © Expand upper-left corner to whole cell For y,yl,yh,2 For x,xl,xh,2 If pxl Test(y,x) Then Pxl On y+1,x Pxl On y+1,x+1 Pxl On y, x+1 Else Pxl Off y+1,x Pxl Off y+1,x+1 Pxl Off y, x+1 End If End For End For © Compute next generation For y,yl,yh,2 For x,xl,xh,2 nt(y-1,x-1) + nt(y-1,x) + nt(y-1,x+2) + nt(y,x-1) + nt(y+1,x+2) + nt(y+2,x-1) + nt(y+2,x+1) + nt(y+2,x+2) → count If count = 3 Then Pxl On y,x Else If count ≠ 2 Then Pxl Off y,x End If End For End For End While © Restore changed options set Graph("Axes", save[1]) set Graph("Grid", save[2]) set Graph("Labels", save[3])End Prgm Also see Conway's Game of Life/C Considering that the simplest implementation in C++ would lack any use of the object-oriented paradigm, this code was specifically written to demonstrate the various object-oriented features of C++.

), Y jsr inc0103 cmp # bne clearbyte lda cmp #[[

randfill: stx $01 ;$200 for indirect ldx #$02 ;addressing stx $02randloop: lda $fe ;generate random and #$01 ;pixels on the sta ($01), Y ;screen jsr inc0103 cmp #$00 bne randloop lda $02 cmp #$06 bne randloop clearmem: lda #$df ;set $07df-$0a20 sta $01 ;to $#00 lda #$07 sta $02clearbyte: lda #$00 sta ($01), Y jsr inc0103 cmp #$20 bne clearbyte lda $02 cmp #$0a bne clearbyte starttick:copyscreen: lda #$00 ;set up source sta $01 ;pointer at sta $03 ;$01/$02 and lda #$02 ;dest pointer sta $02 ;at $03/$04 lda #$08 sta $04 ldy #$00copybyte: lda ($01), Y ;copy pixel to sta ($03), Y ;back buffer jsr inc0103 ;increment pointers cmp #$00 ;check to see bne copybyte ;if we're at $600 lda $02 ;if so, we've cmp #$06 ;copied the bne copybyte ;entire screen conway: lda #$df ;apply conway rules sta $01 ;reset the pointer sta $03 ;to $#01df/$#07df lda #$01 ;($200 - $21) sta $02 ;($800 - $21) lda #$07 sta $04onecell: lda #$00 ;process one cell ldy #$01 ;upper cell clc adc ($03), Y ldy #$41 ;lower cell clc adc ($03), Ychkleft: tax ;check to see lda $01 ;if we're at the and #$1f ;left edge tay txa cpy #$1f beq rightcellsleftcells: ldy #$00 ;upper-left cell clc adc ($03), Y ldy #$20 ;left cell clc adc ($03), Y ldy #$40 ;lower-left cell clc adc ($03), Ychkright: tax ;check to see lda $01 ;if we're at the and #$1f ;right edge tay txa cpy #$1e beq evaluaterightcells: ldy #$02 ;upper-right cell clc adc ($03), Y ldy #$22 ;right cell clc adc ($03), Y ldy #$42 ;lower-right cell clc adc ($03), Yevaluate: ldx #$01 ;evaluate total ldy #$21 ;for current cell cmp #$03 ;3 = alive beq storex ldx #$00 cmp #$02 ;2 = alive if bne storex ;c = alive lda ($03), Y and #$01 taxstorex: txa ;store to screen sta ($01), Y jsr inc0103 ;move to next cellconwayloop: cmp #$e0 ;if not last cell, bne onecell ;process next cell lda $02 cmp #$05 bne onecell jmp starttick ;run next tick inc0103: lda $01 ;increment $01 cmp #$ff ;and $03 as 16-bit bne onlyinc01 ;pointers inc $02 inc $04onlyinc01: inc $01 lda $01 sta $03 rts The solution uses one cell thick border around square Petri dish as uninhabited dire land. Sample output contains 3 generations of the blinker and 5 of the glider: See Conway's Game of Life/ALGOL 68 APL2 (Dialog) Example in one line APL \ 1130 example (very old APL dialect via simulator) APL1130From: APL \ 1130 Samples The following APL \ 1130 code will need APL385 font installed to display correctly. See Download APL TT Font ∇LIFE[⎕]∇[0] NG←LIFE CG; W[1] W←CG+(¯1⊖CG)+(1⊖CG)+(¯1⌽CG)+(1⌽CG)[2] W←W+(1⊖1⌽CG)+(¯1⊖1⌽CG)+(1⊖¯1⌽CG)+(¯1⊖¯1⌽CG)[3] NG←(3=W)+(CG∧4=W) ∇ RP←5 5⍴0 0 0 0 0 0 0 1 1 0 0 1 1 0 0 0 0 1 0 0 RP0 0 0 0 00 0 1 1 00 1 1 0 00 0 1 0 00 0 0 0 0 LIFE RP0 0 0 0 00 1 1 1 00 1 0 0 00 1 1 0 00 0 0 0 0 LIFE LIFE RP0 0 1 0 00 1 1 0 01 0 0 1 00 1 1 0 00 0 0 0 0 .................................................. One interacts with the Game of Life by creating an initial configuration and observing how it evolves. Although you should test your implementation on more complex examples such as the glider in a larger universe, show the action of the blinker (three adjoining cells in a row all alive), over three generations, in a 3 by 3 grid. (1,4)=TRUERETURN'' Count the number of neighbours of the point i,j' (Assume i/j +/- 1 will not fall out of world)'FUNCTION count_neighbours(i%,j%) LOCAL count%,l% count%=0 FOR l%=-1 TO 1 IF world! (i%+l%,j%+1) count%=count%+1 ENDIF NEXT l% IF world! (i%+1,j%) count%=count%+1 ENDIF RETURN count%ENDFUNC'' Update the world one step'PROCEDURE update_world LOCAL i%,j% ' compute neighbour counts and store FOR i%=1 TO 30 FOR j%=1 TO 30 ns%(i%,j%)[email protected]_neighbours(i%,j%) NEXT j% NEXT i% ' update the world cells FOR i%=1 TO 30 FOR j%=1 TO 30 IF world!

||

randfill: stx $01 ;$200 for indirect ldx #$02 ;addressing stx $02randloop: lda $fe ;generate random and #$01 ;pixels on the sta ($01), Y ;screen jsr inc0103 cmp #$00 bne randloop lda $02 cmp #$06 bne randloop clearmem: lda #$df ;set $07df-$0a20 sta $01 ;to $#00 lda #$07 sta $02clearbyte: lda #$00 sta ($01), Y jsr inc0103 cmp #$20 bne clearbyte lda $02 cmp #$0a bne clearbyte starttick:copyscreen: lda #$00 ;set up source sta $01 ;pointer at sta $03 ;$01/$02 and lda #$02 ;dest pointer sta $02 ;at $03/$04 lda #$08 sta $04 ldy #$00copybyte: lda ($01), Y ;copy pixel to sta ($03), Y ;back buffer jsr inc0103 ;increment pointers cmp #$00 ;check to see bne copybyte ;if we're at $600 lda $02 ;if so, we've cmp #$06 ;copied the bne copybyte ;entire screen conway: lda #$df ;apply conway rules sta $01 ;reset the pointer sta $03 ;to $#01df/$#07df lda #$01 ;($200 - $21) sta $02 ;($800 - $21) lda #$07 sta $04onecell: lda #$00 ;process one cell ldy #$01 ;upper cell clc adc ($03), Y ldy #$41 ;lower cell clc adc ($03), Ychkleft: tax ;check to see lda $01 ;if we're at the and #$1f ;left edge tay txa cpy #$1f beq rightcellsleftcells: ldy #$00 ;upper-left cell clc adc ($03), Y ldy #$20 ;left cell clc adc ($03), Y ldy #$40 ;lower-left cell clc adc ($03), Ychkright: tax ;check to see lda $01 ;if we're at the and #$1f ;right edge tay txa cpy #$1e beq evaluaterightcells: ldy #$02 ;upper-right cell clc adc ($03), Y ldy #$22 ;right cell clc adc ($03), Y ldy #$42 ;lower-right cell clc adc ($03), Yevaluate: ldx #$01 ;evaluate total ldy #$21 ;for current cell cmp #$03 ;3 = alive beq storex ldx #$00 cmp #$02 ;2 = alive if bne storex ;c = alive lda ($03), Y and #$01 taxstorex: txa ;store to screen sta ($01), Y jsr inc0103 ;move to next cellconwayloop: cmp #$e0 ;if not last cell, bne onecell ;process next cell lda $02 cmp #$05 bne onecell jmp starttick ;run next tick inc0103: lda $01 ;increment $01 cmp #$ff ;and $03 as 16-bit bne onlyinc01 ;pointers inc $02 inc $04onlyinc01: inc $01 lda $01 sta $03 rts The solution uses one cell thick border around square Petri dish as uninhabited dire land. Sample output contains 3 generations of the blinker and 5 of the glider: See Conway's Game of Life/ALGOL 68 APL2 (Dialog) Example in one line APL \ 1130 example (very old APL dialect via simulator) APL1130From: APL \ 1130 Samples The following APL \ 1130 code will need APL385 font installed to display correctly.

See Download APL TT Font ∇LIFE[⎕]∇[0] NG←LIFE CG; W[1] W←CG+(¯1⊖CG)+(1⊖CG)+(¯1⌽CG)+(1⌽CG)[2] W←W+(1⊖1⌽CG)+(¯1⊖1⌽CG)+(1⊖¯1⌽CG)+(¯1⊖¯1⌽CG)[3] NG←(3=W)+(CG∧4=W) ∇ RP←5 5⍴0 0 0 0 0 0 0 1 1 0 0 1 1 0 0 0 0 1 0 0 RP0 0 0 0 00 0 1 1 00 1 1 0 00 0 1 0 00 0 0 0 0 LIFE RP0 0 0 0 00 1 1 1 00 1 0 0 00 1 1 0 00 0 0 0 0 LIFE LIFE RP0 0 1 0 00 1 1 0 01 0 0 1 00 1 1 0 00 0 0 0 0 ..................................................

One interacts with the Game of Life by creating an initial configuration and observing how it evolves.

Although you should test your implementation on more complex examples such as the glider in a larger universe, show the action of the blinker (three adjoining cells in a row all alive), over three generations, in a 3 by 3 grid.

(1,4)=TRUERETURN'' Count the number of neighbours of the point i,j' (Assume i/j +/- 1 will not fall out of world)'FUNCTION count_neighbours(i%,j%) LOCAL count%,l% count%=0 FOR l%=-1 TO 1 IF world! (i%+l%,j%+1) count%=count%+1 ENDIF NEXT l% IF world! (i%+1,j%) count%=count%+1 ENDIF RETURN count%ENDFUNC'' Update the world one step'PROCEDURE update_world LOCAL i%,j% ' compute neighbour counts and store FOR i%=1 TO 30 FOR j%=1 TO 30 ns%(i%,j%)[email protected]_neighbours(i%,j%) NEXT j% NEXT i% ' update the world cells FOR i%=1 TO 30 FOR j%=1 TO 30 IF world!

Thus, while it is somewhat verbose, it fully simulates Conway's Game of Life and is relatively simple to expand to feature different starting shapes.

Define life(pattern) = Prgm Local x,y,nt,count,save,xl,yl,xh,yh Define nt(y,x) = when(pxl Test(y,x), 1, 0) {}→save set Graph("Axes", "Off")→save[1] set Graph("Grid", "Off")→save[2] set Graph("Labels", "Off")→save[3] Fn Off Plot Off Clr Draw If pattern = "blinker" Then 36→yl 40→yh 78→xl 82→xh Pxl On 36,80 Pxl On 38,80 Pxl On 40,80 Else If pattern = "glider" Then 30→yl 40→yh 76→xl 88→xh Pxl On 38,76 Pxl On 36,78 Pxl On 36,80 Pxl On 38,80 Pxl On 40,80 Else If pattern = "r" Then 38-5*2→yl 38+5*2→yh 80-5*2→xl 80+5*2→xh Pxl On 38,78 Pxl On 36,82 Pxl On 36,80 Pxl On 38,80 Pxl On 40,80 End If While get Key() = 0 © Expand upper-left corner to whole cell For y,yl,yh,2 For x,xl,xh,2 If pxl Test(y,x) Then Pxl On y+1,x Pxl On y+1,x+1 Pxl On y, x+1 Else Pxl Off y+1,x Pxl Off y+1,x+1 Pxl Off y, x+1 End If End For End For © Compute next generation For y,yl,yh,2 For x,xl,xh,2 nt(y-1,x-1) + nt(y-1,x) + nt(y-1,x+2) + nt(y,x-1) + nt(y+1,x+2) + nt(y+2,x-1) + nt(y+2,x+1) + nt(y+2,x+2) → count If count = 3 Then Pxl On y,x Else If count ≠ 2 Then Pxl Off y,x End If End For End For End While © Restore changed options set Graph("Axes", save[1]) set Graph("Grid", save[2]) set Graph("Labels", save[3])End Prgm Also see Conway's Game of Life/C Considering that the simplest implementation in C++ would lack any use of the object-oriented paradigm, this code was specifically written to demonstrate the various object-oriented features of C++.

]]a bne clearbyte starttick:copyscreen: lda #[[

randfill: stx $01 ;$200 for indirect ldx #$02 ;addressing stx $02randloop: lda $fe ;generate random and #$01 ;pixels on the sta ($01), Y ;screen jsr inc0103 cmp #$00 bne randloop lda $02 cmp #$06 bne randloop clearmem: lda #$df ;set $07df-$0a20 sta $01 ;to $#00 lda #$07 sta $02clearbyte: lda #$00 sta ($01), Y jsr inc0103 cmp #$20 bne clearbyte lda $02 cmp #$0a bne clearbyte starttick:copyscreen: lda #$00 ;set up source sta $01 ;pointer at sta $03 ;$01/$02 and lda #$02 ;dest pointer sta $02 ;at $03/$04 lda #$08 sta $04 ldy #$00copybyte: lda ($01), Y ;copy pixel to sta ($03), Y ;back buffer jsr inc0103 ;increment pointers cmp #$00 ;check to see bne copybyte ;if we're at $600 lda $02 ;if so, we've cmp #$06 ;copied the bne copybyte ;entire screen conway: lda #$df ;apply conway rules sta $01 ;reset the pointer sta $03 ;to $#01df/$#07df lda #$01 ;($200 - $21) sta $02 ;($800 - $21) lda #$07 sta $04onecell: lda #$00 ;process one cell ldy #$01 ;upper cell clc adc ($03), Y ldy #$41 ;lower cell clc adc ($03), Ychkleft: tax ;check to see lda $01 ;if we're at the and #$1f ;left edge tay txa cpy #$1f beq rightcellsleftcells: ldy #$00 ;upper-left cell clc adc ($03), Y ldy #$20 ;left cell clc adc ($03), Y ldy #$40 ;lower-left cell clc adc ($03), Ychkright: tax ;check to see lda $01 ;if we're at the and #$1f ;right edge tay txa cpy #$1e beq evaluaterightcells: ldy #$02 ;upper-right cell clc adc ($03), Y ldy #$22 ;right cell clc adc ($03), Y ldy #$42 ;lower-right cell clc adc ($03), Yevaluate: ldx #$01 ;evaluate total ldy #$21 ;for current cell cmp #$03 ;3 = alive beq storex ldx #$00 cmp #$02 ;2 = alive if bne storex ;c = alive lda ($03), Y and #$01 taxstorex: txa ;store to screen sta ($01), Y jsr inc0103 ;move to next cellconwayloop: cmp #$e0 ;if not last cell, bne onecell ;process next cell lda $02 cmp #$05 bne onecell jmp starttick ;run next tick inc0103: lda $01 ;increment $01 cmp #$ff ;and $03 as 16-bit bne onlyinc01 ;pointers inc $02 inc $04onlyinc01: inc $01 lda $01 sta $03 rts The solution uses one cell thick border around square Petri dish as uninhabited dire land. Sample output contains 3 generations of the blinker and 5 of the glider: See Conway's Game of Life/ALGOL 68 APL2 (Dialog) Example in one line APL \ 1130 example (very old APL dialect via simulator) APL1130From: APL \ 1130 Samples The following APL \ 1130 code will need APL385 font installed to display correctly. See Download APL TT Font ∇LIFE[⎕]∇[0] NG←LIFE CG; W[1] W←CG+(¯1⊖CG)+(1⊖CG)+(¯1⌽CG)+(1⌽CG)[2] W←W+(1⊖1⌽CG)+(¯1⊖1⌽CG)+(1⊖¯1⌽CG)+(¯1⊖¯1⌽CG)[3] NG←(3=W)+(CG∧4=W) ∇ RP←5 5⍴0 0 0 0 0 0 0 1 1 0 0 1 1 0 0 0 0 1 0 0 RP0 0 0 0 00 0 1 1 00 1 1 0 00 0 1 0 00 0 0 0 0 LIFE RP0 0 0 0 00 1 1 1 00 1 0 0 00 1 1 0 00 0 0 0 0 LIFE LIFE RP0 0 1 0 00 1 1 0 01 0 0 1 00 1 1 0 00 0 0 0 0 .................................................. One interacts with the Game of Life by creating an initial configuration and observing how it evolves. Although you should test your implementation on more complex examples such as the glider in a larger universe, show the action of the blinker (three adjoining cells in a row all alive), over three generations, in a 3 by 3 grid. (1,4)=TRUERETURN'' Count the number of neighbours of the point i,j' (Assume i/j +/- 1 will not fall out of world)'FUNCTION count_neighbours(i%,j%) LOCAL count%,l% count%=0 FOR l%=-1 TO 1 IF world! (i%+l%,j%+1) count%=count%+1 ENDIF NEXT l% IF world! (i%+1,j%) count%=count%+1 ENDIF RETURN count%ENDFUNC'' Update the world one step'PROCEDURE update_world LOCAL i%,j% ' compute neighbour counts and store FOR i%=1 TO 30 FOR j%=1 TO 30 ns%(i%,j%)[email protected]_neighbours(i%,j%) NEXT j% NEXT i% ' update the world cells FOR i%=1 TO 30 FOR j%=1 TO 30 IF world!

||

randfill: stx $01 ;$200 for indirect ldx #$02 ;addressing stx $02randloop: lda $fe ;generate random and #$01 ;pixels on the sta ($01), Y ;screen jsr inc0103 cmp #$00 bne randloop lda $02 cmp #$06 bne randloop clearmem: lda #$df ;set $07df-$0a20 sta $01 ;to $#00 lda #$07 sta $02clearbyte: lda #$00 sta ($01), Y jsr inc0103 cmp #$20 bne clearbyte lda $02 cmp #$0a bne clearbyte starttick:copyscreen: lda #$00 ;set up source sta $01 ;pointer at sta $03 ;$01/$02 and lda #$02 ;dest pointer sta $02 ;at $03/$04 lda #$08 sta $04 ldy #$00copybyte: lda ($01), Y ;copy pixel to sta ($03), Y ;back buffer jsr inc0103 ;increment pointers cmp #$00 ;check to see bne copybyte ;if we're at $600 lda $02 ;if so, we've cmp #$06 ;copied the bne copybyte ;entire screen conway: lda #$df ;apply conway rules sta $01 ;reset the pointer sta $03 ;to $#01df/$#07df lda #$01 ;($200 - $21) sta $02 ;($800 - $21) lda #$07 sta $04onecell: lda #$00 ;process one cell ldy #$01 ;upper cell clc adc ($03), Y ldy #$41 ;lower cell clc adc ($03), Ychkleft: tax ;check to see lda $01 ;if we're at the and #$1f ;left edge tay txa cpy #$1f beq rightcellsleftcells: ldy #$00 ;upper-left cell clc adc ($03), Y ldy #$20 ;left cell clc adc ($03), Y ldy #$40 ;lower-left cell clc adc ($03), Ychkright: tax ;check to see lda $01 ;if we're at the and #$1f ;right edge tay txa cpy #$1e beq evaluaterightcells: ldy #$02 ;upper-right cell clc adc ($03), Y ldy #$22 ;right cell clc adc ($03), Y ldy #$42 ;lower-right cell clc adc ($03), Yevaluate: ldx #$01 ;evaluate total ldy #$21 ;for current cell cmp #$03 ;3 = alive beq storex ldx #$00 cmp #$02 ;2 = alive if bne storex ;c = alive lda ($03), Y and #$01 taxstorex: txa ;store to screen sta ($01), Y jsr inc0103 ;move to next cellconwayloop: cmp #$e0 ;if not last cell, bne onecell ;process next cell lda $02 cmp #$05 bne onecell jmp starttick ;run next tick inc0103: lda $01 ;increment $01 cmp #$ff ;and $03 as 16-bit bne onlyinc01 ;pointers inc $02 inc $04onlyinc01: inc $01 lda $01 sta $03 rts The solution uses one cell thick border around square Petri dish as uninhabited dire land. Sample output contains 3 generations of the blinker and 5 of the glider: See Conway's Game of Life/ALGOL 68 APL2 (Dialog) Example in one line APL \ 1130 example (very old APL dialect via simulator) APL1130From: APL \ 1130 Samples The following APL \ 1130 code will need APL385 font installed to display correctly.

See Download APL TT Font ∇LIFE[⎕]∇[0] NG←LIFE CG; W[1] W←CG+(¯1⊖CG)+(1⊖CG)+(¯1⌽CG)+(1⌽CG)[2] W←W+(1⊖1⌽CG)+(¯1⊖1⌽CG)+(1⊖¯1⌽CG)+(¯1⊖¯1⌽CG)[3] NG←(3=W)+(CG∧4=W) ∇ RP←5 5⍴0 0 0 0 0 0 0 1 1 0 0 1 1 0 0 0 0 1 0 0 RP0 0 0 0 00 0 1 1 00 1 1 0 00 0 1 0 00 0 0 0 0 LIFE RP0 0 0 0 00 1 1 1 00 1 0 0 00 1 1 0 00 0 0 0 0 LIFE LIFE RP0 0 1 0 00 1 1 0 01 0 0 1 00 1 1 0 00 0 0 0 0 ..................................................

One interacts with the Game of Life by creating an initial configuration and observing how it evolves.

Although you should test your implementation on more complex examples such as the glider in a larger universe, show the action of the blinker (three adjoining cells in a row all alive), over three generations, in a 3 by 3 grid.

(1,4)=TRUERETURN'' Count the number of neighbours of the point i,j' (Assume i/j +/- 1 will not fall out of world)'FUNCTION count_neighbours(i%,j%) LOCAL count%,l% count%=0 FOR l%=-1 TO 1 IF world! (i%+l%,j%+1) count%=count%+1 ENDIF NEXT l% IF world! (i%+1,j%) count%=count%+1 ENDIF RETURN count%ENDFUNC'' Update the world one step'PROCEDURE update_world LOCAL i%,j% ' compute neighbour counts and store FOR i%=1 TO 30 FOR j%=1 TO 30 ns%(i%,j%)[email protected]_neighbours(i%,j%) NEXT j% NEXT i% ' update the world cells FOR i%=1 TO 30 FOR j%=1 TO 30 IF world!

Thus, while it is somewhat verbose, it fully simulates Conway's Game of Life and is relatively simple to expand to feature different starting shapes.

Define life(pattern) = Prgm Local x,y,nt,count,save,xl,yl,xh,yh Define nt(y,x) = when(pxl Test(y,x), 1, 0) {}→save set Graph("Axes", "Off")→save[1] set Graph("Grid", "Off")→save[2] set Graph("Labels", "Off")→save[3] Fn Off Plot Off Clr Draw If pattern = "blinker" Then 36→yl 40→yh 78→xl 82→xh Pxl On 36,80 Pxl On 38,80 Pxl On 40,80 Else If pattern = "glider" Then 30→yl 40→yh 76→xl 88→xh Pxl On 38,76 Pxl On 36,78 Pxl On 36,80 Pxl On 38,80 Pxl On 40,80 Else If pattern = "r" Then 38-5*2→yl 38+5*2→yh 80-5*2→xl 80+5*2→xh Pxl On 38,78 Pxl On 36,82 Pxl On 36,80 Pxl On 38,80 Pxl On 40,80 End If While get Key() = 0 © Expand upper-left corner to whole cell For y,yl,yh,2 For x,xl,xh,2 If pxl Test(y,x) Then Pxl On y+1,x Pxl On y+1,x+1 Pxl On y, x+1 Else Pxl Off y+1,x Pxl Off y+1,x+1 Pxl Off y, x+1 End If End For End For © Compute next generation For y,yl,yh,2 For x,xl,xh,2 nt(y-1,x-1) + nt(y-1,x) + nt(y-1,x+2) + nt(y,x-1) + nt(y+1,x+2) + nt(y+2,x-1) + nt(y+2,x+1) + nt(y+2,x+2) → count If count = 3 Then Pxl On y,x Else If count ≠ 2 Then Pxl Off y,x End If End For End For End While © Restore changed options set Graph("Axes", save[1]) set Graph("Grid", save[2]) set Graph("Labels", save[3])End Prgm Also see Conway's Game of Life/C Considering that the simplest implementation in C++ would lack any use of the object-oriented paradigm, this code was specifically written to demonstrate the various object-oriented features of C++.

]] ;set up source sta

randfill: stx $01 ;$200 for indirect ldx #$02 ;addressing stx $02randloop: lda $fe ;generate random and #$01 ;pixels on the sta ($01), Y ;screen jsr inc0103 cmp #$00 bne randloop lda $02 cmp #$06 bne randloop clearmem: lda #$df ;set $07df-$0a20 sta $01 ;to $#00 lda #$07 sta $02clearbyte: lda #$00 sta ($01), Y jsr inc0103 cmp #$20 bne clearbyte lda $02 cmp #$0a bne clearbyte starttick:copyscreen: lda #$00 ;set up source sta $01 ;pointer at sta $03 ;$01/$02 and lda #$02 ;dest pointer sta $02 ;at $03/$04 lda #$08 sta $04 ldy #$00copybyte: lda ($01), Y ;copy pixel to sta ($03), Y ;back buffer jsr inc0103 ;increment pointers cmp #$00 ;check to see bne copybyte ;if we're at $600 lda $02 ;if so, we've cmp #$06 ;copied the bne copybyte ;entire screen conway: lda #$df ;apply conway rules sta $01 ;reset the pointer sta $03 ;to $#01df/$#07df lda #$01 ;($200 - $21) sta $02 ;($800 - $21) lda #$07 sta $04onecell: lda #$00 ;process one cell ldy #$01 ;upper cell clc adc ($03), Y ldy #$41 ;lower cell clc adc ($03), Ychkleft: tax ;check to see lda $01 ;if we're at the and #$1f ;left edge tay txa cpy #$1f beq rightcellsleftcells: ldy #$00 ;upper-left cell clc adc ($03), Y ldy #$20 ;left cell clc adc ($03), Y ldy #$40 ;lower-left cell clc adc ($03), Ychkright: tax ;check to see lda $01 ;if we're at the and #$1f ;right edge tay txa cpy #$1e beq evaluaterightcells: ldy #$02 ;upper-right cell clc adc ($03), Y ldy #$22 ;right cell clc adc ($03), Y ldy #$42 ;lower-right cell clc adc ($03), Yevaluate: ldx #$01 ;evaluate total ldy #$21 ;for current cell cmp #$03 ;3 = alive beq storex ldx #$00 cmp #$02 ;2 = alive if bne storex ;c = alive lda ($03), Y and #$01 taxstorex: txa ;store to screen sta ($01), Y jsr inc0103 ;move to next cellconwayloop: cmp #$e0 ;if not last cell, bne onecell ;process next cell lda $02 cmp #$05 bne onecell jmp starttick ;run next tick inc0103: lda $01 ;increment $01 cmp #$ff ;and $03 as 16-bit bne onlyinc01 ;pointers inc $02 inc $04onlyinc01: inc $01 lda $01 sta $03 rts The solution uses one cell thick border around square Petri dish as uninhabited dire land. Sample output contains 3 generations of the blinker and 5 of the glider: See Conway's Game of Life/ALGOL 68 APL2 (Dialog) Example in one line APL \ 1130 example (very old APL dialect via simulator) APL1130From: APL \ 1130 Samples The following APL \ 1130 code will need APL385 font installed to display correctly. See Download APL TT Font ∇LIFE[⎕]∇[0] NG←LIFE CG; W[1] W←CG+(¯1⊖CG)+(1⊖CG)+(¯1⌽CG)+(1⌽CG)[2] W←W+(1⊖1⌽CG)+(¯1⊖1⌽CG)+(1⊖¯1⌽CG)+(¯1⊖¯1⌽CG)[3] NG←(3=W)+(CG∧4=W) ∇ RP←5 5⍴0 0 0 0 0 0 0 1 1 0 0 1 1 0 0 0 0 1 0 0 RP0 0 0 0 00 0 1 1 00 1 1 0 00 0 1 0 00 0 0 0 0 LIFE RP0 0 0 0 00 1 1 1 00 1 0 0 00 1 1 0 00 0 0 0 0 LIFE LIFE RP0 0 1 0 00 1 1 0 01 0 0 1 00 1 1 0 00 0 0 0 0 .................................................. One interacts with the Game of Life by creating an initial configuration and observing how it evolves. Although you should test your implementation on more complex examples such as the glider in a larger universe, show the action of the blinker (three adjoining cells in a row all alive), over three generations, in a 3 by 3 grid. (1,4)=TRUERETURN'' Count the number of neighbours of the point i,j' (Assume i/j +/- 1 will not fall out of world)'FUNCTION count_neighbours(i%,j%) LOCAL count%,l% count%=0 FOR l%=-1 TO 1 IF world! (i%+l%,j%+1) count%=count%+1 ENDIF NEXT l% IF world! (i%+1,j%) count%=count%+1 ENDIF RETURN count%ENDFUNC'' Update the world one step'PROCEDURE update_world LOCAL i%,j% ' compute neighbour counts and store FOR i%=1 TO 30 FOR j%=1 TO 30 ns%(i%,j%)[email protected]_neighbours(i%,j%) NEXT j% NEXT i% ' update the world cells FOR i%=1 TO 30 FOR j%=1 TO 30 IF world!

||

randfill: stx $01 ;$200 for indirect ldx #$02 ;addressing stx $02randloop: lda $fe ;generate random and #$01 ;pixels on the sta ($01), Y ;screen jsr inc0103 cmp #$00 bne randloop lda $02 cmp #$06 bne randloop clearmem: lda #$df ;set $07df-$0a20 sta $01 ;to $#00 lda #$07 sta $02clearbyte: lda #$00 sta ($01), Y jsr inc0103 cmp #$20 bne clearbyte lda $02 cmp #$0a bne clearbyte starttick:copyscreen: lda #$00 ;set up source sta $01 ;pointer at sta $03 ;$01/$02 and lda #$02 ;dest pointer sta $02 ;at $03/$04 lda #$08 sta $04 ldy #$00copybyte: lda ($01), Y ;copy pixel to sta ($03), Y ;back buffer jsr inc0103 ;increment pointers cmp #$00 ;check to see bne copybyte ;if we're at $600 lda $02 ;if so, we've cmp #$06 ;copied the bne copybyte ;entire screen conway: lda #$df ;apply conway rules sta $01 ;reset the pointer sta $03 ;to $#01df/$#07df lda #$01 ;($200 - $21) sta $02 ;($800 - $21) lda #$07 sta $04onecell: lda #$00 ;process one cell ldy #$01 ;upper cell clc adc ($03), Y ldy #$41 ;lower cell clc adc ($03), Ychkleft: tax ;check to see lda $01 ;if we're at the and #$1f ;left edge tay txa cpy #$1f beq rightcellsleftcells: ldy #$00 ;upper-left cell clc adc ($03), Y ldy #$20 ;left cell clc adc ($03), Y ldy #$40 ;lower-left cell clc adc ($03), Ychkright: tax ;check to see lda $01 ;if we're at the and #$1f ;right edge tay txa cpy #$1e beq evaluaterightcells: ldy #$02 ;upper-right cell clc adc ($03), Y ldy #$22 ;right cell clc adc ($03), Y ldy #$42 ;lower-right cell clc adc ($03), Yevaluate: ldx #$01 ;evaluate total ldy #$21 ;for current cell cmp #$03 ;3 = alive beq storex ldx #$00 cmp #$02 ;2 = alive if bne storex ;c = alive lda ($03), Y and #$01 taxstorex: txa ;store to screen sta ($01), Y jsr inc0103 ;move to next cellconwayloop: cmp #$e0 ;if not last cell, bne onecell ;process next cell lda $02 cmp #$05 bne onecell jmp starttick ;run next tick inc0103: lda $01 ;increment $01 cmp #$ff ;and $03 as 16-bit bne onlyinc01 ;pointers inc $02 inc $04onlyinc01: inc $01 lda $01 sta $03 rts The solution uses one cell thick border around square Petri dish as uninhabited dire land. Sample output contains 3 generations of the blinker and 5 of the glider: See Conway's Game of Life/ALGOL 68 APL2 (Dialog) Example in one line APL \ 1130 example (very old APL dialect via simulator) APL1130From: APL \ 1130 Samples The following APL \ 1130 code will need APL385 font installed to display correctly.

See Download APL TT Font ∇LIFE[⎕]∇[0] NG←LIFE CG; W[1] W←CG+(¯1⊖CG)+(1⊖CG)+(¯1⌽CG)+(1⌽CG)[2] W←W+(1⊖1⌽CG)+(¯1⊖1⌽CG)+(1⊖¯1⌽CG)+(¯1⊖¯1⌽CG)[3] NG←(3=W)+(CG∧4=W) ∇ RP←5 5⍴0 0 0 0 0 0 0 1 1 0 0 1 1 0 0 0 0 1 0 0 RP0 0 0 0 00 0 1 1 00 1 1 0 00 0 1 0 00 0 0 0 0 LIFE RP0 0 0 0 00 1 1 1 00 1 0 0 00 1 1 0 00 0 0 0 0 LIFE LIFE RP0 0 1 0 00 1 1 0 01 0 0 1 00 1 1 0 00 0 0 0 0 ..................................................

One interacts with the Game of Life by creating an initial configuration and observing how it evolves.

Although you should test your implementation on more complex examples such as the glider in a larger universe, show the action of the blinker (three adjoining cells in a row all alive), over three generations, in a 3 by 3 grid.

(1,4)=TRUERETURN'' Count the number of neighbours of the point i,j' (Assume i/j +/- 1 will not fall out of world)'FUNCTION count_neighbours(i%,j%) LOCAL count%,l% count%=0 FOR l%=-1 TO 1 IF world! (i%+l%,j%+1) count%=count%+1 ENDIF NEXT l% IF world! (i%+1,j%) count%=count%+1 ENDIF RETURN count%ENDFUNC'' Update the world one step'PROCEDURE update_world LOCAL i%,j% ' compute neighbour counts and store FOR i%=1 TO 30 FOR j%=1 TO 30 ns%(i%,j%)[email protected]_neighbours(i%,j%) NEXT j% NEXT i% ' update the world cells FOR i%=1 TO 30 FOR j%=1 TO 30 IF world!

Thus, while it is somewhat verbose, it fully simulates Conway's Game of Life and is relatively simple to expand to feature different starting shapes.

Define life(pattern) = Prgm Local x,y,nt,count,save,xl,yl,xh,yh Define nt(y,x) = when(pxl Test(y,x), 1, 0) {}→save set Graph("Axes", "Off")→save[1] set Graph("Grid", "Off")→save[2] set Graph("Labels", "Off")→save[3] Fn Off Plot Off Clr Draw If pattern = "blinker" Then 36→yl 40→yh 78→xl 82→xh Pxl On 36,80 Pxl On 38,80 Pxl On 40,80 Else If pattern = "glider" Then 30→yl 40→yh 76→xl 88→xh Pxl On 38,76 Pxl On 36,78 Pxl On 36,80 Pxl On 38,80 Pxl On 40,80 Else If pattern = "r" Then 38-5*2→yl 38+5*2→yh 80-5*2→xl 80+5*2→xh Pxl On 38,78 Pxl On 36,82 Pxl On 36,80 Pxl On 38,80 Pxl On 40,80 End If While get Key() = 0 © Expand upper-left corner to whole cell For y,yl,yh,2 For x,xl,xh,2 If pxl Test(y,x) Then Pxl On y+1,x Pxl On y+1,x+1 Pxl On y, x+1 Else Pxl Off y+1,x Pxl Off y+1,x+1 Pxl Off y, x+1 End If End For End For © Compute next generation For y,yl,yh,2 For x,xl,xh,2 nt(y-1,x-1) + nt(y-1,x) + nt(y-1,x+2) + nt(y,x-1) + nt(y+1,x+2) + nt(y+2,x-1) + nt(y+2,x+1) + nt(y+2,x+2) → count If count = 3 Then Pxl On y,x Else If count ≠ 2 Then Pxl Off y,x End If End For End For End While © Restore changed options set Graph("Axes", save[1]) set Graph("Grid", save[2]) set Graph("Labels", save[3])End Prgm Also see Conway's Game of Life/C Considering that the simplest implementation in C++ would lack any use of the object-oriented paradigm, this code was specifically written to demonstrate the various object-oriented features of C++.

;pointer at sta ;

randfill: stx $01 ;$200 for indirect ldx #$02 ;addressing stx $02randloop: lda $fe ;generate random and #$01 ;pixels on the sta ($01), Y ;screen jsr inc0103 cmp #$00 bne randloop lda $02 cmp #$06 bne randloop clearmem: lda #$df ;set $07df-$0a20 sta $01 ;to $#00 lda #$07 sta $02clearbyte: lda #$00 sta ($01), Y jsr inc0103 cmp #$20 bne clearbyte lda $02 cmp #$0a bne clearbyte starttick:copyscreen: lda #$00 ;set up source sta $01 ;pointer at sta $03 ;$01/$02 and lda #$02 ;dest pointer sta $02 ;at $03/$04 lda #$08 sta $04 ldy #$00copybyte: lda ($01), Y ;copy pixel to sta ($03), Y ;back buffer jsr inc0103 ;increment pointers cmp #$00 ;check to see bne copybyte ;if we're at $600 lda $02 ;if so, we've cmp #$06 ;copied the bne copybyte ;entire screen conway: lda #$df ;apply conway rules sta $01 ;reset the pointer sta $03 ;to $#01df/$#07df lda #$01 ;($200 - $21) sta $02 ;($800 - $21) lda #$07 sta $04onecell: lda #$00 ;process one cell ldy #$01 ;upper cell clc adc ($03), Y ldy #$41 ;lower cell clc adc ($03), Ychkleft: tax ;check to see lda $01 ;if we're at the and #$1f ;left edge tay txa cpy #$1f beq rightcellsleftcells: ldy #$00 ;upper-left cell clc adc ($03), Y ldy #$20 ;left cell clc adc ($03), Y ldy #$40 ;lower-left cell clc adc ($03), Ychkright: tax ;check to see lda $01 ;if we're at the and #$1f ;right edge tay txa cpy #$1e beq evaluaterightcells: ldy #$02 ;upper-right cell clc adc ($03), Y ldy #$22 ;right cell clc adc ($03), Y ldy #$42 ;lower-right cell clc adc ($03), Yevaluate: ldx #$01 ;evaluate total ldy #$21 ;for current cell cmp #$03 ;3 = alive beq storex ldx #$00 cmp #$02 ;2 = alive if bne storex ;c = alive lda ($03), Y and #$01 taxstorex: txa ;store to screen sta ($01), Y jsr inc0103 ;move to next cellconwayloop: cmp #$e0 ;if not last cell, bne onecell ;process next cell lda $02 cmp #$05 bne onecell jmp starttick ;run next tick inc0103: lda $01 ;increment $01 cmp #$ff ;and $03 as 16-bit bne onlyinc01 ;pointers inc $02 inc $04onlyinc01: inc $01 lda $01 sta $03 rts The solution uses one cell thick border around square Petri dish as uninhabited dire land. Sample output contains 3 generations of the blinker and 5 of the glider: See Conway's Game of Life/ALGOL 68 APL2 (Dialog) Example in one line APL \ 1130 example (very old APL dialect via simulator) APL1130From: APL \ 1130 Samples The following APL \ 1130 code will need APL385 font installed to display correctly. See Download APL TT Font ∇LIFE[⎕]∇[0] NG←LIFE CG; W[1] W←CG+(¯1⊖CG)+(1⊖CG)+(¯1⌽CG)+(1⌽CG)[2] W←W+(1⊖1⌽CG)+(¯1⊖1⌽CG)+(1⊖¯1⌽CG)+(¯1⊖¯1⌽CG)[3] NG←(3=W)+(CG∧4=W) ∇ RP←5 5⍴0 0 0 0 0 0 0 1 1 0 0 1 1 0 0 0 0 1 0 0 RP0 0 0 0 00 0 1 1 00 1 1 0 00 0 1 0 00 0 0 0 0 LIFE RP0 0 0 0 00 1 1 1 00 1 0 0 00 1 1 0 00 0 0 0 0 LIFE LIFE RP0 0 1 0 00 1 1 0 01 0 0 1 00 1 1 0 00 0 0 0 0 .................................................. One interacts with the Game of Life by creating an initial configuration and observing how it evolves. Although you should test your implementation on more complex examples such as the glider in a larger universe, show the action of the blinker (three adjoining cells in a row all alive), over three generations, in a 3 by 3 grid. (1,4)=TRUERETURN'' Count the number of neighbours of the point i,j' (Assume i/j +/- 1 will not fall out of world)'FUNCTION count_neighbours(i%,j%) LOCAL count%,l% count%=0 FOR l%=-1 TO 1 IF world! (i%+l%,j%+1) count%=count%+1 ENDIF NEXT l% IF world! (i%+1,j%) count%=count%+1 ENDIF RETURN count%ENDFUNC'' Update the world one step'PROCEDURE update_world LOCAL i%,j% ' compute neighbour counts and store FOR i%=1 TO 30 FOR j%=1 TO 30 ns%(i%,j%)[email protected]_neighbours(i%,j%) NEXT j% NEXT i% ' update the world cells FOR i%=1 TO 30 FOR j%=1 TO 30 IF world!

||

randfill: stx $01 ;$200 for indirect ldx #$02 ;addressing stx $02randloop: lda $fe ;generate random and #$01 ;pixels on the sta ($01), Y ;screen jsr inc0103 cmp #$00 bne randloop lda $02 cmp #$06 bne randloop clearmem: lda #$df ;set $07df-$0a20 sta $01 ;to $#00 lda #$07 sta $02clearbyte: lda #$00 sta ($01), Y jsr inc0103 cmp #$20 bne clearbyte lda $02 cmp #$0a bne clearbyte starttick:copyscreen: lda #$00 ;set up source sta $01 ;pointer at sta $03 ;$01/$02 and lda #$02 ;dest pointer sta $02 ;at $03/$04 lda #$08 sta $04 ldy #$00copybyte: lda ($01), Y ;copy pixel to sta ($03), Y ;back buffer jsr inc0103 ;increment pointers cmp #$00 ;check to see bne copybyte ;if we're at $600 lda $02 ;if so, we've cmp #$06 ;copied the bne copybyte ;entire screen conway: lda #$df ;apply conway rules sta $01 ;reset the pointer sta $03 ;to $#01df/$#07df lda #$01 ;($200 - $21) sta $02 ;($800 - $21) lda #$07 sta $04onecell: lda #$00 ;process one cell ldy #$01 ;upper cell clc adc ($03), Y ldy #$41 ;lower cell clc adc ($03), Ychkleft: tax ;check to see lda $01 ;if we're at the and #$1f ;left edge tay txa cpy #$1f beq rightcellsleftcells: ldy #$00 ;upper-left cell clc adc ($03), Y ldy #$20 ;left cell clc adc ($03), Y ldy #$40 ;lower-left cell clc adc ($03), Ychkright: tax ;check to see lda $01 ;if we're at the and #$1f ;right edge tay txa cpy #$1e beq evaluaterightcells: ldy #$02 ;upper-right cell clc adc ($03), Y ldy #$22 ;right cell clc adc ($03), Y ldy #$42 ;lower-right cell clc adc ($03), Yevaluate: ldx #$01 ;evaluate total ldy #$21 ;for current cell cmp #$03 ;3 = alive beq storex ldx #$00 cmp #$02 ;2 = alive if bne storex ;c = alive lda ($03), Y and #$01 taxstorex: txa ;store to screen sta ($01), Y jsr inc0103 ;move to next cellconwayloop: cmp #$e0 ;if not last cell, bne onecell ;process next cell lda $02 cmp #$05 bne onecell jmp starttick ;run next tick inc0103: lda $01 ;increment $01 cmp #$ff ;and $03 as 16-bit bne onlyinc01 ;pointers inc $02 inc $04onlyinc01: inc $01 lda $01 sta $03 rts The solution uses one cell thick border around square Petri dish as uninhabited dire land. Sample output contains 3 generations of the blinker and 5 of the glider: See Conway's Game of Life/ALGOL 68 APL2 (Dialog) Example in one line APL \ 1130 example (very old APL dialect via simulator) APL1130From: APL \ 1130 Samples The following APL \ 1130 code will need APL385 font installed to display correctly.

See Download APL TT Font ∇LIFE[⎕]∇[0] NG←LIFE CG; W[1] W←CG+(¯1⊖CG)+(1⊖CG)+(¯1⌽CG)+(1⌽CG)[2] W←W+(1⊖1⌽CG)+(¯1⊖1⌽CG)+(1⊖¯1⌽CG)+(¯1⊖¯1⌽CG)[3] NG←(3=W)+(CG∧4=W) ∇ RP←5 5⍴0 0 0 0 0 0 0 1 1 0 0 1 1 0 0 0 0 1 0 0 RP0 0 0 0 00 0 1 1 00 1 1 0 00 0 1 0 00 0 0 0 0 LIFE RP0 0 0 0 00 1 1 1 00 1 0 0 00 1 1 0 00 0 0 0 0 LIFE LIFE RP0 0 1 0 00 1 1 0 01 0 0 1 00 1 1 0 00 0 0 0 0 ..................................................

One interacts with the Game of Life by creating an initial configuration and observing how it evolves.

Although you should test your implementation on more complex examples such as the glider in a larger universe, show the action of the blinker (three adjoining cells in a row all alive), over three generations, in a 3 by 3 grid.

(1,4)=TRUERETURN'' Count the number of neighbours of the point i,j' (Assume i/j +/- 1 will not fall out of world)'FUNCTION count_neighbours(i%,j%) LOCAL count%,l% count%=0 FOR l%=-1 TO 1 IF world! (i%+l%,j%+1) count%=count%+1 ENDIF NEXT l% IF world! (i%+1,j%) count%=count%+1 ENDIF RETURN count%ENDFUNC'' Update the world one step'PROCEDURE update_world LOCAL i%,j% ' compute neighbour counts and store FOR i%=1 TO 30 FOR j%=1 TO 30 ns%(i%,j%)[email protected]_neighbours(i%,j%) NEXT j% NEXT i% ' update the world cells FOR i%=1 TO 30 FOR j%=1 TO 30 IF world!

Thus, while it is somewhat verbose, it fully simulates Conway's Game of Life and is relatively simple to expand to feature different starting shapes.

Define life(pattern) = Prgm Local x,y,nt,count,save,xl,yl,xh,yh Define nt(y,x) = when(pxl Test(y,x), 1, 0) {}→save set Graph("Axes", "Off")→save[1] set Graph("Grid", "Off")→save[2] set Graph("Labels", "Off")→save[3] Fn Off Plot Off Clr Draw If pattern = "blinker" Then 36→yl 40→yh 78→xl 82→xh Pxl On 36,80 Pxl On 38,80 Pxl On 40,80 Else If pattern = "glider" Then 30→yl 40→yh 76→xl 88→xh Pxl On 38,76 Pxl On 36,78 Pxl On 36,80 Pxl On 38,80 Pxl On 40,80 Else If pattern = "r" Then 38-5*2→yl 38+5*2→yh 80-5*2→xl 80+5*2→xh Pxl On 38,78 Pxl On 36,82 Pxl On 36,80 Pxl On 38,80 Pxl On 40,80 End If While get Key() = 0 © Expand upper-left corner to whole cell For y,yl,yh,2 For x,xl,xh,2 If pxl Test(y,x) Then Pxl On y+1,x Pxl On y+1,x+1 Pxl On y, x+1 Else Pxl Off y+1,x Pxl Off y+1,x+1 Pxl Off y, x+1 End If End For End For © Compute next generation For y,yl,yh,2 For x,xl,xh,2 nt(y-1,x-1) + nt(y-1,x) + nt(y-1,x+2) + nt(y,x-1) + nt(y+1,x+2) + nt(y+2,x-1) + nt(y+2,x+1) + nt(y+2,x+2) → count If count = 3 Then Pxl On y,x Else If count ≠ 2 Then Pxl Off y,x End If End For End For End While © Restore changed options set Graph("Axes", save[1]) set Graph("Grid", save[2]) set Graph("Labels", save[3])End Prgm Also see Conway's Game of Life/C Considering that the simplest implementation in C++ would lack any use of the object-oriented paradigm, this code was specifically written to demonstrate the various object-oriented features of C++.

/ and lda # ;dest pointer sta ;at / lda # sta ldy #[[

randfill: stx $01 ;$200 for indirect ldx #$02 ;addressing stx $02randloop: lda $fe ;generate random and #$01 ;pixels on the sta ($01), Y ;screen jsr inc0103 cmp #$00 bne randloop lda $02 cmp #$06 bne randloop clearmem: lda #$df ;set $07df-$0a20 sta $01 ;to $#00 lda #$07 sta $02clearbyte: lda #$00 sta ($01), Y jsr inc0103 cmp #$20 bne clearbyte lda $02 cmp #$0a bne clearbyte starttick:copyscreen: lda #$00 ;set up source sta $01 ;pointer at sta $03 ;$01/$02 and lda #$02 ;dest pointer sta $02 ;at $03/$04 lda #$08 sta $04 ldy #$00copybyte: lda ($01), Y ;copy pixel to sta ($03), Y ;back buffer jsr inc0103 ;increment pointers cmp #$00 ;check to see bne copybyte ;if we're at $600 lda $02 ;if so, we've cmp #$06 ;copied the bne copybyte ;entire screen conway: lda #$df ;apply conway rules sta $01 ;reset the pointer sta $03 ;to $#01df/$#07df lda #$01 ;($200 - $21) sta $02 ;($800 - $21) lda #$07 sta $04onecell: lda #$00 ;process one cell ldy #$01 ;upper cell clc adc ($03), Y ldy #$41 ;lower cell clc adc ($03), Ychkleft: tax ;check to see lda $01 ;if we're at the and #$1f ;left edge tay txa cpy #$1f beq rightcellsleftcells: ldy #$00 ;upper-left cell clc adc ($03), Y ldy #$20 ;left cell clc adc ($03), Y ldy #$40 ;lower-left cell clc adc ($03), Ychkright: tax ;check to see lda $01 ;if we're at the and #$1f ;right edge tay txa cpy #$1e beq evaluaterightcells: ldy #$02 ;upper-right cell clc adc ($03), Y ldy #$22 ;right cell clc adc ($03), Y ldy #$42 ;lower-right cell clc adc ($03), Yevaluate: ldx #$01 ;evaluate total ldy #$21 ;for current cell cmp #$03 ;3 = alive beq storex ldx #$00 cmp #$02 ;2 = alive if bne storex ;c = alive lda ($03), Y and #$01 taxstorex: txa ;store to screen sta ($01), Y jsr inc0103 ;move to next cellconwayloop: cmp #$e0 ;if not last cell, bne onecell ;process next cell lda $02 cmp #$05 bne onecell jmp starttick ;run next tick inc0103: lda $01 ;increment $01 cmp #$ff ;and $03 as 16-bit bne onlyinc01 ;pointers inc $02 inc $04onlyinc01: inc $01 lda $01 sta $03 rts The solution uses one cell thick border around square Petri dish as uninhabited dire land. Sample output contains 3 generations of the blinker and 5 of the glider: See Conway's Game of Life/ALGOL 68 APL2 (Dialog) Example in one line APL \ 1130 example (very old APL dialect via simulator) APL1130From: APL \ 1130 Samples The following APL \ 1130 code will need APL385 font installed to display correctly. See Download APL TT Font ∇LIFE[⎕]∇[0] NG←LIFE CG; W[1] W←CG+(¯1⊖CG)+(1⊖CG)+(¯1⌽CG)+(1⌽CG)[2] W←W+(1⊖1⌽CG)+(¯1⊖1⌽CG)+(1⊖¯1⌽CG)+(¯1⊖¯1⌽CG)[3] NG←(3=W)+(CG∧4=W) ∇ RP←5 5⍴0 0 0 0 0 0 0 1 1 0 0 1 1 0 0 0 0 1 0 0 RP0 0 0 0 00 0 1 1 00 1 1 0 00 0 1 0 00 0 0 0 0 LIFE RP0 0 0 0 00 1 1 1 00 1 0 0 00 1 1 0 00 0 0 0 0 LIFE LIFE RP0 0 1 0 00 1 1 0 01 0 0 1 00 1 1 0 00 0 0 0 0 .................................................. One interacts with the Game of Life by creating an initial configuration and observing how it evolves. Although you should test your implementation on more complex examples such as the glider in a larger universe, show the action of the blinker (three adjoining cells in a row all alive), over three generations, in a 3 by 3 grid. (1,4)=TRUERETURN'' Count the number of neighbours of the point i,j' (Assume i/j +/- 1 will not fall out of world)'FUNCTION count_neighbours(i%,j%) LOCAL count%,l% count%=0 FOR l%=-1 TO 1 IF world! (i%+l%,j%+1) count%=count%+1 ENDIF NEXT l% IF world! (i%+1,j%) count%=count%+1 ENDIF RETURN count%ENDFUNC'' Update the world one step'PROCEDURE update_world LOCAL i%,j% ' compute neighbour counts and store FOR i%=1 TO 30 FOR j%=1 TO 30 ns%(i%,j%)[email protected]_neighbours(i%,j%) NEXT j% NEXT i% ' update the world cells FOR i%=1 TO 30 FOR j%=1 TO 30 IF world!

||

randfill: stx $01 ;$200 for indirect ldx #$02 ;addressing stx $02randloop: lda $fe ;generate random and #$01 ;pixels on the sta ($01), Y ;screen jsr inc0103 cmp #$00 bne randloop lda $02 cmp #$06 bne randloop clearmem: lda #$df ;set $07df-$0a20 sta $01 ;to $#00 lda #$07 sta $02clearbyte: lda #$00 sta ($01), Y jsr inc0103 cmp #$20 bne clearbyte lda $02 cmp #$0a bne clearbyte starttick:copyscreen: lda #$00 ;set up source sta $01 ;pointer at sta $03 ;$01/$02 and lda #$02 ;dest pointer sta $02 ;at $03/$04 lda #$08 sta $04 ldy #$00copybyte: lda ($01), Y ;copy pixel to sta ($03), Y ;back buffer jsr inc0103 ;increment pointers cmp #$00 ;check to see bne copybyte ;if we're at $600 lda $02 ;if so, we've cmp #$06 ;copied the bne copybyte ;entire screen conway: lda #$df ;apply conway rules sta $01 ;reset the pointer sta $03 ;to $#01df/$#07df lda #$01 ;($200 - $21) sta $02 ;($800 - $21) lda #$07 sta $04onecell: lda #$00 ;process one cell ldy #$01 ;upper cell clc adc ($03), Y ldy #$41 ;lower cell clc adc ($03), Ychkleft: tax ;check to see lda $01 ;if we're at the and #$1f ;left edge tay txa cpy #$1f beq rightcellsleftcells: ldy #$00 ;upper-left cell clc adc ($03), Y ldy #$20 ;left cell clc adc ($03), Y ldy #$40 ;lower-left cell clc adc ($03), Ychkright: tax ;check to see lda $01 ;if we're at the and #$1f ;right edge tay txa cpy #$1e beq evaluaterightcells: ldy #$02 ;upper-right cell clc adc ($03), Y ldy #$22 ;right cell clc adc ($03), Y ldy #$42 ;lower-right cell clc adc ($03), Yevaluate: ldx #$01 ;evaluate total ldy #$21 ;for current cell cmp #$03 ;3 = alive beq storex ldx #$00 cmp #$02 ;2 = alive if bne storex ;c = alive lda ($03), Y and #$01 taxstorex: txa ;store to screen sta ($01), Y jsr inc0103 ;move to next cellconwayloop: cmp #$e0 ;if not last cell, bne onecell ;process next cell lda $02 cmp #$05 bne onecell jmp starttick ;run next tick inc0103: lda $01 ;increment $01 cmp #$ff ;and $03 as 16-bit bne onlyinc01 ;pointers inc $02 inc $04onlyinc01: inc $01 lda $01 sta $03 rts The solution uses one cell thick border around square Petri dish as uninhabited dire land. Sample output contains 3 generations of the blinker and 5 of the glider: See Conway's Game of Life/ALGOL 68 APL2 (Dialog) Example in one line APL \ 1130 example (very old APL dialect via simulator) APL1130From: APL \ 1130 Samples The following APL \ 1130 code will need APL385 font installed to display correctly.

See Download APL TT Font ∇LIFE[⎕]∇[0] NG←LIFE CG; W[1] W←CG+(¯1⊖CG)+(1⊖CG)+(¯1⌽CG)+(1⌽CG)[2] W←W+(1⊖1⌽CG)+(¯1⊖1⌽CG)+(1⊖¯1⌽CG)+(¯1⊖¯1⌽CG)[3] NG←(3=W)+(CG∧4=W) ∇ RP←5 5⍴0 0 0 0 0 0 0 1 1 0 0 1 1 0 0 0 0 1 0 0 RP0 0 0 0 00 0 1 1 00 1 1 0 00 0 1 0 00 0 0 0 0 LIFE RP0 0 0 0 00 1 1 1 00 1 0 0 00 1 1 0 00 0 0 0 0 LIFE LIFE RP0 0 1 0 00 1 1 0 01 0 0 1 00 1 1 0 00 0 0 0 0 ..................................................

One interacts with the Game of Life by creating an initial configuration and observing how it evolves.

Although you should test your implementation on more complex examples such as the glider in a larger universe, show the action of the blinker (three adjoining cells in a row all alive), over three generations, in a 3 by 3 grid.

(1,4)=TRUERETURN'' Count the number of neighbours of the point i,j' (Assume i/j +/- 1 will not fall out of world)'FUNCTION count_neighbours(i%,j%) LOCAL count%,l% count%=0 FOR l%=-1 TO 1 IF world! (i%+l%,j%+1) count%=count%+1 ENDIF NEXT l% IF world! (i%+1,j%) count%=count%+1 ENDIF RETURN count%ENDFUNC'' Update the world one step'PROCEDURE update_world LOCAL i%,j% ' compute neighbour counts and store FOR i%=1 TO 30 FOR j%=1 TO 30 ns%(i%,j%)[email protected]_neighbours(i%,j%) NEXT j% NEXT i% ' update the world cells FOR i%=1 TO 30 FOR j%=1 TO 30 IF world!

Thus, while it is somewhat verbose, it fully simulates Conway's Game of Life and is relatively simple to expand to feature different starting shapes.

Define life(pattern) = Prgm Local x,y,nt,count,save,xl,yl,xh,yh Define nt(y,x) = when(pxl Test(y,x), 1, 0) {}→save set Graph("Axes", "Off")→save[1] set Graph("Grid", "Off")→save[2] set Graph("Labels", "Off")→save[3] Fn Off Plot Off Clr Draw If pattern = "blinker" Then 36→yl 40→yh 78→xl 82→xh Pxl On 36,80 Pxl On 38,80 Pxl On 40,80 Else If pattern = "glider" Then 30→yl 40→yh 76→xl 88→xh Pxl On 38,76 Pxl On 36,78 Pxl On 36,80 Pxl On 38,80 Pxl On 40,80 Else If pattern = "r" Then 38-5*2→yl 38+5*2→yh 80-5*2→xl 80+5*2→xh Pxl On 38,78 Pxl On 36,82 Pxl On 36,80 Pxl On 38,80 Pxl On 40,80 End If While get Key() = 0 © Expand upper-left corner to whole cell For y,yl,yh,2 For x,xl,xh,2 If pxl Test(y,x) Then Pxl On y+1,x Pxl On y+1,x+1 Pxl On y, x+1 Else Pxl Off y+1,x Pxl Off y+1,x+1 Pxl Off y, x+1 End If End For End For © Compute next generation For y,yl,yh,2 For x,xl,xh,2 nt(y-1,x-1) + nt(y-1,x) + nt(y-1,x+2) + nt(y,x-1) + nt(y+1,x+2) + nt(y+2,x-1) + nt(y+2,x+1) + nt(y+2,x+2) → count If count = 3 Then Pxl On y,x Else If count ≠ 2 Then Pxl Off y,x End If End For End For End While © Restore changed options set Graph("Axes", save[1]) set Graph("Grid", save[2]) set Graph("Labels", save[3])End Prgm Also see Conway's Game of Life/C Considering that the simplest implementation in C++ would lack any use of the object-oriented paradigm, this code was specifically written to demonstrate the various object-oriented features of C++.

]]copybyte: lda (

randfill: stx $01 ;$200 for indirect ldx #$02 ;addressing stx $02randloop: lda $fe ;generate random and #$01 ;pixels on the sta ($01), Y ;screen jsr inc0103 cmp #$00 bne randloop lda $02 cmp #$06 bne randloop clearmem: lda #$df ;set $07df-$0a20 sta $01 ;to $#00 lda #$07 sta $02clearbyte: lda #$00 sta ($01), Y jsr inc0103 cmp #$20 bne clearbyte lda $02 cmp #$0a bne clearbyte starttick:copyscreen: lda #$00 ;set up source sta $01 ;pointer at sta $03 ;$01/$02 and lda #$02 ;dest pointer sta $02 ;at $03/$04 lda #$08 sta $04 ldy #$00copybyte: lda ($01), Y ;copy pixel to sta ($03), Y ;back buffer jsr inc0103 ;increment pointers cmp #$00 ;check to see bne copybyte ;if we're at $600 lda $02 ;if so, we've cmp #$06 ;copied the bne copybyte ;entire screen conway: lda #$df ;apply conway rules sta $01 ;reset the pointer sta $03 ;to $#01df/$#07df lda #$01 ;($200 - $21) sta $02 ;($800 - $21) lda #$07 sta $04onecell: lda #$00 ;process one cell ldy #$01 ;upper cell clc adc ($03), Y ldy #$41 ;lower cell clc adc ($03), Ychkleft: tax ;check to see lda $01 ;if we're at the and #$1f ;left edge tay txa cpy #$1f beq rightcellsleftcells: ldy #$00 ;upper-left cell clc adc ($03), Y ldy #$20 ;left cell clc adc ($03), Y ldy #$40 ;lower-left cell clc adc ($03), Ychkright: tax ;check to see lda $01 ;if we're at the and #$1f ;right edge tay txa cpy #$1e beq evaluaterightcells: ldy #$02 ;upper-right cell clc adc ($03), Y ldy #$22 ;right cell clc adc ($03), Y ldy #$42 ;lower-right cell clc adc ($03), Yevaluate: ldx #$01 ;evaluate total ldy #$21 ;for current cell cmp #$03 ;3 = alive beq storex ldx #$00 cmp #$02 ;2 = alive if bne storex ;c = alive lda ($03), Y and #$01 taxstorex: txa ;store to screen sta ($01), Y jsr inc0103 ;move to next cellconwayloop: cmp #$e0 ;if not last cell, bne onecell ;process next cell lda $02 cmp #$05 bne onecell jmp starttick ;run next tick inc0103: lda $01 ;increment $01 cmp #$ff ;and $03 as 16-bit bne onlyinc01 ;pointers inc $02 inc $04onlyinc01: inc $01 lda $01 sta $03 rts The solution uses one cell thick border around square Petri dish as uninhabited dire land. Sample output contains 3 generations of the blinker and 5 of the glider: See Conway's Game of Life/ALGOL 68 APL2 (Dialog) Example in one line APL \ 1130 example (very old APL dialect via simulator) APL1130From: APL \ 1130 Samples The following APL \ 1130 code will need APL385 font installed to display correctly. See Download APL TT Font ∇LIFE[⎕]∇[0] NG←LIFE CG; W[1] W←CG+(¯1⊖CG)+(1⊖CG)+(¯1⌽CG)+(1⌽CG)[2] W←W+(1⊖1⌽CG)+(¯1⊖1⌽CG)+(1⊖¯1⌽CG)+(¯1⊖¯1⌽CG)[3] NG←(3=W)+(CG∧4=W) ∇ RP←5 5⍴0 0 0 0 0 0 0 1 1 0 0 1 1 0 0 0 0 1 0 0 RP0 0 0 0 00 0 1 1 00 1 1 0 00 0 1 0 00 0 0 0 0 LIFE RP0 0 0 0 00 1 1 1 00 1 0 0 00 1 1 0 00 0 0 0 0 LIFE LIFE RP0 0 1 0 00 1 1 0 01 0 0 1 00 1 1 0 00 0 0 0 0 .................................................. One interacts with the Game of Life by creating an initial configuration and observing how it evolves. Although you should test your implementation on more complex examples such as the glider in a larger universe, show the action of the blinker (three adjoining cells in a row all alive), over three generations, in a 3 by 3 grid. (1,4)=TRUERETURN'' Count the number of neighbours of the point i,j' (Assume i/j +/- 1 will not fall out of world)'FUNCTION count_neighbours(i%,j%) LOCAL count%,l% count%=0 FOR l%=-1 TO 1 IF world! (i%+l%,j%+1) count%=count%+1 ENDIF NEXT l% IF world! (i%+1,j%) count%=count%+1 ENDIF RETURN count%ENDFUNC'' Update the world one step'PROCEDURE update_world LOCAL i%,j% ' compute neighbour counts and store FOR i%=1 TO 30 FOR j%=1 TO 30 ns%(i%,j%)[email protected]_neighbours(i%,j%) NEXT j% NEXT i% ' update the world cells FOR i%=1 TO 30 FOR j%=1 TO 30 IF world!

||

randfill: stx $01 ;$200 for indirect ldx #$02 ;addressing stx $02randloop: lda $fe ;generate random and #$01 ;pixels on the sta ($01), Y ;screen jsr inc0103 cmp #$00 bne randloop lda $02 cmp #$06 bne randloop clearmem: lda #$df ;set $07df-$0a20 sta $01 ;to $#00 lda #$07 sta $02clearbyte: lda #$00 sta ($01), Y jsr inc0103 cmp #$20 bne clearbyte lda $02 cmp #$0a bne clearbyte starttick:copyscreen: lda #$00 ;set up source sta $01 ;pointer at sta $03 ;$01/$02 and lda #$02 ;dest pointer sta $02 ;at $03/$04 lda #$08 sta $04 ldy #$00copybyte: lda ($01), Y ;copy pixel to sta ($03), Y ;back buffer jsr inc0103 ;increment pointers cmp #$00 ;check to see bne copybyte ;if we're at $600 lda $02 ;if so, we've cmp #$06 ;copied the bne copybyte ;entire screen conway: lda #$df ;apply conway rules sta $01 ;reset the pointer sta $03 ;to $#01df/$#07df lda #$01 ;($200 - $21) sta $02 ;($800 - $21) lda #$07 sta $04onecell: lda #$00 ;process one cell ldy #$01 ;upper cell clc adc ($03), Y ldy #$41 ;lower cell clc adc ($03), Ychkleft: tax ;check to see lda $01 ;if we're at the and #$1f ;left edge tay txa cpy #$1f beq rightcellsleftcells: ldy #$00 ;upper-left cell clc adc ($03), Y ldy #$20 ;left cell clc adc ($03), Y ldy #$40 ;lower-left cell clc adc ($03), Ychkright: tax ;check to see lda $01 ;if we're at the and #$1f ;right edge tay txa cpy #$1e beq evaluaterightcells: ldy #$02 ;upper-right cell clc adc ($03), Y ldy #$22 ;right cell clc adc ($03), Y ldy #$42 ;lower-right cell clc adc ($03), Yevaluate: ldx #$01 ;evaluate total ldy #$21 ;for current cell cmp #$03 ;3 = alive beq storex ldx #$00 cmp #$02 ;2 = alive if bne storex ;c = alive lda ($03), Y and #$01 taxstorex: txa ;store to screen sta ($01), Y jsr inc0103 ;move to next cellconwayloop: cmp #$e0 ;if not last cell, bne onecell ;process next cell lda $02 cmp #$05 bne onecell jmp starttick ;run next tick inc0103: lda $01 ;increment $01 cmp #$ff ;and $03 as 16-bit bne onlyinc01 ;pointers inc $02 inc $04onlyinc01: inc $01 lda $01 sta $03 rts The solution uses one cell thick border around square Petri dish as uninhabited dire land. Sample output contains 3 generations of the blinker and 5 of the glider: See Conway's Game of Life/ALGOL 68 APL2 (Dialog) Example in one line APL \ 1130 example (very old APL dialect via simulator) APL1130From: APL \ 1130 Samples The following APL \ 1130 code will need APL385 font installed to display correctly.

See Download APL TT Font ∇LIFE[⎕]∇[0] NG←LIFE CG; W[1] W←CG+(¯1⊖CG)+(1⊖CG)+(¯1⌽CG)+(1⌽CG)[2] W←W+(1⊖1⌽CG)+(¯1⊖1⌽CG)+(1⊖¯1⌽CG)+(¯1⊖¯1⌽CG)[3] NG←(3=W)+(CG∧4=W) ∇ RP←5 5⍴0 0 0 0 0 0 0 1 1 0 0 1 1 0 0 0 0 1 0 0 RP0 0 0 0 00 0 1 1 00 1 1 0 00 0 1 0 00 0 0 0 0 LIFE RP0 0 0 0 00 1 1 1 00 1 0 0 00 1 1 0 00 0 0 0 0 LIFE LIFE RP0 0 1 0 00 1 1 0 01 0 0 1 00 1 1 0 00 0 0 0 0 ..................................................

One interacts with the Game of Life by creating an initial configuration and observing how it evolves.

Although you should test your implementation on more complex examples such as the glider in a larger universe, show the action of the blinker (three adjoining cells in a row all alive), over three generations, in a 3 by 3 grid.

(1,4)=TRUERETURN'' Count the number of neighbours of the point i,j' (Assume i/j +/- 1 will not fall out of world)'FUNCTION count_neighbours(i%,j%) LOCAL count%,l% count%=0 FOR l%=-1 TO 1 IF world! (i%+l%,j%+1) count%=count%+1 ENDIF NEXT l% IF world! (i%+1,j%) count%=count%+1 ENDIF RETURN count%ENDFUNC'' Update the world one step'PROCEDURE update_world LOCAL i%,j% ' compute neighbour counts and store FOR i%=1 TO 30 FOR j%=1 TO 30 ns%(i%,j%)[email protected]_neighbours(i%,j%) NEXT j% NEXT i% ' update the world cells FOR i%=1 TO 30 FOR j%=1 TO 30 IF world!

Thus, while it is somewhat verbose, it fully simulates Conway's Game of Life and is relatively simple to expand to feature different starting shapes.

Define life(pattern) = Prgm Local x,y,nt,count,save,xl,yl,xh,yh Define nt(y,x) = when(pxl Test(y,x), 1, 0) {}→save set Graph("Axes", "Off")→save[1] set Graph("Grid", "Off")→save[2] set Graph("Labels", "Off")→save[3] Fn Off Plot Off Clr Draw If pattern = "blinker" Then 36→yl 40→yh 78→xl 82→xh Pxl On 36,80 Pxl On 38,80 Pxl On 40,80 Else If pattern = "glider" Then 30→yl 40→yh 76→xl 88→xh Pxl On 38,76 Pxl On 36,78 Pxl On 36,80 Pxl On 38,80 Pxl On 40,80 Else If pattern = "r" Then 38-5*2→yl 38+5*2→yh 80-5*2→xl 80+5*2→xh Pxl On 38,78 Pxl On 36,82 Pxl On 36,80 Pxl On 38,80 Pxl On 40,80 End If While get Key() = 0 © Expand upper-left corner to whole cell For y,yl,yh,2 For x,xl,xh,2 If pxl Test(y,x) Then Pxl On y+1,x Pxl On y+1,x+1 Pxl On y, x+1 Else Pxl Off y+1,x Pxl Off y+1,x+1 Pxl Off y, x+1 End If End For End For © Compute next generation For y,yl,yh,2 For x,xl,xh,2 nt(y-1,x-1) + nt(y-1,x) + nt(y-1,x+2) + nt(y,x-1) + nt(y+1,x+2) + nt(y+2,x-1) + nt(y+2,x+1) + nt(y+2,x+2) → count If count = 3 Then Pxl On y,x Else If count ≠ 2 Then Pxl Off y,x End If End For End For End While © Restore changed options set Graph("Axes", save[1]) set Graph("Grid", save[2]) set Graph("Labels", save[3])End Prgm Also see Conway's Game of Life/C Considering that the simplest implementation in C++ would lack any use of the object-oriented paradigm, this code was specifically written to demonstrate the various object-oriented features of C++.

), Y ;copy pixel to sta (), Y ;back buffer jsr inc0103 ;increment pointers cmp #[[

randfill: stx $01 ;$200 for indirect ldx #$02 ;addressing stx $02randloop: lda $fe ;generate random and #$01 ;pixels on the sta ($01), Y ;screen jsr inc0103 cmp #$00 bne randloop lda $02 cmp #$06 bne randloop clearmem: lda #$df ;set $07df-$0a20 sta $01 ;to $#00 lda #$07 sta $02clearbyte: lda #$00 sta ($01), Y jsr inc0103 cmp #$20 bne clearbyte lda $02 cmp #$0a bne clearbyte starttick:copyscreen: lda #$00 ;set up source sta $01 ;pointer at sta $03 ;$01/$02 and lda #$02 ;dest pointer sta $02 ;at $03/$04 lda #$08 sta $04 ldy #$00copybyte: lda ($01), Y ;copy pixel to sta ($03), Y ;back buffer jsr inc0103 ;increment pointers cmp #$00 ;check to see bne copybyte ;if we're at $600 lda $02 ;if so, we've cmp #$06 ;copied the bne copybyte ;entire screen conway: lda #$df ;apply conway rules sta $01 ;reset the pointer sta $03 ;to $#01df/$#07df lda #$01 ;($200 - $21) sta $02 ;($800 - $21) lda #$07 sta $04onecell: lda #$00 ;process one cell ldy #$01 ;upper cell clc adc ($03), Y ldy #$41 ;lower cell clc adc ($03), Ychkleft: tax ;check to see lda $01 ;if we're at the and #$1f ;left edge tay txa cpy #$1f beq rightcellsleftcells: ldy #$00 ;upper-left cell clc adc ($03), Y ldy #$20 ;left cell clc adc ($03), Y ldy #$40 ;lower-left cell clc adc ($03), Ychkright: tax ;check to see lda $01 ;if we're at the and #$1f ;right edge tay txa cpy #$1e beq evaluaterightcells: ldy #$02 ;upper-right cell clc adc ($03), Y ldy #$22 ;right cell clc adc ($03), Y ldy #$42 ;lower-right cell clc adc ($03), Yevaluate: ldx #$01 ;evaluate total ldy #$21 ;for current cell cmp #$03 ;3 = alive beq storex ldx #$00 cmp #$02 ;2 = alive if bne storex ;c = alive lda ($03), Y and #$01 taxstorex: txa ;store to screen sta ($01), Y jsr inc0103 ;move to next cellconwayloop: cmp #$e0 ;if not last cell, bne onecell ;process next cell lda $02 cmp #$05 bne onecell jmp starttick ;run next tick inc0103: lda $01 ;increment $01 cmp #$ff ;and $03 as 16-bit bne onlyinc01 ;pointers inc $02 inc $04onlyinc01: inc $01 lda $01 sta $03 rts The solution uses one cell thick border around square Petri dish as uninhabited dire land. Sample output contains 3 generations of the blinker and 5 of the glider: See Conway's Game of Life/ALGOL 68 APL2 (Dialog) Example in one line APL \ 1130 example (very old APL dialect via simulator) APL1130From: APL \ 1130 Samples The following APL \ 1130 code will need APL385 font installed to display correctly. See Download APL TT Font ∇LIFE[⎕]∇[0] NG←LIFE CG; W[1] W←CG+(¯1⊖CG)+(1⊖CG)+(¯1⌽CG)+(1⌽CG)[2] W←W+(1⊖1⌽CG)+(¯1⊖1⌽CG)+(1⊖¯1⌽CG)+(¯1⊖¯1⌽CG)[3] NG←(3=W)+(CG∧4=W) ∇ RP←5 5⍴0 0 0 0 0 0 0 1 1 0 0 1 1 0 0 0 0 1 0 0 RP0 0 0 0 00 0 1 1 00 1 1 0 00 0 1 0 00 0 0 0 0 LIFE RP0 0 0 0 00 1 1 1 00 1 0 0 00 1 1 0 00 0 0 0 0 LIFE LIFE RP0 0 1 0 00 1 1 0 01 0 0 1 00 1 1 0 00 0 0 0 0 .................................................. One interacts with the Game of Life by creating an initial configuration and observing how it evolves. Although you should test your implementation on more complex examples such as the glider in a larger universe, show the action of the blinker (three adjoining cells in a row all alive), over three generations, in a 3 by 3 grid. (1,4)=TRUERETURN'' Count the number of neighbours of the point i,j' (Assume i/j +/- 1 will not fall out of world)'FUNCTION count_neighbours(i%,j%) LOCAL count%,l% count%=0 FOR l%=-1 TO 1 IF world! (i%+l%,j%+1) count%=count%+1 ENDIF NEXT l% IF world! (i%+1,j%) count%=count%+1 ENDIF RETURN count%ENDFUNC'' Update the world one step'PROCEDURE update_world LOCAL i%,j% ' compute neighbour counts and store FOR i%=1 TO 30 FOR j%=1 TO 30 ns%(i%,j%)[email protected]_neighbours(i%,j%) NEXT j% NEXT i% ' update the world cells FOR i%=1 TO 30 FOR j%=1 TO 30 IF world!

||

randfill: stx $01 ;$200 for indirect ldx #$02 ;addressing stx $02randloop: lda $fe ;generate random and #$01 ;pixels on the sta ($01), Y ;screen jsr inc0103 cmp #$00 bne randloop lda $02 cmp #$06 bne randloop clearmem: lda #$df ;set $07df-$0a20 sta $01 ;to $#00 lda #$07 sta $02clearbyte: lda #$00 sta ($01), Y jsr inc0103 cmp #$20 bne clearbyte lda $02 cmp #$0a bne clearbyte starttick:copyscreen: lda #$00 ;set up source sta $01 ;pointer at sta $03 ;$01/$02 and lda #$02 ;dest pointer sta $02 ;at $03/$04 lda #$08 sta $04 ldy #$00copybyte: lda ($01), Y ;copy pixel to sta ($03), Y ;back buffer jsr inc0103 ;increment pointers cmp #$00 ;check to see bne copybyte ;if we're at $600 lda $02 ;if so, we've cmp #$06 ;copied the bne copybyte ;entire screen conway: lda #$df ;apply conway rules sta $01 ;reset the pointer sta $03 ;to $#01df/$#07df lda #$01 ;($200 - $21) sta $02 ;($800 - $21) lda #$07 sta $04onecell: lda #$00 ;process one cell ldy #$01 ;upper cell clc adc ($03), Y ldy #$41 ;lower cell clc adc ($03), Ychkleft: tax ;check to see lda $01 ;if we're at the and #$1f ;left edge tay txa cpy #$1f beq rightcellsleftcells: ldy #$00 ;upper-left cell clc adc ($03), Y ldy #$20 ;left cell clc adc ($03), Y ldy #$40 ;lower-left cell clc adc ($03), Ychkright: tax ;check to see lda $01 ;if we're at the and #$1f ;right edge tay txa cpy #$1e beq evaluaterightcells: ldy #$02 ;upper-right cell clc adc ($03), Y ldy #$22 ;right cell clc adc ($03), Y ldy #$42 ;lower-right cell clc adc ($03), Yevaluate: ldx #$01 ;evaluate total ldy #$21 ;for current cell cmp #$03 ;3 = alive beq storex ldx #$00 cmp #$02 ;2 = alive if bne storex ;c = alive lda ($03), Y and #$01 taxstorex: txa ;store to screen sta ($01), Y jsr inc0103 ;move to next cellconwayloop: cmp #$e0 ;if not last cell, bne onecell ;process next cell lda $02 cmp #$05 bne onecell jmp starttick ;run next tick inc0103: lda $01 ;increment $01 cmp #$ff ;and $03 as 16-bit bne onlyinc01 ;pointers inc $02 inc $04onlyinc01: inc $01 lda $01 sta $03 rts The solution uses one cell thick border around square Petri dish as uninhabited dire land. Sample output contains 3 generations of the blinker and 5 of the glider: See Conway's Game of Life/ALGOL 68 APL2 (Dialog) Example in one line APL \ 1130 example (very old APL dialect via simulator) APL1130From: APL \ 1130 Samples The following APL \ 1130 code will need APL385 font installed to display correctly.

See Download APL TT Font ∇LIFE[⎕]∇[0] NG←LIFE CG; W[1] W←CG+(¯1⊖CG)+(1⊖CG)+(¯1⌽CG)+(1⌽CG)[2] W←W+(1⊖1⌽CG)+(¯1⊖1⌽CG)+(1⊖¯1⌽CG)+(¯1⊖¯1⌽CG)[3] NG←(3=W)+(CG∧4=W) ∇ RP←5 5⍴0 0 0 0 0 0 0 1 1 0 0 1 1 0 0 0 0 1 0 0 RP0 0 0 0 00 0 1 1 00 1 1 0 00 0 1 0 00 0 0 0 0 LIFE RP0 0 0 0 00 1 1 1 00 1 0 0 00 1 1 0 00 0 0 0 0 LIFE LIFE RP0 0 1 0 00 1 1 0 01 0 0 1 00 1 1 0 00 0 0 0 0 ..................................................

One interacts with the Game of Life by creating an initial configuration and observing how it evolves.

Although you should test your implementation on more complex examples such as the glider in a larger universe, show the action of the blinker (three adjoining cells in a row all alive), over three generations, in a 3 by 3 grid.

(1,4)=TRUERETURN'' Count the number of neighbours of the point i,j' (Assume i/j +/- 1 will not fall out of world)'FUNCTION count_neighbours(i%,j%) LOCAL count%,l% count%=0 FOR l%=-1 TO 1 IF world! (i%+l%,j%+1) count%=count%+1 ENDIF NEXT l% IF world! (i%+1,j%) count%=count%+1 ENDIF RETURN count%ENDFUNC'' Update the world one step'PROCEDURE update_world LOCAL i%,j% ' compute neighbour counts and store FOR i%=1 TO 30 FOR j%=1 TO 30 ns%(i%,j%)[email protected]_neighbours(i%,j%) NEXT j% NEXT i% ' update the world cells FOR i%=1 TO 30 FOR j%=1 TO 30 IF world!

Thus, while it is somewhat verbose, it fully simulates Conway's Game of Life and is relatively simple to expand to feature different starting shapes.

Define life(pattern) = Prgm Local x,y,nt,count,save,xl,yl,xh,yh Define nt(y,x) = when(pxl Test(y,x), 1, 0) {}→save set Graph("Axes", "Off")→save[1] set Graph("Grid", "Off")→save[2] set Graph("Labels", "Off")→save[3] Fn Off Plot Off Clr Draw If pattern = "blinker" Then 36→yl 40→yh 78→xl 82→xh Pxl On 36,80 Pxl On 38,80 Pxl On 40,80 Else If pattern = "glider" Then 30→yl 40→yh 76→xl 88→xh Pxl On 38,76 Pxl On 36,78 Pxl On 36,80 Pxl On 38,80 Pxl On 40,80 Else If pattern = "r" Then 38-5*2→yl 38+5*2→yh 80-5*2→xl 80+5*2→xh Pxl On 38,78 Pxl On 36,82 Pxl On 36,80 Pxl On 38,80 Pxl On 40,80 End If While get Key() = 0 © Expand upper-left corner to whole cell For y,yl,yh,2 For x,xl,xh,2 If pxl Test(y,x) Then Pxl On y+1,x Pxl On y+1,x+1 Pxl On y, x+1 Else Pxl Off y+1,x Pxl Off y+1,x+1 Pxl Off y, x+1 End If End For End For © Compute next generation For y,yl,yh,2 For x,xl,xh,2 nt(y-1,x-1) + nt(y-1,x) + nt(y-1,x+2) + nt(y,x-1) + nt(y+1,x+2) + nt(y+2,x-1) + nt(y+2,x+1) + nt(y+2,x+2) → count If count = 3 Then Pxl On y,x Else If count ≠ 2 Then Pxl Off y,x End If End For End For End While © Restore changed options set Graph("Axes", save[1]) set Graph("Grid", save[2]) set Graph("Labels", save[3])End Prgm Also see Conway's Game of Life/C Considering that the simplest implementation in C++ would lack any use of the object-oriented paradigm, this code was specifically written to demonstrate the various object-oriented features of C++.

]] ;check to see bne copybyte ;if we're at 0 lda ;if so, we've cmp # ;copied the bne copybyte ;entire screen conway: lda #$df ;apply conway rules sta

randfill: stx $01 ;$200 for indirect ldx #$02 ;addressing stx $02randloop: lda $fe ;generate random and #$01 ;pixels on the sta ($01), Y ;screen jsr inc0103 cmp #$00 bne randloop lda $02 cmp #$06 bne randloop clearmem: lda #$df ;set $07df-$0a20 sta $01 ;to $#00 lda #$07 sta $02clearbyte: lda #$00 sta ($01), Y jsr inc0103 cmp #$20 bne clearbyte lda $02 cmp #$0a bne clearbyte starttick:copyscreen: lda #$00 ;set up source sta $01 ;pointer at sta $03 ;$01/$02 and lda #$02 ;dest pointer sta $02 ;at $03/$04 lda #$08 sta $04 ldy #$00copybyte: lda ($01), Y ;copy pixel to sta ($03), Y ;back buffer jsr inc0103 ;increment pointers cmp #$00 ;check to see bne copybyte ;if we're at $600 lda $02 ;if so, we've cmp #$06 ;copied the bne copybyte ;entire screen conway: lda #$df ;apply conway rules sta $01 ;reset the pointer sta $03 ;to $#01df/$#07df lda #$01 ;($200 - $21) sta $02 ;($800 - $21) lda #$07 sta $04onecell: lda #$00 ;process one cell ldy #$01 ;upper cell clc adc ($03), Y ldy #$41 ;lower cell clc adc ($03), Ychkleft: tax ;check to see lda $01 ;if we're at the and #$1f ;left edge tay txa cpy #$1f beq rightcellsleftcells: ldy #$00 ;upper-left cell clc adc ($03), Y ldy #$20 ;left cell clc adc ($03), Y ldy #$40 ;lower-left cell clc adc ($03), Ychkright: tax ;check to see lda $01 ;if we're at the and #$1f ;right edge tay txa cpy #$1e beq evaluaterightcells: ldy #$02 ;upper-right cell clc adc ($03), Y ldy #$22 ;right cell clc adc ($03), Y ldy #$42 ;lower-right cell clc adc ($03), Yevaluate: ldx #$01 ;evaluate total ldy #$21 ;for current cell cmp #$03 ;3 = alive beq storex ldx #$00 cmp #$02 ;2 = alive if bne storex ;c = alive lda ($03), Y and #$01 taxstorex: txa ;store to screen sta ($01), Y jsr inc0103 ;move to next cellconwayloop: cmp #$e0 ;if not last cell, bne onecell ;process next cell lda $02 cmp #$05 bne onecell jmp starttick ;run next tick inc0103: lda $01 ;increment $01 cmp #$ff ;and $03 as 16-bit bne onlyinc01 ;pointers inc $02 inc $04onlyinc01: inc $01 lda $01 sta $03 rts The solution uses one cell thick border around square Petri dish as uninhabited dire land. Sample output contains 3 generations of the blinker and 5 of the glider: See Conway's Game of Life/ALGOL 68 APL2 (Dialog) Example in one line APL \ 1130 example (very old APL dialect via simulator) APL1130From: APL \ 1130 Samples The following APL \ 1130 code will need APL385 font installed to display correctly. See Download APL TT Font ∇LIFE[⎕]∇[0] NG←LIFE CG; W[1] W←CG+(¯1⊖CG)+(1⊖CG)+(¯1⌽CG)+(1⌽CG)[2] W←W+(1⊖1⌽CG)+(¯1⊖1⌽CG)+(1⊖¯1⌽CG)+(¯1⊖¯1⌽CG)[3] NG←(3=W)+(CG∧4=W) ∇ RP←5 5⍴0 0 0 0 0 0 0 1 1 0 0 1 1 0 0 0 0 1 0 0 RP0 0 0 0 00 0 1 1 00 1 1 0 00 0 1 0 00 0 0 0 0 LIFE RP0 0 0 0 00 1 1 1 00 1 0 0 00 1 1 0 00 0 0 0 0 LIFE LIFE RP0 0 1 0 00 1 1 0 01 0 0 1 00 1 1 0 00 0 0 0 0 .................................................. One interacts with the Game of Life by creating an initial configuration and observing how it evolves. Although you should test your implementation on more complex examples such as the glider in a larger universe, show the action of the blinker (three adjoining cells in a row all alive), over three generations, in a 3 by 3 grid. (1,4)=TRUERETURN'' Count the number of neighbours of the point i,j' (Assume i/j +/- 1 will not fall out of world)'FUNCTION count_neighbours(i%,j%) LOCAL count%,l% count%=0 FOR l%=-1 TO 1 IF world! (i%+l%,j%+1) count%=count%+1 ENDIF NEXT l% IF world! (i%+1,j%) count%=count%+1 ENDIF RETURN count%ENDFUNC'' Update the world one step'PROCEDURE update_world LOCAL i%,j% ' compute neighbour counts and store FOR i%=1 TO 30 FOR j%=1 TO 30 ns%(i%,j%)[email protected]_neighbours(i%,j%) NEXT j% NEXT i% ' update the world cells FOR i%=1 TO 30 FOR j%=1 TO 30 IF world!

||

randfill: stx $01 ;$200 for indirect ldx #$02 ;addressing stx $02randloop: lda $fe ;generate random and #$01 ;pixels on the sta ($01), Y ;screen jsr inc0103 cmp #$00 bne randloop lda $02 cmp #$06 bne randloop clearmem: lda #$df ;set $07df-$0a20 sta $01 ;to $#00 lda #$07 sta $02clearbyte: lda #$00 sta ($01), Y jsr inc0103 cmp #$20 bne clearbyte lda $02 cmp #$0a bne clearbyte starttick:copyscreen: lda #$00 ;set up source sta $01 ;pointer at sta $03 ;$01/$02 and lda #$02 ;dest pointer sta $02 ;at $03/$04 lda #$08 sta $04 ldy #$00copybyte: lda ($01), Y ;copy pixel to sta ($03), Y ;back buffer jsr inc0103 ;increment pointers cmp #$00 ;check to see bne copybyte ;if we're at $600 lda $02 ;if so, we've cmp #$06 ;copied the bne copybyte ;entire screen conway: lda #$df ;apply conway rules sta $01 ;reset the pointer sta $03 ;to $#01df/$#07df lda #$01 ;($200 - $21) sta $02 ;($800 - $21) lda #$07 sta $04onecell: lda #$00 ;process one cell ldy #$01 ;upper cell clc adc ($03), Y ldy #$41 ;lower cell clc adc ($03), Ychkleft: tax ;check to see lda $01 ;if we're at the and #$1f ;left edge tay txa cpy #$1f beq rightcellsleftcells: ldy #$00 ;upper-left cell clc adc ($03), Y ldy #$20 ;left cell clc adc ($03), Y ldy #$40 ;lower-left cell clc adc ($03), Ychkright: tax ;check to see lda $01 ;if we're at the and #$1f ;right edge tay txa cpy #$1e beq evaluaterightcells: ldy #$02 ;upper-right cell clc adc ($03), Y ldy #$22 ;right cell clc adc ($03), Y ldy #$42 ;lower-right cell clc adc ($03), Yevaluate: ldx #$01 ;evaluate total ldy #$21 ;for current cell cmp #$03 ;3 = alive beq storex ldx #$00 cmp #$02 ;2 = alive if bne storex ;c = alive lda ($03), Y and #$01 taxstorex: txa ;store to screen sta ($01), Y jsr inc0103 ;move to next cellconwayloop: cmp #$e0 ;if not last cell, bne onecell ;process next cell lda $02 cmp #$05 bne onecell jmp starttick ;run next tick inc0103: lda $01 ;increment $01 cmp #$ff ;and $03 as 16-bit bne onlyinc01 ;pointers inc $02 inc $04onlyinc01: inc $01 lda $01 sta $03 rts The solution uses one cell thick border around square Petri dish as uninhabited dire land. Sample output contains 3 generations of the blinker and 5 of the glider: See Conway's Game of Life/ALGOL 68 APL2 (Dialog) Example in one line APL \ 1130 example (very old APL dialect via simulator) APL1130From: APL \ 1130 Samples The following APL \ 1130 code will need APL385 font installed to display correctly.

See Download APL TT Font ∇LIFE[⎕]∇[0] NG←LIFE CG; W[1] W←CG+(¯1⊖CG)+(1⊖CG)+(¯1⌽CG)+(1⌽CG)[2] W←W+(1⊖1⌽CG)+(¯1⊖1⌽CG)+(1⊖¯1⌽CG)+(¯1⊖¯1⌽CG)[3] NG←(3=W)+(CG∧4=W) ∇ RP←5 5⍴0 0 0 0 0 0 0 1 1 0 0 1 1 0 0 0 0 1 0 0 RP0 0 0 0 00 0 1 1 00 1 1 0 00 0 1 0 00 0 0 0 0 LIFE RP0 0 0 0 00 1 1 1 00 1 0 0 00 1 1 0 00 0 0 0 0 LIFE LIFE RP0 0 1 0 00 1 1 0 01 0 0 1 00 1 1 0 00 0 0 0 0 ..................................................

One interacts with the Game of Life by creating an initial configuration and observing how it evolves.

Although you should test your implementation on more complex examples such as the glider in a larger universe, show the action of the blinker (three adjoining cells in a row all alive), over three generations, in a 3 by 3 grid.

(1,4)=TRUERETURN'' Count the number of neighbours of the point i,j' (Assume i/j +/- 1 will not fall out of world)'FUNCTION count_neighbours(i%,j%) LOCAL count%,l% count%=0 FOR l%=-1 TO 1 IF world! (i%+l%,j%+1) count%=count%+1 ENDIF NEXT l% IF world! (i%+1,j%) count%=count%+1 ENDIF RETURN count%ENDFUNC'' Update the world one step'PROCEDURE update_world LOCAL i%,j% ' compute neighbour counts and store FOR i%=1 TO 30 FOR j%=1 TO 30 ns%(i%,j%)[email protected]_neighbours(i%,j%) NEXT j% NEXT i% ' update the world cells FOR i%=1 TO 30 FOR j%=1 TO 30 IF world!

Thus, while it is somewhat verbose, it fully simulates Conway's Game of Life and is relatively simple to expand to feature different starting shapes.

Define life(pattern) = Prgm Local x,y,nt,count,save,xl,yl,xh,yh Define nt(y,x) = when(pxl Test(y,x), 1, 0) {}→save set Graph("Axes", "Off")→save[1] set Graph("Grid", "Off")→save[2] set Graph("Labels", "Off")→save[3] Fn Off Plot Off Clr Draw If pattern = "blinker" Then 36→yl 40→yh 78→xl 82→xh Pxl On 36,80 Pxl On 38,80 Pxl On 40,80 Else If pattern = "glider" Then 30→yl 40→yh 76→xl 88→xh Pxl On 38,76 Pxl On 36,78 Pxl On 36,80 Pxl On 38,80 Pxl On 40,80 Else If pattern = "r" Then 38-5*2→yl 38+5*2→yh 80-5*2→xl 80+5*2→xh Pxl On 38,78 Pxl On 36,82 Pxl On 36,80 Pxl On 38,80 Pxl On 40,80 End If While get Key() = 0 © Expand upper-left corner to whole cell For y,yl,yh,2 For x,xl,xh,2 If pxl Test(y,x) Then Pxl On y+1,x Pxl On y+1,x+1 Pxl On y, x+1 Else Pxl Off y+1,x Pxl Off y+1,x+1 Pxl Off y, x+1 End If End For End For © Compute next generation For y,yl,yh,2 For x,xl,xh,2 nt(y-1,x-1) + nt(y-1,x) + nt(y-1,x+2) + nt(y,x-1) + nt(y+1,x+2) + nt(y+2,x-1) + nt(y+2,x+1) + nt(y+2,x+2) → count If count = 3 Then Pxl On y,x Else If count ≠ 2 Then Pxl Off y,x End If End For End For End While © Restore changed options set Graph("Axes", save[1]) set Graph("Grid", save[2]) set Graph("Labels", save[3])End Prgm Also see Conway's Game of Life/C Considering that the simplest implementation in C++ would lack any use of the object-oriented paradigm, this code was specifically written to demonstrate the various object-oriented features of C++.

;reset the pointer sta ;to $#01df/$#07df lda #

randfill: stx $01 ;$200 for indirect ldx #$02 ;addressing stx $02randloop: lda $fe ;generate random and #$01 ;pixels on the sta ($01), Y ;screen jsr inc0103 cmp #$00 bne randloop lda $02 cmp #$06 bne randloop clearmem: lda #$df ;set $07df-$0a20 sta $01 ;to $#00 lda #$07 sta $02clearbyte: lda #$00 sta ($01), Y jsr inc0103 cmp #$20 bne clearbyte lda $02 cmp #$0a bne clearbyte starttick:copyscreen: lda #$00 ;set up source sta $01 ;pointer at sta $03 ;$01/$02 and lda #$02 ;dest pointer sta $02 ;at $03/$04 lda #$08 sta $04 ldy #$00copybyte: lda ($01), Y ;copy pixel to sta ($03), Y ;back buffer jsr inc0103 ;increment pointers cmp #$00 ;check to see bne copybyte ;if we're at $600 lda $02 ;if so, we've cmp #$06 ;copied the bne copybyte ;entire screen conway: lda #$df ;apply conway rules sta $01 ;reset the pointer sta $03 ;to $#01df/$#07df lda #$01 ;($200 - $21) sta $02 ;($800 - $21) lda #$07 sta $04onecell: lda #$00 ;process one cell ldy #$01 ;upper cell clc adc ($03), Y ldy #$41 ;lower cell clc adc ($03), Ychkleft: tax ;check to see lda $01 ;if we're at the and #$1f ;left edge tay txa cpy #$1f beq rightcellsleftcells: ldy #$00 ;upper-left cell clc adc ($03), Y ldy #$20 ;left cell clc adc ($03), Y ldy #$40 ;lower-left cell clc adc ($03), Ychkright: tax ;check to see lda $01 ;if we're at the and #$1f ;right edge tay txa cpy #$1e beq evaluaterightcells: ldy #$02 ;upper-right cell clc adc ($03), Y ldy #$22 ;right cell clc adc ($03), Y ldy #$42 ;lower-right cell clc adc ($03), Yevaluate: ldx #$01 ;evaluate total ldy #$21 ;for current cell cmp #$03 ;3 = alive beq storex ldx #$00 cmp #$02 ;2 = alive if bne storex ;c = alive lda ($03), Y and #$01 taxstorex: txa ;store to screen sta ($01), Y jsr inc0103 ;move to next cellconwayloop: cmp #$e0 ;if not last cell, bne onecell ;process next cell lda $02 cmp #$05 bne onecell jmp starttick ;run next tick inc0103: lda $01 ;increment $01 cmp #$ff ;and $03 as 16-bit bne onlyinc01 ;pointers inc $02 inc $04onlyinc01: inc $01 lda $01 sta $03 rts The solution uses one cell thick border around square Petri dish as uninhabited dire land. Sample output contains 3 generations of the blinker and 5 of the glider: See Conway's Game of Life/ALGOL 68 APL2 (Dialog) Example in one line APL \ 1130 example (very old APL dialect via simulator) APL1130From: APL \ 1130 Samples The following APL \ 1130 code will need APL385 font installed to display correctly. See Download APL TT Font ∇LIFE[⎕]∇[0] NG←LIFE CG; W[1] W←CG+(¯1⊖CG)+(1⊖CG)+(¯1⌽CG)+(1⌽CG)[2] W←W+(1⊖1⌽CG)+(¯1⊖1⌽CG)+(1⊖¯1⌽CG)+(¯1⊖¯1⌽CG)[3] NG←(3=W)+(CG∧4=W) ∇ RP←5 5⍴0 0 0 0 0 0 0 1 1 0 0 1 1 0 0 0 0 1 0 0 RP0 0 0 0 00 0 1 1 00 1 1 0 00 0 1 0 00 0 0 0 0 LIFE RP0 0 0 0 00 1 1 1 00 1 0 0 00 1 1 0 00 0 0 0 0 LIFE LIFE RP0 0 1 0 00 1 1 0 01 0 0 1 00 1 1 0 00 0 0 0 0 .................................................. One interacts with the Game of Life by creating an initial configuration and observing how it evolves. Although you should test your implementation on more complex examples such as the glider in a larger universe, show the action of the blinker (three adjoining cells in a row all alive), over three generations, in a 3 by 3 grid. (1,4)=TRUERETURN'' Count the number of neighbours of the point i,j' (Assume i/j +/- 1 will not fall out of world)'FUNCTION count_neighbours(i%,j%) LOCAL count%,l% count%=0 FOR l%=-1 TO 1 IF world! (i%+l%,j%+1) count%=count%+1 ENDIF NEXT l% IF world! (i%+1,j%) count%=count%+1 ENDIF RETURN count%ENDFUNC'' Update the world one step'PROCEDURE update_world LOCAL i%,j% ' compute neighbour counts and store FOR i%=1 TO 30 FOR j%=1 TO 30 ns%(i%,j%)[email protected]_neighbours(i%,j%) NEXT j% NEXT i% ' update the world cells FOR i%=1 TO 30 FOR j%=1 TO 30 IF world!

||

randfill: stx $01 ;$200 for indirect ldx #$02 ;addressing stx $02randloop: lda $fe ;generate random and #$01 ;pixels on the sta ($01), Y ;screen jsr inc0103 cmp #$00 bne randloop lda $02 cmp #$06 bne randloop clearmem: lda #$df ;set $07df-$0a20 sta $01 ;to $#00 lda #$07 sta $02clearbyte: lda #$00 sta ($01), Y jsr inc0103 cmp #$20 bne clearbyte lda $02 cmp #$0a bne clearbyte starttick:copyscreen: lda #$00 ;set up source sta $01 ;pointer at sta $03 ;$01/$02 and lda #$02 ;dest pointer sta $02 ;at $03/$04 lda #$08 sta $04 ldy #$00copybyte: lda ($01), Y ;copy pixel to sta ($03), Y ;back buffer jsr inc0103 ;increment pointers cmp #$00 ;check to see bne copybyte ;if we're at $600 lda $02 ;if so, we've cmp #$06 ;copied the bne copybyte ;entire screen conway: lda #$df ;apply conway rules sta $01 ;reset the pointer sta $03 ;to $#01df/$#07df lda #$01 ;($200 - $21) sta $02 ;($800 - $21) lda #$07 sta $04onecell: lda #$00 ;process one cell ldy #$01 ;upper cell clc adc ($03), Y ldy #$41 ;lower cell clc adc ($03), Ychkleft: tax ;check to see lda $01 ;if we're at the and #$1f ;left edge tay txa cpy #$1f beq rightcellsleftcells: ldy #$00 ;upper-left cell clc adc ($03), Y ldy #$20 ;left cell clc adc ($03), Y ldy #$40 ;lower-left cell clc adc ($03), Ychkright: tax ;check to see lda $01 ;if we're at the and #$1f ;right edge tay txa cpy #$1e beq evaluaterightcells: ldy #$02 ;upper-right cell clc adc ($03), Y ldy #$22 ;right cell clc adc ($03), Y ldy #$42 ;lower-right cell clc adc ($03), Yevaluate: ldx #$01 ;evaluate total ldy #$21 ;for current cell cmp #$03 ;3 = alive beq storex ldx #$00 cmp #$02 ;2 = alive if bne storex ;c = alive lda ($03), Y and #$01 taxstorex: txa ;store to screen sta ($01), Y jsr inc0103 ;move to next cellconwayloop: cmp #$e0 ;if not last cell, bne onecell ;process next cell lda $02 cmp #$05 bne onecell jmp starttick ;run next tick inc0103: lda $01 ;increment $01 cmp #$ff ;and $03 as 16-bit bne onlyinc01 ;pointers inc $02 inc $04onlyinc01: inc $01 lda $01 sta $03 rts The solution uses one cell thick border around square Petri dish as uninhabited dire land. Sample output contains 3 generations of the blinker and 5 of the glider: See Conway's Game of Life/ALGOL 68 APL2 (Dialog) Example in one line APL \ 1130 example (very old APL dialect via simulator) APL1130From: APL \ 1130 Samples The following APL \ 1130 code will need APL385 font installed to display correctly.

See Download APL TT Font ∇LIFE[⎕]∇[0] NG←LIFE CG; W[1] W←CG+(¯1⊖CG)+(1⊖CG)+(¯1⌽CG)+(1⌽CG)[2] W←W+(1⊖1⌽CG)+(¯1⊖1⌽CG)+(1⊖¯1⌽CG)+(¯1⊖¯1⌽CG)[3] NG←(3=W)+(CG∧4=W) ∇ RP←5 5⍴0 0 0 0 0 0 0 1 1 0 0 1 1 0 0 0 0 1 0 0 RP0 0 0 0 00 0 1 1 00 1 1 0 00 0 1 0 00 0 0 0 0 LIFE RP0 0 0 0 00 1 1 1 00 1 0 0 00 1 1 0 00 0 0 0 0 LIFE LIFE RP0 0 1 0 00 1 1 0 01 0 0 1 00 1 1 0 00 0 0 0 0 ..................................................

One interacts with the Game of Life by creating an initial configuration and observing how it evolves.

Although you should test your implementation on more complex examples such as the glider in a larger universe, show the action of the blinker (three adjoining cells in a row all alive), over three generations, in a 3 by 3 grid.

(1,4)=TRUERETURN'' Count the number of neighbours of the point i,j' (Assume i/j +/- 1 will not fall out of world)'FUNCTION count_neighbours(i%,j%) LOCAL count%,l% count%=0 FOR l%=-1 TO 1 IF world! (i%+l%,j%+1) count%=count%+1 ENDIF NEXT l% IF world! (i%+1,j%) count%=count%+1 ENDIF RETURN count%ENDFUNC'' Update the world one step'PROCEDURE update_world LOCAL i%,j% ' compute neighbour counts and store FOR i%=1 TO 30 FOR j%=1 TO 30 ns%(i%,j%)[email protected]_neighbours(i%,j%) NEXT j% NEXT i% ' update the world cells FOR i%=1 TO 30 FOR j%=1 TO 30 IF world!

Thus, while it is somewhat verbose, it fully simulates Conway's Game of Life and is relatively simple to expand to feature different starting shapes.

Define life(pattern) = Prgm Local x,y,nt,count,save,xl,yl,xh,yh Define nt(y,x) = when(pxl Test(y,x), 1, 0) {}→save set Graph("Axes", "Off")→save[1] set Graph("Grid", "Off")→save[2] set Graph("Labels", "Off")→save[3] Fn Off Plot Off Clr Draw If pattern = "blinker" Then 36→yl 40→yh 78→xl 82→xh Pxl On 36,80 Pxl On 38,80 Pxl On 40,80 Else If pattern = "glider" Then 30→yl 40→yh 76→xl 88→xh Pxl On 38,76 Pxl On 36,78 Pxl On 36,80 Pxl On 38,80 Pxl On 40,80 Else If pattern = "r" Then 38-5*2→yl 38+5*2→yh 80-5*2→xl 80+5*2→xh Pxl On 38,78 Pxl On 36,82 Pxl On 36,80 Pxl On 38,80 Pxl On 40,80 End If While get Key() = 0 © Expand upper-left corner to whole cell For y,yl,yh,2 For x,xl,xh,2 If pxl Test(y,x) Then Pxl On y+1,x Pxl On y+1,x+1 Pxl On y, x+1 Else Pxl Off y+1,x Pxl Off y+1,x+1 Pxl Off y, x+1 End If End For End For © Compute next generation For y,yl,yh,2 For x,xl,xh,2 nt(y-1,x-1) + nt(y-1,x) + nt(y-1,x+2) + nt(y,x-1) + nt(y+1,x+2) + nt(y+2,x-1) + nt(y+2,x+1) + nt(y+2,x+2) → count If count = 3 Then Pxl On y,x Else If count ≠ 2 Then Pxl Off y,x End If End For End For End While © Restore changed options set Graph("Axes", save[1]) set Graph("Grid", save[2]) set Graph("Labels", save[3])End Prgm Also see Conway's Game of Life/C Considering that the simplest implementation in C++ would lack any use of the object-oriented paradigm, this code was specifically written to demonstrate the various object-oriented features of C++.

;(0 - ) sta ;(0 - ) lda # sta onecell: lda #[[

randfill: stx $01 ;$200 for indirect ldx #$02 ;addressing stx $02randloop: lda $fe ;generate random and #$01 ;pixels on the sta ($01), Y ;screen jsr inc0103 cmp #$00 bne randloop lda $02 cmp #$06 bne randloop clearmem: lda #$df ;set $07df-$0a20 sta $01 ;to $#00 lda #$07 sta $02clearbyte: lda #$00 sta ($01), Y jsr inc0103 cmp #$20 bne clearbyte lda $02 cmp #$0a bne clearbyte starttick:copyscreen: lda #$00 ;set up source sta $01 ;pointer at sta $03 ;$01/$02 and lda #$02 ;dest pointer sta $02 ;at $03/$04 lda #$08 sta $04 ldy #$00copybyte: lda ($01), Y ;copy pixel to sta ($03), Y ;back buffer jsr inc0103 ;increment pointers cmp #$00 ;check to see bne copybyte ;if we're at $600 lda $02 ;if so, we've cmp #$06 ;copied the bne copybyte ;entire screen conway: lda #$df ;apply conway rules sta $01 ;reset the pointer sta $03 ;to $#01df/$#07df lda #$01 ;($200 - $21) sta $02 ;($800 - $21) lda #$07 sta $04onecell: lda #$00 ;process one cell ldy #$01 ;upper cell clc adc ($03), Y ldy #$41 ;lower cell clc adc ($03), Ychkleft: tax ;check to see lda $01 ;if we're at the and #$1f ;left edge tay txa cpy #$1f beq rightcellsleftcells: ldy #$00 ;upper-left cell clc adc ($03), Y ldy #$20 ;left cell clc adc ($03), Y ldy #$40 ;lower-left cell clc adc ($03), Ychkright: tax ;check to see lda $01 ;if we're at the and #$1f ;right edge tay txa cpy #$1e beq evaluaterightcells: ldy #$02 ;upper-right cell clc adc ($03), Y ldy #$22 ;right cell clc adc ($03), Y ldy #$42 ;lower-right cell clc adc ($03), Yevaluate: ldx #$01 ;evaluate total ldy #$21 ;for current cell cmp #$03 ;3 = alive beq storex ldx #$00 cmp #$02 ;2 = alive if bne storex ;c = alive lda ($03), Y and #$01 taxstorex: txa ;store to screen sta ($01), Y jsr inc0103 ;move to next cellconwayloop: cmp #$e0 ;if not last cell, bne onecell ;process next cell lda $02 cmp #$05 bne onecell jmp starttick ;run next tick inc0103: lda $01 ;increment $01 cmp #$ff ;and $03 as 16-bit bne onlyinc01 ;pointers inc $02 inc $04onlyinc01: inc $01 lda $01 sta $03 rts The solution uses one cell thick border around square Petri dish as uninhabited dire land. Sample output contains 3 generations of the blinker and 5 of the glider: See Conway's Game of Life/ALGOL 68 APL2 (Dialog) Example in one line APL \ 1130 example (very old APL dialect via simulator) APL1130From: APL \ 1130 Samples The following APL \ 1130 code will need APL385 font installed to display correctly. See Download APL TT Font ∇LIFE[⎕]∇[0] NG←LIFE CG; W[1] W←CG+(¯1⊖CG)+(1⊖CG)+(¯1⌽CG)+(1⌽CG)[2] W←W+(1⊖1⌽CG)+(¯1⊖1⌽CG)+(1⊖¯1⌽CG)+(¯1⊖¯1⌽CG)[3] NG←(3=W)+(CG∧4=W) ∇ RP←5 5⍴0 0 0 0 0 0 0 1 1 0 0 1 1 0 0 0 0 1 0 0 RP0 0 0 0 00 0 1 1 00 1 1 0 00 0 1 0 00 0 0 0 0 LIFE RP0 0 0 0 00 1 1 1 00 1 0 0 00 1 1 0 00 0 0 0 0 LIFE LIFE RP0 0 1 0 00 1 1 0 01 0 0 1 00 1 1 0 00 0 0 0 0 .................................................. One interacts with the Game of Life by creating an initial configuration and observing how it evolves. Although you should test your implementation on more complex examples such as the glider in a larger universe, show the action of the blinker (three adjoining cells in a row all alive), over three generations, in a 3 by 3 grid. (1,4)=TRUERETURN'' Count the number of neighbours of the point i,j' (Assume i/j +/- 1 will not fall out of world)'FUNCTION count_neighbours(i%,j%) LOCAL count%,l% count%=0 FOR l%=-1 TO 1 IF world! (i%+l%,j%+1) count%=count%+1 ENDIF NEXT l% IF world! (i%+1,j%) count%=count%+1 ENDIF RETURN count%ENDFUNC'' Update the world one step'PROCEDURE update_world LOCAL i%,j% ' compute neighbour counts and store FOR i%=1 TO 30 FOR j%=1 TO 30 ns%(i%,j%)[email protected]_neighbours(i%,j%) NEXT j% NEXT i% ' update the world cells FOR i%=1 TO 30 FOR j%=1 TO 30 IF world!

||

randfill: stx $01 ;$200 for indirect ldx #$02 ;addressing stx $02randloop: lda $fe ;generate random and #$01 ;pixels on the sta ($01), Y ;screen jsr inc0103 cmp #$00 bne randloop lda $02 cmp #$06 bne randloop clearmem: lda #$df ;set $07df-$0a20 sta $01 ;to $#00 lda #$07 sta $02clearbyte: lda #$00 sta ($01), Y jsr inc0103 cmp #$20 bne clearbyte lda $02 cmp #$0a bne clearbyte starttick:copyscreen: lda #$00 ;set up source sta $01 ;pointer at sta $03 ;$01/$02 and lda #$02 ;dest pointer sta $02 ;at $03/$04 lda #$08 sta $04 ldy #$00copybyte: lda ($01), Y ;copy pixel to sta ($03), Y ;back buffer jsr inc0103 ;increment pointers cmp #$00 ;check to see bne copybyte ;if we're at $600 lda $02 ;if so, we've cmp #$06 ;copied the bne copybyte ;entire screen conway: lda #$df ;apply conway rules sta $01 ;reset the pointer sta $03 ;to $#01df/$#07df lda #$01 ;($200 - $21) sta $02 ;($800 - $21) lda #$07 sta $04onecell: lda #$00 ;process one cell ldy #$01 ;upper cell clc adc ($03), Y ldy #$41 ;lower cell clc adc ($03), Ychkleft: tax ;check to see lda $01 ;if we're at the and #$1f ;left edge tay txa cpy #$1f beq rightcellsleftcells: ldy #$00 ;upper-left cell clc adc ($03), Y ldy #$20 ;left cell clc adc ($03), Y ldy #$40 ;lower-left cell clc adc ($03), Ychkright: tax ;check to see lda $01 ;if we're at the and #$1f ;right edge tay txa cpy #$1e beq evaluaterightcells: ldy #$02 ;upper-right cell clc adc ($03), Y ldy #$22 ;right cell clc adc ($03), Y ldy #$42 ;lower-right cell clc adc ($03), Yevaluate: ldx #$01 ;evaluate total ldy #$21 ;for current cell cmp #$03 ;3 = alive beq storex ldx #$00 cmp #$02 ;2 = alive if bne storex ;c = alive lda ($03), Y and #$01 taxstorex: txa ;store to screen sta ($01), Y jsr inc0103 ;move to next cellconwayloop: cmp #$e0 ;if not last cell, bne onecell ;process next cell lda $02 cmp #$05 bne onecell jmp starttick ;run next tick inc0103: lda $01 ;increment $01 cmp #$ff ;and $03 as 16-bit bne onlyinc01 ;pointers inc $02 inc $04onlyinc01: inc $01 lda $01 sta $03 rts The solution uses one cell thick border around square Petri dish as uninhabited dire land. Sample output contains 3 generations of the blinker and 5 of the glider: See Conway's Game of Life/ALGOL 68 APL2 (Dialog) Example in one line APL \ 1130 example (very old APL dialect via simulator) APL1130From: APL \ 1130 Samples The following APL \ 1130 code will need APL385 font installed to display correctly.

See Download APL TT Font ∇LIFE[⎕]∇[0] NG←LIFE CG; W[1] W←CG+(¯1⊖CG)+(1⊖CG)+(¯1⌽CG)+(1⌽CG)[2] W←W+(1⊖1⌽CG)+(¯1⊖1⌽CG)+(1⊖¯1⌽CG)+(¯1⊖¯1⌽CG)[3] NG←(3=W)+(CG∧4=W) ∇ RP←5 5⍴0 0 0 0 0 0 0 1 1 0 0 1 1 0 0 0 0 1 0 0 RP0 0 0 0 00 0 1 1 00 1 1 0 00 0 1 0 00 0 0 0 0 LIFE RP0 0 0 0 00 1 1 1 00 1 0 0 00 1 1 0 00 0 0 0 0 LIFE LIFE RP0 0 1 0 00 1 1 0 01 0 0 1 00 1 1 0 00 0 0 0 0 ..................................................

One interacts with the Game of Life by creating an initial configuration and observing how it evolves.

Although you should test your implementation on more complex examples such as the glider in a larger universe, show the action of the blinker (three adjoining cells in a row all alive), over three generations, in a 3 by 3 grid.

(1,4)=TRUERETURN'' Count the number of neighbours of the point i,j' (Assume i/j +/- 1 will not fall out of world)'FUNCTION count_neighbours(i%,j%) LOCAL count%,l% count%=0 FOR l%=-1 TO 1 IF world! (i%+l%,j%+1) count%=count%+1 ENDIF NEXT l% IF world! (i%+1,j%) count%=count%+1 ENDIF RETURN count%ENDFUNC'' Update the world one step'PROCEDURE update_world LOCAL i%,j% ' compute neighbour counts and store FOR i%=1 TO 30 FOR j%=1 TO 30 ns%(i%,j%)[email protected]_neighbours(i%,j%) NEXT j% NEXT i% ' update the world cells FOR i%=1 TO 30 FOR j%=1 TO 30 IF world!

Thus, while it is somewhat verbose, it fully simulates Conway's Game of Life and is relatively simple to expand to feature different starting shapes.

Define life(pattern) = Prgm Local x,y,nt,count,save,xl,yl,xh,yh Define nt(y,x) = when(pxl Test(y,x), 1, 0) {}→save set Graph("Axes", "Off")→save[1] set Graph("Grid", "Off")→save[2] set Graph("Labels", "Off")→save[3] Fn Off Plot Off Clr Draw If pattern = "blinker" Then 36→yl 40→yh 78→xl 82→xh Pxl On 36,80 Pxl On 38,80 Pxl On 40,80 Else If pattern = "glider" Then 30→yl 40→yh 76→xl 88→xh Pxl On 38,76 Pxl On 36,78 Pxl On 36,80 Pxl On 38,80 Pxl On 40,80 Else If pattern = "r" Then 38-5*2→yl 38+5*2→yh 80-5*2→xl 80+5*2→xh Pxl On 38,78 Pxl On 36,82 Pxl On 36,80 Pxl On 38,80 Pxl On 40,80 End If While get Key() = 0 © Expand upper-left corner to whole cell For y,yl,yh,2 For x,xl,xh,2 If pxl Test(y,x) Then Pxl On y+1,x Pxl On y+1,x+1 Pxl On y, x+1 Else Pxl Off y+1,x Pxl Off y+1,x+1 Pxl Off y, x+1 End If End For End For © Compute next generation For y,yl,yh,2 For x,xl,xh,2 nt(y-1,x-1) + nt(y-1,x) + nt(y-1,x+2) + nt(y,x-1) + nt(y+1,x+2) + nt(y+2,x-1) + nt(y+2,x+1) + nt(y+2,x+2) → count If count = 3 Then Pxl On y,x Else If count ≠ 2 Then Pxl Off y,x End If End For End For End While © Restore changed options set Graph("Axes", save[1]) set Graph("Grid", save[2]) set Graph("Labels", save[3])End Prgm Also see Conway's Game of Life/C Considering that the simplest implementation in C++ would lack any use of the object-oriented paradigm, this code was specifically written to demonstrate the various object-oriented features of C++.

]] ;process one cell ldy #

randfill: stx $01 ;$200 for indirect ldx #$02 ;addressing stx $02randloop: lda $fe ;generate random and #$01 ;pixels on the sta ($01), Y ;screen jsr inc0103 cmp #$00 bne randloop lda $02 cmp #$06 bne randloop clearmem: lda #$df ;set $07df-$0a20 sta $01 ;to $#00 lda #$07 sta $02clearbyte: lda #$00 sta ($01), Y jsr inc0103 cmp #$20 bne clearbyte lda $02 cmp #$0a bne clearbyte starttick:copyscreen: lda #$00 ;set up source sta $01 ;pointer at sta $03 ;$01/$02 and lda #$02 ;dest pointer sta $02 ;at $03/$04 lda #$08 sta $04 ldy #$00copybyte: lda ($01), Y ;copy pixel to sta ($03), Y ;back buffer jsr inc0103 ;increment pointers cmp #$00 ;check to see bne copybyte ;if we're at $600 lda $02 ;if so, we've cmp #$06 ;copied the bne copybyte ;entire screen conway: lda #$df ;apply conway rules sta $01 ;reset the pointer sta $03 ;to $#01df/$#07df lda #$01 ;($200 - $21) sta $02 ;($800 - $21) lda #$07 sta $04onecell: lda #$00 ;process one cell ldy #$01 ;upper cell clc adc ($03), Y ldy #$41 ;lower cell clc adc ($03), Ychkleft: tax ;check to see lda $01 ;if we're at the and #$1f ;left edge tay txa cpy #$1f beq rightcellsleftcells: ldy #$00 ;upper-left cell clc adc ($03), Y ldy #$20 ;left cell clc adc ($03), Y ldy #$40 ;lower-left cell clc adc ($03), Ychkright: tax ;check to see lda $01 ;if we're at the and #$1f ;right edge tay txa cpy #$1e beq evaluaterightcells: ldy #$02 ;upper-right cell clc adc ($03), Y ldy #$22 ;right cell clc adc ($03), Y ldy #$42 ;lower-right cell clc adc ($03), Yevaluate: ldx #$01 ;evaluate total ldy #$21 ;for current cell cmp #$03 ;3 = alive beq storex ldx #$00 cmp #$02 ;2 = alive if bne storex ;c = alive lda ($03), Y and #$01 taxstorex: txa ;store to screen sta ($01), Y jsr inc0103 ;move to next cellconwayloop: cmp #$e0 ;if not last cell, bne onecell ;process next cell lda $02 cmp #$05 bne onecell jmp starttick ;run next tick inc0103: lda $01 ;increment $01 cmp #$ff ;and $03 as 16-bit bne onlyinc01 ;pointers inc $02 inc $04onlyinc01: inc $01 lda $01 sta $03 rts The solution uses one cell thick border around square Petri dish as uninhabited dire land. Sample output contains 3 generations of the blinker and 5 of the glider: See Conway's Game of Life/ALGOL 68 APL2 (Dialog) Example in one line APL \ 1130 example (very old APL dialect via simulator) APL1130From: APL \ 1130 Samples The following APL \ 1130 code will need APL385 font installed to display correctly. See Download APL TT Font ∇LIFE[⎕]∇[0] NG←LIFE CG; W[1] W←CG+(¯1⊖CG)+(1⊖CG)+(¯1⌽CG)+(1⌽CG)[2] W←W+(1⊖1⌽CG)+(¯1⊖1⌽CG)+(1⊖¯1⌽CG)+(¯1⊖¯1⌽CG)[3] NG←(3=W)+(CG∧4=W) ∇ RP←5 5⍴0 0 0 0 0 0 0 1 1 0 0 1 1 0 0 0 0 1 0 0 RP0 0 0 0 00 0 1 1 00 1 1 0 00 0 1 0 00 0 0 0 0 LIFE RP0 0 0 0 00 1 1 1 00 1 0 0 00 1 1 0 00 0 0 0 0 LIFE LIFE RP0 0 1 0 00 1 1 0 01 0 0 1 00 1 1 0 00 0 0 0 0 .................................................. One interacts with the Game of Life by creating an initial configuration and observing how it evolves. Although you should test your implementation on more complex examples such as the glider in a larger universe, show the action of the blinker (three adjoining cells in a row all alive), over three generations, in a 3 by 3 grid. (1,4)=TRUERETURN'' Count the number of neighbours of the point i,j' (Assume i/j +/- 1 will not fall out of world)'FUNCTION count_neighbours(i%,j%) LOCAL count%,l% count%=0 FOR l%=-1 TO 1 IF world! (i%+l%,j%+1) count%=count%+1 ENDIF NEXT l% IF world! (i%+1,j%) count%=count%+1 ENDIF RETURN count%ENDFUNC'' Update the world one step'PROCEDURE update_world LOCAL i%,j% ' compute neighbour counts and store FOR i%=1 TO 30 FOR j%=1 TO 30 ns%(i%,j%)[email protected]_neighbours(i%,j%) NEXT j% NEXT i% ' update the world cells FOR i%=1 TO 30 FOR j%=1 TO 30 IF world!

||

randfill: stx $01 ;$200 for indirect ldx #$02 ;addressing stx $02randloop: lda $fe ;generate random and #$01 ;pixels on the sta ($01), Y ;screen jsr inc0103 cmp #$00 bne randloop lda $02 cmp #$06 bne randloop clearmem: lda #$df ;set $07df-$0a20 sta $01 ;to $#00 lda #$07 sta $02clearbyte: lda #$00 sta ($01), Y jsr inc0103 cmp #$20 bne clearbyte lda $02 cmp #$0a bne clearbyte starttick:copyscreen: lda #$00 ;set up source sta $01 ;pointer at sta $03 ;$01/$02 and lda #$02 ;dest pointer sta $02 ;at $03/$04 lda #$08 sta $04 ldy #$00copybyte: lda ($01), Y ;copy pixel to sta ($03), Y ;back buffer jsr inc0103 ;increment pointers cmp #$00 ;check to see bne copybyte ;if we're at $600 lda $02 ;if so, we've cmp #$06 ;copied the bne copybyte ;entire screen conway: lda #$df ;apply conway rules sta $01 ;reset the pointer sta $03 ;to $#01df/$#07df lda #$01 ;($200 - $21) sta $02 ;($800 - $21) lda #$07 sta $04onecell: lda #$00 ;process one cell ldy #$01 ;upper cell clc adc ($03), Y ldy #$41 ;lower cell clc adc ($03), Ychkleft: tax ;check to see lda $01 ;if we're at the and #$1f ;left edge tay txa cpy #$1f beq rightcellsleftcells: ldy #$00 ;upper-left cell clc adc ($03), Y ldy #$20 ;left cell clc adc ($03), Y ldy #$40 ;lower-left cell clc adc ($03), Ychkright: tax ;check to see lda $01 ;if we're at the and #$1f ;right edge tay txa cpy #$1e beq evaluaterightcells: ldy #$02 ;upper-right cell clc adc ($03), Y ldy #$22 ;right cell clc adc ($03), Y ldy #$42 ;lower-right cell clc adc ($03), Yevaluate: ldx #$01 ;evaluate total ldy #$21 ;for current cell cmp #$03 ;3 = alive beq storex ldx #$00 cmp #$02 ;2 = alive if bne storex ;c = alive lda ($03), Y and #$01 taxstorex: txa ;store to screen sta ($01), Y jsr inc0103 ;move to next cellconwayloop: cmp #$e0 ;if not last cell, bne onecell ;process next cell lda $02 cmp #$05 bne onecell jmp starttick ;run next tick inc0103: lda $01 ;increment $01 cmp #$ff ;and $03 as 16-bit bne onlyinc01 ;pointers inc $02 inc $04onlyinc01: inc $01 lda $01 sta $03 rts The solution uses one cell thick border around square Petri dish as uninhabited dire land. Sample output contains 3 generations of the blinker and 5 of the glider: See Conway's Game of Life/ALGOL 68 APL2 (Dialog) Example in one line APL \ 1130 example (very old APL dialect via simulator) APL1130From: APL \ 1130 Samples The following APL \ 1130 code will need APL385 font installed to display correctly.

See Download APL TT Font ∇LIFE[⎕]∇[0] NG←LIFE CG; W[1] W←CG+(¯1⊖CG)+(1⊖CG)+(¯1⌽CG)+(1⌽CG)[2] W←W+(1⊖1⌽CG)+(¯1⊖1⌽CG)+(1⊖¯1⌽CG)+(¯1⊖¯1⌽CG)[3] NG←(3=W)+(CG∧4=W) ∇ RP←5 5⍴0 0 0 0 0 0 0 1 1 0 0 1 1 0 0 0 0 1 0 0 RP0 0 0 0 00 0 1 1 00 1 1 0 00 0 1 0 00 0 0 0 0 LIFE RP0 0 0 0 00 1 1 1 00 1 0 0 00 1 1 0 00 0 0 0 0 LIFE LIFE RP0 0 1 0 00 1 1 0 01 0 0 1 00 1 1 0 00 0 0 0 0 ..................................................

One interacts with the Game of Life by creating an initial configuration and observing how it evolves.

Although you should test your implementation on more complex examples such as the glider in a larger universe, show the action of the blinker (three adjoining cells in a row all alive), over three generations, in a 3 by 3 grid.

(1,4)=TRUERETURN'' Count the number of neighbours of the point i,j' (Assume i/j +/- 1 will not fall out of world)'FUNCTION count_neighbours(i%,j%) LOCAL count%,l% count%=0 FOR l%=-1 TO 1 IF world! (i%+l%,j%+1) count%=count%+1 ENDIF NEXT l% IF world! (i%+1,j%) count%=count%+1 ENDIF RETURN count%ENDFUNC'' Update the world one step'PROCEDURE update_world LOCAL i%,j% ' compute neighbour counts and store FOR i%=1 TO 30 FOR j%=1 TO 30 ns%(i%,j%)[email protected]_neighbours(i%,j%) NEXT j% NEXT i% ' update the world cells FOR i%=1 TO 30 FOR j%=1 TO 30 IF world!

Thus, while it is somewhat verbose, it fully simulates Conway's Game of Life and is relatively simple to expand to feature different starting shapes.

Define life(pattern) = Prgm Local x,y,nt,count,save,xl,yl,xh,yh Define nt(y,x) = when(pxl Test(y,x), 1, 0) {}→save set Graph("Axes", "Off")→save[1] set Graph("Grid", "Off")→save[2] set Graph("Labels", "Off")→save[3] Fn Off Plot Off Clr Draw If pattern = "blinker" Then 36→yl 40→yh 78→xl 82→xh Pxl On 36,80 Pxl On 38,80 Pxl On 40,80 Else If pattern = "glider" Then 30→yl 40→yh 76→xl 88→xh Pxl On 38,76 Pxl On 36,78 Pxl On 36,80 Pxl On 38,80 Pxl On 40,80 Else If pattern = "r" Then 38-5*2→yl 38+5*2→yh 80-5*2→xl 80+5*2→xh Pxl On 38,78 Pxl On 36,82 Pxl On 36,80 Pxl On 38,80 Pxl On 40,80 End If While get Key() = 0 © Expand upper-left corner to whole cell For y,yl,yh,2 For x,xl,xh,2 If pxl Test(y,x) Then Pxl On y+1,x Pxl On y+1,x+1 Pxl On y, x+1 Else Pxl Off y+1,x Pxl Off y+1,x+1 Pxl Off y, x+1 End If End For End For © Compute next generation For y,yl,yh,2 For x,xl,xh,2 nt(y-1,x-1) + nt(y-1,x) + nt(y-1,x+2) + nt(y,x-1) + nt(y+1,x+2) + nt(y+2,x-1) + nt(y+2,x+1) + nt(y+2,x+2) → count If count = 3 Then Pxl On y,x Else If count ≠ 2 Then Pxl Off y,x End If End For End For End While © Restore changed options set Graph("Axes", save[1]) set Graph("Grid", save[2]) set Graph("Labels", save[3])End Prgm Also see Conway's Game of Life/C Considering that the simplest implementation in C++ would lack any use of the object-oriented paradigm, this code was specifically written to demonstrate the various object-oriented features of C++.

;upper cell clc adc (), Y ldy # ;lower cell clc adc (), Ychkleft: tax ;check to see lda

randfill: stx $01 ;$200 for indirect ldx #$02 ;addressing stx $02randloop: lda $fe ;generate random and #$01 ;pixels on the sta ($01), Y ;screen jsr inc0103 cmp #$00 bne randloop lda $02 cmp #$06 bne randloop clearmem: lda #$df ;set $07df-$0a20 sta $01 ;to $#00 lda #$07 sta $02clearbyte: lda #$00 sta ($01), Y jsr inc0103 cmp #$20 bne clearbyte lda $02 cmp #$0a bne clearbyte starttick:copyscreen: lda #$00 ;set up source sta $01 ;pointer at sta $03 ;$01/$02 and lda #$02 ;dest pointer sta $02 ;at $03/$04 lda #$08 sta $04 ldy #$00copybyte: lda ($01), Y ;copy pixel to sta ($03), Y ;back buffer jsr inc0103 ;increment pointers cmp #$00 ;check to see bne copybyte ;if we're at $600 lda $02 ;if so, we've cmp #$06 ;copied the bne copybyte ;entire screen conway: lda #$df ;apply conway rules sta $01 ;reset the pointer sta $03 ;to $#01df/$#07df lda #$01 ;($200 - $21) sta $02 ;($800 - $21) lda #$07 sta $04onecell: lda #$00 ;process one cell ldy #$01 ;upper cell clc adc ($03), Y ldy #$41 ;lower cell clc adc ($03), Ychkleft: tax ;check to see lda $01 ;if we're at the and #$1f ;left edge tay txa cpy #$1f beq rightcellsleftcells: ldy #$00 ;upper-left cell clc adc ($03), Y ldy #$20 ;left cell clc adc ($03), Y ldy #$40 ;lower-left cell clc adc ($03), Ychkright: tax ;check to see lda $01 ;if we're at the and #$1f ;right edge tay txa cpy #$1e beq evaluaterightcells: ldy #$02 ;upper-right cell clc adc ($03), Y ldy #$22 ;right cell clc adc ($03), Y ldy #$42 ;lower-right cell clc adc ($03), Yevaluate: ldx #$01 ;evaluate total ldy #$21 ;for current cell cmp #$03 ;3 = alive beq storex ldx #$00 cmp #$02 ;2 = alive if bne storex ;c = alive lda ($03), Y and #$01 taxstorex: txa ;store to screen sta ($01), Y jsr inc0103 ;move to next cellconwayloop: cmp #$e0 ;if not last cell, bne onecell ;process next cell lda $02 cmp #$05 bne onecell jmp starttick ;run next tick inc0103: lda $01 ;increment $01 cmp #$ff ;and $03 as 16-bit bne onlyinc01 ;pointers inc $02 inc $04onlyinc01: inc $01 lda $01 sta $03 rts The solution uses one cell thick border around square Petri dish as uninhabited dire land. Sample output contains 3 generations of the blinker and 5 of the glider: See Conway's Game of Life/ALGOL 68 APL2 (Dialog) Example in one line APL \ 1130 example (very old APL dialect via simulator) APL1130From: APL \ 1130 Samples The following APL \ 1130 code will need APL385 font installed to display correctly. See Download APL TT Font ∇LIFE[⎕]∇[0] NG←LIFE CG; W[1] W←CG+(¯1⊖CG)+(1⊖CG)+(¯1⌽CG)+(1⌽CG)[2] W←W+(1⊖1⌽CG)+(¯1⊖1⌽CG)+(1⊖¯1⌽CG)+(¯1⊖¯1⌽CG)[3] NG←(3=W)+(CG∧4=W) ∇ RP←5 5⍴0 0 0 0 0 0 0 1 1 0 0 1 1 0 0 0 0 1 0 0 RP0 0 0 0 00 0 1 1 00 1 1 0 00 0 1 0 00 0 0 0 0 LIFE RP0 0 0 0 00 1 1 1 00 1 0 0 00 1 1 0 00 0 0 0 0 LIFE LIFE RP0 0 1 0 00 1 1 0 01 0 0 1 00 1 1 0 00 0 0 0 0 .................................................. One interacts with the Game of Life by creating an initial configuration and observing how it evolves. Although you should test your implementation on more complex examples such as the glider in a larger universe, show the action of the blinker (three adjoining cells in a row all alive), over three generations, in a 3 by 3 grid. (1,4)=TRUERETURN'' Count the number of neighbours of the point i,j' (Assume i/j +/- 1 will not fall out of world)'FUNCTION count_neighbours(i%,j%) LOCAL count%,l% count%=0 FOR l%=-1 TO 1 IF world! (i%+l%,j%+1) count%=count%+1 ENDIF NEXT l% IF world! (i%+1,j%) count%=count%+1 ENDIF RETURN count%ENDFUNC'' Update the world one step'PROCEDURE update_world LOCAL i%,j% ' compute neighbour counts and store FOR i%=1 TO 30 FOR j%=1 TO 30 ns%(i%,j%)[email protected]_neighbours(i%,j%) NEXT j% NEXT i% ' update the world cells FOR i%=1 TO 30 FOR j%=1 TO 30 IF world!

||

randfill: stx $01 ;$200 for indirect ldx #$02 ;addressing stx $02randloop: lda $fe ;generate random and #$01 ;pixels on the sta ($01), Y ;screen jsr inc0103 cmp #$00 bne randloop lda $02 cmp #$06 bne randloop clearmem: lda #$df ;set $07df-$0a20 sta $01 ;to $#00 lda #$07 sta $02clearbyte: lda #$00 sta ($01), Y jsr inc0103 cmp #$20 bne clearbyte lda $02 cmp #$0a bne clearbyte starttick:copyscreen: lda #$00 ;set up source sta $01 ;pointer at sta $03 ;$01/$02 and lda #$02 ;dest pointer sta $02 ;at $03/$04 lda #$08 sta $04 ldy #$00copybyte: lda ($01), Y ;copy pixel to sta ($03), Y ;back buffer jsr inc0103 ;increment pointers cmp #$00 ;check to see bne copybyte ;if we're at $600 lda $02 ;if so, we've cmp #$06 ;copied the bne copybyte ;entire screen conway: lda #$df ;apply conway rules sta $01 ;reset the pointer sta $03 ;to $#01df/$#07df lda #$01 ;($200 - $21) sta $02 ;($800 - $21) lda #$07 sta $04onecell: lda #$00 ;process one cell ldy #$01 ;upper cell clc adc ($03), Y ldy #$41 ;lower cell clc adc ($03), Ychkleft: tax ;check to see lda $01 ;if we're at the and #$1f ;left edge tay txa cpy #$1f beq rightcellsleftcells: ldy #$00 ;upper-left cell clc adc ($03), Y ldy #$20 ;left cell clc adc ($03), Y ldy #$40 ;lower-left cell clc adc ($03), Ychkright: tax ;check to see lda $01 ;if we're at the and #$1f ;right edge tay txa cpy #$1e beq evaluaterightcells: ldy #$02 ;upper-right cell clc adc ($03), Y ldy #$22 ;right cell clc adc ($03), Y ldy #$42 ;lower-right cell clc adc ($03), Yevaluate: ldx #$01 ;evaluate total ldy #$21 ;for current cell cmp #$03 ;3 = alive beq storex ldx #$00 cmp #$02 ;2 = alive if bne storex ;c = alive lda ($03), Y and #$01 taxstorex: txa ;store to screen sta ($01), Y jsr inc0103 ;move to next cellconwayloop: cmp #$e0 ;if not last cell, bne onecell ;process next cell lda $02 cmp #$05 bne onecell jmp starttick ;run next tick inc0103: lda $01 ;increment $01 cmp #$ff ;and $03 as 16-bit bne onlyinc01 ;pointers inc $02 inc $04onlyinc01: inc $01 lda $01 sta $03 rts The solution uses one cell thick border around square Petri dish as uninhabited dire land. Sample output contains 3 generations of the blinker and 5 of the glider: See Conway's Game of Life/ALGOL 68 APL2 (Dialog) Example in one line APL \ 1130 example (very old APL dialect via simulator) APL1130From: APL \ 1130 Samples The following APL \ 1130 code will need APL385 font installed to display correctly.

See Download APL TT Font ∇LIFE[⎕]∇[0] NG←LIFE CG; W[1] W←CG+(¯1⊖CG)+(1⊖CG)+(¯1⌽CG)+(1⌽CG)[2] W←W+(1⊖1⌽CG)+(¯1⊖1⌽CG)+(1⊖¯1⌽CG)+(¯1⊖¯1⌽CG)[3] NG←(3=W)+(CG∧4=W) ∇ RP←5 5⍴0 0 0 0 0 0 0 1 1 0 0 1 1 0 0 0 0 1 0 0 RP0 0 0 0 00 0 1 1 00 1 1 0 00 0 1 0 00 0 0 0 0 LIFE RP0 0 0 0 00 1 1 1 00 1 0 0 00 1 1 0 00 0 0 0 0 LIFE LIFE RP0 0 1 0 00 1 1 0 01 0 0 1 00 1 1 0 00 0 0 0 0 ..................................................

One interacts with the Game of Life by creating an initial configuration and observing how it evolves.

Although you should test your implementation on more complex examples such as the glider in a larger universe, show the action of the blinker (three adjoining cells in a row all alive), over three generations, in a 3 by 3 grid.

(1,4)=TRUERETURN'' Count the number of neighbours of the point i,j' (Assume i/j +/- 1 will not fall out of world)'FUNCTION count_neighbours(i%,j%) LOCAL count%,l% count%=0 FOR l%=-1 TO 1 IF world! (i%+l%,j%+1) count%=count%+1 ENDIF NEXT l% IF world! (i%+1,j%) count%=count%+1 ENDIF RETURN count%ENDFUNC'' Update the world one step'PROCEDURE update_world LOCAL i%,j% ' compute neighbour counts and store FOR i%=1 TO 30 FOR j%=1 TO 30 ns%(i%,j%)[email protected]_neighbours(i%,j%) NEXT j% NEXT i% ' update the world cells FOR i%=1 TO 30 FOR j%=1 TO 30 IF world!

Thus, while it is somewhat verbose, it fully simulates Conway's Game of Life and is relatively simple to expand to feature different starting shapes.

Define life(pattern) = Prgm Local x,y,nt,count,save,xl,yl,xh,yh Define nt(y,x) = when(pxl Test(y,x), 1, 0) {}→save set Graph("Axes", "Off")→save[1] set Graph("Grid", "Off")→save[2] set Graph("Labels", "Off")→save[3] Fn Off Plot Off Clr Draw If pattern = "blinker" Then 36→yl 40→yh 78→xl 82→xh Pxl On 36,80 Pxl On 38,80 Pxl On 40,80 Else If pattern = "glider" Then 30→yl 40→yh 76→xl 88→xh Pxl On 38,76 Pxl On 36,78 Pxl On 36,80 Pxl On 38,80 Pxl On 40,80 Else If pattern = "r" Then 38-5*2→yl 38+5*2→yh 80-5*2→xl 80+5*2→xh Pxl On 38,78 Pxl On 36,82 Pxl On 36,80 Pxl On 38,80 Pxl On 40,80 End If While get Key() = 0 © Expand upper-left corner to whole cell For y,yl,yh,2 For x,xl,xh,2 If pxl Test(y,x) Then Pxl On y+1,x Pxl On y+1,x+1 Pxl On y, x+1 Else Pxl Off y+1,x Pxl Off y+1,x+1 Pxl Off y, x+1 End If End For End For © Compute next generation For y,yl,yh,2 For x,xl,xh,2 nt(y-1,x-1) + nt(y-1,x) + nt(y-1,x+2) + nt(y,x-1) + nt(y+1,x+2) + nt(y+2,x-1) + nt(y+2,x+1) + nt(y+2,x+2) → count If count = 3 Then Pxl On y,x Else If count ≠ 2 Then Pxl Off y,x End If End For End For End While © Restore changed options set Graph("Axes", save[1]) set Graph("Grid", save[2]) set Graph("Labels", save[3])End Prgm Also see Conway's Game of Life/C Considering that the simplest implementation in C++ would lack any use of the object-oriented paradigm, this code was specifically written to demonstrate the various object-oriented features of C++.

;if we're at the and #

randfill: stx $01 ;$200 for indirect ldx #$02 ;addressing stx $02randloop: lda $fe ;generate random and #$01 ;pixels on the sta ($01), Y ;screen jsr inc0103 cmp #$00 bne randloop lda $02 cmp #$06 bne randloop clearmem: lda #$df ;set $07df-$0a20 sta $01 ;to $#00 lda #$07 sta $02clearbyte: lda #$00 sta ($01), Y jsr inc0103 cmp #$20 bne clearbyte lda $02 cmp #$0a bne clearbyte starttick:copyscreen: lda #$00 ;set up source sta $01 ;pointer at sta $03 ;$01/$02 and lda #$02 ;dest pointer sta $02 ;at $03/$04 lda #$08 sta $04 ldy #$00copybyte: lda ($01), Y ;copy pixel to sta ($03), Y ;back buffer jsr inc0103 ;increment pointers cmp #$00 ;check to see bne copybyte ;if we're at $600 lda $02 ;if so, we've cmp #$06 ;copied the bne copybyte ;entire screen conway: lda #$df ;apply conway rules sta $01 ;reset the pointer sta $03 ;to $#01df/$#07df lda #$01 ;($200 - $21) sta $02 ;($800 - $21) lda #$07 sta $04onecell: lda #$00 ;process one cell ldy #$01 ;upper cell clc adc ($03), Y ldy #$41 ;lower cell clc adc ($03), Ychkleft: tax ;check to see lda $01 ;if we're at the and #$1f ;left edge tay txa cpy #$1f beq rightcellsleftcells: ldy #$00 ;upper-left cell clc adc ($03), Y ldy #$20 ;left cell clc adc ($03), Y ldy #$40 ;lower-left cell clc adc ($03), Ychkright: tax ;check to see lda $01 ;if we're at the and #$1f ;right edge tay txa cpy #$1e beq evaluaterightcells: ldy #$02 ;upper-right cell clc adc ($03), Y ldy #$22 ;right cell clc adc ($03), Y ldy #$42 ;lower-right cell clc adc ($03), Yevaluate: ldx #$01 ;evaluate total ldy #$21 ;for current cell cmp #$03 ;3 = alive beq storex ldx #$00 cmp #$02 ;2 = alive if bne storex ;c = alive lda ($03), Y and #$01 taxstorex: txa ;store to screen sta ($01), Y jsr inc0103 ;move to next cellconwayloop: cmp #$e0 ;if not last cell, bne onecell ;process next cell lda $02 cmp #$05 bne onecell jmp starttick ;run next tick inc0103: lda $01 ;increment $01 cmp #$ff ;and $03 as 16-bit bne onlyinc01 ;pointers inc $02 inc $04onlyinc01: inc $01 lda $01 sta $03 rts The solution uses one cell thick border around square Petri dish as uninhabited dire land. Sample output contains 3 generations of the blinker and 5 of the glider: See Conway's Game of Life/ALGOL 68 APL2 (Dialog) Example in one line APL \ 1130 example (very old APL dialect via simulator) APL1130From: APL \ 1130 Samples The following APL \ 1130 code will need APL385 font installed to display correctly. See Download APL TT Font ∇LIFE[⎕]∇[0] NG←LIFE CG; W[1] W←CG+(¯1⊖CG)+(1⊖CG)+(¯1⌽CG)+(1⌽CG)[2] W←W+(1⊖1⌽CG)+(¯1⊖1⌽CG)+(1⊖¯1⌽CG)+(¯1⊖¯1⌽CG)[3] NG←(3=W)+(CG∧4=W) ∇ RP←5 5⍴0 0 0 0 0 0 0 1 1 0 0 1 1 0 0 0 0 1 0 0 RP0 0 0 0 00 0 1 1 00 1 1 0 00 0 1 0 00 0 0 0 0 LIFE RP0 0 0 0 00 1 1 1 00 1 0 0 00 1 1 0 00 0 0 0 0 LIFE LIFE RP0 0 1 0 00 1 1 0 01 0 0 1 00 1 1 0 00 0 0 0 0 .................................................. One interacts with the Game of Life by creating an initial configuration and observing how it evolves. Although you should test your implementation on more complex examples such as the glider in a larger universe, show the action of the blinker (three adjoining cells in a row all alive), over three generations, in a 3 by 3 grid. (1,4)=TRUERETURN'' Count the number of neighbours of the point i,j' (Assume i/j +/- 1 will not fall out of world)'FUNCTION count_neighbours(i%,j%) LOCAL count%,l% count%=0 FOR l%=-1 TO 1 IF world! (i%+l%,j%+1) count%=count%+1 ENDIF NEXT l% IF world! (i%+1,j%) count%=count%+1 ENDIF RETURN count%ENDFUNC'' Update the world one step'PROCEDURE update_world LOCAL i%,j% ' compute neighbour counts and store FOR i%=1 TO 30 FOR j%=1 TO 30 ns%(i%,j%)[email protected]_neighbours(i%,j%) NEXT j% NEXT i% ' update the world cells FOR i%=1 TO 30 FOR j%=1 TO 30 IF world!

||

randfill: stx $01 ;$200 for indirect ldx #$02 ;addressing stx $02randloop: lda $fe ;generate random and #$01 ;pixels on the sta ($01), Y ;screen jsr inc0103 cmp #$00 bne randloop lda $02 cmp #$06 bne randloop clearmem: lda #$df ;set $07df-$0a20 sta $01 ;to $#00 lda #$07 sta $02clearbyte: lda #$00 sta ($01), Y jsr inc0103 cmp #$20 bne clearbyte lda $02 cmp #$0a bne clearbyte starttick:copyscreen: lda #$00 ;set up source sta $01 ;pointer at sta $03 ;$01/$02 and lda #$02 ;dest pointer sta $02 ;at $03/$04 lda #$08 sta $04 ldy #$00copybyte: lda ($01), Y ;copy pixel to sta ($03), Y ;back buffer jsr inc0103 ;increment pointers cmp #$00 ;check to see bne copybyte ;if we're at $600 lda $02 ;if so, we've cmp #$06 ;copied the bne copybyte ;entire screen conway: lda #$df ;apply conway rules sta $01 ;reset the pointer sta $03 ;to $#01df/$#07df lda #$01 ;($200 - $21) sta $02 ;($800 - $21) lda #$07 sta $04onecell: lda #$00 ;process one cell ldy #$01 ;upper cell clc adc ($03), Y ldy #$41 ;lower cell clc adc ($03), Ychkleft: tax ;check to see lda $01 ;if we're at the and #$1f ;left edge tay txa cpy #$1f beq rightcellsleftcells: ldy #$00 ;upper-left cell clc adc ($03), Y ldy #$20 ;left cell clc adc ($03), Y ldy #$40 ;lower-left cell clc adc ($03), Ychkright: tax ;check to see lda $01 ;if we're at the and #$1f ;right edge tay txa cpy #$1e beq evaluaterightcells: ldy #$02 ;upper-right cell clc adc ($03), Y ldy #$22 ;right cell clc adc ($03), Y ldy #$42 ;lower-right cell clc adc ($03), Yevaluate: ldx #$01 ;evaluate total ldy #$21 ;for current cell cmp #$03 ;3 = alive beq storex ldx #$00 cmp #$02 ;2 = alive if bne storex ;c = alive lda ($03), Y and #$01 taxstorex: txa ;store to screen sta ($01), Y jsr inc0103 ;move to next cellconwayloop: cmp #$e0 ;if not last cell, bne onecell ;process next cell lda $02 cmp #$05 bne onecell jmp starttick ;run next tick inc0103: lda $01 ;increment $01 cmp #$ff ;and $03 as 16-bit bne onlyinc01 ;pointers inc $02 inc $04onlyinc01: inc $01 lda $01 sta $03 rts The solution uses one cell thick border around square Petri dish as uninhabited dire land. Sample output contains 3 generations of the blinker and 5 of the glider: See Conway's Game of Life/ALGOL 68 APL2 (Dialog) Example in one line APL \ 1130 example (very old APL dialect via simulator) APL1130From: APL \ 1130 Samples The following APL \ 1130 code will need APL385 font installed to display correctly.

See Download APL TT Font ∇LIFE[⎕]∇[0] NG←LIFE CG; W[1] W←CG+(¯1⊖CG)+(1⊖CG)+(¯1⌽CG)+(1⌽CG)[2] W←W+(1⊖1⌽CG)+(¯1⊖1⌽CG)+(1⊖¯1⌽CG)+(¯1⊖¯1⌽CG)[3] NG←(3=W)+(CG∧4=W) ∇ RP←5 5⍴0 0 0 0 0 0 0 1 1 0 0 1 1 0 0 0 0 1 0 0 RP0 0 0 0 00 0 1 1 00 1 1 0 00 0 1 0 00 0 0 0 0 LIFE RP0 0 0 0 00 1 1 1 00 1 0 0 00 1 1 0 00 0 0 0 0 LIFE LIFE RP0 0 1 0 00 1 1 0 01 0 0 1 00 1 1 0 00 0 0 0 0 ..................................................

One interacts with the Game of Life by creating an initial configuration and observing how it evolves.

Although you should test your implementation on more complex examples such as the glider in a larger universe, show the action of the blinker (three adjoining cells in a row all alive), over three generations, in a 3 by 3 grid.

(1,4)=TRUERETURN'' Count the number of neighbours of the point i,j' (Assume i/j +/- 1 will not fall out of world)'FUNCTION count_neighbours(i%,j%) LOCAL count%,l% count%=0 FOR l%=-1 TO 1 IF world! (i%+l%,j%+1) count%=count%+1 ENDIF NEXT l% IF world! (i%+1,j%) count%=count%+1 ENDIF RETURN count%ENDFUNC'' Update the world one step'PROCEDURE update_world LOCAL i%,j% ' compute neighbour counts and store FOR i%=1 TO 30 FOR j%=1 TO 30 ns%(i%,j%)[email protected]_neighbours(i%,j%) NEXT j% NEXT i% ' update the world cells FOR i%=1 TO 30 FOR j%=1 TO 30 IF world!

Thus, while it is somewhat verbose, it fully simulates Conway's Game of Life and is relatively simple to expand to feature different starting shapes.

Define life(pattern) = Prgm Local x,y,nt,count,save,xl,yl,xh,yh Define nt(y,x) = when(pxl Test(y,x), 1, 0) {}→save set Graph("Axes", "Off")→save[1] set Graph("Grid", "Off")→save[2] set Graph("Labels", "Off")→save[3] Fn Off Plot Off Clr Draw If pattern = "blinker" Then 36→yl 40→yh 78→xl 82→xh Pxl On 36,80 Pxl On 38,80 Pxl On 40,80 Else If pattern = "glider" Then 30→yl 40→yh 76→xl 88→xh Pxl On 38,76 Pxl On 36,78 Pxl On 36,80 Pxl On 38,80 Pxl On 40,80 Else If pattern = "r" Then 38-5*2→yl 38+5*2→yh 80-5*2→xl 80+5*2→xh Pxl On 38,78 Pxl On 36,82 Pxl On 36,80 Pxl On 38,80 Pxl On 40,80 End If While get Key() = 0 © Expand upper-left corner to whole cell For y,yl,yh,2 For x,xl,xh,2 If pxl Test(y,x) Then Pxl On y+1,x Pxl On y+1,x+1 Pxl On y, x+1 Else Pxl Off y+1,x Pxl Off y+1,x+1 Pxl Off y, x+1 End If End For End For © Compute next generation For y,yl,yh,2 For x,xl,xh,2 nt(y-1,x-1) + nt(y-1,x) + nt(y-1,x+2) + nt(y,x-1) + nt(y+1,x+2) + nt(y+2,x-1) + nt(y+2,x+1) + nt(y+2,x+2) → count If count = 3 Then Pxl On y,x Else If count ≠ 2 Then Pxl Off y,x End If End For End For End While © Restore changed options set Graph("Axes", save[1]) set Graph("Grid", save[2]) set Graph("Labels", save[3])End Prgm Also see Conway's Game of Life/C Considering that the simplest implementation in C++ would lack any use of the object-oriented paradigm, this code was specifically written to demonstrate the various object-oriented features of C++.

f ;left edge tay txa cpy #

randfill: stx $01 ;$200 for indirect ldx #$02 ;addressing stx $02randloop: lda $fe ;generate random and #$01 ;pixels on the sta ($01), Y ;screen jsr inc0103 cmp #$00 bne randloop lda $02 cmp #$06 bne randloop clearmem: lda #$df ;set $07df-$0a20 sta $01 ;to $#00 lda #$07 sta $02clearbyte: lda #$00 sta ($01), Y jsr inc0103 cmp #$20 bne clearbyte lda $02 cmp #$0a bne clearbyte starttick:copyscreen: lda #$00 ;set up source sta $01 ;pointer at sta $03 ;$01/$02 and lda #$02 ;dest pointer sta $02 ;at $03/$04 lda #$08 sta $04 ldy #$00copybyte: lda ($01), Y ;copy pixel to sta ($03), Y ;back buffer jsr inc0103 ;increment pointers cmp #$00 ;check to see bne copybyte ;if we're at $600 lda $02 ;if so, we've cmp #$06 ;copied the bne copybyte ;entire screen conway: lda #$df ;apply conway rules sta $01 ;reset the pointer sta $03 ;to $#01df/$#07df lda #$01 ;($200 - $21) sta $02 ;($800 - $21) lda #$07 sta $04onecell: lda #$00 ;process one cell ldy #$01 ;upper cell clc adc ($03), Y ldy #$41 ;lower cell clc adc ($03), Ychkleft: tax ;check to see lda $01 ;if we're at the and #$1f ;left edge tay txa cpy #$1f beq rightcellsleftcells: ldy #$00 ;upper-left cell clc adc ($03), Y ldy #$20 ;left cell clc adc ($03), Y ldy #$40 ;lower-left cell clc adc ($03), Ychkright: tax ;check to see lda $01 ;if we're at the and #$1f ;right edge tay txa cpy #$1e beq evaluaterightcells: ldy #$02 ;upper-right cell clc adc ($03), Y ldy #$22 ;right cell clc adc ($03), Y ldy #$42 ;lower-right cell clc adc ($03), Yevaluate: ldx #$01 ;evaluate total ldy #$21 ;for current cell cmp #$03 ;3 = alive beq storex ldx #$00 cmp #$02 ;2 = alive if bne storex ;c = alive lda ($03), Y and #$01 taxstorex: txa ;store to screen sta ($01), Y jsr inc0103 ;move to next cellconwayloop: cmp #$e0 ;if not last cell, bne onecell ;process next cell lda $02 cmp #$05 bne onecell jmp starttick ;run next tick inc0103: lda $01 ;increment $01 cmp #$ff ;and $03 as 16-bit bne onlyinc01 ;pointers inc $02 inc $04onlyinc01: inc $01 lda $01 sta $03 rts The solution uses one cell thick border around square Petri dish as uninhabited dire land. Sample output contains 3 generations of the blinker and 5 of the glider: See Conway's Game of Life/ALGOL 68 APL2 (Dialog) Example in one line APL \ 1130 example (very old APL dialect via simulator) APL1130From: APL \ 1130 Samples The following APL \ 1130 code will need APL385 font installed to display correctly. See Download APL TT Font ∇LIFE[⎕]∇[0] NG←LIFE CG; W[1] W←CG+(¯1⊖CG)+(1⊖CG)+(¯1⌽CG)+(1⌽CG)[2] W←W+(1⊖1⌽CG)+(¯1⊖1⌽CG)+(1⊖¯1⌽CG)+(¯1⊖¯1⌽CG)[3] NG←(3=W)+(CG∧4=W) ∇ RP←5 5⍴0 0 0 0 0 0 0 1 1 0 0 1 1 0 0 0 0 1 0 0 RP0 0 0 0 00 0 1 1 00 1 1 0 00 0 1 0 00 0 0 0 0 LIFE RP0 0 0 0 00 1 1 1 00 1 0 0 00 1 1 0 00 0 0 0 0 LIFE LIFE RP0 0 1 0 00 1 1 0 01 0 0 1 00 1 1 0 00 0 0 0 0 .................................................. One interacts with the Game of Life by creating an initial configuration and observing how it evolves. Although you should test your implementation on more complex examples such as the glider in a larger universe, show the action of the blinker (three adjoining cells in a row all alive), over three generations, in a 3 by 3 grid. (1,4)=TRUERETURN'' Count the number of neighbours of the point i,j' (Assume i/j +/- 1 will not fall out of world)'FUNCTION count_neighbours(i%,j%) LOCAL count%,l% count%=0 FOR l%=-1 TO 1 IF world! (i%+l%,j%+1) count%=count%+1 ENDIF NEXT l% IF world! (i%+1,j%) count%=count%+1 ENDIF RETURN count%ENDFUNC'' Update the world one step'PROCEDURE update_world LOCAL i%,j% ' compute neighbour counts and store FOR i%=1 TO 30 FOR j%=1 TO 30 ns%(i%,j%)[email protected]_neighbours(i%,j%) NEXT j% NEXT i% ' update the world cells FOR i%=1 TO 30 FOR j%=1 TO 30 IF world!

||

randfill: stx $01 ;$200 for indirect ldx #$02 ;addressing stx $02randloop: lda $fe ;generate random and #$01 ;pixels on the sta ($01), Y ;screen jsr inc0103 cmp #$00 bne randloop lda $02 cmp #$06 bne randloop clearmem: lda #$df ;set $07df-$0a20 sta $01 ;to $#00 lda #$07 sta $02clearbyte: lda #$00 sta ($01), Y jsr inc0103 cmp #$20 bne clearbyte lda $02 cmp #$0a bne clearbyte starttick:copyscreen: lda #$00 ;set up source sta $01 ;pointer at sta $03 ;$01/$02 and lda #$02 ;dest pointer sta $02 ;at $03/$04 lda #$08 sta $04 ldy #$00copybyte: lda ($01), Y ;copy pixel to sta ($03), Y ;back buffer jsr inc0103 ;increment pointers cmp #$00 ;check to see bne copybyte ;if we're at $600 lda $02 ;if so, we've cmp #$06 ;copied the bne copybyte ;entire screen conway: lda #$df ;apply conway rules sta $01 ;reset the pointer sta $03 ;to $#01df/$#07df lda #$01 ;($200 - $21) sta $02 ;($800 - $21) lda #$07 sta $04onecell: lda #$00 ;process one cell ldy #$01 ;upper cell clc adc ($03), Y ldy #$41 ;lower cell clc adc ($03), Ychkleft: tax ;check to see lda $01 ;if we're at the and #$1f ;left edge tay txa cpy #$1f beq rightcellsleftcells: ldy #$00 ;upper-left cell clc adc ($03), Y ldy #$20 ;left cell clc adc ($03), Y ldy #$40 ;lower-left cell clc adc ($03), Ychkright: tax ;check to see lda $01 ;if we're at the and #$1f ;right edge tay txa cpy #$1e beq evaluaterightcells: ldy #$02 ;upper-right cell clc adc ($03), Y ldy #$22 ;right cell clc adc ($03), Y ldy #$42 ;lower-right cell clc adc ($03), Yevaluate: ldx #$01 ;evaluate total ldy #$21 ;for current cell cmp #$03 ;3 = alive beq storex ldx #$00 cmp #$02 ;2 = alive if bne storex ;c = alive lda ($03), Y and #$01 taxstorex: txa ;store to screen sta ($01), Y jsr inc0103 ;move to next cellconwayloop: cmp #$e0 ;if not last cell, bne onecell ;process next cell lda $02 cmp #$05 bne onecell jmp starttick ;run next tick inc0103: lda $01 ;increment $01 cmp #$ff ;and $03 as 16-bit bne onlyinc01 ;pointers inc $02 inc $04onlyinc01: inc $01 lda $01 sta $03 rts The solution uses one cell thick border around square Petri dish as uninhabited dire land. Sample output contains 3 generations of the blinker and 5 of the glider: See Conway's Game of Life/ALGOL 68 APL2 (Dialog) Example in one line APL \ 1130 example (very old APL dialect via simulator) APL1130From: APL \ 1130 Samples The following APL \ 1130 code will need APL385 font installed to display correctly.

See Download APL TT Font ∇LIFE[⎕]∇[0] NG←LIFE CG; W[1] W←CG+(¯1⊖CG)+(1⊖CG)+(¯1⌽CG)+(1⌽CG)[2] W←W+(1⊖1⌽CG)+(¯1⊖1⌽CG)+(1⊖¯1⌽CG)+(¯1⊖¯1⌽CG)[3] NG←(3=W)+(CG∧4=W) ∇ RP←5 5⍴0 0 0 0 0 0 0 1 1 0 0 1 1 0 0 0 0 1 0 0 RP0 0 0 0 00 0 1 1 00 1 1 0 00 0 1 0 00 0 0 0 0 LIFE RP0 0 0 0 00 1 1 1 00 1 0 0 00 1 1 0 00 0 0 0 0 LIFE LIFE RP0 0 1 0 00 1 1 0 01 0 0 1 00 1 1 0 00 0 0 0 0 ..................................................

One interacts with the Game of Life by creating an initial configuration and observing how it evolves.

Although you should test your implementation on more complex examples such as the glider in a larger universe, show the action of the blinker (three adjoining cells in a row all alive), over three generations, in a 3 by 3 grid.

(1,4)=TRUERETURN'' Count the number of neighbours of the point i,j' (Assume i/j +/- 1 will not fall out of world)'FUNCTION count_neighbours(i%,j%) LOCAL count%,l% count%=0 FOR l%=-1 TO 1 IF world! (i%+l%,j%+1) count%=count%+1 ENDIF NEXT l% IF world! (i%+1,j%) count%=count%+1 ENDIF RETURN count%ENDFUNC'' Update the world one step'PROCEDURE update_world LOCAL i%,j% ' compute neighbour counts and store FOR i%=1 TO 30 FOR j%=1 TO 30 ns%(i%,j%)[email protected]_neighbours(i%,j%) NEXT j% NEXT i% ' update the world cells FOR i%=1 TO 30 FOR j%=1 TO 30 IF world!

Thus, while it is somewhat verbose, it fully simulates Conway's Game of Life and is relatively simple to expand to feature different starting shapes.

Define life(pattern) = Prgm Local x,y,nt,count,save,xl,yl,xh,yh Define nt(y,x) = when(pxl Test(y,x), 1, 0) {}→save set Graph("Axes", "Off")→save[1] set Graph("Grid", "Off")→save[2] set Graph("Labels", "Off")→save[3] Fn Off Plot Off Clr Draw If pattern = "blinker" Then 36→yl 40→yh 78→xl 82→xh Pxl On 36,80 Pxl On 38,80 Pxl On 40,80 Else If pattern = "glider" Then 30→yl 40→yh 76→xl 88→xh Pxl On 38,76 Pxl On 36,78 Pxl On 36,80 Pxl On 38,80 Pxl On 40,80 Else If pattern = "r" Then 38-5*2→yl 38+5*2→yh 80-5*2→xl 80+5*2→xh Pxl On 38,78 Pxl On 36,82 Pxl On 36,80 Pxl On 38,80 Pxl On 40,80 End If While get Key() = 0 © Expand upper-left corner to whole cell For y,yl,yh,2 For x,xl,xh,2 If pxl Test(y,x) Then Pxl On y+1,x Pxl On y+1,x+1 Pxl On y, x+1 Else Pxl Off y+1,x Pxl Off y+1,x+1 Pxl Off y, x+1 End If End For End For © Compute next generation For y,yl,yh,2 For x,xl,xh,2 nt(y-1,x-1) + nt(y-1,x) + nt(y-1,x+2) + nt(y,x-1) + nt(y+1,x+2) + nt(y+2,x-1) + nt(y+2,x+1) + nt(y+2,x+2) → count If count = 3 Then Pxl On y,x Else If count ≠ 2 Then Pxl Off y,x End If End For End For End While © Restore changed options set Graph("Axes", save[1]) set Graph("Grid", save[2]) set Graph("Labels", save[3])End Prgm Also see Conway's Game of Life/C Considering that the simplest implementation in C++ would lack any use of the object-oriented paradigm, this code was specifically written to demonstrate the various object-oriented features of C++.

f beq rightcellsleftcells: ldy #[[

randfill: stx $01 ;$200 for indirect ldx #$02 ;addressing stx $02randloop: lda $fe ;generate random and #$01 ;pixels on the sta ($01), Y ;screen jsr inc0103 cmp #$00 bne randloop lda $02 cmp #$06 bne randloop clearmem: lda #$df ;set $07df-$0a20 sta $01 ;to $#00 lda #$07 sta $02clearbyte: lda #$00 sta ($01), Y jsr inc0103 cmp #$20 bne clearbyte lda $02 cmp #$0a bne clearbyte starttick:copyscreen: lda #$00 ;set up source sta $01 ;pointer at sta $03 ;$01/$02 and lda #$02 ;dest pointer sta $02 ;at $03/$04 lda #$08 sta $04 ldy #$00copybyte: lda ($01), Y ;copy pixel to sta ($03), Y ;back buffer jsr inc0103 ;increment pointers cmp #$00 ;check to see bne copybyte ;if we're at $600 lda $02 ;if so, we've cmp #$06 ;copied the bne copybyte ;entire screen conway: lda #$df ;apply conway rules sta $01 ;reset the pointer sta $03 ;to $#01df/$#07df lda #$01 ;($200 - $21) sta $02 ;($800 - $21) lda #$07 sta $04onecell: lda #$00 ;process one cell ldy #$01 ;upper cell clc adc ($03), Y ldy #$41 ;lower cell clc adc ($03), Ychkleft: tax ;check to see lda $01 ;if we're at the and #$1f ;left edge tay txa cpy #$1f beq rightcellsleftcells: ldy #$00 ;upper-left cell clc adc ($03), Y ldy #$20 ;left cell clc adc ($03), Y ldy #$40 ;lower-left cell clc adc ($03), Ychkright: tax ;check to see lda $01 ;if we're at the and #$1f ;right edge tay txa cpy #$1e beq evaluaterightcells: ldy #$02 ;upper-right cell clc adc ($03), Y ldy #$22 ;right cell clc adc ($03), Y ldy #$42 ;lower-right cell clc adc ($03), Yevaluate: ldx #$01 ;evaluate total ldy #$21 ;for current cell cmp #$03 ;3 = alive beq storex ldx #$00 cmp #$02 ;2 = alive if bne storex ;c = alive lda ($03), Y and #$01 taxstorex: txa ;store to screen sta ($01), Y jsr inc0103 ;move to next cellconwayloop: cmp #$e0 ;if not last cell, bne onecell ;process next cell lda $02 cmp #$05 bne onecell jmp starttick ;run next tick inc0103: lda $01 ;increment $01 cmp #$ff ;and $03 as 16-bit bne onlyinc01 ;pointers inc $02 inc $04onlyinc01: inc $01 lda $01 sta $03 rts The solution uses one cell thick border around square Petri dish as uninhabited dire land. Sample output contains 3 generations of the blinker and 5 of the glider: See Conway's Game of Life/ALGOL 68 APL2 (Dialog) Example in one line APL \ 1130 example (very old APL dialect via simulator) APL1130From: APL \ 1130 Samples The following APL \ 1130 code will need APL385 font installed to display correctly. See Download APL TT Font ∇LIFE[⎕]∇[0] NG←LIFE CG; W[1] W←CG+(¯1⊖CG)+(1⊖CG)+(¯1⌽CG)+(1⌽CG)[2] W←W+(1⊖1⌽CG)+(¯1⊖1⌽CG)+(1⊖¯1⌽CG)+(¯1⊖¯1⌽CG)[3] NG←(3=W)+(CG∧4=W) ∇ RP←5 5⍴0 0 0 0 0 0 0 1 1 0 0 1 1 0 0 0 0 1 0 0 RP0 0 0 0 00 0 1 1 00 1 1 0 00 0 1 0 00 0 0 0 0 LIFE RP0 0 0 0 00 1 1 1 00 1 0 0 00 1 1 0 00 0 0 0 0 LIFE LIFE RP0 0 1 0 00 1 1 0 01 0 0 1 00 1 1 0 00 0 0 0 0 .................................................. One interacts with the Game of Life by creating an initial configuration and observing how it evolves. Although you should test your implementation on more complex examples such as the glider in a larger universe, show the action of the blinker (three adjoining cells in a row all alive), over three generations, in a 3 by 3 grid. (1,4)=TRUERETURN'' Count the number of neighbours of the point i,j' (Assume i/j +/- 1 will not fall out of world)'FUNCTION count_neighbours(i%,j%) LOCAL count%,l% count%=0 FOR l%=-1 TO 1 IF world! (i%+l%,j%+1) count%=count%+1 ENDIF NEXT l% IF world! (i%+1,j%) count%=count%+1 ENDIF RETURN count%ENDFUNC'' Update the world one step'PROCEDURE update_world LOCAL i%,j% ' compute neighbour counts and store FOR i%=1 TO 30 FOR j%=1 TO 30 ns%(i%,j%)[email protected]_neighbours(i%,j%) NEXT j% NEXT i% ' update the world cells FOR i%=1 TO 30 FOR j%=1 TO 30 IF world!

||

randfill: stx $01 ;$200 for indirect ldx #$02 ;addressing stx $02randloop: lda $fe ;generate random and #$01 ;pixels on the sta ($01), Y ;screen jsr inc0103 cmp #$00 bne randloop lda $02 cmp #$06 bne randloop clearmem: lda #$df ;set $07df-$0a20 sta $01 ;to $#00 lda #$07 sta $02clearbyte: lda #$00 sta ($01), Y jsr inc0103 cmp #$20 bne clearbyte lda $02 cmp #$0a bne clearbyte starttick:copyscreen: lda #$00 ;set up source sta $01 ;pointer at sta $03 ;$01/$02 and lda #$02 ;dest pointer sta $02 ;at $03/$04 lda #$08 sta $04 ldy #$00copybyte: lda ($01), Y ;copy pixel to sta ($03), Y ;back buffer jsr inc0103 ;increment pointers cmp #$00 ;check to see bne copybyte ;if we're at $600 lda $02 ;if so, we've cmp #$06 ;copied the bne copybyte ;entire screen conway: lda #$df ;apply conway rules sta $01 ;reset the pointer sta $03 ;to $#01df/$#07df lda #$01 ;($200 - $21) sta $02 ;($800 - $21) lda #$07 sta $04onecell: lda #$00 ;process one cell ldy #$01 ;upper cell clc adc ($03), Y ldy #$41 ;lower cell clc adc ($03), Ychkleft: tax ;check to see lda $01 ;if we're at the and #$1f ;left edge tay txa cpy #$1f beq rightcellsleftcells: ldy #$00 ;upper-left cell clc adc ($03), Y ldy #$20 ;left cell clc adc ($03), Y ldy #$40 ;lower-left cell clc adc ($03), Ychkright: tax ;check to see lda $01 ;if we're at the and #$1f ;right edge tay txa cpy #$1e beq evaluaterightcells: ldy #$02 ;upper-right cell clc adc ($03), Y ldy #$22 ;right cell clc adc ($03), Y ldy #$42 ;lower-right cell clc adc ($03), Yevaluate: ldx #$01 ;evaluate total ldy #$21 ;for current cell cmp #$03 ;3 = alive beq storex ldx #$00 cmp #$02 ;2 = alive if bne storex ;c = alive lda ($03), Y and #$01 taxstorex: txa ;store to screen sta ($01), Y jsr inc0103 ;move to next cellconwayloop: cmp #$e0 ;if not last cell, bne onecell ;process next cell lda $02 cmp #$05 bne onecell jmp starttick ;run next tick inc0103: lda $01 ;increment $01 cmp #$ff ;and $03 as 16-bit bne onlyinc01 ;pointers inc $02 inc $04onlyinc01: inc $01 lda $01 sta $03 rts The solution uses one cell thick border around square Petri dish as uninhabited dire land. Sample output contains 3 generations of the blinker and 5 of the glider: See Conway's Game of Life/ALGOL 68 APL2 (Dialog) Example in one line APL \ 1130 example (very old APL dialect via simulator) APL1130From: APL \ 1130 Samples The following APL \ 1130 code will need APL385 font installed to display correctly.

See Download APL TT Font ∇LIFE[⎕]∇[0] NG←LIFE CG; W[1] W←CG+(¯1⊖CG)+(1⊖CG)+(¯1⌽CG)+(1⌽CG)[2] W←W+(1⊖1⌽CG)+(¯1⊖1⌽CG)+(1⊖¯1⌽CG)+(¯1⊖¯1⌽CG)[3] NG←(3=W)+(CG∧4=W) ∇ RP←5 5⍴0 0 0 0 0 0 0 1 1 0 0 1 1 0 0 0 0 1 0 0 RP0 0 0 0 00 0 1 1 00 1 1 0 00 0 1 0 00 0 0 0 0 LIFE RP0 0 0 0 00 1 1 1 00 1 0 0 00 1 1 0 00 0 0 0 0 LIFE LIFE RP0 0 1 0 00 1 1 0 01 0 0 1 00 1 1 0 00 0 0 0 0 ..................................................

One interacts with the Game of Life by creating an initial configuration and observing how it evolves.

Although you should test your implementation on more complex examples such as the glider in a larger universe, show the action of the blinker (three adjoining cells in a row all alive), over three generations, in a 3 by 3 grid.

(1,4)=TRUERETURN'' Count the number of neighbours of the point i,j' (Assume i/j +/- 1 will not fall out of world)'FUNCTION count_neighbours(i%,j%) LOCAL count%,l% count%=0 FOR l%=-1 TO 1 IF world! (i%+l%,j%+1) count%=count%+1 ENDIF NEXT l% IF world! (i%+1,j%) count%=count%+1 ENDIF RETURN count%ENDFUNC'' Update the world one step'PROCEDURE update_world LOCAL i%,j% ' compute neighbour counts and store FOR i%=1 TO 30 FOR j%=1 TO 30 ns%(i%,j%)[email protected]_neighbours(i%,j%) NEXT j% NEXT i% ' update the world cells FOR i%=1 TO 30 FOR j%=1 TO 30 IF world!

Thus, while it is somewhat verbose, it fully simulates Conway's Game of Life and is relatively simple to expand to feature different starting shapes.

Define life(pattern) = Prgm Local x,y,nt,count,save,xl,yl,xh,yh Define nt(y,x) = when(pxl Test(y,x), 1, 0) {}→save set Graph("Axes", "Off")→save[1] set Graph("Grid", "Off")→save[2] set Graph("Labels", "Off")→save[3] Fn Off Plot Off Clr Draw If pattern = "blinker" Then 36→yl 40→yh 78→xl 82→xh Pxl On 36,80 Pxl On 38,80 Pxl On 40,80 Else If pattern = "glider" Then 30→yl 40→yh 76→xl 88→xh Pxl On 38,76 Pxl On 36,78 Pxl On 36,80 Pxl On 38,80 Pxl On 40,80 Else If pattern = "r" Then 38-5*2→yl 38+5*2→yh 80-5*2→xl 80+5*2→xh Pxl On 38,78 Pxl On 36,82 Pxl On 36,80 Pxl On 38,80 Pxl On 40,80 End If While get Key() = 0 © Expand upper-left corner to whole cell For y,yl,yh,2 For x,xl,xh,2 If pxl Test(y,x) Then Pxl On y+1,x Pxl On y+1,x+1 Pxl On y, x+1 Else Pxl Off y+1,x Pxl Off y+1,x+1 Pxl Off y, x+1 End If End For End For © Compute next generation For y,yl,yh,2 For x,xl,xh,2 nt(y-1,x-1) + nt(y-1,x) + nt(y-1,x+2) + nt(y,x-1) + nt(y+1,x+2) + nt(y+2,x-1) + nt(y+2,x+1) + nt(y+2,x+2) → count If count = 3 Then Pxl On y,x Else If count ≠ 2 Then Pxl Off y,x End If End For End For End While © Restore changed options set Graph("Axes", save[1]) set Graph("Grid", save[2]) set Graph("Labels", save[3])End Prgm Also see Conway's Game of Life/C Considering that the simplest implementation in C++ would lack any use of the object-oriented paradigm, this code was specifically written to demonstrate the various object-oriented features of C++.

]] ;upper-left cell clc adc (), Y ldy # ;left cell clc adc (), Y ldy # ;lower-left cell clc adc (), Ychkright: tax ;check to see lda

randfill: stx $01 ;$200 for indirect ldx #$02 ;addressing stx $02randloop: lda $fe ;generate random and #$01 ;pixels on the sta ($01), Y ;screen jsr inc0103 cmp #$00 bne randloop lda $02 cmp #$06 bne randloop clearmem: lda #$df ;set $07df-$0a20 sta $01 ;to $#00 lda #$07 sta $02clearbyte: lda #$00 sta ($01), Y jsr inc0103 cmp #$20 bne clearbyte lda $02 cmp #$0a bne clearbyte starttick:copyscreen: lda #$00 ;set up source sta $01 ;pointer at sta $03 ;$01/$02 and lda #$02 ;dest pointer sta $02 ;at $03/$04 lda #$08 sta $04 ldy #$00copybyte: lda ($01), Y ;copy pixel to sta ($03), Y ;back buffer jsr inc0103 ;increment pointers cmp #$00 ;check to see bne copybyte ;if we're at $600 lda $02 ;if so, we've cmp #$06 ;copied the bne copybyte ;entire screen conway: lda #$df ;apply conway rules sta $01 ;reset the pointer sta $03 ;to $#01df/$#07df lda #$01 ;($200 - $21) sta $02 ;($800 - $21) lda #$07 sta $04onecell: lda #$00 ;process one cell ldy #$01 ;upper cell clc adc ($03), Y ldy #$41 ;lower cell clc adc ($03), Ychkleft: tax ;check to see lda $01 ;if we're at the and #$1f ;left edge tay txa cpy #$1f beq rightcellsleftcells: ldy #$00 ;upper-left cell clc adc ($03), Y ldy #$20 ;left cell clc adc ($03), Y ldy #$40 ;lower-left cell clc adc ($03), Ychkright: tax ;check to see lda $01 ;if we're at the and #$1f ;right edge tay txa cpy #$1e beq evaluaterightcells: ldy #$02 ;upper-right cell clc adc ($03), Y ldy #$22 ;right cell clc adc ($03), Y ldy #$42 ;lower-right cell clc adc ($03), Yevaluate: ldx #$01 ;evaluate total ldy #$21 ;for current cell cmp #$03 ;3 = alive beq storex ldx #$00 cmp #$02 ;2 = alive if bne storex ;c = alive lda ($03), Y and #$01 taxstorex: txa ;store to screen sta ($01), Y jsr inc0103 ;move to next cellconwayloop: cmp #$e0 ;if not last cell, bne onecell ;process next cell lda $02 cmp #$05 bne onecell jmp starttick ;run next tick inc0103: lda $01 ;increment $01 cmp #$ff ;and $03 as 16-bit bne onlyinc01 ;pointers inc $02 inc $04onlyinc01: inc $01 lda $01 sta $03 rts The solution uses one cell thick border around square Petri dish as uninhabited dire land. Sample output contains 3 generations of the blinker and 5 of the glider: See Conway's Game of Life/ALGOL 68 APL2 (Dialog) Example in one line APL \ 1130 example (very old APL dialect via simulator) APL1130From: APL \ 1130 Samples The following APL \ 1130 code will need APL385 font installed to display correctly. See Download APL TT Font ∇LIFE[⎕]∇[0] NG←LIFE CG; W[1] W←CG+(¯1⊖CG)+(1⊖CG)+(¯1⌽CG)+(1⌽CG)[2] W←W+(1⊖1⌽CG)+(¯1⊖1⌽CG)+(1⊖¯1⌽CG)+(¯1⊖¯1⌽CG)[3] NG←(3=W)+(CG∧4=W) ∇ RP←5 5⍴0 0 0 0 0 0 0 1 1 0 0 1 1 0 0 0 0 1 0 0 RP0 0 0 0 00 0 1 1 00 1 1 0 00 0 1 0 00 0 0 0 0 LIFE RP0 0 0 0 00 1 1 1 00 1 0 0 00 1 1 0 00 0 0 0 0 LIFE LIFE RP0 0 1 0 00 1 1 0 01 0 0 1 00 1 1 0 00 0 0 0 0 .................................................. One interacts with the Game of Life by creating an initial configuration and observing how it evolves. Although you should test your implementation on more complex examples such as the glider in a larger universe, show the action of the blinker (three adjoining cells in a row all alive), over three generations, in a 3 by 3 grid. (1,4)=TRUERETURN'' Count the number of neighbours of the point i,j' (Assume i/j +/- 1 will not fall out of world)'FUNCTION count_neighbours(i%,j%) LOCAL count%,l% count%=0 FOR l%=-1 TO 1 IF world! (i%+l%,j%+1) count%=count%+1 ENDIF NEXT l% IF world! (i%+1,j%) count%=count%+1 ENDIF RETURN count%ENDFUNC'' Update the world one step'PROCEDURE update_world LOCAL i%,j% ' compute neighbour counts and store FOR i%=1 TO 30 FOR j%=1 TO 30 ns%(i%,j%)[email protected]_neighbours(i%,j%) NEXT j% NEXT i% ' update the world cells FOR i%=1 TO 30 FOR j%=1 TO 30 IF world!

||

randfill: stx $01 ;$200 for indirect ldx #$02 ;addressing stx $02randloop: lda $fe ;generate random and #$01 ;pixels on the sta ($01), Y ;screen jsr inc0103 cmp #$00 bne randloop lda $02 cmp #$06 bne randloop clearmem: lda #$df ;set $07df-$0a20 sta $01 ;to $#00 lda #$07 sta $02clearbyte: lda #$00 sta ($01), Y jsr inc0103 cmp #$20 bne clearbyte lda $02 cmp #$0a bne clearbyte starttick:copyscreen: lda #$00 ;set up source sta $01 ;pointer at sta $03 ;$01/$02 and lda #$02 ;dest pointer sta $02 ;at $03/$04 lda #$08 sta $04 ldy #$00copybyte: lda ($01), Y ;copy pixel to sta ($03), Y ;back buffer jsr inc0103 ;increment pointers cmp #$00 ;check to see bne copybyte ;if we're at $600 lda $02 ;if so, we've cmp #$06 ;copied the bne copybyte ;entire screen conway: lda #$df ;apply conway rules sta $01 ;reset the pointer sta $03 ;to $#01df/$#07df lda #$01 ;($200 - $21) sta $02 ;($800 - $21) lda #$07 sta $04onecell: lda #$00 ;process one cell ldy #$01 ;upper cell clc adc ($03), Y ldy #$41 ;lower cell clc adc ($03), Ychkleft: tax ;check to see lda $01 ;if we're at the and #$1f ;left edge tay txa cpy #$1f beq rightcellsleftcells: ldy #$00 ;upper-left cell clc adc ($03), Y ldy #$20 ;left cell clc adc ($03), Y ldy #$40 ;lower-left cell clc adc ($03), Ychkright: tax ;check to see lda $01 ;if we're at the and #$1f ;right edge tay txa cpy #$1e beq evaluaterightcells: ldy #$02 ;upper-right cell clc adc ($03), Y ldy #$22 ;right cell clc adc ($03), Y ldy #$42 ;lower-right cell clc adc ($03), Yevaluate: ldx #$01 ;evaluate total ldy #$21 ;for current cell cmp #$03 ;3 = alive beq storex ldx #$00 cmp #$02 ;2 = alive if bne storex ;c = alive lda ($03), Y and #$01 taxstorex: txa ;store to screen sta ($01), Y jsr inc0103 ;move to next cellconwayloop: cmp #$e0 ;if not last cell, bne onecell ;process next cell lda $02 cmp #$05 bne onecell jmp starttick ;run next tick inc0103: lda $01 ;increment $01 cmp #$ff ;and $03 as 16-bit bne onlyinc01 ;pointers inc $02 inc $04onlyinc01: inc $01 lda $01 sta $03 rts The solution uses one cell thick border around square Petri dish as uninhabited dire land. Sample output contains 3 generations of the blinker and 5 of the glider: See Conway's Game of Life/ALGOL 68 APL2 (Dialog) Example in one line APL \ 1130 example (very old APL dialect via simulator) APL1130From: APL \ 1130 Samples The following APL \ 1130 code will need APL385 font installed to display correctly.

See Download APL TT Font ∇LIFE[⎕]∇[0] NG←LIFE CG; W[1] W←CG+(¯1⊖CG)+(1⊖CG)+(¯1⌽CG)+(1⌽CG)[2] W←W+(1⊖1⌽CG)+(¯1⊖1⌽CG)+(1⊖¯1⌽CG)+(¯1⊖¯1⌽CG)[3] NG←(3=W)+(CG∧4=W) ∇ RP←5 5⍴0 0 0 0 0 0 0 1 1 0 0 1 1 0 0 0 0 1 0 0 RP0 0 0 0 00 0 1 1 00 1 1 0 00 0 1 0 00 0 0 0 0 LIFE RP0 0 0 0 00 1 1 1 00 1 0 0 00 1 1 0 00 0 0 0 0 LIFE LIFE RP0 0 1 0 00 1 1 0 01 0 0 1 00 1 1 0 00 0 0 0 0 ..................................................

One interacts with the Game of Life by creating an initial configuration and observing how it evolves.

Although you should test your implementation on more complex examples such as the glider in a larger universe, show the action of the blinker (three adjoining cells in a row all alive), over three generations, in a 3 by 3 grid.

(1,4)=TRUERETURN'' Count the number of neighbours of the point i,j' (Assume i/j +/- 1 will not fall out of world)'FUNCTION count_neighbours(i%,j%) LOCAL count%,l% count%=0 FOR l%=-1 TO 1 IF world! (i%+l%,j%+1) count%=count%+1 ENDIF NEXT l% IF world! (i%+1,j%) count%=count%+1 ENDIF RETURN count%ENDFUNC'' Update the world one step'PROCEDURE update_world LOCAL i%,j% ' compute neighbour counts and store FOR i%=1 TO 30 FOR j%=1 TO 30 ns%(i%,j%)[email protected]_neighbours(i%,j%) NEXT j% NEXT i% ' update the world cells FOR i%=1 TO 30 FOR j%=1 TO 30 IF world!

Thus, while it is somewhat verbose, it fully simulates Conway's Game of Life and is relatively simple to expand to feature different starting shapes.

Define life(pattern) = Prgm Local x,y,nt,count,save,xl,yl,xh,yh Define nt(y,x) = when(pxl Test(y,x), 1, 0) {}→save set Graph("Axes", "Off")→save[1] set Graph("Grid", "Off")→save[2] set Graph("Labels", "Off")→save[3] Fn Off Plot Off Clr Draw If pattern = "blinker" Then 36→yl 40→yh 78→xl 82→xh Pxl On 36,80 Pxl On 38,80 Pxl On 40,80 Else If pattern = "glider" Then 30→yl 40→yh 76→xl 88→xh Pxl On 38,76 Pxl On 36,78 Pxl On 36,80 Pxl On 38,80 Pxl On 40,80 Else If pattern = "r" Then 38-5*2→yl 38+5*2→yh 80-5*2→xl 80+5*2→xh Pxl On 38,78 Pxl On 36,82 Pxl On 36,80 Pxl On 38,80 Pxl On 40,80 End If While get Key() = 0 © Expand upper-left corner to whole cell For y,yl,yh,2 For x,xl,xh,2 If pxl Test(y,x) Then Pxl On y+1,x Pxl On y+1,x+1 Pxl On y, x+1 Else Pxl Off y+1,x Pxl Off y+1,x+1 Pxl Off y, x+1 End If End For End For © Compute next generation For y,yl,yh,2 For x,xl,xh,2 nt(y-1,x-1) + nt(y-1,x) + nt(y-1,x+2) + nt(y,x-1) + nt(y+1,x+2) + nt(y+2,x-1) + nt(y+2,x+1) + nt(y+2,x+2) → count If count = 3 Then Pxl On y,x Else If count ≠ 2 Then Pxl Off y,x End If End For End For End While © Restore changed options set Graph("Axes", save[1]) set Graph("Grid", save[2]) set Graph("Labels", save[3])End Prgm Also see Conway's Game of Life/C Considering that the simplest implementation in C++ would lack any use of the object-oriented paradigm, this code was specifically written to demonstrate the various object-oriented features of C++.

;if we're at the and #

randfill: stx $01 ;$200 for indirect ldx #$02 ;addressing stx $02randloop: lda $fe ;generate random and #$01 ;pixels on the sta ($01), Y ;screen jsr inc0103 cmp #$00 bne randloop lda $02 cmp #$06 bne randloop clearmem: lda #$df ;set $07df-$0a20 sta $01 ;to $#00 lda #$07 sta $02clearbyte: lda #$00 sta ($01), Y jsr inc0103 cmp #$20 bne clearbyte lda $02 cmp #$0a bne clearbyte starttick:copyscreen: lda #$00 ;set up source sta $01 ;pointer at sta $03 ;$01/$02 and lda #$02 ;dest pointer sta $02 ;at $03/$04 lda #$08 sta $04 ldy #$00copybyte: lda ($01), Y ;copy pixel to sta ($03), Y ;back buffer jsr inc0103 ;increment pointers cmp #$00 ;check to see bne copybyte ;if we're at $600 lda $02 ;if so, we've cmp #$06 ;copied the bne copybyte ;entire screen conway: lda #$df ;apply conway rules sta $01 ;reset the pointer sta $03 ;to $#01df/$#07df lda #$01 ;($200 - $21) sta $02 ;($800 - $21) lda #$07 sta $04onecell: lda #$00 ;process one cell ldy #$01 ;upper cell clc adc ($03), Y ldy #$41 ;lower cell clc adc ($03), Ychkleft: tax ;check to see lda $01 ;if we're at the and #$1f ;left edge tay txa cpy #$1f beq rightcellsleftcells: ldy #$00 ;upper-left cell clc adc ($03), Y ldy #$20 ;left cell clc adc ($03), Y ldy #$40 ;lower-left cell clc adc ($03), Ychkright: tax ;check to see lda $01 ;if we're at the and #$1f ;right edge tay txa cpy #$1e beq evaluaterightcells: ldy #$02 ;upper-right cell clc adc ($03), Y ldy #$22 ;right cell clc adc ($03), Y ldy #$42 ;lower-right cell clc adc ($03), Yevaluate: ldx #$01 ;evaluate total ldy #$21 ;for current cell cmp #$03 ;3 = alive beq storex ldx #$00 cmp #$02 ;2 = alive if bne storex ;c = alive lda ($03), Y and #$01 taxstorex: txa ;store to screen sta ($01), Y jsr inc0103 ;move to next cellconwayloop: cmp #$e0 ;if not last cell, bne onecell ;process next cell lda $02 cmp #$05 bne onecell jmp starttick ;run next tick inc0103: lda $01 ;increment $01 cmp #$ff ;and $03 as 16-bit bne onlyinc01 ;pointers inc $02 inc $04onlyinc01: inc $01 lda $01 sta $03 rts The solution uses one cell thick border around square Petri dish as uninhabited dire land. Sample output contains 3 generations of the blinker and 5 of the glider: See Conway's Game of Life/ALGOL 68 APL2 (Dialog) Example in one line APL \ 1130 example (very old APL dialect via simulator) APL1130From: APL \ 1130 Samples The following APL \ 1130 code will need APL385 font installed to display correctly. See Download APL TT Font ∇LIFE[⎕]∇[0] NG←LIFE CG; W[1] W←CG+(¯1⊖CG)+(1⊖CG)+(¯1⌽CG)+(1⌽CG)[2] W←W+(1⊖1⌽CG)+(¯1⊖1⌽CG)+(1⊖¯1⌽CG)+(¯1⊖¯1⌽CG)[3] NG←(3=W)+(CG∧4=W) ∇ RP←5 5⍴0 0 0 0 0 0 0 1 1 0 0 1 1 0 0 0 0 1 0 0 RP0 0 0 0 00 0 1 1 00 1 1 0 00 0 1 0 00 0 0 0 0 LIFE RP0 0 0 0 00 1 1 1 00 1 0 0 00 1 1 0 00 0 0 0 0 LIFE LIFE RP0 0 1 0 00 1 1 0 01 0 0 1 00 1 1 0 00 0 0 0 0 .................................................. One interacts with the Game of Life by creating an initial configuration and observing how it evolves. Although you should test your implementation on more complex examples such as the glider in a larger universe, show the action of the blinker (three adjoining cells in a row all alive), over three generations, in a 3 by 3 grid. (1,4)=TRUERETURN'' Count the number of neighbours of the point i,j' (Assume i/j +/- 1 will not fall out of world)'FUNCTION count_neighbours(i%,j%) LOCAL count%,l% count%=0 FOR l%=-1 TO 1 IF world! (i%+l%,j%+1) count%=count%+1 ENDIF NEXT l% IF world! (i%+1,j%) count%=count%+1 ENDIF RETURN count%ENDFUNC'' Update the world one step'PROCEDURE update_world LOCAL i%,j% ' compute neighbour counts and store FOR i%=1 TO 30 FOR j%=1 TO 30 ns%(i%,j%)[email protected]_neighbours(i%,j%) NEXT j% NEXT i% ' update the world cells FOR i%=1 TO 30 FOR j%=1 TO 30 IF world!

||

randfill: stx $01 ;$200 for indirect ldx #$02 ;addressing stx $02randloop: lda $fe ;generate random and #$01 ;pixels on the sta ($01), Y ;screen jsr inc0103 cmp #$00 bne randloop lda $02 cmp #$06 bne randloop clearmem: lda #$df ;set $07df-$0a20 sta $01 ;to $#00 lda #$07 sta $02clearbyte: lda #$00 sta ($01), Y jsr inc0103 cmp #$20 bne clearbyte lda $02 cmp #$0a bne clearbyte starttick:copyscreen: lda #$00 ;set up source sta $01 ;pointer at sta $03 ;$01/$02 and lda #$02 ;dest pointer sta $02 ;at $03/$04 lda #$08 sta $04 ldy #$00copybyte: lda ($01), Y ;copy pixel to sta ($03), Y ;back buffer jsr inc0103 ;increment pointers cmp #$00 ;check to see bne copybyte ;if we're at $600 lda $02 ;if so, we've cmp #$06 ;copied the bne copybyte ;entire screen conway: lda #$df ;apply conway rules sta $01 ;reset the pointer sta $03 ;to $#01df/$#07df lda #$01 ;($200 - $21) sta $02 ;($800 - $21) lda #$07 sta $04onecell: lda #$00 ;process one cell ldy #$01 ;upper cell clc adc ($03), Y ldy #$41 ;lower cell clc adc ($03), Ychkleft: tax ;check to see lda $01 ;if we're at the and #$1f ;left edge tay txa cpy #$1f beq rightcellsleftcells: ldy #$00 ;upper-left cell clc adc ($03), Y ldy #$20 ;left cell clc adc ($03), Y ldy #$40 ;lower-left cell clc adc ($03), Ychkright: tax ;check to see lda $01 ;if we're at the and #$1f ;right edge tay txa cpy #$1e beq evaluaterightcells: ldy #$02 ;upper-right cell clc adc ($03), Y ldy #$22 ;right cell clc adc ($03), Y ldy #$42 ;lower-right cell clc adc ($03), Yevaluate: ldx #$01 ;evaluate total ldy #$21 ;for current cell cmp #$03 ;3 = alive beq storex ldx #$00 cmp #$02 ;2 = alive if bne storex ;c = alive lda ($03), Y and #$01 taxstorex: txa ;store to screen sta ($01), Y jsr inc0103 ;move to next cellconwayloop: cmp #$e0 ;if not last cell, bne onecell ;process next cell lda $02 cmp #$05 bne onecell jmp starttick ;run next tick inc0103: lda $01 ;increment $01 cmp #$ff ;and $03 as 16-bit bne onlyinc01 ;pointers inc $02 inc $04onlyinc01: inc $01 lda $01 sta $03 rts The solution uses one cell thick border around square Petri dish as uninhabited dire land. Sample output contains 3 generations of the blinker and 5 of the glider: See Conway's Game of Life/ALGOL 68 APL2 (Dialog) Example in one line APL \ 1130 example (very old APL dialect via simulator) APL1130From: APL \ 1130 Samples The following APL \ 1130 code will need APL385 font installed to display correctly.

See Download APL TT Font ∇LIFE[⎕]∇[0] NG←LIFE CG; W[1] W←CG+(¯1⊖CG)+(1⊖CG)+(¯1⌽CG)+(1⌽CG)[2] W←W+(1⊖1⌽CG)+(¯1⊖1⌽CG)+(1⊖¯1⌽CG)+(¯1⊖¯1⌽CG)[3] NG←(3=W)+(CG∧4=W) ∇ RP←5 5⍴0 0 0 0 0 0 0 1 1 0 0 1 1 0 0 0 0 1 0 0 RP0 0 0 0 00 0 1 1 00 1 1 0 00 0 1 0 00 0 0 0 0 LIFE RP0 0 0 0 00 1 1 1 00 1 0 0 00 1 1 0 00 0 0 0 0 LIFE LIFE RP0 0 1 0 00 1 1 0 01 0 0 1 00 1 1 0 00 0 0 0 0 ..................................................

One interacts with the Game of Life by creating an initial configuration and observing how it evolves.

Although you should test your implementation on more complex examples such as the glider in a larger universe, show the action of the blinker (three adjoining cells in a row all alive), over three generations, in a 3 by 3 grid.

(1,4)=TRUERETURN'' Count the number of neighbours of the point i,j' (Assume i/j +/- 1 will not fall out of world)'FUNCTION count_neighbours(i%,j%) LOCAL count%,l% count%=0 FOR l%=-1 TO 1 IF world! (i%+l%,j%+1) count%=count%+1 ENDIF NEXT l% IF world! (i%+1,j%) count%=count%+1 ENDIF RETURN count%ENDFUNC'' Update the world one step'PROCEDURE update_world LOCAL i%,j% ' compute neighbour counts and store FOR i%=1 TO 30 FOR j%=1 TO 30 ns%(i%,j%)[email protected]_neighbours(i%,j%) NEXT j% NEXT i% ' update the world cells FOR i%=1 TO 30 FOR j%=1 TO 30 IF world!

Thus, while it is somewhat verbose, it fully simulates Conway's Game of Life and is relatively simple to expand to feature different starting shapes.

Define life(pattern) = Prgm Local x,y,nt,count,save,xl,yl,xh,yh Define nt(y,x) = when(pxl Test(y,x), 1, 0) {}→save set Graph("Axes", "Off")→save[1] set Graph("Grid", "Off")→save[2] set Graph("Labels", "Off")→save[3] Fn Off Plot Off Clr Draw If pattern = "blinker" Then 36→yl 40→yh 78→xl 82→xh Pxl On 36,80 Pxl On 38,80 Pxl On 40,80 Else If pattern = "glider" Then 30→yl 40→yh 76→xl 88→xh Pxl On 38,76 Pxl On 36,78 Pxl On 36,80 Pxl On 38,80 Pxl On 40,80 Else If pattern = "r" Then 38-5*2→yl 38+5*2→yh 80-5*2→xl 80+5*2→xh Pxl On 38,78 Pxl On 36,82 Pxl On 36,80 Pxl On 38,80 Pxl On 40,80 End If While get Key() = 0 © Expand upper-left corner to whole cell For y,yl,yh,2 For x,xl,xh,2 If pxl Test(y,x) Then Pxl On y+1,x Pxl On y+1,x+1 Pxl On y, x+1 Else Pxl Off y+1,x Pxl Off y+1,x+1 Pxl Off y, x+1 End If End For End For © Compute next generation For y,yl,yh,2 For x,xl,xh,2 nt(y-1,x-1) + nt(y-1,x) + nt(y-1,x+2) + nt(y,x-1) + nt(y+1,x+2) + nt(y+2,x-1) + nt(y+2,x+1) + nt(y+2,x+2) → count If count = 3 Then Pxl On y,x Else If count ≠ 2 Then Pxl Off y,x End If End For End For End While © Restore changed options set Graph("Axes", save[1]) set Graph("Grid", save[2]) set Graph("Labels", save[3])End Prgm Also see Conway's Game of Life/C Considering that the simplest implementation in C++ would lack any use of the object-oriented paradigm, this code was specifically written to demonstrate the various object-oriented features of C++.

f ;right edge tay txa cpy #

randfill: stx $01 ;$200 for indirect ldx #$02 ;addressing stx $02randloop: lda $fe ;generate random and #$01 ;pixels on the sta ($01), Y ;screen jsr inc0103 cmp #$00 bne randloop lda $02 cmp #$06 bne randloop clearmem: lda #$df ;set $07df-$0a20 sta $01 ;to $#00 lda #$07 sta $02clearbyte: lda #$00 sta ($01), Y jsr inc0103 cmp #$20 bne clearbyte lda $02 cmp #$0a bne clearbyte starttick:copyscreen: lda #$00 ;set up source sta $01 ;pointer at sta $03 ;$01/$02 and lda #$02 ;dest pointer sta $02 ;at $03/$04 lda #$08 sta $04 ldy #$00copybyte: lda ($01), Y ;copy pixel to sta ($03), Y ;back buffer jsr inc0103 ;increment pointers cmp #$00 ;check to see bne copybyte ;if we're at $600 lda $02 ;if so, we've cmp #$06 ;copied the bne copybyte ;entire screen conway: lda #$df ;apply conway rules sta $01 ;reset the pointer sta $03 ;to $#01df/$#07df lda #$01 ;($200 - $21) sta $02 ;($800 - $21) lda #$07 sta $04onecell: lda #$00 ;process one cell ldy #$01 ;upper cell clc adc ($03), Y ldy #$41 ;lower cell clc adc ($03), Ychkleft: tax ;check to see lda $01 ;if we're at the and #$1f ;left edge tay txa cpy #$1f beq rightcellsleftcells: ldy #$00 ;upper-left cell clc adc ($03), Y ldy #$20 ;left cell clc adc ($03), Y ldy #$40 ;lower-left cell clc adc ($03), Ychkright: tax ;check to see lda $01 ;if we're at the and #$1f ;right edge tay txa cpy #$1e beq evaluaterightcells: ldy #$02 ;upper-right cell clc adc ($03), Y ldy #$22 ;right cell clc adc ($03), Y ldy #$42 ;lower-right cell clc adc ($03), Yevaluate: ldx #$01 ;evaluate total ldy #$21 ;for current cell cmp #$03 ;3 = alive beq storex ldx #$00 cmp #$02 ;2 = alive if bne storex ;c = alive lda ($03), Y and #$01 taxstorex: txa ;store to screen sta ($01), Y jsr inc0103 ;move to next cellconwayloop: cmp #$e0 ;if not last cell, bne onecell ;process next cell lda $02 cmp #$05 bne onecell jmp starttick ;run next tick inc0103: lda $01 ;increment $01 cmp #$ff ;and $03 as 16-bit bne onlyinc01 ;pointers inc $02 inc $04onlyinc01: inc $01 lda $01 sta $03 rts The solution uses one cell thick border around square Petri dish as uninhabited dire land. Sample output contains 3 generations of the blinker and 5 of the glider: See Conway's Game of Life/ALGOL 68 APL2 (Dialog) Example in one line APL \ 1130 example (very old APL dialect via simulator) APL1130From: APL \ 1130 Samples The following APL \ 1130 code will need APL385 font installed to display correctly. See Download APL TT Font ∇LIFE[⎕]∇[0] NG←LIFE CG; W[1] W←CG+(¯1⊖CG)+(1⊖CG)+(¯1⌽CG)+(1⌽CG)[2] W←W+(1⊖1⌽CG)+(¯1⊖1⌽CG)+(1⊖¯1⌽CG)+(¯1⊖¯1⌽CG)[3] NG←(3=W)+(CG∧4=W) ∇ RP←5 5⍴0 0 0 0 0 0 0 1 1 0 0 1 1 0 0 0 0 1 0 0 RP0 0 0 0 00 0 1 1 00 1 1 0 00 0 1 0 00 0 0 0 0 LIFE RP0 0 0 0 00 1 1 1 00 1 0 0 00 1 1 0 00 0 0 0 0 LIFE LIFE RP0 0 1 0 00 1 1 0 01 0 0 1 00 1 1 0 00 0 0 0 0 .................................................. One interacts with the Game of Life by creating an initial configuration and observing how it evolves. Although you should test your implementation on more complex examples such as the glider in a larger universe, show the action of the blinker (three adjoining cells in a row all alive), over three generations, in a 3 by 3 grid. (1,4)=TRUERETURN'' Count the number of neighbours of the point i,j' (Assume i/j +/- 1 will not fall out of world)'FUNCTION count_neighbours(i%,j%) LOCAL count%,l% count%=0 FOR l%=-1 TO 1 IF world! (i%+l%,j%+1) count%=count%+1 ENDIF NEXT l% IF world! (i%+1,j%) count%=count%+1 ENDIF RETURN count%ENDFUNC'' Update the world one step'PROCEDURE update_world LOCAL i%,j% ' compute neighbour counts and store FOR i%=1 TO 30 FOR j%=1 TO 30 ns%(i%,j%)[email protected]_neighbours(i%,j%) NEXT j% NEXT i% ' update the world cells FOR i%=1 TO 30 FOR j%=1 TO 30 IF world!

||

randfill: stx $01 ;$200 for indirect ldx #$02 ;addressing stx $02randloop: lda $fe ;generate random and #$01 ;pixels on the sta ($01), Y ;screen jsr inc0103 cmp #$00 bne randloop lda $02 cmp #$06 bne randloop clearmem: lda #$df ;set $07df-$0a20 sta $01 ;to $#00 lda #$07 sta $02clearbyte: lda #$00 sta ($01), Y jsr inc0103 cmp #$20 bne clearbyte lda $02 cmp #$0a bne clearbyte starttick:copyscreen: lda #$00 ;set up source sta $01 ;pointer at sta $03 ;$01/$02 and lda #$02 ;dest pointer sta $02 ;at $03/$04 lda #$08 sta $04 ldy #$00copybyte: lda ($01), Y ;copy pixel to sta ($03), Y ;back buffer jsr inc0103 ;increment pointers cmp #$00 ;check to see bne copybyte ;if we're at $600 lda $02 ;if so, we've cmp #$06 ;copied the bne copybyte ;entire screen conway: lda #$df ;apply conway rules sta $01 ;reset the pointer sta $03 ;to $#01df/$#07df lda #$01 ;($200 - $21) sta $02 ;($800 - $21) lda #$07 sta $04onecell: lda #$00 ;process one cell ldy #$01 ;upper cell clc adc ($03), Y ldy #$41 ;lower cell clc adc ($03), Ychkleft: tax ;check to see lda $01 ;if we're at the and #$1f ;left edge tay txa cpy #$1f beq rightcellsleftcells: ldy #$00 ;upper-left cell clc adc ($03), Y ldy #$20 ;left cell clc adc ($03), Y ldy #$40 ;lower-left cell clc adc ($03), Ychkright: tax ;check to see lda $01 ;if we're at the and #$1f ;right edge tay txa cpy #$1e beq evaluaterightcells: ldy #$02 ;upper-right cell clc adc ($03), Y ldy #$22 ;right cell clc adc ($03), Y ldy #$42 ;lower-right cell clc adc ($03), Yevaluate: ldx #$01 ;evaluate total ldy #$21 ;for current cell cmp #$03 ;3 = alive beq storex ldx #$00 cmp #$02 ;2 = alive if bne storex ;c = alive lda ($03), Y and #$01 taxstorex: txa ;store to screen sta ($01), Y jsr inc0103 ;move to next cellconwayloop: cmp #$e0 ;if not last cell, bne onecell ;process next cell lda $02 cmp #$05 bne onecell jmp starttick ;run next tick inc0103: lda $01 ;increment $01 cmp #$ff ;and $03 as 16-bit bne onlyinc01 ;pointers inc $02 inc $04onlyinc01: inc $01 lda $01 sta $03 rts The solution uses one cell thick border around square Petri dish as uninhabited dire land. Sample output contains 3 generations of the blinker and 5 of the glider: See Conway's Game of Life/ALGOL 68 APL2 (Dialog) Example in one line APL \ 1130 example (very old APL dialect via simulator) APL1130From: APL \ 1130 Samples The following APL \ 1130 code will need APL385 font installed to display correctly.

See Download APL TT Font ∇LIFE[⎕]∇[0] NG←LIFE CG; W[1] W←CG+(¯1⊖CG)+(1⊖CG)+(¯1⌽CG)+(1⌽CG)[2] W←W+(1⊖1⌽CG)+(¯1⊖1⌽CG)+(1⊖¯1⌽CG)+(¯1⊖¯1⌽CG)[3] NG←(3=W)+(CG∧4=W) ∇ RP←5 5⍴0 0 0 0 0 0 0 1 1 0 0 1 1 0 0 0 0 1 0 0 RP0 0 0 0 00 0 1 1 00 1 1 0 00 0 1 0 00 0 0 0 0 LIFE RP0 0 0 0 00 1 1 1 00 1 0 0 00 1 1 0 00 0 0 0 0 LIFE LIFE RP0 0 1 0 00 1 1 0 01 0 0 1 00 1 1 0 00 0 0 0 0 ..................................................

One interacts with the Game of Life by creating an initial configuration and observing how it evolves.

Although you should test your implementation on more complex examples such as the glider in a larger universe, show the action of the blinker (three adjoining cells in a row all alive), over three generations, in a 3 by 3 grid.

(1,4)=TRUERETURN'' Count the number of neighbours of the point i,j' (Assume i/j +/- 1 will not fall out of world)'FUNCTION count_neighbours(i%,j%) LOCAL count%,l% count%=0 FOR l%=-1 TO 1 IF world! (i%+l%,j%+1) count%=count%+1 ENDIF NEXT l% IF world! (i%+1,j%) count%=count%+1 ENDIF RETURN count%ENDFUNC'' Update the world one step'PROCEDURE update_world LOCAL i%,j% ' compute neighbour counts and store FOR i%=1 TO 30 FOR j%=1 TO 30 ns%(i%,j%)[email protected]_neighbours(i%,j%) NEXT j% NEXT i% ' update the world cells FOR i%=1 TO 30 FOR j%=1 TO 30 IF world!

Thus, while it is somewhat verbose, it fully simulates Conway's Game of Life and is relatively simple to expand to feature different starting shapes.

Define life(pattern) = Prgm Local x,y,nt,count,save,xl,yl,xh,yh Define nt(y,x) = when(pxl Test(y,x), 1, 0) {}→save set Graph("Axes", "Off")→save[1] set Graph("Grid", "Off")→save[2] set Graph("Labels", "Off")→save[3] Fn Off Plot Off Clr Draw If pattern = "blinker" Then 36→yl 40→yh 78→xl 82→xh Pxl On 36,80 Pxl On 38,80 Pxl On 40,80 Else If pattern = "glider" Then 30→yl 40→yh 76→xl 88→xh Pxl On 38,76 Pxl On 36,78 Pxl On 36,80 Pxl On 38,80 Pxl On 40,80 Else If pattern = "r" Then 38-5*2→yl 38+5*2→yh 80-5*2→xl 80+5*2→xh Pxl On 38,78 Pxl On 36,82 Pxl On 36,80 Pxl On 38,80 Pxl On 40,80 End If While get Key() = 0 © Expand upper-left corner to whole cell For y,yl,yh,2 For x,xl,xh,2 If pxl Test(y,x) Then Pxl On y+1,x Pxl On y+1,x+1 Pxl On y, x+1 Else Pxl Off y+1,x Pxl Off y+1,x+1 Pxl Off y, x+1 End If End For End For © Compute next generation For y,yl,yh,2 For x,xl,xh,2 nt(y-1,x-1) + nt(y-1,x) + nt(y-1,x+2) + nt(y,x-1) + nt(y+1,x+2) + nt(y+2,x-1) + nt(y+2,x+1) + nt(y+2,x+2) → count If count = 3 Then Pxl On y,x Else If count ≠ 2 Then Pxl Off y,x End If End For End For End While © Restore changed options set Graph("Axes", save[1]) set Graph("Grid", save[2]) set Graph("Labels", save[3])End Prgm Also see Conway's Game of Life/C Considering that the simplest implementation in C++ would lack any use of the object-oriented paradigm, this code was specifically written to demonstrate the various object-oriented features of C++.

e beq evaluaterightcells: ldy # ;upper-right cell clc adc (), Y ldy # ;right cell clc adc (), Y ldy # ;lower-right cell clc adc (), Yevaluate: ldx #

randfill: stx $01 ;$200 for indirect ldx #$02 ;addressing stx $02randloop: lda $fe ;generate random and #$01 ;pixels on the sta ($01), Y ;screen jsr inc0103 cmp #$00 bne randloop lda $02 cmp #$06 bne randloop clearmem: lda #$df ;set $07df-$0a20 sta $01 ;to $#00 lda #$07 sta $02clearbyte: lda #$00 sta ($01), Y jsr inc0103 cmp #$20 bne clearbyte lda $02 cmp #$0a bne clearbyte starttick:copyscreen: lda #$00 ;set up source sta $01 ;pointer at sta $03 ;$01/$02 and lda #$02 ;dest pointer sta $02 ;at $03/$04 lda #$08 sta $04 ldy #$00copybyte: lda ($01), Y ;copy pixel to sta ($03), Y ;back buffer jsr inc0103 ;increment pointers cmp #$00 ;check to see bne copybyte ;if we're at $600 lda $02 ;if so, we've cmp #$06 ;copied the bne copybyte ;entire screen conway: lda #$df ;apply conway rules sta $01 ;reset the pointer sta $03 ;to $#01df/$#07df lda #$01 ;($200 - $21) sta $02 ;($800 - $21) lda #$07 sta $04onecell: lda #$00 ;process one cell ldy #$01 ;upper cell clc adc ($03), Y ldy #$41 ;lower cell clc adc ($03), Ychkleft: tax ;check to see lda $01 ;if we're at the and #$1f ;left edge tay txa cpy #$1f beq rightcellsleftcells: ldy #$00 ;upper-left cell clc adc ($03), Y ldy #$20 ;left cell clc adc ($03), Y ldy #$40 ;lower-left cell clc adc ($03), Ychkright: tax ;check to see lda $01 ;if we're at the and #$1f ;right edge tay txa cpy #$1e beq evaluaterightcells: ldy #$02 ;upper-right cell clc adc ($03), Y ldy #$22 ;right cell clc adc ($03), Y ldy #$42 ;lower-right cell clc adc ($03), Yevaluate: ldx #$01 ;evaluate total ldy #$21 ;for current cell cmp #$03 ;3 = alive beq storex ldx #$00 cmp #$02 ;2 = alive if bne storex ;c = alive lda ($03), Y and #$01 taxstorex: txa ;store to screen sta ($01), Y jsr inc0103 ;move to next cellconwayloop: cmp #$e0 ;if not last cell, bne onecell ;process next cell lda $02 cmp #$05 bne onecell jmp starttick ;run next tick inc0103: lda $01 ;increment $01 cmp #$ff ;and $03 as 16-bit bne onlyinc01 ;pointers inc $02 inc $04onlyinc01: inc $01 lda $01 sta $03 rts The solution uses one cell thick border around square Petri dish as uninhabited dire land. Sample output contains 3 generations of the blinker and 5 of the glider: See Conway's Game of Life/ALGOL 68 APL2 (Dialog) Example in one line APL \ 1130 example (very old APL dialect via simulator) APL1130From: APL \ 1130 Samples The following APL \ 1130 code will need APL385 font installed to display correctly. See Download APL TT Font ∇LIFE[⎕]∇[0] NG←LIFE CG; W[1] W←CG+(¯1⊖CG)+(1⊖CG)+(¯1⌽CG)+(1⌽CG)[2] W←W+(1⊖1⌽CG)+(¯1⊖1⌽CG)+(1⊖¯1⌽CG)+(¯1⊖¯1⌽CG)[3] NG←(3=W)+(CG∧4=W) ∇ RP←5 5⍴0 0 0 0 0 0 0 1 1 0 0 1 1 0 0 0 0 1 0 0 RP0 0 0 0 00 0 1 1 00 1 1 0 00 0 1 0 00 0 0 0 0 LIFE RP0 0 0 0 00 1 1 1 00 1 0 0 00 1 1 0 00 0 0 0 0 LIFE LIFE RP0 0 1 0 00 1 1 0 01 0 0 1 00 1 1 0 00 0 0 0 0 .................................................. One interacts with the Game of Life by creating an initial configuration and observing how it evolves. Although you should test your implementation on more complex examples such as the glider in a larger universe, show the action of the blinker (three adjoining cells in a row all alive), over three generations, in a 3 by 3 grid. (1,4)=TRUERETURN'' Count the number of neighbours of the point i,j' (Assume i/j +/- 1 will not fall out of world)'FUNCTION count_neighbours(i%,j%) LOCAL count%,l% count%=0 FOR l%=-1 TO 1 IF world! (i%+l%,j%+1) count%=count%+1 ENDIF NEXT l% IF world! (i%+1,j%) count%=count%+1 ENDIF RETURN count%ENDFUNC'' Update the world one step'PROCEDURE update_world LOCAL i%,j% ' compute neighbour counts and store FOR i%=1 TO 30 FOR j%=1 TO 30 ns%(i%,j%)[email protected]_neighbours(i%,j%) NEXT j% NEXT i% ' update the world cells FOR i%=1 TO 30 FOR j%=1 TO 30 IF world!

||

randfill: stx $01 ;$200 for indirect ldx #$02 ;addressing stx $02randloop: lda $fe ;generate random and #$01 ;pixels on the sta ($01), Y ;screen jsr inc0103 cmp #$00 bne randloop lda $02 cmp #$06 bne randloop clearmem: lda #$df ;set $07df-$0a20 sta $01 ;to $#00 lda #$07 sta $02clearbyte: lda #$00 sta ($01), Y jsr inc0103 cmp #$20 bne clearbyte lda $02 cmp #$0a bne clearbyte starttick:copyscreen: lda #$00 ;set up source sta $01 ;pointer at sta $03 ;$01/$02 and lda #$02 ;dest pointer sta $02 ;at $03/$04 lda #$08 sta $04 ldy #$00copybyte: lda ($01), Y ;copy pixel to sta ($03), Y ;back buffer jsr inc0103 ;increment pointers cmp #$00 ;check to see bne copybyte ;if we're at $600 lda $02 ;if so, we've cmp #$06 ;copied the bne copybyte ;entire screen conway: lda #$df ;apply conway rules sta $01 ;reset the pointer sta $03 ;to $#01df/$#07df lda #$01 ;($200 - $21) sta $02 ;($800 - $21) lda #$07 sta $04onecell: lda #$00 ;process one cell ldy #$01 ;upper cell clc adc ($03), Y ldy #$41 ;lower cell clc adc ($03), Ychkleft: tax ;check to see lda $01 ;if we're at the and #$1f ;left edge tay txa cpy #$1f beq rightcellsleftcells: ldy #$00 ;upper-left cell clc adc ($03), Y ldy #$20 ;left cell clc adc ($03), Y ldy #$40 ;lower-left cell clc adc ($03), Ychkright: tax ;check to see lda $01 ;if we're at the and #$1f ;right edge tay txa cpy #$1e beq evaluaterightcells: ldy #$02 ;upper-right cell clc adc ($03), Y ldy #$22 ;right cell clc adc ($03), Y ldy #$42 ;lower-right cell clc adc ($03), Yevaluate: ldx #$01 ;evaluate total ldy #$21 ;for current cell cmp #$03 ;3 = alive beq storex ldx #$00 cmp #$02 ;2 = alive if bne storex ;c = alive lda ($03), Y and #$01 taxstorex: txa ;store to screen sta ($01), Y jsr inc0103 ;move to next cellconwayloop: cmp #$e0 ;if not last cell, bne onecell ;process next cell lda $02 cmp #$05 bne onecell jmp starttick ;run next tick inc0103: lda $01 ;increment $01 cmp #$ff ;and $03 as 16-bit bne onlyinc01 ;pointers inc $02 inc $04onlyinc01: inc $01 lda $01 sta $03 rts The solution uses one cell thick border around square Petri dish as uninhabited dire land. Sample output contains 3 generations of the blinker and 5 of the glider: See Conway's Game of Life/ALGOL 68 APL2 (Dialog) Example in one line APL \ 1130 example (very old APL dialect via simulator) APL1130From: APL \ 1130 Samples The following APL \ 1130 code will need APL385 font installed to display correctly.

See Download APL TT Font ∇LIFE[⎕]∇[0] NG←LIFE CG; W[1] W←CG+(¯1⊖CG)+(1⊖CG)+(¯1⌽CG)+(1⌽CG)[2] W←W+(1⊖1⌽CG)+(¯1⊖1⌽CG)+(1⊖¯1⌽CG)+(¯1⊖¯1⌽CG)[3] NG←(3=W)+(CG∧4=W) ∇ RP←5 5⍴0 0 0 0 0 0 0 1 1 0 0 1 1 0 0 0 0 1 0 0 RP0 0 0 0 00 0 1 1 00 1 1 0 00 0 1 0 00 0 0 0 0 LIFE RP0 0 0 0 00 1 1 1 00 1 0 0 00 1 1 0 00 0 0 0 0 LIFE LIFE RP0 0 1 0 00 1 1 0 01 0 0 1 00 1 1 0 00 0 0 0 0 ..................................................

One interacts with the Game of Life by creating an initial configuration and observing how it evolves.

Although you should test your implementation on more complex examples such as the glider in a larger universe, show the action of the blinker (three adjoining cells in a row all alive), over three generations, in a 3 by 3 grid.

(1,4)=TRUERETURN'' Count the number of neighbours of the point i,j' (Assume i/j +/- 1 will not fall out of world)'FUNCTION count_neighbours(i%,j%) LOCAL count%,l% count%=0 FOR l%=-1 TO 1 IF world! (i%+l%,j%+1) count%=count%+1 ENDIF NEXT l% IF world! (i%+1,j%) count%=count%+1 ENDIF RETURN count%ENDFUNC'' Update the world one step'PROCEDURE update_world LOCAL i%,j% ' compute neighbour counts and store FOR i%=1 TO 30 FOR j%=1 TO 30 ns%(i%,j%)[email protected]_neighbours(i%,j%) NEXT j% NEXT i% ' update the world cells FOR i%=1 TO 30 FOR j%=1 TO 30 IF world!

Thus, while it is somewhat verbose, it fully simulates Conway's Game of Life and is relatively simple to expand to feature different starting shapes.

Define life(pattern) = Prgm Local x,y,nt,count,save,xl,yl,xh,yh Define nt(y,x) = when(pxl Test(y,x), 1, 0) {}→save set Graph("Axes", "Off")→save[1] set Graph("Grid", "Off")→save[2] set Graph("Labels", "Off")→save[3] Fn Off Plot Off Clr Draw If pattern = "blinker" Then 36→yl 40→yh 78→xl 82→xh Pxl On 36,80 Pxl On 38,80 Pxl On 40,80 Else If pattern = "glider" Then 30→yl 40→yh 76→xl 88→xh Pxl On 38,76 Pxl On 36,78 Pxl On 36,80 Pxl On 38,80 Pxl On 40,80 Else If pattern = "r" Then 38-5*2→yl 38+5*2→yh 80-5*2→xl 80+5*2→xh Pxl On 38,78 Pxl On 36,82 Pxl On 36,80 Pxl On 38,80 Pxl On 40,80 End If While get Key() = 0 © Expand upper-left corner to whole cell For y,yl,yh,2 For x,xl,xh,2 If pxl Test(y,x) Then Pxl On y+1,x Pxl On y+1,x+1 Pxl On y, x+1 Else Pxl Off y+1,x Pxl Off y+1,x+1 Pxl Off y, x+1 End If End For End For © Compute next generation For y,yl,yh,2 For x,xl,xh,2 nt(y-1,x-1) + nt(y-1,x) + nt(y-1,x+2) + nt(y,x-1) + nt(y+1,x+2) + nt(y+2,x-1) + nt(y+2,x+1) + nt(y+2,x+2) → count If count = 3 Then Pxl On y,x Else If count ≠ 2 Then Pxl Off y,x End If End For End For End While © Restore changed options set Graph("Axes", save[1]) set Graph("Grid", save[2]) set Graph("Labels", save[3])End Prgm Also see Conway's Game of Life/C Considering that the simplest implementation in C++ would lack any use of the object-oriented paradigm, this code was specifically written to demonstrate the various object-oriented features of C++.

;evaluate total ldy # ;for current cell cmp # ;3 = alive beq storex ldx #[[

randfill: stx $01 ;$200 for indirect ldx #$02 ;addressing stx $02randloop: lda $fe ;generate random and #$01 ;pixels on the sta ($01), Y ;screen jsr inc0103 cmp #$00 bne randloop lda $02 cmp #$06 bne randloop clearmem: lda #$df ;set $07df-$0a20 sta $01 ;to $#00 lda #$07 sta $02clearbyte: lda #$00 sta ($01), Y jsr inc0103 cmp #$20 bne clearbyte lda $02 cmp #$0a bne clearbyte starttick:copyscreen: lda #$00 ;set up source sta $01 ;pointer at sta $03 ;$01/$02 and lda #$02 ;dest pointer sta $02 ;at $03/$04 lda #$08 sta $04 ldy #$00copybyte: lda ($01), Y ;copy pixel to sta ($03), Y ;back buffer jsr inc0103 ;increment pointers cmp #$00 ;check to see bne copybyte ;if we're at $600 lda $02 ;if so, we've cmp #$06 ;copied the bne copybyte ;entire screen conway: lda #$df ;apply conway rules sta $01 ;reset the pointer sta $03 ;to $#01df/$#07df lda #$01 ;($200 - $21) sta $02 ;($800 - $21) lda #$07 sta $04onecell: lda #$00 ;process one cell ldy #$01 ;upper cell clc adc ($03), Y ldy #$41 ;lower cell clc adc ($03), Ychkleft: tax ;check to see lda $01 ;if we're at the and #$1f ;left edge tay txa cpy #$1f beq rightcellsleftcells: ldy #$00 ;upper-left cell clc adc ($03), Y ldy #$20 ;left cell clc adc ($03), Y ldy #$40 ;lower-left cell clc adc ($03), Ychkright: tax ;check to see lda $01 ;if we're at the and #$1f ;right edge tay txa cpy #$1e beq evaluaterightcells: ldy #$02 ;upper-right cell clc adc ($03), Y ldy #$22 ;right cell clc adc ($03), Y ldy #$42 ;lower-right cell clc adc ($03), Yevaluate: ldx #$01 ;evaluate total ldy #$21 ;for current cell cmp #$03 ;3 = alive beq storex ldx #$00 cmp #$02 ;2 = alive if bne storex ;c = alive lda ($03), Y and #$01 taxstorex: txa ;store to screen sta ($01), Y jsr inc0103 ;move to next cellconwayloop: cmp #$e0 ;if not last cell, bne onecell ;process next cell lda $02 cmp #$05 bne onecell jmp starttick ;run next tick inc0103: lda $01 ;increment $01 cmp #$ff ;and $03 as 16-bit bne onlyinc01 ;pointers inc $02 inc $04onlyinc01: inc $01 lda $01 sta $03 rts The solution uses one cell thick border around square Petri dish as uninhabited dire land. Sample output contains 3 generations of the blinker and 5 of the glider: See Conway's Game of Life/ALGOL 68 APL2 (Dialog) Example in one line APL \ 1130 example (very old APL dialect via simulator) APL1130From: APL \ 1130 Samples The following APL \ 1130 code will need APL385 font installed to display correctly. See Download APL TT Font ∇LIFE[⎕]∇[0] NG←LIFE CG; W[1] W←CG+(¯1⊖CG)+(1⊖CG)+(¯1⌽CG)+(1⌽CG)[2] W←W+(1⊖1⌽CG)+(¯1⊖1⌽CG)+(1⊖¯1⌽CG)+(¯1⊖¯1⌽CG)[3] NG←(3=W)+(CG∧4=W) ∇ RP←5 5⍴0 0 0 0 0 0 0 1 1 0 0 1 1 0 0 0 0 1 0 0 RP0 0 0 0 00 0 1 1 00 1 1 0 00 0 1 0 00 0 0 0 0 LIFE RP0 0 0 0 00 1 1 1 00 1 0 0 00 1 1 0 00 0 0 0 0 LIFE LIFE RP0 0 1 0 00 1 1 0 01 0 0 1 00 1 1 0 00 0 0 0 0 .................................................. One interacts with the Game of Life by creating an initial configuration and observing how it evolves. Although you should test your implementation on more complex examples such as the glider in a larger universe, show the action of the blinker (three adjoining cells in a row all alive), over three generations, in a 3 by 3 grid. (1,4)=TRUERETURN'' Count the number of neighbours of the point i,j' (Assume i/j +/- 1 will not fall out of world)'FUNCTION count_neighbours(i%,j%) LOCAL count%,l% count%=0 FOR l%=-1 TO 1 IF world! (i%+l%,j%+1) count%=count%+1 ENDIF NEXT l% IF world! (i%+1,j%) count%=count%+1 ENDIF RETURN count%ENDFUNC'' Update the world one step'PROCEDURE update_world LOCAL i%,j% ' compute neighbour counts and store FOR i%=1 TO 30 FOR j%=1 TO 30 ns%(i%,j%)[email protected]_neighbours(i%,j%) NEXT j% NEXT i% ' update the world cells FOR i%=1 TO 30 FOR j%=1 TO 30 IF world!

||

randfill: stx $01 ;$200 for indirect ldx #$02 ;addressing stx $02randloop: lda $fe ;generate random and #$01 ;pixels on the sta ($01), Y ;screen jsr inc0103 cmp #$00 bne randloop lda $02 cmp #$06 bne randloop clearmem: lda #$df ;set $07df-$0a20 sta $01 ;to $#00 lda #$07 sta $02clearbyte: lda #$00 sta ($01), Y jsr inc0103 cmp #$20 bne clearbyte lda $02 cmp #$0a bne clearbyte starttick:copyscreen: lda #$00 ;set up source sta $01 ;pointer at sta $03 ;$01/$02 and lda #$02 ;dest pointer sta $02 ;at $03/$04 lda #$08 sta $04 ldy #$00copybyte: lda ($01), Y ;copy pixel to sta ($03), Y ;back buffer jsr inc0103 ;increment pointers cmp #$00 ;check to see bne copybyte ;if we're at $600 lda $02 ;if so, we've cmp #$06 ;copied the bne copybyte ;entire screen conway: lda #$df ;apply conway rules sta $01 ;reset the pointer sta $03 ;to $#01df/$#07df lda #$01 ;($200 - $21) sta $02 ;($800 - $21) lda #$07 sta $04onecell: lda #$00 ;process one cell ldy #$01 ;upper cell clc adc ($03), Y ldy #$41 ;lower cell clc adc ($03), Ychkleft: tax ;check to see lda $01 ;if we're at the and #$1f ;left edge tay txa cpy #$1f beq rightcellsleftcells: ldy #$00 ;upper-left cell clc adc ($03), Y ldy #$20 ;left cell clc adc ($03), Y ldy #$40 ;lower-left cell clc adc ($03), Ychkright: tax ;check to see lda $01 ;if we're at the and #$1f ;right edge tay txa cpy #$1e beq evaluaterightcells: ldy #$02 ;upper-right cell clc adc ($03), Y ldy #$22 ;right cell clc adc ($03), Y ldy #$42 ;lower-right cell clc adc ($03), Yevaluate: ldx #$01 ;evaluate total ldy #$21 ;for current cell cmp #$03 ;3 = alive beq storex ldx #$00 cmp #$02 ;2 = alive if bne storex ;c = alive lda ($03), Y and #$01 taxstorex: txa ;store to screen sta ($01), Y jsr inc0103 ;move to next cellconwayloop: cmp #$e0 ;if not last cell, bne onecell ;process next cell lda $02 cmp #$05 bne onecell jmp starttick ;run next tick inc0103: lda $01 ;increment $01 cmp #$ff ;and $03 as 16-bit bne onlyinc01 ;pointers inc $02 inc $04onlyinc01: inc $01 lda $01 sta $03 rts The solution uses one cell thick border around square Petri dish as uninhabited dire land. Sample output contains 3 generations of the blinker and 5 of the glider: See Conway's Game of Life/ALGOL 68 APL2 (Dialog) Example in one line APL \ 1130 example (very old APL dialect via simulator) APL1130From: APL \ 1130 Samples The following APL \ 1130 code will need APL385 font installed to display correctly.

See Download APL TT Font ∇LIFE[⎕]∇[0] NG←LIFE CG; W[1] W←CG+(¯1⊖CG)+(1⊖CG)+(¯1⌽CG)+(1⌽CG)[2] W←W+(1⊖1⌽CG)+(¯1⊖1⌽CG)+(1⊖¯1⌽CG)+(¯1⊖¯1⌽CG)[3] NG←(3=W)+(CG∧4=W) ∇ RP←5 5⍴0 0 0 0 0 0 0 1 1 0 0 1 1 0 0 0 0 1 0 0 RP0 0 0 0 00 0 1 1 00 1 1 0 00 0 1 0 00 0 0 0 0 LIFE RP0 0 0 0 00 1 1 1 00 1 0 0 00 1 1 0 00 0 0 0 0 LIFE LIFE RP0 0 1 0 00 1 1 0 01 0 0 1 00 1 1 0 00 0 0 0 0 ..................................................

One interacts with the Game of Life by creating an initial configuration and observing how it evolves.

Although you should test your implementation on more complex examples such as the glider in a larger universe, show the action of the blinker (three adjoining cells in a row all alive), over three generations, in a 3 by 3 grid.

(1,4)=TRUERETURN'' Count the number of neighbours of the point i,j' (Assume i/j +/- 1 will not fall out of world)'FUNCTION count_neighbours(i%,j%) LOCAL count%,l% count%=0 FOR l%=-1 TO 1 IF world! (i%+l%,j%+1) count%=count%+1 ENDIF NEXT l% IF world! (i%+1,j%) count%=count%+1 ENDIF RETURN count%ENDFUNC'' Update the world one step'PROCEDURE update_world LOCAL i%,j% ' compute neighbour counts and store FOR i%=1 TO 30 FOR j%=1 TO 30 ns%(i%,j%)[email protected]_neighbours(i%,j%) NEXT j% NEXT i% ' update the world cells FOR i%=1 TO 30 FOR j%=1 TO 30 IF world!

Thus, while it is somewhat verbose, it fully simulates Conway's Game of Life and is relatively simple to expand to feature different starting shapes.

Define life(pattern) = Prgm Local x,y,nt,count,save,xl,yl,xh,yh Define nt(y,x) = when(pxl Test(y,x), 1, 0) {}→save set Graph("Axes", "Off")→save[1] set Graph("Grid", "Off")→save[2] set Graph("Labels", "Off")→save[3] Fn Off Plot Off Clr Draw If pattern = "blinker" Then 36→yl 40→yh 78→xl 82→xh Pxl On 36,80 Pxl On 38,80 Pxl On 40,80 Else If pattern = "glider" Then 30→yl 40→yh 76→xl 88→xh Pxl On 38,76 Pxl On 36,78 Pxl On 36,80 Pxl On 38,80 Pxl On 40,80 Else If pattern = "r" Then 38-5*2→yl 38+5*2→yh 80-5*2→xl 80+5*2→xh Pxl On 38,78 Pxl On 36,82 Pxl On 36,80 Pxl On 38,80 Pxl On 40,80 End If While get Key() = 0 © Expand upper-left corner to whole cell For y,yl,yh,2 For x,xl,xh,2 If pxl Test(y,x) Then Pxl On y+1,x Pxl On y+1,x+1 Pxl On y, x+1 Else Pxl Off y+1,x Pxl Off y+1,x+1 Pxl Off y, x+1 End If End For End For © Compute next generation For y,yl,yh,2 For x,xl,xh,2 nt(y-1,x-1) + nt(y-1,x) + nt(y-1,x+2) + nt(y,x-1) + nt(y+1,x+2) + nt(y+2,x-1) + nt(y+2,x+1) + nt(y+2,x+2) → count If count = 3 Then Pxl On y,x Else If count ≠ 2 Then Pxl Off y,x End If End For End For End While © Restore changed options set Graph("Axes", save[1]) set Graph("Grid", save[2]) set Graph("Labels", save[3])End Prgm Also see Conway's Game of Life/C Considering that the simplest implementation in C++ would lack any use of the object-oriented paradigm, this code was specifically written to demonstrate the various object-oriented features of C++.

]] cmp # ;2 = alive if bne storex ;c = alive lda (), Y and #

randfill: stx $01 ;$200 for indirect ldx #$02 ;addressing stx $02randloop: lda $fe ;generate random and #$01 ;pixels on the sta ($01), Y ;screen jsr inc0103 cmp #$00 bne randloop lda $02 cmp #$06 bne randloop clearmem: lda #$df ;set $07df-$0a20 sta $01 ;to $#00 lda #$07 sta $02clearbyte: lda #$00 sta ($01), Y jsr inc0103 cmp #$20 bne clearbyte lda $02 cmp #$0a bne clearbyte starttick:copyscreen: lda #$00 ;set up source sta $01 ;pointer at sta $03 ;$01/$02 and lda #$02 ;dest pointer sta $02 ;at $03/$04 lda #$08 sta $04 ldy #$00copybyte: lda ($01), Y ;copy pixel to sta ($03), Y ;back buffer jsr inc0103 ;increment pointers cmp #$00 ;check to see bne copybyte ;if we're at $600 lda $02 ;if so, we've cmp #$06 ;copied the bne copybyte ;entire screen conway: lda #$df ;apply conway rules sta $01 ;reset the pointer sta $03 ;to $#01df/$#07df lda #$01 ;($200 - $21) sta $02 ;($800 - $21) lda #$07 sta $04onecell: lda #$00 ;process one cell ldy #$01 ;upper cell clc adc ($03), Y ldy #$41 ;lower cell clc adc ($03), Ychkleft: tax ;check to see lda $01 ;if we're at the and #$1f ;left edge tay txa cpy #$1f beq rightcellsleftcells: ldy #$00 ;upper-left cell clc adc ($03), Y ldy #$20 ;left cell clc adc ($03), Y ldy #$40 ;lower-left cell clc adc ($03), Ychkright: tax ;check to see lda $01 ;if we're at the and #$1f ;right edge tay txa cpy #$1e beq evaluaterightcells: ldy #$02 ;upper-right cell clc adc ($03), Y ldy #$22 ;right cell clc adc ($03), Y ldy #$42 ;lower-right cell clc adc ($03), Yevaluate: ldx #$01 ;evaluate total ldy #$21 ;for current cell cmp #$03 ;3 = alive beq storex ldx #$00 cmp #$02 ;2 = alive if bne storex ;c = alive lda ($03), Y and #$01 taxstorex: txa ;store to screen sta ($01), Y jsr inc0103 ;move to next cellconwayloop: cmp #$e0 ;if not last cell, bne onecell ;process next cell lda $02 cmp #$05 bne onecell jmp starttick ;run next tick inc0103: lda $01 ;increment $01 cmp #$ff ;and $03 as 16-bit bne onlyinc01 ;pointers inc $02 inc $04onlyinc01: inc $01 lda $01 sta $03 rts The solution uses one cell thick border around square Petri dish as uninhabited dire land. Sample output contains 3 generations of the blinker and 5 of the glider: See Conway's Game of Life/ALGOL 68 APL2 (Dialog) Example in one line APL \ 1130 example (very old APL dialect via simulator) APL1130From: APL \ 1130 Samples The following APL \ 1130 code will need APL385 font installed to display correctly. See Download APL TT Font ∇LIFE[⎕]∇[0] NG←LIFE CG; W[1] W←CG+(¯1⊖CG)+(1⊖CG)+(¯1⌽CG)+(1⌽CG)[2] W←W+(1⊖1⌽CG)+(¯1⊖1⌽CG)+(1⊖¯1⌽CG)+(¯1⊖¯1⌽CG)[3] NG←(3=W)+(CG∧4=W) ∇ RP←5 5⍴0 0 0 0 0 0 0 1 1 0 0 1 1 0 0 0 0 1 0 0 RP0 0 0 0 00 0 1 1 00 1 1 0 00 0 1 0 00 0 0 0 0 LIFE RP0 0 0 0 00 1 1 1 00 1 0 0 00 1 1 0 00 0 0 0 0 LIFE LIFE RP0 0 1 0 00 1 1 0 01 0 0 1 00 1 1 0 00 0 0 0 0 .................................................. One interacts with the Game of Life by creating an initial configuration and observing how it evolves. Although you should test your implementation on more complex examples such as the glider in a larger universe, show the action of the blinker (three adjoining cells in a row all alive), over three generations, in a 3 by 3 grid. (1,4)=TRUERETURN'' Count the number of neighbours of the point i,j' (Assume i/j +/- 1 will not fall out of world)'FUNCTION count_neighbours(i%,j%) LOCAL count%,l% count%=0 FOR l%=-1 TO 1 IF world! (i%+l%,j%+1) count%=count%+1 ENDIF NEXT l% IF world! (i%+1,j%) count%=count%+1 ENDIF RETURN count%ENDFUNC'' Update the world one step'PROCEDURE update_world LOCAL i%,j% ' compute neighbour counts and store FOR i%=1 TO 30 FOR j%=1 TO 30 ns%(i%,j%)[email protected]_neighbours(i%,j%) NEXT j% NEXT i% ' update the world cells FOR i%=1 TO 30 FOR j%=1 TO 30 IF world!

||

randfill: stx $01 ;$200 for indirect ldx #$02 ;addressing stx $02randloop: lda $fe ;generate random and #$01 ;pixels on the sta ($01), Y ;screen jsr inc0103 cmp #$00 bne randloop lda $02 cmp #$06 bne randloop clearmem: lda #$df ;set $07df-$0a20 sta $01 ;to $#00 lda #$07 sta $02clearbyte: lda #$00 sta ($01), Y jsr inc0103 cmp #$20 bne clearbyte lda $02 cmp #$0a bne clearbyte starttick:copyscreen: lda #$00 ;set up source sta $01 ;pointer at sta $03 ;$01/$02 and lda #$02 ;dest pointer sta $02 ;at $03/$04 lda #$08 sta $04 ldy #$00copybyte: lda ($01), Y ;copy pixel to sta ($03), Y ;back buffer jsr inc0103 ;increment pointers cmp #$00 ;check to see bne copybyte ;if we're at $600 lda $02 ;if so, we've cmp #$06 ;copied the bne copybyte ;entire screen conway: lda #$df ;apply conway rules sta $01 ;reset the pointer sta $03 ;to $#01df/$#07df lda #$01 ;($200 - $21) sta $02 ;($800 - $21) lda #$07 sta $04onecell: lda #$00 ;process one cell ldy #$01 ;upper cell clc adc ($03), Y ldy #$41 ;lower cell clc adc ($03), Ychkleft: tax ;check to see lda $01 ;if we're at the and #$1f ;left edge tay txa cpy #$1f beq rightcellsleftcells: ldy #$00 ;upper-left cell clc adc ($03), Y ldy #$20 ;left cell clc adc ($03), Y ldy #$40 ;lower-left cell clc adc ($03), Ychkright: tax ;check to see lda $01 ;if we're at the and #$1f ;right edge tay txa cpy #$1e beq evaluaterightcells: ldy #$02 ;upper-right cell clc adc ($03), Y ldy #$22 ;right cell clc adc ($03), Y ldy #$42 ;lower-right cell clc adc ($03), Yevaluate: ldx #$01 ;evaluate total ldy #$21 ;for current cell cmp #$03 ;3 = alive beq storex ldx #$00 cmp #$02 ;2 = alive if bne storex ;c = alive lda ($03), Y and #$01 taxstorex: txa ;store to screen sta ($01), Y jsr inc0103 ;move to next cellconwayloop: cmp #$e0 ;if not last cell, bne onecell ;process next cell lda $02 cmp #$05 bne onecell jmp starttick ;run next tick inc0103: lda $01 ;increment $01 cmp #$ff ;and $03 as 16-bit bne onlyinc01 ;pointers inc $02 inc $04onlyinc01: inc $01 lda $01 sta $03 rts The solution uses one cell thick border around square Petri dish as uninhabited dire land. Sample output contains 3 generations of the blinker and 5 of the glider: See Conway's Game of Life/ALGOL 68 APL2 (Dialog) Example in one line APL \ 1130 example (very old APL dialect via simulator) APL1130From: APL \ 1130 Samples The following APL \ 1130 code will need APL385 font installed to display correctly.

See Download APL TT Font ∇LIFE[⎕]∇[0] NG←LIFE CG; W[1] W←CG+(¯1⊖CG)+(1⊖CG)+(¯1⌽CG)+(1⌽CG)[2] W←W+(1⊖1⌽CG)+(¯1⊖1⌽CG)+(1⊖¯1⌽CG)+(¯1⊖¯1⌽CG)[3] NG←(3=W)+(CG∧4=W) ∇ RP←5 5⍴0 0 0 0 0 0 0 1 1 0 0 1 1 0 0 0 0 1 0 0 RP0 0 0 0 00 0 1 1 00 1 1 0 00 0 1 0 00 0 0 0 0 LIFE RP0 0 0 0 00 1 1 1 00 1 0 0 00 1 1 0 00 0 0 0 0 LIFE LIFE RP0 0 1 0 00 1 1 0 01 0 0 1 00 1 1 0 00 0 0 0 0 ..................................................

One interacts with the Game of Life by creating an initial configuration and observing how it evolves.

Although you should test your implementation on more complex examples such as the glider in a larger universe, show the action of the blinker (three adjoining cells in a row all alive), over three generations, in a 3 by 3 grid.

(1,4)=TRUERETURN'' Count the number of neighbours of the point i,j' (Assume i/j +/- 1 will not fall out of world)'FUNCTION count_neighbours(i%,j%) LOCAL count%,l% count%=0 FOR l%=-1 TO 1 IF world! (i%+l%,j%+1) count%=count%+1 ENDIF NEXT l% IF world! (i%+1,j%) count%=count%+1 ENDIF RETURN count%ENDFUNC'' Update the world one step'PROCEDURE update_world LOCAL i%,j% ' compute neighbour counts and store FOR i%=1 TO 30 FOR j%=1 TO 30 ns%(i%,j%)[email protected]_neighbours(i%,j%) NEXT j% NEXT i% ' update the world cells FOR i%=1 TO 30 FOR j%=1 TO 30 IF world!

Thus, while it is somewhat verbose, it fully simulates Conway's Game of Life and is relatively simple to expand to feature different starting shapes.

Define life(pattern) = Prgm Local x,y,nt,count,save,xl,yl,xh,yh Define nt(y,x) = when(pxl Test(y,x), 1, 0) {}→save set Graph("Axes", "Off")→save[1] set Graph("Grid", "Off")→save[2] set Graph("Labels", "Off")→save[3] Fn Off Plot Off Clr Draw If pattern = "blinker" Then 36→yl 40→yh 78→xl 82→xh Pxl On 36,80 Pxl On 38,80 Pxl On 40,80 Else If pattern = "glider" Then 30→yl 40→yh 76→xl 88→xh Pxl On 38,76 Pxl On 36,78 Pxl On 36,80 Pxl On 38,80 Pxl On 40,80 Else If pattern = "r" Then 38-5*2→yl 38+5*2→yh 80-5*2→xl 80+5*2→xh Pxl On 38,78 Pxl On 36,82 Pxl On 36,80 Pxl On 38,80 Pxl On 40,80 End If While get Key() = 0 © Expand upper-left corner to whole cell For y,yl,yh,2 For x,xl,xh,2 If pxl Test(y,x) Then Pxl On y+1,x Pxl On y+1,x+1 Pxl On y, x+1 Else Pxl Off y+1,x Pxl Off y+1,x+1 Pxl Off y, x+1 End If End For End For © Compute next generation For y,yl,yh,2 For x,xl,xh,2 nt(y-1,x-1) + nt(y-1,x) + nt(y-1,x+2) + nt(y,x-1) + nt(y+1,x+2) + nt(y+2,x-1) + nt(y+2,x+1) + nt(y+2,x+2) → count If count = 3 Then Pxl On y,x Else If count ≠ 2 Then Pxl Off y,x End If End For End For End While © Restore changed options set Graph("Axes", save[1]) set Graph("Grid", save[2]) set Graph("Labels", save[3])End Prgm Also see Conway's Game of Life/C Considering that the simplest implementation in C++ would lack any use of the object-oriented paradigm, this code was specifically written to demonstrate the various object-oriented features of C++.

taxstorex: txa ;store to screen sta (

randfill: stx $01 ;$200 for indirect ldx #$02 ;addressing stx $02randloop: lda $fe ;generate random and #$01 ;pixels on the sta ($01), Y ;screen jsr inc0103 cmp #$00 bne randloop lda $02 cmp #$06 bne randloop clearmem: lda #$df ;set $07df-$0a20 sta $01 ;to $#00 lda #$07 sta $02clearbyte: lda #$00 sta ($01), Y jsr inc0103 cmp #$20 bne clearbyte lda $02 cmp #$0a bne clearbyte starttick:copyscreen: lda #$00 ;set up source sta $01 ;pointer at sta $03 ;$01/$02 and lda #$02 ;dest pointer sta $02 ;at $03/$04 lda #$08 sta $04 ldy #$00copybyte: lda ($01), Y ;copy pixel to sta ($03), Y ;back buffer jsr inc0103 ;increment pointers cmp #$00 ;check to see bne copybyte ;if we're at $600 lda $02 ;if so, we've cmp #$06 ;copied the bne copybyte ;entire screen conway: lda #$df ;apply conway rules sta $01 ;reset the pointer sta $03 ;to $#01df/$#07df lda #$01 ;($200 - $21) sta $02 ;($800 - $21) lda #$07 sta $04onecell: lda #$00 ;process one cell ldy #$01 ;upper cell clc adc ($03), Y ldy #$41 ;lower cell clc adc ($03), Ychkleft: tax ;check to see lda $01 ;if we're at the and #$1f ;left edge tay txa cpy #$1f beq rightcellsleftcells: ldy #$00 ;upper-left cell clc adc ($03), Y ldy #$20 ;left cell clc adc ($03), Y ldy #$40 ;lower-left cell clc adc ($03), Ychkright: tax ;check to see lda $01 ;if we're at the and #$1f ;right edge tay txa cpy #$1e beq evaluaterightcells: ldy #$02 ;upper-right cell clc adc ($03), Y ldy #$22 ;right cell clc adc ($03), Y ldy #$42 ;lower-right cell clc adc ($03), Yevaluate: ldx #$01 ;evaluate total ldy #$21 ;for current cell cmp #$03 ;3 = alive beq storex ldx #$00 cmp #$02 ;2 = alive if bne storex ;c = alive lda ($03), Y and #$01 taxstorex: txa ;store to screen sta ($01), Y jsr inc0103 ;move to next cellconwayloop: cmp #$e0 ;if not last cell, bne onecell ;process next cell lda $02 cmp #$05 bne onecell jmp starttick ;run next tick inc0103: lda $01 ;increment $01 cmp #$ff ;and $03 as 16-bit bne onlyinc01 ;pointers inc $02 inc $04onlyinc01: inc $01 lda $01 sta $03 rts The solution uses one cell thick border around square Petri dish as uninhabited dire land. Sample output contains 3 generations of the blinker and 5 of the glider: See Conway's Game of Life/ALGOL 68 APL2 (Dialog) Example in one line APL \ 1130 example (very old APL dialect via simulator) APL1130From: APL \ 1130 Samples The following APL \ 1130 code will need APL385 font installed to display correctly. See Download APL TT Font ∇LIFE[⎕]∇[0] NG←LIFE CG; W[1] W←CG+(¯1⊖CG)+(1⊖CG)+(¯1⌽CG)+(1⌽CG)[2] W←W+(1⊖1⌽CG)+(¯1⊖1⌽CG)+(1⊖¯1⌽CG)+(¯1⊖¯1⌽CG)[3] NG←(3=W)+(CG∧4=W) ∇ RP←5 5⍴0 0 0 0 0 0 0 1 1 0 0 1 1 0 0 0 0 1 0 0 RP0 0 0 0 00 0 1 1 00 1 1 0 00 0 1 0 00 0 0 0 0 LIFE RP0 0 0 0 00 1 1 1 00 1 0 0 00 1 1 0 00 0 0 0 0 LIFE LIFE RP0 0 1 0 00 1 1 0 01 0 0 1 00 1 1 0 00 0 0 0 0 .................................................. One interacts with the Game of Life by creating an initial configuration and observing how it evolves. Although you should test your implementation on more complex examples such as the glider in a larger universe, show the action of the blinker (three adjoining cells in a row all alive), over three generations, in a 3 by 3 grid. (1,4)=TRUERETURN'' Count the number of neighbours of the point i,j' (Assume i/j +/- 1 will not fall out of world)'FUNCTION count_neighbours(i%,j%) LOCAL count%,l% count%=0 FOR l%=-1 TO 1 IF world! (i%+l%,j%+1) count%=count%+1 ENDIF NEXT l% IF world! (i%+1,j%) count%=count%+1 ENDIF RETURN count%ENDFUNC'' Update the world one step'PROCEDURE update_world LOCAL i%,j% ' compute neighbour counts and store FOR i%=1 TO 30 FOR j%=1 TO 30 ns%(i%,j%)[email protected]_neighbours(i%,j%) NEXT j% NEXT i% ' update the world cells FOR i%=1 TO 30 FOR j%=1 TO 30 IF world!

||

randfill: stx $01 ;$200 for indirect ldx #$02 ;addressing stx $02randloop: lda $fe ;generate random and #$01 ;pixels on the sta ($01), Y ;screen jsr inc0103 cmp #$00 bne randloop lda $02 cmp #$06 bne randloop clearmem: lda #$df ;set $07df-$0a20 sta $01 ;to $#00 lda #$07 sta $02clearbyte: lda #$00 sta ($01), Y jsr inc0103 cmp #$20 bne clearbyte lda $02 cmp #$0a bne clearbyte starttick:copyscreen: lda #$00 ;set up source sta $01 ;pointer at sta $03 ;$01/$02 and lda #$02 ;dest pointer sta $02 ;at $03/$04 lda #$08 sta $04 ldy #$00copybyte: lda ($01), Y ;copy pixel to sta ($03), Y ;back buffer jsr inc0103 ;increment pointers cmp #$00 ;check to see bne copybyte ;if we're at $600 lda $02 ;if so, we've cmp #$06 ;copied the bne copybyte ;entire screen conway: lda #$df ;apply conway rules sta $01 ;reset the pointer sta $03 ;to $#01df/$#07df lda #$01 ;($200 - $21) sta $02 ;($800 - $21) lda #$07 sta $04onecell: lda #$00 ;process one cell ldy #$01 ;upper cell clc adc ($03), Y ldy #$41 ;lower cell clc adc ($03), Ychkleft: tax ;check to see lda $01 ;if we're at the and #$1f ;left edge tay txa cpy #$1f beq rightcellsleftcells: ldy #$00 ;upper-left cell clc adc ($03), Y ldy #$20 ;left cell clc adc ($03), Y ldy #$40 ;lower-left cell clc adc ($03), Ychkright: tax ;check to see lda $01 ;if we're at the and #$1f ;right edge tay txa cpy #$1e beq evaluaterightcells: ldy #$02 ;upper-right cell clc adc ($03), Y ldy #$22 ;right cell clc adc ($03), Y ldy #$42 ;lower-right cell clc adc ($03), Yevaluate: ldx #$01 ;evaluate total ldy #$21 ;for current cell cmp #$03 ;3 = alive beq storex ldx #$00 cmp #$02 ;2 = alive if bne storex ;c = alive lda ($03), Y and #$01 taxstorex: txa ;store to screen sta ($01), Y jsr inc0103 ;move to next cellconwayloop: cmp #$e0 ;if not last cell, bne onecell ;process next cell lda $02 cmp #$05 bne onecell jmp starttick ;run next tick inc0103: lda $01 ;increment $01 cmp #$ff ;and $03 as 16-bit bne onlyinc01 ;pointers inc $02 inc $04onlyinc01: inc $01 lda $01 sta $03 rts The solution uses one cell thick border around square Petri dish as uninhabited dire land. Sample output contains 3 generations of the blinker and 5 of the glider: See Conway's Game of Life/ALGOL 68 APL2 (Dialog) Example in one line APL \ 1130 example (very old APL dialect via simulator) APL1130From: APL \ 1130 Samples The following APL \ 1130 code will need APL385 font installed to display correctly.

See Download APL TT Font ∇LIFE[⎕]∇[0] NG←LIFE CG; W[1] W←CG+(¯1⊖CG)+(1⊖CG)+(¯1⌽CG)+(1⌽CG)[2] W←W+(1⊖1⌽CG)+(¯1⊖1⌽CG)+(1⊖¯1⌽CG)+(¯1⊖¯1⌽CG)[3] NG←(3=W)+(CG∧4=W) ∇ RP←5 5⍴0 0 0 0 0 0 0 1 1 0 0 1 1 0 0 0 0 1 0 0 RP0 0 0 0 00 0 1 1 00 1 1 0 00 0 1 0 00 0 0 0 0 LIFE RP0 0 0 0 00 1 1 1 00 1 0 0 00 1 1 0 00 0 0 0 0 LIFE LIFE RP0 0 1 0 00 1 1 0 01 0 0 1 00 1 1 0 00 0 0 0 0 ..................................................

One interacts with the Game of Life by creating an initial configuration and observing how it evolves.

Although you should test your implementation on more complex examples such as the glider in a larger universe, show the action of the blinker (three adjoining cells in a row all alive), over three generations, in a 3 by 3 grid.

(1,4)=TRUERETURN'' Count the number of neighbours of the point i,j' (Assume i/j +/- 1 will not fall out of world)'FUNCTION count_neighbours(i%,j%) LOCAL count%,l% count%=0 FOR l%=-1 TO 1 IF world! (i%+l%,j%+1) count%=count%+1 ENDIF NEXT l% IF world! (i%+1,j%) count%=count%+1 ENDIF RETURN count%ENDFUNC'' Update the world one step'PROCEDURE update_world LOCAL i%,j% ' compute neighbour counts and store FOR i%=1 TO 30 FOR j%=1 TO 30 ns%(i%,j%)[email protected]_neighbours(i%,j%) NEXT j% NEXT i% ' update the world cells FOR i%=1 TO 30 FOR j%=1 TO 30 IF world!

Thus, while it is somewhat verbose, it fully simulates Conway's Game of Life and is relatively simple to expand to feature different starting shapes.

Define life(pattern) = Prgm Local x,y,nt,count,save,xl,yl,xh,yh Define nt(y,x) = when(pxl Test(y,x), 1, 0) {}→save set Graph("Axes", "Off")→save[1] set Graph("Grid", "Off")→save[2] set Graph("Labels", "Off")→save[3] Fn Off Plot Off Clr Draw If pattern = "blinker" Then 36→yl 40→yh 78→xl 82→xh Pxl On 36,80 Pxl On 38,80 Pxl On 40,80 Else If pattern = "glider" Then 30→yl 40→yh 76→xl 88→xh Pxl On 38,76 Pxl On 36,78 Pxl On 36,80 Pxl On 38,80 Pxl On 40,80 Else If pattern = "r" Then 38-5*2→yl 38+5*2→yh 80-5*2→xl 80+5*2→xh Pxl On 38,78 Pxl On 36,82 Pxl On 36,80 Pxl On 38,80 Pxl On 40,80 End If While get Key() = 0 © Expand upper-left corner to whole cell For y,yl,yh,2 For x,xl,xh,2 If pxl Test(y,x) Then Pxl On y+1,x Pxl On y+1,x+1 Pxl On y, x+1 Else Pxl Off y+1,x Pxl Off y+1,x+1 Pxl Off y, x+1 End If End For End For © Compute next generation For y,yl,yh,2 For x,xl,xh,2 nt(y-1,x-1) + nt(y-1,x) + nt(y-1,x+2) + nt(y,x-1) + nt(y+1,x+2) + nt(y+2,x-1) + nt(y+2,x+1) + nt(y+2,x+2) → count If count = 3 Then Pxl On y,x Else If count ≠ 2 Then Pxl Off y,x End If End For End For End While © Restore changed options set Graph("Axes", save[1]) set Graph("Grid", save[2]) set Graph("Labels", save[3])End Prgm Also see Conway's Game of Life/C Considering that the simplest implementation in C++ would lack any use of the object-oriented paradigm, this code was specifically written to demonstrate the various object-oriented features of C++.

), Y jsr inc0103 ;move to next cellconwayloop: cmp #$e0 ;if not last cell, bne onecell ;process next cell lda cmp # bne onecell jmp starttick ;run next tick inc0103: lda

randfill: stx $01 ;$200 for indirect ldx #$02 ;addressing stx $02randloop: lda $fe ;generate random and #$01 ;pixels on the sta ($01), Y ;screen jsr inc0103 cmp #$00 bne randloop lda $02 cmp #$06 bne randloop clearmem: lda #$df ;set $07df-$0a20 sta $01 ;to $#00 lda #$07 sta $02clearbyte: lda #$00 sta ($01), Y jsr inc0103 cmp #$20 bne clearbyte lda $02 cmp #$0a bne clearbyte starttick:copyscreen: lda #$00 ;set up source sta $01 ;pointer at sta $03 ;$01/$02 and lda #$02 ;dest pointer sta $02 ;at $03/$04 lda #$08 sta $04 ldy #$00copybyte: lda ($01), Y ;copy pixel to sta ($03), Y ;back buffer jsr inc0103 ;increment pointers cmp #$00 ;check to see bne copybyte ;if we're at $600 lda $02 ;if so, we've cmp #$06 ;copied the bne copybyte ;entire screen conway: lda #$df ;apply conway rules sta $01 ;reset the pointer sta $03 ;to $#01df/$#07df lda #$01 ;($200 - $21) sta $02 ;($800 - $21) lda #$07 sta $04onecell: lda #$00 ;process one cell ldy #$01 ;upper cell clc adc ($03), Y ldy #$41 ;lower cell clc adc ($03), Ychkleft: tax ;check to see lda $01 ;if we're at the and #$1f ;left edge tay txa cpy #$1f beq rightcellsleftcells: ldy #$00 ;upper-left cell clc adc ($03), Y ldy #$20 ;left cell clc adc ($03), Y ldy #$40 ;lower-left cell clc adc ($03), Ychkright: tax ;check to see lda $01 ;if we're at the and #$1f ;right edge tay txa cpy #$1e beq evaluaterightcells: ldy #$02 ;upper-right cell clc adc ($03), Y ldy #$22 ;right cell clc adc ($03), Y ldy #$42 ;lower-right cell clc adc ($03), Yevaluate: ldx #$01 ;evaluate total ldy #$21 ;for current cell cmp #$03 ;3 = alive beq storex ldx #$00 cmp #$02 ;2 = alive if bne storex ;c = alive lda ($03), Y and #$01 taxstorex: txa ;store to screen sta ($01), Y jsr inc0103 ;move to next cellconwayloop: cmp #$e0 ;if not last cell, bne onecell ;process next cell lda $02 cmp #$05 bne onecell jmp starttick ;run next tick inc0103: lda $01 ;increment $01 cmp #$ff ;and $03 as 16-bit bne onlyinc01 ;pointers inc $02 inc $04onlyinc01: inc $01 lda $01 sta $03 rts The solution uses one cell thick border around square Petri dish as uninhabited dire land. Sample output contains 3 generations of the blinker and 5 of the glider: See Conway's Game of Life/ALGOL 68 APL2 (Dialog) Example in one line APL \ 1130 example (very old APL dialect via simulator) APL1130From: APL \ 1130 Samples The following APL \ 1130 code will need APL385 font installed to display correctly. See Download APL TT Font ∇LIFE[⎕]∇[0] NG←LIFE CG; W[1] W←CG+(¯1⊖CG)+(1⊖CG)+(¯1⌽CG)+(1⌽CG)[2] W←W+(1⊖1⌽CG)+(¯1⊖1⌽CG)+(1⊖¯1⌽CG)+(¯1⊖¯1⌽CG)[3] NG←(3=W)+(CG∧4=W) ∇ RP←5 5⍴0 0 0 0 0 0 0 1 1 0 0 1 1 0 0 0 0 1 0 0 RP0 0 0 0 00 0 1 1 00 1 1 0 00 0 1 0 00 0 0 0 0 LIFE RP0 0 0 0 00 1 1 1 00 1 0 0 00 1 1 0 00 0 0 0 0 LIFE LIFE RP0 0 1 0 00 1 1 0 01 0 0 1 00 1 1 0 00 0 0 0 0 .................................................. One interacts with the Game of Life by creating an initial configuration and observing how it evolves. Although you should test your implementation on more complex examples such as the glider in a larger universe, show the action of the blinker (three adjoining cells in a row all alive), over three generations, in a 3 by 3 grid. (1,4)=TRUERETURN'' Count the number of neighbours of the point i,j' (Assume i/j +/- 1 will not fall out of world)'FUNCTION count_neighbours(i%,j%) LOCAL count%,l% count%=0 FOR l%=-1 TO 1 IF world! (i%+l%,j%+1) count%=count%+1 ENDIF NEXT l% IF world! (i%+1,j%) count%=count%+1 ENDIF RETURN count%ENDFUNC'' Update the world one step'PROCEDURE update_world LOCAL i%,j% ' compute neighbour counts and store FOR i%=1 TO 30 FOR j%=1 TO 30 ns%(i%,j%)[email protected]_neighbours(i%,j%) NEXT j% NEXT i% ' update the world cells FOR i%=1 TO 30 FOR j%=1 TO 30 IF world!

||

randfill: stx $01 ;$200 for indirect ldx #$02 ;addressing stx $02randloop: lda $fe ;generate random and #$01 ;pixels on the sta ($01), Y ;screen jsr inc0103 cmp #$00 bne randloop lda $02 cmp #$06 bne randloop clearmem: lda #$df ;set $07df-$0a20 sta $01 ;to $#00 lda #$07 sta $02clearbyte: lda #$00 sta ($01), Y jsr inc0103 cmp #$20 bne clearbyte lda $02 cmp #$0a bne clearbyte starttick:copyscreen: lda #$00 ;set up source sta $01 ;pointer at sta $03 ;$01/$02 and lda #$02 ;dest pointer sta $02 ;at $03/$04 lda #$08 sta $04 ldy #$00copybyte: lda ($01), Y ;copy pixel to sta ($03), Y ;back buffer jsr inc0103 ;increment pointers cmp #$00 ;check to see bne copybyte ;if we're at $600 lda $02 ;if so, we've cmp #$06 ;copied the bne copybyte ;entire screen conway: lda #$df ;apply conway rules sta $01 ;reset the pointer sta $03 ;to $#01df/$#07df lda #$01 ;($200 - $21) sta $02 ;($800 - $21) lda #$07 sta $04onecell: lda #$00 ;process one cell ldy #$01 ;upper cell clc adc ($03), Y ldy #$41 ;lower cell clc adc ($03), Ychkleft: tax ;check to see lda $01 ;if we're at the and #$1f ;left edge tay txa cpy #$1f beq rightcellsleftcells: ldy #$00 ;upper-left cell clc adc ($03), Y ldy #$20 ;left cell clc adc ($03), Y ldy #$40 ;lower-left cell clc adc ($03), Ychkright: tax ;check to see lda $01 ;if we're at the and #$1f ;right edge tay txa cpy #$1e beq evaluaterightcells: ldy #$02 ;upper-right cell clc adc ($03), Y ldy #$22 ;right cell clc adc ($03), Y ldy #$42 ;lower-right cell clc adc ($03), Yevaluate: ldx #$01 ;evaluate total ldy #$21 ;for current cell cmp #$03 ;3 = alive beq storex ldx #$00 cmp #$02 ;2 = alive if bne storex ;c = alive lda ($03), Y and #$01 taxstorex: txa ;store to screen sta ($01), Y jsr inc0103 ;move to next cellconwayloop: cmp #$e0 ;if not last cell, bne onecell ;process next cell lda $02 cmp #$05 bne onecell jmp starttick ;run next tick inc0103: lda $01 ;increment $01 cmp #$ff ;and $03 as 16-bit bne onlyinc01 ;pointers inc $02 inc $04onlyinc01: inc $01 lda $01 sta $03 rts The solution uses one cell thick border around square Petri dish as uninhabited dire land. Sample output contains 3 generations of the blinker and 5 of the glider: See Conway's Game of Life/ALGOL 68 APL2 (Dialog) Example in one line APL \ 1130 example (very old APL dialect via simulator) APL1130From: APL \ 1130 Samples The following APL \ 1130 code will need APL385 font installed to display correctly.

See Download APL TT Font ∇LIFE[⎕]∇[0] NG←LIFE CG; W[1] W←CG+(¯1⊖CG)+(1⊖CG)+(¯1⌽CG)+(1⌽CG)[2] W←W+(1⊖1⌽CG)+(¯1⊖1⌽CG)+(1⊖¯1⌽CG)+(¯1⊖¯1⌽CG)[3] NG←(3=W)+(CG∧4=W) ∇ RP←5 5⍴0 0 0 0 0 0 0 1 1 0 0 1 1 0 0 0 0 1 0 0 RP0 0 0 0 00 0 1 1 00 1 1 0 00 0 1 0 00 0 0 0 0 LIFE RP0 0 0 0 00 1 1 1 00 1 0 0 00 1 1 0 00 0 0 0 0 LIFE LIFE RP0 0 1 0 00 1 1 0 01 0 0 1 00 1 1 0 00 0 0 0 0 ..................................................

One interacts with the Game of Life by creating an initial configuration and observing how it evolves.

Although you should test your implementation on more complex examples such as the glider in a larger universe, show the action of the blinker (three adjoining cells in a row all alive), over three generations, in a 3 by 3 grid.

(1,4)=TRUERETURN'' Count the number of neighbours of the point i,j' (Assume i/j +/- 1 will not fall out of world)'FUNCTION count_neighbours(i%,j%) LOCAL count%,l% count%=0 FOR l%=-1 TO 1 IF world! (i%+l%,j%+1) count%=count%+1 ENDIF NEXT l% IF world! (i%+1,j%) count%=count%+1 ENDIF RETURN count%ENDFUNC'' Update the world one step'PROCEDURE update_world LOCAL i%,j% ' compute neighbour counts and store FOR i%=1 TO 30 FOR j%=1 TO 30 ns%(i%,j%)[email protected]_neighbours(i%,j%) NEXT j% NEXT i% ' update the world cells FOR i%=1 TO 30 FOR j%=1 TO 30 IF world!

Thus, while it is somewhat verbose, it fully simulates Conway's Game of Life and is relatively simple to expand to feature different starting shapes.

Define life(pattern) = Prgm Local x,y,nt,count,save,xl,yl,xh,yh Define nt(y,x) = when(pxl Test(y,x), 1, 0) {}→save set Graph("Axes", "Off")→save[1] set Graph("Grid", "Off")→save[2] set Graph("Labels", "Off")→save[3] Fn Off Plot Off Clr Draw If pattern = "blinker" Then 36→yl 40→yh 78→xl 82→xh Pxl On 36,80 Pxl On 38,80 Pxl On 40,80 Else If pattern = "glider" Then 30→yl 40→yh 76→xl 88→xh Pxl On 38,76 Pxl On 36,78 Pxl On 36,80 Pxl On 38,80 Pxl On 40,80 Else If pattern = "r" Then 38-5*2→yl 38+5*2→yh 80-5*2→xl 80+5*2→xh Pxl On 38,78 Pxl On 36,82 Pxl On 36,80 Pxl On 38,80 Pxl On 40,80 End If While get Key() = 0 © Expand upper-left corner to whole cell For y,yl,yh,2 For x,xl,xh,2 If pxl Test(y,x) Then Pxl On y+1,x Pxl On y+1,x+1 Pxl On y, x+1 Else Pxl Off y+1,x Pxl Off y+1,x+1 Pxl Off y, x+1 End If End For End For © Compute next generation For y,yl,yh,2 For x,xl,xh,2 nt(y-1,x-1) + nt(y-1,x) + nt(y-1,x+2) + nt(y,x-1) + nt(y+1,x+2) + nt(y+2,x-1) + nt(y+2,x+1) + nt(y+2,x+2) → count If count = 3 Then Pxl On y,x Else If count ≠ 2 Then Pxl Off y,x End If End For End For End While © Restore changed options set Graph("Axes", save[1]) set Graph("Grid", save[2]) set Graph("Labels", save[3])End Prgm Also see Conway's Game of Life/C Considering that the simplest implementation in C++ would lack any use of the object-oriented paradigm, this code was specifically written to demonstrate the various object-oriented features of C++.

;increment

randfill: stx $01 ;$200 for indirect ldx #$02 ;addressing stx $02randloop: lda $fe ;generate random and #$01 ;pixels on the sta ($01), Y ;screen jsr inc0103 cmp #$00 bne randloop lda $02 cmp #$06 bne randloop clearmem: lda #$df ;set $07df-$0a20 sta $01 ;to $#00 lda #$07 sta $02clearbyte: lda #$00 sta ($01), Y jsr inc0103 cmp #$20 bne clearbyte lda $02 cmp #$0a bne clearbyte starttick:copyscreen: lda #$00 ;set up source sta $01 ;pointer at sta $03 ;$01/$02 and lda #$02 ;dest pointer sta $02 ;at $03/$04 lda #$08 sta $04 ldy #$00copybyte: lda ($01), Y ;copy pixel to sta ($03), Y ;back buffer jsr inc0103 ;increment pointers cmp #$00 ;check to see bne copybyte ;if we're at $600 lda $02 ;if so, we've cmp #$06 ;copied the bne copybyte ;entire screen conway: lda #$df ;apply conway rules sta $01 ;reset the pointer sta $03 ;to $#01df/$#07df lda #$01 ;($200 - $21) sta $02 ;($800 - $21) lda #$07 sta $04onecell: lda #$00 ;process one cell ldy #$01 ;upper cell clc adc ($03), Y ldy #$41 ;lower cell clc adc ($03), Ychkleft: tax ;check to see lda $01 ;if we're at the and #$1f ;left edge tay txa cpy #$1f beq rightcellsleftcells: ldy #$00 ;upper-left cell clc adc ($03), Y ldy #$20 ;left cell clc adc ($03), Y ldy #$40 ;lower-left cell clc adc ($03), Ychkright: tax ;check to see lda $01 ;if we're at the and #$1f ;right edge tay txa cpy #$1e beq evaluaterightcells: ldy #$02 ;upper-right cell clc adc ($03), Y ldy #$22 ;right cell clc adc ($03), Y ldy #$42 ;lower-right cell clc adc ($03), Yevaluate: ldx #$01 ;evaluate total ldy #$21 ;for current cell cmp #$03 ;3 = alive beq storex ldx #$00 cmp #$02 ;2 = alive if bne storex ;c = alive lda ($03), Y and #$01 taxstorex: txa ;store to screen sta ($01), Y jsr inc0103 ;move to next cellconwayloop: cmp #$e0 ;if not last cell, bne onecell ;process next cell lda $02 cmp #$05 bne onecell jmp starttick ;run next tick inc0103: lda $01 ;increment $01 cmp #$ff ;and $03 as 16-bit bne onlyinc01 ;pointers inc $02 inc $04onlyinc01: inc $01 lda $01 sta $03 rts The solution uses one cell thick border around square Petri dish as uninhabited dire land. Sample output contains 3 generations of the blinker and 5 of the glider: See Conway's Game of Life/ALGOL 68 APL2 (Dialog) Example in one line APL \ 1130 example (very old APL dialect via simulator) APL1130From: APL \ 1130 Samples The following APL \ 1130 code will need APL385 font installed to display correctly. See Download APL TT Font ∇LIFE[⎕]∇[0] NG←LIFE CG; W[1] W←CG+(¯1⊖CG)+(1⊖CG)+(¯1⌽CG)+(1⌽CG)[2] W←W+(1⊖1⌽CG)+(¯1⊖1⌽CG)+(1⊖¯1⌽CG)+(¯1⊖¯1⌽CG)[3] NG←(3=W)+(CG∧4=W) ∇ RP←5 5⍴0 0 0 0 0 0 0 1 1 0 0 1 1 0 0 0 0 1 0 0 RP0 0 0 0 00 0 1 1 00 1 1 0 00 0 1 0 00 0 0 0 0 LIFE RP0 0 0 0 00 1 1 1 00 1 0 0 00 1 1 0 00 0 0 0 0 LIFE LIFE RP0 0 1 0 00 1 1 0 01 0 0 1 00 1 1 0 00 0 0 0 0 .................................................. One interacts with the Game of Life by creating an initial configuration and observing how it evolves. Although you should test your implementation on more complex examples such as the glider in a larger universe, show the action of the blinker (three adjoining cells in a row all alive), over three generations, in a 3 by 3 grid. (1,4)=TRUERETURN'' Count the number of neighbours of the point i,j' (Assume i/j +/- 1 will not fall out of world)'FUNCTION count_neighbours(i%,j%) LOCAL count%,l% count%=0 FOR l%=-1 TO 1 IF world! (i%+l%,j%+1) count%=count%+1 ENDIF NEXT l% IF world! (i%+1,j%) count%=count%+1 ENDIF RETURN count%ENDFUNC'' Update the world one step'PROCEDURE update_world LOCAL i%,j% ' compute neighbour counts and store FOR i%=1 TO 30 FOR j%=1 TO 30 ns%(i%,j%)[email protected]_neighbours(i%,j%) NEXT j% NEXT i% ' update the world cells FOR i%=1 TO 30 FOR j%=1 TO 30 IF world!

||

randfill: stx $01 ;$200 for indirect ldx #$02 ;addressing stx $02randloop: lda $fe ;generate random and #$01 ;pixels on the sta ($01), Y ;screen jsr inc0103 cmp #$00 bne randloop lda $02 cmp #$06 bne randloop clearmem: lda #$df ;set $07df-$0a20 sta $01 ;to $#00 lda #$07 sta $02clearbyte: lda #$00 sta ($01), Y jsr inc0103 cmp #$20 bne clearbyte lda $02 cmp #$0a bne clearbyte starttick:copyscreen: lda #$00 ;set up source sta $01 ;pointer at sta $03 ;$01/$02 and lda #$02 ;dest pointer sta $02 ;at $03/$04 lda #$08 sta $04 ldy #$00copybyte: lda ($01), Y ;copy pixel to sta ($03), Y ;back buffer jsr inc0103 ;increment pointers cmp #$00 ;check to see bne copybyte ;if we're at $600 lda $02 ;if so, we've cmp #$06 ;copied the bne copybyte ;entire screen conway: lda #$df ;apply conway rules sta $01 ;reset the pointer sta $03 ;to $#01df/$#07df lda #$01 ;($200 - $21) sta $02 ;($800 - $21) lda #$07 sta $04onecell: lda #$00 ;process one cell ldy #$01 ;upper cell clc adc ($03), Y ldy #$41 ;lower cell clc adc ($03), Ychkleft: tax ;check to see lda $01 ;if we're at the and #$1f ;left edge tay txa cpy #$1f beq rightcellsleftcells: ldy #$00 ;upper-left cell clc adc ($03), Y ldy #$20 ;left cell clc adc ($03), Y ldy #$40 ;lower-left cell clc adc ($03), Ychkright: tax ;check to see lda $01 ;if we're at the and #$1f ;right edge tay txa cpy #$1e beq evaluaterightcells: ldy #$02 ;upper-right cell clc adc ($03), Y ldy #$22 ;right cell clc adc ($03), Y ldy #$42 ;lower-right cell clc adc ($03), Yevaluate: ldx #$01 ;evaluate total ldy #$21 ;for current cell cmp #$03 ;3 = alive beq storex ldx #$00 cmp #$02 ;2 = alive if bne storex ;c = alive lda ($03), Y and #$01 taxstorex: txa ;store to screen sta ($01), Y jsr inc0103 ;move to next cellconwayloop: cmp #$e0 ;if not last cell, bne onecell ;process next cell lda $02 cmp #$05 bne onecell jmp starttick ;run next tick inc0103: lda $01 ;increment $01 cmp #$ff ;and $03 as 16-bit bne onlyinc01 ;pointers inc $02 inc $04onlyinc01: inc $01 lda $01 sta $03 rts The solution uses one cell thick border around square Petri dish as uninhabited dire land. Sample output contains 3 generations of the blinker and 5 of the glider: See Conway's Game of Life/ALGOL 68 APL2 (Dialog) Example in one line APL \ 1130 example (very old APL dialect via simulator) APL1130From: APL \ 1130 Samples The following APL \ 1130 code will need APL385 font installed to display correctly.

See Download APL TT Font ∇LIFE[⎕]∇[0] NG←LIFE CG; W[1] W←CG+(¯1⊖CG)+(1⊖CG)+(¯1⌽CG)+(1⌽CG)[2] W←W+(1⊖1⌽CG)+(¯1⊖1⌽CG)+(1⊖¯1⌽CG)+(¯1⊖¯1⌽CG)[3] NG←(3=W)+(CG∧4=W) ∇ RP←5 5⍴0 0 0 0 0 0 0 1 1 0 0 1 1 0 0 0 0 1 0 0 RP0 0 0 0 00 0 1 1 00 1 1 0 00 0 1 0 00 0 0 0 0 LIFE RP0 0 0 0 00 1 1 1 00 1 0 0 00 1 1 0 00 0 0 0 0 LIFE LIFE RP0 0 1 0 00 1 1 0 01 0 0 1 00 1 1 0 00 0 0 0 0 ..................................................

One interacts with the Game of Life by creating an initial configuration and observing how it evolves.

Although you should test your implementation on more complex examples such as the glider in a larger universe, show the action of the blinker (three adjoining cells in a row all alive), over three generations, in a 3 by 3 grid.

(1,4)=TRUERETURN'' Count the number of neighbours of the point i,j' (Assume i/j +/- 1 will not fall out of world)'FUNCTION count_neighbours(i%,j%) LOCAL count%,l% count%=0 FOR l%=-1 TO 1 IF world! (i%+l%,j%+1) count%=count%+1 ENDIF NEXT l% IF world! (i%+1,j%) count%=count%+1 ENDIF RETURN count%ENDFUNC'' Update the world one step'PROCEDURE update_world LOCAL i%,j% ' compute neighbour counts and store FOR i%=1 TO 30 FOR j%=1 TO 30 ns%(i%,j%)[email protected]_neighbours(i%,j%) NEXT j% NEXT i% ' update the world cells FOR i%=1 TO 30 FOR j%=1 TO 30 IF world!

Thus, while it is somewhat verbose, it fully simulates Conway's Game of Life and is relatively simple to expand to feature different starting shapes.

Define life(pattern) = Prgm Local x,y,nt,count,save,xl,yl,xh,yh Define nt(y,x) = when(pxl Test(y,x), 1, 0) {}→save set Graph("Axes", "Off")→save[1] set Graph("Grid", "Off")→save[2] set Graph("Labels", "Off")→save[3] Fn Off Plot Off Clr Draw If pattern = "blinker" Then 36→yl 40→yh 78→xl 82→xh Pxl On 36,80 Pxl On 38,80 Pxl On 40,80 Else If pattern = "glider" Then 30→yl 40→yh 76→xl 88→xh Pxl On 38,76 Pxl On 36,78 Pxl On 36,80 Pxl On 38,80 Pxl On 40,80 Else If pattern = "r" Then 38-5*2→yl 38+5*2→yh 80-5*2→xl 80+5*2→xh Pxl On 38,78 Pxl On 36,82 Pxl On 36,80 Pxl On 38,80 Pxl On 40,80 End If While get Key() = 0 © Expand upper-left corner to whole cell For y,yl,yh,2 For x,xl,xh,2 If pxl Test(y,x) Then Pxl On y+1,x Pxl On y+1,x+1 Pxl On y, x+1 Else Pxl Off y+1,x Pxl Off y+1,x+1 Pxl Off y, x+1 End If End For End For © Compute next generation For y,yl,yh,2 For x,xl,xh,2 nt(y-1,x-1) + nt(y-1,x) + nt(y-1,x+2) + nt(y,x-1) + nt(y+1,x+2) + nt(y+2,x-1) + nt(y+2,x+1) + nt(y+2,x+2) → count If count = 3 Then Pxl On y,x Else If count ≠ 2 Then Pxl Off y,x End If End For End For End While © Restore changed options set Graph("Axes", save[1]) set Graph("Grid", save[2]) set Graph("Labels", save[3])End Prgm Also see Conway's Game of Life/C Considering that the simplest implementation in C++ would lack any use of the object-oriented paradigm, this code was specifically written to demonstrate the various object-oriented features of C++.

cmp #$ff ;and as 16-bit bne onlyinc01 ;pointers inc inc onlyinc01: inc

randfill: stx $01 ;$200 for indirect ldx #$02 ;addressing stx $02randloop: lda $fe ;generate random and #$01 ;pixels on the sta ($01), Y ;screen jsr inc0103 cmp #$00 bne randloop lda $02 cmp #$06 bne randloop clearmem: lda #$df ;set $07df-$0a20 sta $01 ;to $#00 lda #$07 sta $02clearbyte: lda #$00 sta ($01), Y jsr inc0103 cmp #$20 bne clearbyte lda $02 cmp #$0a bne clearbyte starttick:copyscreen: lda #$00 ;set up source sta $01 ;pointer at sta $03 ;$01/$02 and lda #$02 ;dest pointer sta $02 ;at $03/$04 lda #$08 sta $04 ldy #$00copybyte: lda ($01), Y ;copy pixel to sta ($03), Y ;back buffer jsr inc0103 ;increment pointers cmp #$00 ;check to see bne copybyte ;if we're at $600 lda $02 ;if so, we've cmp #$06 ;copied the bne copybyte ;entire screen conway: lda #$df ;apply conway rules sta $01 ;reset the pointer sta $03 ;to $#01df/$#07df lda #$01 ;($200 - $21) sta $02 ;($800 - $21) lda #$07 sta $04onecell: lda #$00 ;process one cell ldy #$01 ;upper cell clc adc ($03), Y ldy #$41 ;lower cell clc adc ($03), Ychkleft: tax ;check to see lda $01 ;if we're at the and #$1f ;left edge tay txa cpy #$1f beq rightcellsleftcells: ldy #$00 ;upper-left cell clc adc ($03), Y ldy #$20 ;left cell clc adc ($03), Y ldy #$40 ;lower-left cell clc adc ($03), Ychkright: tax ;check to see lda $01 ;if we're at the and #$1f ;right edge tay txa cpy #$1e beq evaluaterightcells: ldy #$02 ;upper-right cell clc adc ($03), Y ldy #$22 ;right cell clc adc ($03), Y ldy #$42 ;lower-right cell clc adc ($03), Yevaluate: ldx #$01 ;evaluate total ldy #$21 ;for current cell cmp #$03 ;3 = alive beq storex ldx #$00 cmp #$02 ;2 = alive if bne storex ;c = alive lda ($03), Y and #$01 taxstorex: txa ;store to screen sta ($01), Y jsr inc0103 ;move to next cellconwayloop: cmp #$e0 ;if not last cell, bne onecell ;process next cell lda $02 cmp #$05 bne onecell jmp starttick ;run next tick inc0103: lda $01 ;increment $01 cmp #$ff ;and $03 as 16-bit bne onlyinc01 ;pointers inc $02 inc $04onlyinc01: inc $01 lda $01 sta $03 rts The solution uses one cell thick border around square Petri dish as uninhabited dire land. Sample output contains 3 generations of the blinker and 5 of the glider: See Conway's Game of Life/ALGOL 68 APL2 (Dialog) Example in one line APL \ 1130 example (very old APL dialect via simulator) APL1130From: APL \ 1130 Samples The following APL \ 1130 code will need APL385 font installed to display correctly. See Download APL TT Font ∇LIFE[⎕]∇[0] NG←LIFE CG; W[1] W←CG+(¯1⊖CG)+(1⊖CG)+(¯1⌽CG)+(1⌽CG)[2] W←W+(1⊖1⌽CG)+(¯1⊖1⌽CG)+(1⊖¯1⌽CG)+(¯1⊖¯1⌽CG)[3] NG←(3=W)+(CG∧4=W) ∇ RP←5 5⍴0 0 0 0 0 0 0 1 1 0 0 1 1 0 0 0 0 1 0 0 RP0 0 0 0 00 0 1 1 00 1 1 0 00 0 1 0 00 0 0 0 0 LIFE RP0 0 0 0 00 1 1 1 00 1 0 0 00 1 1 0 00 0 0 0 0 LIFE LIFE RP0 0 1 0 00 1 1 0 01 0 0 1 00 1 1 0 00 0 0 0 0 .................................................. One interacts with the Game of Life by creating an initial configuration and observing how it evolves. Although you should test your implementation on more complex examples such as the glider in a larger universe, show the action of the blinker (three adjoining cells in a row all alive), over three generations, in a 3 by 3 grid. (1,4)=TRUERETURN'' Count the number of neighbours of the point i,j' (Assume i/j +/- 1 will not fall out of world)'FUNCTION count_neighbours(i%,j%) LOCAL count%,l% count%=0 FOR l%=-1 TO 1 IF world! (i%+l%,j%+1) count%=count%+1 ENDIF NEXT l% IF world! (i%+1,j%) count%=count%+1 ENDIF RETURN count%ENDFUNC'' Update the world one step'PROCEDURE update_world LOCAL i%,j% ' compute neighbour counts and store FOR i%=1 TO 30 FOR j%=1 TO 30 ns%(i%,j%)[email protected]_neighbours(i%,j%) NEXT j% NEXT i% ' update the world cells FOR i%=1 TO 30 FOR j%=1 TO 30 IF world!

||

randfill: stx $01 ;$200 for indirect ldx #$02 ;addressing stx $02randloop: lda $fe ;generate random and #$01 ;pixels on the sta ($01), Y ;screen jsr inc0103 cmp #$00 bne randloop lda $02 cmp #$06 bne randloop clearmem: lda #$df ;set $07df-$0a20 sta $01 ;to $#00 lda #$07 sta $02clearbyte: lda #$00 sta ($01), Y jsr inc0103 cmp #$20 bne clearbyte lda $02 cmp #$0a bne clearbyte starttick:copyscreen: lda #$00 ;set up source sta $01 ;pointer at sta $03 ;$01/$02 and lda #$02 ;dest pointer sta $02 ;at $03/$04 lda #$08 sta $04 ldy #$00copybyte: lda ($01), Y ;copy pixel to sta ($03), Y ;back buffer jsr inc0103 ;increment pointers cmp #$00 ;check to see bne copybyte ;if we're at $600 lda $02 ;if so, we've cmp #$06 ;copied the bne copybyte ;entire screen conway: lda #$df ;apply conway rules sta $01 ;reset the pointer sta $03 ;to $#01df/$#07df lda #$01 ;($200 - $21) sta $02 ;($800 - $21) lda #$07 sta $04onecell: lda #$00 ;process one cell ldy #$01 ;upper cell clc adc ($03), Y ldy #$41 ;lower cell clc adc ($03), Ychkleft: tax ;check to see lda $01 ;if we're at the and #$1f ;left edge tay txa cpy #$1f beq rightcellsleftcells: ldy #$00 ;upper-left cell clc adc ($03), Y ldy #$20 ;left cell clc adc ($03), Y ldy #$40 ;lower-left cell clc adc ($03), Ychkright: tax ;check to see lda $01 ;if we're at the and #$1f ;right edge tay txa cpy #$1e beq evaluaterightcells: ldy #$02 ;upper-right cell clc adc ($03), Y ldy #$22 ;right cell clc adc ($03), Y ldy #$42 ;lower-right cell clc adc ($03), Yevaluate: ldx #$01 ;evaluate total ldy #$21 ;for current cell cmp #$03 ;3 = alive beq storex ldx #$00 cmp #$02 ;2 = alive if bne storex ;c = alive lda ($03), Y and #$01 taxstorex: txa ;store to screen sta ($01), Y jsr inc0103 ;move to next cellconwayloop: cmp #$e0 ;if not last cell, bne onecell ;process next cell lda $02 cmp #$05 bne onecell jmp starttick ;run next tick inc0103: lda $01 ;increment $01 cmp #$ff ;and $03 as 16-bit bne onlyinc01 ;pointers inc $02 inc $04onlyinc01: inc $01 lda $01 sta $03 rts The solution uses one cell thick border around square Petri dish as uninhabited dire land. Sample output contains 3 generations of the blinker and 5 of the glider: See Conway's Game of Life/ALGOL 68 APL2 (Dialog) Example in one line APL \ 1130 example (very old APL dialect via simulator) APL1130From: APL \ 1130 Samples The following APL \ 1130 code will need APL385 font installed to display correctly.

See Download APL TT Font ∇LIFE[⎕]∇[0] NG←LIFE CG; W[1] W←CG+(¯1⊖CG)+(1⊖CG)+(¯1⌽CG)+(1⌽CG)[2] W←W+(1⊖1⌽CG)+(¯1⊖1⌽CG)+(1⊖¯1⌽CG)+(¯1⊖¯1⌽CG)[3] NG←(3=W)+(CG∧4=W) ∇ RP←5 5⍴0 0 0 0 0 0 0 1 1 0 0 1 1 0 0 0 0 1 0 0 RP0 0 0 0 00 0 1 1 00 1 1 0 00 0 1 0 00 0 0 0 0 LIFE RP0 0 0 0 00 1 1 1 00 1 0 0 00 1 1 0 00 0 0 0 0 LIFE LIFE RP0 0 1 0 00 1 1 0 01 0 0 1 00 1 1 0 00 0 0 0 0 ..................................................

One interacts with the Game of Life by creating an initial configuration and observing how it evolves.

Although you should test your implementation on more complex examples such as the glider in a larger universe, show the action of the blinker (three adjoining cells in a row all alive), over three generations, in a 3 by 3 grid.

(1,4)=TRUERETURN'' Count the number of neighbours of the point i,j' (Assume i/j +/- 1 will not fall out of world)'FUNCTION count_neighbours(i%,j%) LOCAL count%,l% count%=0 FOR l%=-1 TO 1 IF world! (i%+l%,j%+1) count%=count%+1 ENDIF NEXT l% IF world! (i%+1,j%) count%=count%+1 ENDIF RETURN count%ENDFUNC'' Update the world one step'PROCEDURE update_world LOCAL i%,j% ' compute neighbour counts and store FOR i%=1 TO 30 FOR j%=1 TO 30 ns%(i%,j%)[email protected]_neighbours(i%,j%) NEXT j% NEXT i% ' update the world cells FOR i%=1 TO 30 FOR j%=1 TO 30 IF world!

Thus, while it is somewhat verbose, it fully simulates Conway's Game of Life and is relatively simple to expand to feature different starting shapes.

Define life(pattern) = Prgm Local x,y,nt,count,save,xl,yl,xh,yh Define nt(y,x) = when(pxl Test(y,x), 1, 0) {}→save set Graph("Axes", "Off")→save[1] set Graph("Grid", "Off")→save[2] set Graph("Labels", "Off")→save[3] Fn Off Plot Off Clr Draw If pattern = "blinker" Then 36→yl 40→yh 78→xl 82→xh Pxl On 36,80 Pxl On 38,80 Pxl On 40,80 Else If pattern = "glider" Then 30→yl 40→yh 76→xl 88→xh Pxl On 38,76 Pxl On 36,78 Pxl On 36,80 Pxl On 38,80 Pxl On 40,80 Else If pattern = "r" Then 38-5*2→yl 38+5*2→yh 80-5*2→xl 80+5*2→xh Pxl On 38,78 Pxl On 36,82 Pxl On 36,80 Pxl On 38,80 Pxl On 40,80 End If While get Key() = 0 © Expand upper-left corner to whole cell For y,yl,yh,2 For x,xl,xh,2 If pxl Test(y,x) Then Pxl On y+1,x Pxl On y+1,x+1 Pxl On y, x+1 Else Pxl Off y+1,x Pxl Off y+1,x+1 Pxl Off y, x+1 End If End For End For © Compute next generation For y,yl,yh,2 For x,xl,xh,2 nt(y-1,x-1) + nt(y-1,x) + nt(y-1,x+2) + nt(y,x-1) + nt(y+1,x+2) + nt(y+2,x-1) + nt(y+2,x+1) + nt(y+2,x+2) → count If count = 3 Then Pxl On y,x Else If count ≠ 2 Then Pxl Off y,x End If End For End For End While © Restore changed options set Graph("Axes", save[1]) set Graph("Grid", save[2]) set Graph("Labels", save[3])End Prgm Also see Conway's Game of Life/C Considering that the simplest implementation in C++ would lack any use of the object-oriented paradigm, this code was specifically written to demonstrate the various object-oriented features of C++.

lda

randfill: stx $01 ;$200 for indirect ldx #$02 ;addressing stx $02randloop: lda $fe ;generate random and #$01 ;pixels on the sta ($01), Y ;screen jsr inc0103 cmp #$00 bne randloop lda $02 cmp #$06 bne randloop clearmem: lda #$df ;set $07df-$0a20 sta $01 ;to $#00 lda #$07 sta $02clearbyte: lda #$00 sta ($01), Y jsr inc0103 cmp #$20 bne clearbyte lda $02 cmp #$0a bne clearbyte starttick:copyscreen: lda #$00 ;set up source sta $01 ;pointer at sta $03 ;$01/$02 and lda #$02 ;dest pointer sta $02 ;at $03/$04 lda #$08 sta $04 ldy #$00copybyte: lda ($01), Y ;copy pixel to sta ($03), Y ;back buffer jsr inc0103 ;increment pointers cmp #$00 ;check to see bne copybyte ;if we're at $600 lda $02 ;if so, we've cmp #$06 ;copied the bne copybyte ;entire screen conway: lda #$df ;apply conway rules sta $01 ;reset the pointer sta $03 ;to $#01df/$#07df lda #$01 ;($200 - $21) sta $02 ;($800 - $21) lda #$07 sta $04onecell: lda #$00 ;process one cell ldy #$01 ;upper cell clc adc ($03), Y ldy #$41 ;lower cell clc adc ($03), Ychkleft: tax ;check to see lda $01 ;if we're at the and #$1f ;left edge tay txa cpy #$1f beq rightcellsleftcells: ldy #$00 ;upper-left cell clc adc ($03), Y ldy #$20 ;left cell clc adc ($03), Y ldy #$40 ;lower-left cell clc adc ($03), Ychkright: tax ;check to see lda $01 ;if we're at the and #$1f ;right edge tay txa cpy #$1e beq evaluaterightcells: ldy #$02 ;upper-right cell clc adc ($03), Y ldy #$22 ;right cell clc adc ($03), Y ldy #$42 ;lower-right cell clc adc ($03), Yevaluate: ldx #$01 ;evaluate total ldy #$21 ;for current cell cmp #$03 ;3 = alive beq storex ldx #$00 cmp #$02 ;2 = alive if bne storex ;c = alive lda ($03), Y and #$01 taxstorex: txa ;store to screen sta ($01), Y jsr inc0103 ;move to next cellconwayloop: cmp #$e0 ;if not last cell, bne onecell ;process next cell lda $02 cmp #$05 bne onecell jmp starttick ;run next tick inc0103: lda $01 ;increment $01 cmp #$ff ;and $03 as 16-bit bne onlyinc01 ;pointers inc $02 inc $04onlyinc01: inc $01 lda $01 sta $03 rts The solution uses one cell thick border around square Petri dish as uninhabited dire land. Sample output contains 3 generations of the blinker and 5 of the glider: See Conway's Game of Life/ALGOL 68 APL2 (Dialog) Example in one line APL \ 1130 example (very old APL dialect via simulator) APL1130From: APL \ 1130 Samples The following APL \ 1130 code will need APL385 font installed to display correctly. See Download APL TT Font ∇LIFE[⎕]∇[0] NG←LIFE CG; W[1] W←CG+(¯1⊖CG)+(1⊖CG)+(¯1⌽CG)+(1⌽CG)[2] W←W+(1⊖1⌽CG)+(¯1⊖1⌽CG)+(1⊖¯1⌽CG)+(¯1⊖¯1⌽CG)[3] NG←(3=W)+(CG∧4=W) ∇ RP←5 5⍴0 0 0 0 0 0 0 1 1 0 0 1 1 0 0 0 0 1 0 0 RP0 0 0 0 00 0 1 1 00 1 1 0 00 0 1 0 00 0 0 0 0 LIFE RP0 0 0 0 00 1 1 1 00 1 0 0 00 1 1 0 00 0 0 0 0 LIFE LIFE RP0 0 1 0 00 1 1 0 01 0 0 1 00 1 1 0 00 0 0 0 0 .................................................. One interacts with the Game of Life by creating an initial configuration and observing how it evolves. Although you should test your implementation on more complex examples such as the glider in a larger universe, show the action of the blinker (three adjoining cells in a row all alive), over three generations, in a 3 by 3 grid. (1,4)=TRUERETURN'' Count the number of neighbours of the point i,j' (Assume i/j +/- 1 will not fall out of world)'FUNCTION count_neighbours(i%,j%) LOCAL count%,l% count%=0 FOR l%=-1 TO 1 IF world! (i%+l%,j%+1) count%=count%+1 ENDIF NEXT l% IF world! (i%+1,j%) count%=count%+1 ENDIF RETURN count%ENDFUNC'' Update the world one step'PROCEDURE update_world LOCAL i%,j% ' compute neighbour counts and store FOR i%=1 TO 30 FOR j%=1 TO 30 ns%(i%,j%)[email protected]_neighbours(i%,j%) NEXT j% NEXT i% ' update the world cells FOR i%=1 TO 30 FOR j%=1 TO 30 IF world!

||

randfill: stx $01 ;$200 for indirect ldx #$02 ;addressing stx $02randloop: lda $fe ;generate random and #$01 ;pixels on the sta ($01), Y ;screen jsr inc0103 cmp #$00 bne randloop lda $02 cmp #$06 bne randloop clearmem: lda #$df ;set $07df-$0a20 sta $01 ;to $#00 lda #$07 sta $02clearbyte: lda #$00 sta ($01), Y jsr inc0103 cmp #$20 bne clearbyte lda $02 cmp #$0a bne clearbyte starttick:copyscreen: lda #$00 ;set up source sta $01 ;pointer at sta $03 ;$01/$02 and lda #$02 ;dest pointer sta $02 ;at $03/$04 lda #$08 sta $04 ldy #$00copybyte: lda ($01), Y ;copy pixel to sta ($03), Y ;back buffer jsr inc0103 ;increment pointers cmp #$00 ;check to see bne copybyte ;if we're at $600 lda $02 ;if so, we've cmp #$06 ;copied the bne copybyte ;entire screen conway: lda #$df ;apply conway rules sta $01 ;reset the pointer sta $03 ;to $#01df/$#07df lda #$01 ;($200 - $21) sta $02 ;($800 - $21) lda #$07 sta $04onecell: lda #$00 ;process one cell ldy #$01 ;upper cell clc adc ($03), Y ldy #$41 ;lower cell clc adc ($03), Ychkleft: tax ;check to see lda $01 ;if we're at the and #$1f ;left edge tay txa cpy #$1f beq rightcellsleftcells: ldy #$00 ;upper-left cell clc adc ($03), Y ldy #$20 ;left cell clc adc ($03), Y ldy #$40 ;lower-left cell clc adc ($03), Ychkright: tax ;check to see lda $01 ;if we're at the and #$1f ;right edge tay txa cpy #$1e beq evaluaterightcells: ldy #$02 ;upper-right cell clc adc ($03), Y ldy #$22 ;right cell clc adc ($03), Y ldy #$42 ;lower-right cell clc adc ($03), Yevaluate: ldx #$01 ;evaluate total ldy #$21 ;for current cell cmp #$03 ;3 = alive beq storex ldx #$00 cmp #$02 ;2 = alive if bne storex ;c = alive lda ($03), Y and #$01 taxstorex: txa ;store to screen sta ($01), Y jsr inc0103 ;move to next cellconwayloop: cmp #$e0 ;if not last cell, bne onecell ;process next cell lda $02 cmp #$05 bne onecell jmp starttick ;run next tick inc0103: lda $01 ;increment $01 cmp #$ff ;and $03 as 16-bit bne onlyinc01 ;pointers inc $02 inc $04onlyinc01: inc $01 lda $01 sta $03 rts The solution uses one cell thick border around square Petri dish as uninhabited dire land. Sample output contains 3 generations of the blinker and 5 of the glider: See Conway's Game of Life/ALGOL 68 APL2 (Dialog) Example in one line APL \ 1130 example (very old APL dialect via simulator) APL1130From: APL \ 1130 Samples The following APL \ 1130 code will need APL385 font installed to display correctly.

See Download APL TT Font ∇LIFE[⎕]∇[0] NG←LIFE CG; W[1] W←CG+(¯1⊖CG)+(1⊖CG)+(¯1⌽CG)+(1⌽CG)[2] W←W+(1⊖1⌽CG)+(¯1⊖1⌽CG)+(1⊖¯1⌽CG)+(¯1⊖¯1⌽CG)[3] NG←(3=W)+(CG∧4=W) ∇ RP←5 5⍴0 0 0 0 0 0 0 1 1 0 0 1 1 0 0 0 0 1 0 0 RP0 0 0 0 00 0 1 1 00 1 1 0 00 0 1 0 00 0 0 0 0 LIFE RP0 0 0 0 00 1 1 1 00 1 0 0 00 1 1 0 00 0 0 0 0 LIFE LIFE RP0 0 1 0 00 1 1 0 01 0 0 1 00 1 1 0 00 0 0 0 0 ..................................................

One interacts with the Game of Life by creating an initial configuration and observing how it evolves.

Although you should test your implementation on more complex examples such as the glider in a larger universe, show the action of the blinker (three adjoining cells in a row all alive), over three generations, in a 3 by 3 grid.

(1,4)=TRUERETURN'' Count the number of neighbours of the point i,j' (Assume i/j +/- 1 will not fall out of world)'FUNCTION count_neighbours(i%,j%) LOCAL count%,l% count%=0 FOR l%=-1 TO 1 IF world! (i%+l%,j%+1) count%=count%+1 ENDIF NEXT l% IF world! (i%+1,j%) count%=count%+1 ENDIF RETURN count%ENDFUNC'' Update the world one step'PROCEDURE update_world LOCAL i%,j% ' compute neighbour counts and store FOR i%=1 TO 30 FOR j%=1 TO 30 ns%(i%,j%)[email protected]_neighbours(i%,j%) NEXT j% NEXT i% ' update the world cells FOR i%=1 TO 30 FOR j%=1 TO 30 IF world!

Thus, while it is somewhat verbose, it fully simulates Conway's Game of Life and is relatively simple to expand to feature different starting shapes.

Define life(pattern) = Prgm Local x,y,nt,count,save,xl,yl,xh,yh Define nt(y,x) = when(pxl Test(y,x), 1, 0) {}→save set Graph("Axes", "Off")→save[1] set Graph("Grid", "Off")→save[2] set Graph("Labels", "Off")→save[3] Fn Off Plot Off Clr Draw If pattern = "blinker" Then 36→yl 40→yh 78→xl 82→xh Pxl On 36,80 Pxl On 38,80 Pxl On 40,80 Else If pattern = "glider" Then 30→yl 40→yh 76→xl 88→xh Pxl On 38,76 Pxl On 36,78 Pxl On 36,80 Pxl On 38,80 Pxl On 40,80 Else If pattern = "r" Then 38-5*2→yl 38+5*2→yh 80-5*2→xl 80+5*2→xh Pxl On 38,78 Pxl On 36,82 Pxl On 36,80 Pxl On 38,80 Pxl On 40,80 End If While get Key() = 0 © Expand upper-left corner to whole cell For y,yl,yh,2 For x,xl,xh,2 If pxl Test(y,x) Then Pxl On y+1,x Pxl On y+1,x+1 Pxl On y, x+1 Else Pxl Off y+1,x Pxl Off y+1,x+1 Pxl Off y, x+1 End If End For End For © Compute next generation For y,yl,yh,2 For x,xl,xh,2 nt(y-1,x-1) + nt(y-1,x) + nt(y-1,x+2) + nt(y,x-1) + nt(y+1,x+2) + nt(y+2,x-1) + nt(y+2,x+1) + nt(y+2,x+2) → count If count = 3 Then Pxl On y,x Else If count ≠ 2 Then Pxl Off y,x End If End For End For End While © Restore changed options set Graph("Axes", save[1]) set Graph("Grid", save[2]) set Graph("Labels", save[3])End Prgm Also see Conway's Game of Life/C Considering that the simplest implementation in C++ would lack any use of the object-oriented paradigm, this code was specifically written to demonstrate the various object-oriented features of C++.

sta rts The solution uses one cell thick border around square Petri dish as uninhabited dire land. Sample output contains 3 generations of the blinker and 5 of the glider: See Conway's Game of Life/ALGOL 68 APL2 (Dialog) Example in one line APL \ 1130 example (very old APL dialect via simulator) APL1130From: APL \ 1130 Samples The following APL \ 1130 code will need APL385 font installed to display correctly.

See Download APL TT Font ∇LIFE[⎕]∇[0] NG←LIFE CG; W[1] W←CG+(¯1⊖CG)+(1⊖CG)+(¯1⌽CG)+(1⌽CG)[2] W←W+(1⊖1⌽CG)+(¯1⊖1⌽CG)+(1⊖¯1⌽CG)+(¯1⊖¯1⌽CG)[3] NG←(3=W)+(CG∧4=W) ∇ RP←5 5⍴0 0 0 0 0 0 0 1 1 0 0 1 1 0 0 0 0 1 0 0 RP0 0 0 0 00 0 1 1 00 1 1 0 00 0 1 0 00 0 0 0 0 LIFE RP0 0 0 0 00 1 1 1 00 1 0 0 00 1 1 0 00 0 0 0 0 LIFE LIFE RP0 0 1 0 00 1 1 0 01 0 0 1 00 1 1 0 00 0 0 0 0 ..................................................

One interacts with the Game of Life by creating an initial configuration and observing how it evolves.

Although you should test your implementation on more complex examples such as the glider in a larger universe, show the action of the blinker (three adjoining cells in a row all alive), over three generations, in a 3 by 3 grid.

(1,4)=TRUERETURN'' Count the number of neighbours of the point i,j' (Assume i/j +/- 1 will not fall out of world)'FUNCTION count_neighbours(i%,j%) LOCAL count%,l% count%=0 FOR l%=-1 TO 1 IF world! (i%+l%,j%+1) count%=count%+1 ENDIF NEXT l% IF world! (i%+1,j%) count%=count%+1 ENDIF RETURN count%ENDFUNC'' Update the world one step'PROCEDURE update_world LOCAL i%,j% ' compute neighbour counts and store FOR i%=1 TO 30 FOR j%=1 TO 30 ns%(i%,j%)[email protected]_neighbours(i%,j%) NEXT j% NEXT i% ' update the world cells FOR i%=1 TO 30 FOR j%=1 TO 30 IF world!

Thus, while it is somewhat verbose, it fully simulates Conway's Game of Life and is relatively simple to expand to feature different starting shapes.

Define life(pattern) = Prgm Local x,y,nt,count,save,xl,yl,xh,yh Define nt(y,x) = when(pxl Test(y,x), 1, 0) {}→save set Graph("Axes", "Off")→save[1] set Graph("Grid", "Off")→save[2] set Graph("Labels", "Off")→save[3] Fn Off Plot Off Clr Draw If pattern = "blinker" Then 36→yl 40→yh 78→xl 82→xh Pxl On 36,80 Pxl On 38,80 Pxl On 40,80 Else If pattern = "glider" Then 30→yl 40→yh 76→xl 88→xh Pxl On 38,76 Pxl On 36,78 Pxl On 36,80 Pxl On 38,80 Pxl On 40,80 Else If pattern = "r" Then 38-5*2→yl 38+5*2→yh 80-5*2→xl 80+5*2→xh Pxl On 38,78 Pxl On 36,82 Pxl On 36,80 Pxl On 38,80 Pxl On 40,80 End If While get Key() = 0 © Expand upper-left corner to whole cell For y,yl,yh,2 For x,xl,xh,2 If pxl Test(y,x) Then Pxl On y+1,x Pxl On y+1,x+1 Pxl On y, x+1 Else Pxl Off y+1,x Pxl Off y+1,x+1 Pxl Off y, x+1 End If End For End For © Compute next generation For y,yl,yh,2 For x,xl,xh,2 nt(y-1,x-1) + nt(y-1,x) + nt(y-1,x+2) + nt(y,x-1) + nt(y+1,x+2) + nt(y+2,x-1) + nt(y+2,x+1) + nt(y+2,x+2) → count If count = 3 Then Pxl On y,x Else If count ≠ 2 Then Pxl Off y,x End If End For End For End While © Restore changed options set Graph("Axes", save[1]) set Graph("Grid", save[2]) set Graph("Labels", save[3])End Prgm Also see Conway's Game of Life/C Considering that the simplest implementation in C++ would lack any use of the object-oriented paradigm, this code was specifically written to demonstrate the various object-oriented features of C++.

bne randloop lda cmp # bne randloop clearmem: lda #$df ;set df-[[

randfill: stx $01 ;$200 for indirect ldx #$02 ;addressing stx $02randloop: lda $fe ;generate random and #$01 ;pixels on the sta ($01), Y ;screen jsr inc0103 cmp #$00 bne randloop lda $02 cmp #$06 bne randloop clearmem: lda #$df ;set $07df-$0a20 sta $01 ;to $#00 lda #$07 sta $02clearbyte: lda #$00 sta ($01), Y jsr inc0103 cmp #$20 bne clearbyte lda $02 cmp #$0a bne clearbyte starttick:copyscreen: lda #$00 ;set up source sta $01 ;pointer at sta $03 ;$01/$02 and lda #$02 ;dest pointer sta $02 ;at $03/$04 lda #$08 sta $04 ldy #$00copybyte: lda ($01), Y ;copy pixel to sta ($03), Y ;back buffer jsr inc0103 ;increment pointers cmp #$00 ;check to see bne copybyte ;if we're at $600 lda $02 ;if so, we've cmp #$06 ;copied the bne copybyte ;entire screen conway: lda #$df ;apply conway rules sta $01 ;reset the pointer sta $03 ;to $#01df/$#07df lda #$01 ;($200 - $21) sta $02 ;($800 - $21) lda #$07 sta $04onecell: lda #$00 ;process one cell ldy #$01 ;upper cell clc adc ($03), Y ldy #$41 ;lower cell clc adc ($03), Ychkleft: tax ;check to see lda $01 ;if we're at the and #$1f ;left edge tay txa cpy #$1f beq rightcellsleftcells: ldy #$00 ;upper-left cell clc adc ($03), Y ldy #$20 ;left cell clc adc ($03), Y ldy #$40 ;lower-left cell clc adc ($03), Ychkright: tax ;check to see lda $01 ;if we're at the and #$1f ;right edge tay txa cpy #$1e beq evaluaterightcells: ldy #$02 ;upper-right cell clc adc ($03), Y ldy #$22 ;right cell clc adc ($03), Y ldy #$42 ;lower-right cell clc adc ($03), Yevaluate: ldx #$01 ;evaluate total ldy #$21 ;for current cell cmp #$03 ;3 = alive beq storex ldx #$00 cmp #$02 ;2 = alive if bne storex ;c = alive lda ($03), Y and #$01 taxstorex: txa ;store to screen sta ($01), Y jsr inc0103 ;move to next cellconwayloop: cmp #$e0 ;if not last cell, bne onecell ;process next cell lda $02 cmp #$05 bne onecell jmp starttick ;run next tick inc0103: lda $01 ;increment $01 cmp #$ff ;and $03 as 16-bit bne onlyinc01 ;pointers inc $02 inc $04onlyinc01: inc $01 lda $01 sta $03 rts The solution uses one cell thick border around square Petri dish as uninhabited dire land. Sample output contains 3 generations of the blinker and 5 of the glider: See Conway's Game of Life/ALGOL 68 APL2 (Dialog) Example in one line APL \ 1130 example (very old APL dialect via simulator) APL1130From: APL \ 1130 Samples The following APL \ 1130 code will need APL385 font installed to display correctly. See Download APL TT Font ∇LIFE[⎕]∇[0] NG←LIFE CG; W[1] W←CG+(¯1⊖CG)+(1⊖CG)+(¯1⌽CG)+(1⌽CG)[2] W←W+(1⊖1⌽CG)+(¯1⊖1⌽CG)+(1⊖¯1⌽CG)+(¯1⊖¯1⌽CG)[3] NG←(3=W)+(CG∧4=W) ∇ RP←5 5⍴0 0 0 0 0 0 0 1 1 0 0 1 1 0 0 0 0 1 0 0 RP0 0 0 0 00 0 1 1 00 1 1 0 00 0 1 0 00 0 0 0 0 LIFE RP0 0 0 0 00 1 1 1 00 1 0 0 00 1 1 0 00 0 0 0 0 LIFE LIFE RP0 0 1 0 00 1 1 0 01 0 0 1 00 1 1 0 00 0 0 0 0 .................................................. One interacts with the Game of Life by creating an initial configuration and observing how it evolves. Although you should test your implementation on more complex examples such as the glider in a larger universe, show the action of the blinker (three adjoining cells in a row all alive), over three generations, in a 3 by 3 grid. (1,4)=TRUERETURN'' Count the number of neighbours of the point i,j' (Assume i/j +/- 1 will not fall out of world)'FUNCTION count_neighbours(i%,j%) LOCAL count%,l% count%=0 FOR l%=-1 TO 1 IF world! (i%+l%,j%+1) count%=count%+1 ENDIF NEXT l% IF world! (i%+1,j%) count%=count%+1 ENDIF RETURN count%ENDFUNC'' Update the world one step'PROCEDURE update_world LOCAL i%,j% ' compute neighbour counts and store FOR i%=1 TO 30 FOR j%=1 TO 30 ns%(i%,j%)[email protected]_neighbours(i%,j%) NEXT j% NEXT i% ' update the world cells FOR i%=1 TO 30 FOR j%=1 TO 30 IF world!

||

randfill: stx $01 ;$200 for indirect ldx #$02 ;addressing stx $02randloop: lda $fe ;generate random and #$01 ;pixels on the sta ($01), Y ;screen jsr inc0103 cmp #$00 bne randloop lda $02 cmp #$06 bne randloop clearmem: lda #$df ;set $07df-$0a20 sta $01 ;to $#00 lda #$07 sta $02clearbyte: lda #$00 sta ($01), Y jsr inc0103 cmp #$20 bne clearbyte lda $02 cmp #$0a bne clearbyte starttick:copyscreen: lda #$00 ;set up source sta $01 ;pointer at sta $03 ;$01/$02 and lda #$02 ;dest pointer sta $02 ;at $03/$04 lda #$08 sta $04 ldy #$00copybyte: lda ($01), Y ;copy pixel to sta ($03), Y ;back buffer jsr inc0103 ;increment pointers cmp #$00 ;check to see bne copybyte ;if we're at $600 lda $02 ;if so, we've cmp #$06 ;copied the bne copybyte ;entire screen conway: lda #$df ;apply conway rules sta $01 ;reset the pointer sta $03 ;to $#01df/$#07df lda #$01 ;($200 - $21) sta $02 ;($800 - $21) lda #$07 sta $04onecell: lda #$00 ;process one cell ldy #$01 ;upper cell clc adc ($03), Y ldy #$41 ;lower cell clc adc ($03), Ychkleft: tax ;check to see lda $01 ;if we're at the and #$1f ;left edge tay txa cpy #$1f beq rightcellsleftcells: ldy #$00 ;upper-left cell clc adc ($03), Y ldy #$20 ;left cell clc adc ($03), Y ldy #$40 ;lower-left cell clc adc ($03), Ychkright: tax ;check to see lda $01 ;if we're at the and #$1f ;right edge tay txa cpy #$1e beq evaluaterightcells: ldy #$02 ;upper-right cell clc adc ($03), Y ldy #$22 ;right cell clc adc ($03), Y ldy #$42 ;lower-right cell clc adc ($03), Yevaluate: ldx #$01 ;evaluate total ldy #$21 ;for current cell cmp #$03 ;3 = alive beq storex ldx #$00 cmp #$02 ;2 = alive if bne storex ;c = alive lda ($03), Y and #$01 taxstorex: txa ;store to screen sta ($01), Y jsr inc0103 ;move to next cellconwayloop: cmp #$e0 ;if not last cell, bne onecell ;process next cell lda $02 cmp #$05 bne onecell jmp starttick ;run next tick inc0103: lda $01 ;increment $01 cmp #$ff ;and $03 as 16-bit bne onlyinc01 ;pointers inc $02 inc $04onlyinc01: inc $01 lda $01 sta $03 rts The solution uses one cell thick border around square Petri dish as uninhabited dire land. Sample output contains 3 generations of the blinker and 5 of the glider: See Conway's Game of Life/ALGOL 68 APL2 (Dialog) Example in one line APL \ 1130 example (very old APL dialect via simulator) APL1130From: APL \ 1130 Samples The following APL \ 1130 code will need APL385 font installed to display correctly.

See Download APL TT Font ∇LIFE[⎕]∇[0] NG←LIFE CG; W[1] W←CG+(¯1⊖CG)+(1⊖CG)+(¯1⌽CG)+(1⌽CG)[2] W←W+(1⊖1⌽CG)+(¯1⊖1⌽CG)+(1⊖¯1⌽CG)+(¯1⊖¯1⌽CG)[3] NG←(3=W)+(CG∧4=W) ∇ RP←5 5⍴0 0 0 0 0 0 0 1 1 0 0 1 1 0 0 0 0 1 0 0 RP0 0 0 0 00 0 1 1 00 1 1 0 00 0 1 0 00 0 0 0 0 LIFE RP0 0 0 0 00 1 1 1 00 1 0 0 00 1 1 0 00 0 0 0 0 LIFE LIFE RP0 0 1 0 00 1 1 0 01 0 0 1 00 1 1 0 00 0 0 0 0 ..................................................

One interacts with the Game of Life by creating an initial configuration and observing how it evolves.

Although you should test your implementation on more complex examples such as the glider in a larger universe, show the action of the blinker (three adjoining cells in a row all alive), over three generations, in a 3 by 3 grid.

(1,4)=TRUERETURN'' Count the number of neighbours of the point i,j' (Assume i/j +/- 1 will not fall out of world)'FUNCTION count_neighbours(i%,j%) LOCAL count%,l% count%=0 FOR l%=-1 TO 1 IF world! (i%+l%,j%+1) count%=count%+1 ENDIF NEXT l% IF world! (i%+1,j%) count%=count%+1 ENDIF RETURN count%ENDFUNC'' Update the world one step'PROCEDURE update_world LOCAL i%,j% ' compute neighbour counts and store FOR i%=1 TO 30 FOR j%=1 TO 30 ns%(i%,j%)[email protected]_neighbours(i%,j%) NEXT j% NEXT i% ' update the world cells FOR i%=1 TO 30 FOR j%=1 TO 30 IF world!

Thus, while it is somewhat verbose, it fully simulates Conway's Game of Life and is relatively simple to expand to feature different starting shapes.

Define life(pattern) = Prgm Local x,y,nt,count,save,xl,yl,xh,yh Define nt(y,x) = when(pxl Test(y,x), 1, 0) {}→save set Graph("Axes", "Off")→save[1] set Graph("Grid", "Off")→save[2] set Graph("Labels", "Off")→save[3] Fn Off Plot Off Clr Draw If pattern = "blinker" Then 36→yl 40→yh 78→xl 82→xh Pxl On 36,80 Pxl On 38,80 Pxl On 40,80 Else If pattern = "glider" Then 30→yl 40→yh 76→xl 88→xh Pxl On 38,76 Pxl On 36,78 Pxl On 36,80 Pxl On 38,80 Pxl On 40,80 Else If pattern = "r" Then 38-5*2→yl 38+5*2→yh 80-5*2→xl 80+5*2→xh Pxl On 38,78 Pxl On 36,82 Pxl On 36,80 Pxl On 38,80 Pxl On 40,80 End If While get Key() = 0 © Expand upper-left corner to whole cell For y,yl,yh,2 For x,xl,xh,2 If pxl Test(y,x) Then Pxl On y+1,x Pxl On y+1,x+1 Pxl On y, x+1 Else Pxl Off y+1,x Pxl Off y+1,x+1 Pxl Off y, x+1 End If End For End For © Compute next generation For y,yl,yh,2 For x,xl,xh,2 nt(y-1,x-1) + nt(y-1,x) + nt(y-1,x+2) + nt(y,x-1) + nt(y+1,x+2) + nt(y+2,x-1) + nt(y+2,x+1) + nt(y+2,x+2) → count If count = 3 Then Pxl On y,x Else If count ≠ 2 Then Pxl Off y,x End If End For End For End While © Restore changed options set Graph("Axes", save[1]) set Graph("Grid", save[2]) set Graph("Labels", save[3])End Prgm Also see Conway's Game of Life/C Considering that the simplest implementation in C++ would lack any use of the object-oriented paradigm, this code was specifically written to demonstrate the various object-oriented features of C++.

]]a20 sta

randfill: stx $01 ;$200 for indirect ldx #$02 ;addressing stx $02randloop: lda $fe ;generate random and #$01 ;pixels on the sta ($01), Y ;screen jsr inc0103 cmp #$00 bne randloop lda $02 cmp #$06 bne randloop clearmem: lda #$df ;set $07df-$0a20 sta $01 ;to $#00 lda #$07 sta $02clearbyte: lda #$00 sta ($01), Y jsr inc0103 cmp #$20 bne clearbyte lda $02 cmp #$0a bne clearbyte starttick:copyscreen: lda #$00 ;set up source sta $01 ;pointer at sta $03 ;$01/$02 and lda #$02 ;dest pointer sta $02 ;at $03/$04 lda #$08 sta $04 ldy #$00copybyte: lda ($01), Y ;copy pixel to sta ($03), Y ;back buffer jsr inc0103 ;increment pointers cmp #$00 ;check to see bne copybyte ;if we're at $600 lda $02 ;if so, we've cmp #$06 ;copied the bne copybyte ;entire screen conway: lda #$df ;apply conway rules sta $01 ;reset the pointer sta $03 ;to $#01df/$#07df lda #$01 ;($200 - $21) sta $02 ;($800 - $21) lda #$07 sta $04onecell: lda #$00 ;process one cell ldy #$01 ;upper cell clc adc ($03), Y ldy #$41 ;lower cell clc adc ($03), Ychkleft: tax ;check to see lda $01 ;if we're at the and #$1f ;left edge tay txa cpy #$1f beq rightcellsleftcells: ldy #$00 ;upper-left cell clc adc ($03), Y ldy #$20 ;left cell clc adc ($03), Y ldy #$40 ;lower-left cell clc adc ($03), Ychkright: tax ;check to see lda $01 ;if we're at the and #$1f ;right edge tay txa cpy #$1e beq evaluaterightcells: ldy #$02 ;upper-right cell clc adc ($03), Y ldy #$22 ;right cell clc adc ($03), Y ldy #$42 ;lower-right cell clc adc ($03), Yevaluate: ldx #$01 ;evaluate total ldy #$21 ;for current cell cmp #$03 ;3 = alive beq storex ldx #$00 cmp #$02 ;2 = alive if bne storex ;c = alive lda ($03), Y and #$01 taxstorex: txa ;store to screen sta ($01), Y jsr inc0103 ;move to next cellconwayloop: cmp #$e0 ;if not last cell, bne onecell ;process next cell lda $02 cmp #$05 bne onecell jmp starttick ;run next tick inc0103: lda $01 ;increment $01 cmp #$ff ;and $03 as 16-bit bne onlyinc01 ;pointers inc $02 inc $04onlyinc01: inc $01 lda $01 sta $03 rts The solution uses one cell thick border around square Petri dish as uninhabited dire land. Sample output contains 3 generations of the blinker and 5 of the glider: See Conway's Game of Life/ALGOL 68 APL2 (Dialog) Example in one line APL \ 1130 example (very old APL dialect via simulator) APL1130From: APL \ 1130 Samples The following APL \ 1130 code will need APL385 font installed to display correctly. See Download APL TT Font ∇LIFE[⎕]∇[0] NG←LIFE CG; W[1] W←CG+(¯1⊖CG)+(1⊖CG)+(¯1⌽CG)+(1⌽CG)[2] W←W+(1⊖1⌽CG)+(¯1⊖1⌽CG)+(1⊖¯1⌽CG)+(¯1⊖¯1⌽CG)[3] NG←(3=W)+(CG∧4=W) ∇ RP←5 5⍴0 0 0 0 0 0 0 1 1 0 0 1 1 0 0 0 0 1 0 0 RP0 0 0 0 00 0 1 1 00 1 1 0 00 0 1 0 00 0 0 0 0 LIFE RP0 0 0 0 00 1 1 1 00 1 0 0 00 1 1 0 00 0 0 0 0 LIFE LIFE RP0 0 1 0 00 1 1 0 01 0 0 1 00 1 1 0 00 0 0 0 0 .................................................. One interacts with the Game of Life by creating an initial configuration and observing how it evolves. Although you should test your implementation on more complex examples such as the glider in a larger universe, show the action of the blinker (three adjoining cells in a row all alive), over three generations, in a 3 by 3 grid. (1,4)=TRUERETURN'' Count the number of neighbours of the point i,j' (Assume i/j +/- 1 will not fall out of world)'FUNCTION count_neighbours(i%,j%) LOCAL count%,l% count%=0 FOR l%=-1 TO 1 IF world! (i%+l%,j%+1) count%=count%+1 ENDIF NEXT l% IF world! (i%+1,j%) count%=count%+1 ENDIF RETURN count%ENDFUNC'' Update the world one step'PROCEDURE update_world LOCAL i%,j% ' compute neighbour counts and store FOR i%=1 TO 30 FOR j%=1 TO 30 ns%(i%,j%)[email protected]_neighbours(i%,j%) NEXT j% NEXT i% ' update the world cells FOR i%=1 TO 30 FOR j%=1 TO 30 IF world!

||

randfill: stx $01 ;$200 for indirect ldx #$02 ;addressing stx $02randloop: lda $fe ;generate random and #$01 ;pixels on the sta ($01), Y ;screen jsr inc0103 cmp #$00 bne randloop lda $02 cmp #$06 bne randloop clearmem: lda #$df ;set $07df-$0a20 sta $01 ;to $#00 lda #$07 sta $02clearbyte: lda #$00 sta ($01), Y jsr inc0103 cmp #$20 bne clearbyte lda $02 cmp #$0a bne clearbyte starttick:copyscreen: lda #$00 ;set up source sta $01 ;pointer at sta $03 ;$01/$02 and lda #$02 ;dest pointer sta $02 ;at $03/$04 lda #$08 sta $04 ldy #$00copybyte: lda ($01), Y ;copy pixel to sta ($03), Y ;back buffer jsr inc0103 ;increment pointers cmp #$00 ;check to see bne copybyte ;if we're at $600 lda $02 ;if so, we've cmp #$06 ;copied the bne copybyte ;entire screen conway: lda #$df ;apply conway rules sta $01 ;reset the pointer sta $03 ;to $#01df/$#07df lda #$01 ;($200 - $21) sta $02 ;($800 - $21) lda #$07 sta $04onecell: lda #$00 ;process one cell ldy #$01 ;upper cell clc adc ($03), Y ldy #$41 ;lower cell clc adc ($03), Ychkleft: tax ;check to see lda $01 ;if we're at the and #$1f ;left edge tay txa cpy #$1f beq rightcellsleftcells: ldy #$00 ;upper-left cell clc adc ($03), Y ldy #$20 ;left cell clc adc ($03), Y ldy #$40 ;lower-left cell clc adc ($03), Ychkright: tax ;check to see lda $01 ;if we're at the and #$1f ;right edge tay txa cpy #$1e beq evaluaterightcells: ldy #$02 ;upper-right cell clc adc ($03), Y ldy #$22 ;right cell clc adc ($03), Y ldy #$42 ;lower-right cell clc adc ($03), Yevaluate: ldx #$01 ;evaluate total ldy #$21 ;for current cell cmp #$03 ;3 = alive beq storex ldx #$00 cmp #$02 ;2 = alive if bne storex ;c = alive lda ($03), Y and #$01 taxstorex: txa ;store to screen sta ($01), Y jsr inc0103 ;move to next cellconwayloop: cmp #$e0 ;if not last cell, bne onecell ;process next cell lda $02 cmp #$05 bne onecell jmp starttick ;run next tick inc0103: lda $01 ;increment $01 cmp #$ff ;and $03 as 16-bit bne onlyinc01 ;pointers inc $02 inc $04onlyinc01: inc $01 lda $01 sta $03 rts The solution uses one cell thick border around square Petri dish as uninhabited dire land. Sample output contains 3 generations of the blinker and 5 of the glider: See Conway's Game of Life/ALGOL 68 APL2 (Dialog) Example in one line APL \ 1130 example (very old APL dialect via simulator) APL1130From: APL \ 1130 Samples The following APL \ 1130 code will need APL385 font installed to display correctly.

See Download APL TT Font ∇LIFE[⎕]∇[0] NG←LIFE CG; W[1] W←CG+(¯1⊖CG)+(1⊖CG)+(¯1⌽CG)+(1⌽CG)[2] W←W+(1⊖1⌽CG)+(¯1⊖1⌽CG)+(1⊖¯1⌽CG)+(¯1⊖¯1⌽CG)[3] NG←(3=W)+(CG∧4=W) ∇ RP←5 5⍴0 0 0 0 0 0 0 1 1 0 0 1 1 0 0 0 0 1 0 0 RP0 0 0 0 00 0 1 1 00 1 1 0 00 0 1 0 00 0 0 0 0 LIFE RP0 0 0 0 00 1 1 1 00 1 0 0 00 1 1 0 00 0 0 0 0 LIFE LIFE RP0 0 1 0 00 1 1 0 01 0 0 1 00 1 1 0 00 0 0 0 0 ..................................................

One interacts with the Game of Life by creating an initial configuration and observing how it evolves.

Although you should test your implementation on more complex examples such as the glider in a larger universe, show the action of the blinker (three adjoining cells in a row all alive), over three generations, in a 3 by 3 grid.

(1,4)=TRUERETURN'' Count the number of neighbours of the point i,j' (Assume i/j +/- 1 will not fall out of world)'FUNCTION count_neighbours(i%,j%) LOCAL count%,l% count%=0 FOR l%=-1 TO 1 IF world! (i%+l%,j%+1) count%=count%+1 ENDIF NEXT l% IF world! (i%+1,j%) count%=count%+1 ENDIF RETURN count%ENDFUNC'' Update the world one step'PROCEDURE update_world LOCAL i%,j% ' compute neighbour counts and store FOR i%=1 TO 30 FOR j%=1 TO 30 ns%(i%,j%)[email protected]_neighbours(i%,j%) NEXT j% NEXT i% ' update the world cells FOR i%=1 TO 30 FOR j%=1 TO 30 IF world!

Thus, while it is somewhat verbose, it fully simulates Conway's Game of Life and is relatively simple to expand to feature different starting shapes.

Define life(pattern) = Prgm Local x,y,nt,count,save,xl,yl,xh,yh Define nt(y,x) = when(pxl Test(y,x), 1, 0) {}→save set Graph("Axes", "Off")→save[1] set Graph("Grid", "Off")→save[2] set Graph("Labels", "Off")→save[3] Fn Off Plot Off Clr Draw If pattern = "blinker" Then 36→yl 40→yh 78→xl 82→xh Pxl On 36,80 Pxl On 38,80 Pxl On 40,80 Else If pattern = "glider" Then 30→yl 40→yh 76→xl 88→xh Pxl On 38,76 Pxl On 36,78 Pxl On 36,80 Pxl On 38,80 Pxl On 40,80 Else If pattern = "r" Then 38-5*2→yl 38+5*2→yh 80-5*2→xl 80+5*2→xh Pxl On 38,78 Pxl On 36,82 Pxl On 36,80 Pxl On 38,80 Pxl On 40,80 End If While get Key() = 0 © Expand upper-left corner to whole cell For y,yl,yh,2 For x,xl,xh,2 If pxl Test(y,x) Then Pxl On y+1,x Pxl On y+1,x+1 Pxl On y, x+1 Else Pxl Off y+1,x Pxl Off y+1,x+1 Pxl Off y, x+1 End If End For End For © Compute next generation For y,yl,yh,2 For x,xl,xh,2 nt(y-1,x-1) + nt(y-1,x) + nt(y-1,x+2) + nt(y,x-1) + nt(y+1,x+2) + nt(y+2,x-1) + nt(y+2,x+1) + nt(y+2,x+2) → count If count = 3 Then Pxl On y,x Else If count ≠ 2 Then Pxl Off y,x End If End For End For End While © Restore changed options set Graph("Axes", save[1]) set Graph("Grid", save[2]) set Graph("Labels", save[3])End Prgm Also see Conway's Game of Life/C Considering that the simplest implementation in C++ would lack any use of the object-oriented paradigm, this code was specifically written to demonstrate the various object-oriented features of C++.

;to $#00 lda # sta clearbyte: lda #[[

randfill: stx $01 ;$200 for indirect ldx #$02 ;addressing stx $02randloop: lda $fe ;generate random and #$01 ;pixels on the sta ($01), Y ;screen jsr inc0103 cmp #$00 bne randloop lda $02 cmp #$06 bne randloop clearmem: lda #$df ;set $07df-$0a20 sta $01 ;to $#00 lda #$07 sta $02clearbyte: lda #$00 sta ($01), Y jsr inc0103 cmp #$20 bne clearbyte lda $02 cmp #$0a bne clearbyte starttick:copyscreen: lda #$00 ;set up source sta $01 ;pointer at sta $03 ;$01/$02 and lda #$02 ;dest pointer sta $02 ;at $03/$04 lda #$08 sta $04 ldy #$00copybyte: lda ($01), Y ;copy pixel to sta ($03), Y ;back buffer jsr inc0103 ;increment pointers cmp #$00 ;check to see bne copybyte ;if we're at $600 lda $02 ;if so, we've cmp #$06 ;copied the bne copybyte ;entire screen conway: lda #$df ;apply conway rules sta $01 ;reset the pointer sta $03 ;to $#01df/$#07df lda #$01 ;($200 - $21) sta $02 ;($800 - $21) lda #$07 sta $04onecell: lda #$00 ;process one cell ldy #$01 ;upper cell clc adc ($03), Y ldy #$41 ;lower cell clc adc ($03), Ychkleft: tax ;check to see lda $01 ;if we're at the and #$1f ;left edge tay txa cpy #$1f beq rightcellsleftcells: ldy #$00 ;upper-left cell clc adc ($03), Y ldy #$20 ;left cell clc adc ($03), Y ldy #$40 ;lower-left cell clc adc ($03), Ychkright: tax ;check to see lda $01 ;if we're at the and #$1f ;right edge tay txa cpy #$1e beq evaluaterightcells: ldy #$02 ;upper-right cell clc adc ($03), Y ldy #$22 ;right cell clc adc ($03), Y ldy #$42 ;lower-right cell clc adc ($03), Yevaluate: ldx #$01 ;evaluate total ldy #$21 ;for current cell cmp #$03 ;3 = alive beq storex ldx #$00 cmp #$02 ;2 = alive if bne storex ;c = alive lda ($03), Y and #$01 taxstorex: txa ;store to screen sta ($01), Y jsr inc0103 ;move to next cellconwayloop: cmp #$e0 ;if not last cell, bne onecell ;process next cell lda $02 cmp #$05 bne onecell jmp starttick ;run next tick inc0103: lda $01 ;increment $01 cmp #$ff ;and $03 as 16-bit bne onlyinc01 ;pointers inc $02 inc $04onlyinc01: inc $01 lda $01 sta $03 rts The solution uses one cell thick border around square Petri dish as uninhabited dire land. Sample output contains 3 generations of the blinker and 5 of the glider: See Conway's Game of Life/ALGOL 68 APL2 (Dialog) Example in one line APL \ 1130 example (very old APL dialect via simulator) APL1130From: APL \ 1130 Samples The following APL \ 1130 code will need APL385 font installed to display correctly. See Download APL TT Font ∇LIFE[⎕]∇[0] NG←LIFE CG; W[1] W←CG+(¯1⊖CG)+(1⊖CG)+(¯1⌽CG)+(1⌽CG)[2] W←W+(1⊖1⌽CG)+(¯1⊖1⌽CG)+(1⊖¯1⌽CG)+(¯1⊖¯1⌽CG)[3] NG←(3=W)+(CG∧4=W) ∇ RP←5 5⍴0 0 0 0 0 0 0 1 1 0 0 1 1 0 0 0 0 1 0 0 RP0 0 0 0 00 0 1 1 00 1 1 0 00 0 1 0 00 0 0 0 0 LIFE RP0 0 0 0 00 1 1 1 00 1 0 0 00 1 1 0 00 0 0 0 0 LIFE LIFE RP0 0 1 0 00 1 1 0 01 0 0 1 00 1 1 0 00 0 0 0 0 .................................................. One interacts with the Game of Life by creating an initial configuration and observing how it evolves. Although you should test your implementation on more complex examples such as the glider in a larger universe, show the action of the blinker (three adjoining cells in a row all alive), over three generations, in a 3 by 3 grid. (1,4)=TRUERETURN'' Count the number of neighbours of the point i,j' (Assume i/j +/- 1 will not fall out of world)'FUNCTION count_neighbours(i%,j%) LOCAL count%,l% count%=0 FOR l%=-1 TO 1 IF world! (i%+l%,j%+1) count%=count%+1 ENDIF NEXT l% IF world! (i%+1,j%) count%=count%+1 ENDIF RETURN count%ENDFUNC'' Update the world one step'PROCEDURE update_world LOCAL i%,j% ' compute neighbour counts and store FOR i%=1 TO 30 FOR j%=1 TO 30 ns%(i%,j%)[email protected]_neighbours(i%,j%) NEXT j% NEXT i% ' update the world cells FOR i%=1 TO 30 FOR j%=1 TO 30 IF world!

||

randfill: stx $01 ;$200 for indirect ldx #$02 ;addressing stx $02randloop: lda $fe ;generate random and #$01 ;pixels on the sta ($01), Y ;screen jsr inc0103 cmp #$00 bne randloop lda $02 cmp #$06 bne randloop clearmem: lda #$df ;set $07df-$0a20 sta $01 ;to $#00 lda #$07 sta $02clearbyte: lda #$00 sta ($01), Y jsr inc0103 cmp #$20 bne clearbyte lda $02 cmp #$0a bne clearbyte starttick:copyscreen: lda #$00 ;set up source sta $01 ;pointer at sta $03 ;$01/$02 and lda #$02 ;dest pointer sta $02 ;at $03/$04 lda #$08 sta $04 ldy #$00copybyte: lda ($01), Y ;copy pixel to sta ($03), Y ;back buffer jsr inc0103 ;increment pointers cmp #$00 ;check to see bne copybyte ;if we're at $600 lda $02 ;if so, we've cmp #$06 ;copied the bne copybyte ;entire screen conway: lda #$df ;apply conway rules sta $01 ;reset the pointer sta $03 ;to $#01df/$#07df lda #$01 ;($200 - $21) sta $02 ;($800 - $21) lda #$07 sta $04onecell: lda #$00 ;process one cell ldy #$01 ;upper cell clc adc ($03), Y ldy #$41 ;lower cell clc adc ($03), Ychkleft: tax ;check to see lda $01 ;if we're at the and #$1f ;left edge tay txa cpy #$1f beq rightcellsleftcells: ldy #$00 ;upper-left cell clc adc ($03), Y ldy #$20 ;left cell clc adc ($03), Y ldy #$40 ;lower-left cell clc adc ($03), Ychkright: tax ;check to see lda $01 ;if we're at the and #$1f ;right edge tay txa cpy #$1e beq evaluaterightcells: ldy #$02 ;upper-right cell clc adc ($03), Y ldy #$22 ;right cell clc adc ($03), Y ldy #$42 ;lower-right cell clc adc ($03), Yevaluate: ldx #$01 ;evaluate total ldy #$21 ;for current cell cmp #$03 ;3 = alive beq storex ldx #$00 cmp #$02 ;2 = alive if bne storex ;c = alive lda ($03), Y and #$01 taxstorex: txa ;store to screen sta ($01), Y jsr inc0103 ;move to next cellconwayloop: cmp #$e0 ;if not last cell, bne onecell ;process next cell lda $02 cmp #$05 bne onecell jmp starttick ;run next tick inc0103: lda $01 ;increment $01 cmp #$ff ;and $03 as 16-bit bne onlyinc01 ;pointers inc $02 inc $04onlyinc01: inc $01 lda $01 sta $03 rts The solution uses one cell thick border around square Petri dish as uninhabited dire land. Sample output contains 3 generations of the blinker and 5 of the glider: See Conway's Game of Life/ALGOL 68 APL2 (Dialog) Example in one line APL \ 1130 example (very old APL dialect via simulator) APL1130From: APL \ 1130 Samples The following APL \ 1130 code will need APL385 font installed to display correctly.

See Download APL TT Font ∇LIFE[⎕]∇[0] NG←LIFE CG; W[1] W←CG+(¯1⊖CG)+(1⊖CG)+(¯1⌽CG)+(1⌽CG)[2] W←W+(1⊖1⌽CG)+(¯1⊖1⌽CG)+(1⊖¯1⌽CG)+(¯1⊖¯1⌽CG)[3] NG←(3=W)+(CG∧4=W) ∇ RP←5 5⍴0 0 0 0 0 0 0 1 1 0 0 1 1 0 0 0 0 1 0 0 RP0 0 0 0 00 0 1 1 00 1 1 0 00 0 1 0 00 0 0 0 0 LIFE RP0 0 0 0 00 1 1 1 00 1 0 0 00 1 1 0 00 0 0 0 0 LIFE LIFE RP0 0 1 0 00 1 1 0 01 0 0 1 00 1 1 0 00 0 0 0 0 ..................................................

One interacts with the Game of Life by creating an initial configuration and observing how it evolves.

Although you should test your implementation on more complex examples such as the glider in a larger universe, show the action of the blinker (three adjoining cells in a row all alive), over three generations, in a 3 by 3 grid.

(1,4)=TRUERETURN'' Count the number of neighbours of the point i,j' (Assume i/j +/- 1 will not fall out of world)'FUNCTION count_neighbours(i%,j%) LOCAL count%,l% count%=0 FOR l%=-1 TO 1 IF world! (i%+l%,j%+1) count%=count%+1 ENDIF NEXT l% IF world! (i%+1,j%) count%=count%+1 ENDIF RETURN count%ENDFUNC'' Update the world one step'PROCEDURE update_world LOCAL i%,j% ' compute neighbour counts and store FOR i%=1 TO 30 FOR j%=1 TO 30 ns%(i%,j%)[email protected]_neighbours(i%,j%) NEXT j% NEXT i% ' update the world cells FOR i%=1 TO 30 FOR j%=1 TO 30 IF world!

Thus, while it is somewhat verbose, it fully simulates Conway's Game of Life and is relatively simple to expand to feature different starting shapes.

Define life(pattern) = Prgm Local x,y,nt,count,save,xl,yl,xh,yh Define nt(y,x) = when(pxl Test(y,x), 1, 0) {}→save set Graph("Axes", "Off")→save[1] set Graph("Grid", "Off")→save[2] set Graph("Labels", "Off")→save[3] Fn Off Plot Off Clr Draw If pattern = "blinker" Then 36→yl 40→yh 78→xl 82→xh Pxl On 36,80 Pxl On 38,80 Pxl On 40,80 Else If pattern = "glider" Then 30→yl 40→yh 76→xl 88→xh Pxl On 38,76 Pxl On 36,78 Pxl On 36,80 Pxl On 38,80 Pxl On 40,80 Else If pattern = "r" Then 38-5*2→yl 38+5*2→yh 80-5*2→xl 80+5*2→xh Pxl On 38,78 Pxl On 36,82 Pxl On 36,80 Pxl On 38,80 Pxl On 40,80 End If While get Key() = 0 © Expand upper-left corner to whole cell For y,yl,yh,2 For x,xl,xh,2 If pxl Test(y,x) Then Pxl On y+1,x Pxl On y+1,x+1 Pxl On y, x+1 Else Pxl Off y+1,x Pxl Off y+1,x+1 Pxl Off y, x+1 End If End For End For © Compute next generation For y,yl,yh,2 For x,xl,xh,2 nt(y-1,x-1) + nt(y-1,x) + nt(y-1,x+2) + nt(y,x-1) + nt(y+1,x+2) + nt(y+2,x-1) + nt(y+2,x+1) + nt(y+2,x+2) → count If count = 3 Then Pxl On y,x Else If count ≠ 2 Then Pxl Off y,x End If End For End For End While © Restore changed options set Graph("Axes", save[1]) set Graph("Grid", save[2]) set Graph("Labels", save[3])End Prgm Also see Conway's Game of Life/C Considering that the simplest implementation in C++ would lack any use of the object-oriented paradigm, this code was specifically written to demonstrate the various object-oriented features of C++.

]] sta (

randfill: stx $01 ;$200 for indirect ldx #$02 ;addressing stx $02randloop: lda $fe ;generate random and #$01 ;pixels on the sta ($01), Y ;screen jsr inc0103 cmp #$00 bne randloop lda $02 cmp #$06 bne randloop clearmem: lda #$df ;set $07df-$0a20 sta $01 ;to $#00 lda #$07 sta $02clearbyte: lda #$00 sta ($01), Y jsr inc0103 cmp #$20 bne clearbyte lda $02 cmp #$0a bne clearbyte starttick:copyscreen: lda #$00 ;set up source sta $01 ;pointer at sta $03 ;$01/$02 and lda #$02 ;dest pointer sta $02 ;at $03/$04 lda #$08 sta $04 ldy #$00copybyte: lda ($01), Y ;copy pixel to sta ($03), Y ;back buffer jsr inc0103 ;increment pointers cmp #$00 ;check to see bne copybyte ;if we're at $600 lda $02 ;if so, we've cmp #$06 ;copied the bne copybyte ;entire screen conway: lda #$df ;apply conway rules sta $01 ;reset the pointer sta $03 ;to $#01df/$#07df lda #$01 ;($200 - $21) sta $02 ;($800 - $21) lda #$07 sta $04onecell: lda #$00 ;process one cell ldy #$01 ;upper cell clc adc ($03), Y ldy #$41 ;lower cell clc adc ($03), Ychkleft: tax ;check to see lda $01 ;if we're at the and #$1f ;left edge tay txa cpy #$1f beq rightcellsleftcells: ldy #$00 ;upper-left cell clc adc ($03), Y ldy #$20 ;left cell clc adc ($03), Y ldy #$40 ;lower-left cell clc adc ($03), Ychkright: tax ;check to see lda $01 ;if we're at the and #$1f ;right edge tay txa cpy #$1e beq evaluaterightcells: ldy #$02 ;upper-right cell clc adc ($03), Y ldy #$22 ;right cell clc adc ($03), Y ldy #$42 ;lower-right cell clc adc ($03), Yevaluate: ldx #$01 ;evaluate total ldy #$21 ;for current cell cmp #$03 ;3 = alive beq storex ldx #$00 cmp #$02 ;2 = alive if bne storex ;c = alive lda ($03), Y and #$01 taxstorex: txa ;store to screen sta ($01), Y jsr inc0103 ;move to next cellconwayloop: cmp #$e0 ;if not last cell, bne onecell ;process next cell lda $02 cmp #$05 bne onecell jmp starttick ;run next tick inc0103: lda $01 ;increment $01 cmp #$ff ;and $03 as 16-bit bne onlyinc01 ;pointers inc $02 inc $04onlyinc01: inc $01 lda $01 sta $03 rts The solution uses one cell thick border around square Petri dish as uninhabited dire land. Sample output contains 3 generations of the blinker and 5 of the glider: See Conway's Game of Life/ALGOL 68 APL2 (Dialog) Example in one line APL \ 1130 example (very old APL dialect via simulator) APL1130From: APL \ 1130 Samples The following APL \ 1130 code will need APL385 font installed to display correctly. See Download APL TT Font ∇LIFE[⎕]∇[0] NG←LIFE CG; W[1] W←CG+(¯1⊖CG)+(1⊖CG)+(¯1⌽CG)+(1⌽CG)[2] W←W+(1⊖1⌽CG)+(¯1⊖1⌽CG)+(1⊖¯1⌽CG)+(¯1⊖¯1⌽CG)[3] NG←(3=W)+(CG∧4=W) ∇ RP←5 5⍴0 0 0 0 0 0 0 1 1 0 0 1 1 0 0 0 0 1 0 0 RP0 0 0 0 00 0 1 1 00 1 1 0 00 0 1 0 00 0 0 0 0 LIFE RP0 0 0 0 00 1 1 1 00 1 0 0 00 1 1 0 00 0 0 0 0 LIFE LIFE RP0 0 1 0 00 1 1 0 01 0 0 1 00 1 1 0 00 0 0 0 0 .................................................. One interacts with the Game of Life by creating an initial configuration and observing how it evolves. Although you should test your implementation on more complex examples such as the glider in a larger universe, show the action of the blinker (three adjoining cells in a row all alive), over three generations, in a 3 by 3 grid. (1,4)=TRUERETURN'' Count the number of neighbours of the point i,j' (Assume i/j +/- 1 will not fall out of world)'FUNCTION count_neighbours(i%,j%) LOCAL count%,l% count%=0 FOR l%=-1 TO 1 IF world! (i%+l%,j%+1) count%=count%+1 ENDIF NEXT l% IF world! (i%+1,j%) count%=count%+1 ENDIF RETURN count%ENDFUNC'' Update the world one step'PROCEDURE update_world LOCAL i%,j% ' compute neighbour counts and store FOR i%=1 TO 30 FOR j%=1 TO 30 ns%(i%,j%)[email protected]_neighbours(i%,j%) NEXT j% NEXT i% ' update the world cells FOR i%=1 TO 30 FOR j%=1 TO 30 IF world!

||

randfill: stx $01 ;$200 for indirect ldx #$02 ;addressing stx $02randloop: lda $fe ;generate random and #$01 ;pixels on the sta ($01), Y ;screen jsr inc0103 cmp #$00 bne randloop lda $02 cmp #$06 bne randloop clearmem: lda #$df ;set $07df-$0a20 sta $01 ;to $#00 lda #$07 sta $02clearbyte: lda #$00 sta ($01), Y jsr inc0103 cmp #$20 bne clearbyte lda $02 cmp #$0a bne clearbyte starttick:copyscreen: lda #$00 ;set up source sta $01 ;pointer at sta $03 ;$01/$02 and lda #$02 ;dest pointer sta $02 ;at $03/$04 lda #$08 sta $04 ldy #$00copybyte: lda ($01), Y ;copy pixel to sta ($03), Y ;back buffer jsr inc0103 ;increment pointers cmp #$00 ;check to see bne copybyte ;if we're at $600 lda $02 ;if so, we've cmp #$06 ;copied the bne copybyte ;entire screen conway: lda #$df ;apply conway rules sta $01 ;reset the pointer sta $03 ;to $#01df/$#07df lda #$01 ;($200 - $21) sta $02 ;($800 - $21) lda #$07 sta $04onecell: lda #$00 ;process one cell ldy #$01 ;upper cell clc adc ($03), Y ldy #$41 ;lower cell clc adc ($03), Ychkleft: tax ;check to see lda $01 ;if we're at the and #$1f ;left edge tay txa cpy #$1f beq rightcellsleftcells: ldy #$00 ;upper-left cell clc adc ($03), Y ldy #$20 ;left cell clc adc ($03), Y ldy #$40 ;lower-left cell clc adc ($03), Ychkright: tax ;check to see lda $01 ;if we're at the and #$1f ;right edge tay txa cpy #$1e beq evaluaterightcells: ldy #$02 ;upper-right cell clc adc ($03), Y ldy #$22 ;right cell clc adc ($03), Y ldy #$42 ;lower-right cell clc adc ($03), Yevaluate: ldx #$01 ;evaluate total ldy #$21 ;for current cell cmp #$03 ;3 = alive beq storex ldx #$00 cmp #$02 ;2 = alive if bne storex ;c = alive lda ($03), Y and #$01 taxstorex: txa ;store to screen sta ($01), Y jsr inc0103 ;move to next cellconwayloop: cmp #$e0 ;if not last cell, bne onecell ;process next cell lda $02 cmp #$05 bne onecell jmp starttick ;run next tick inc0103: lda $01 ;increment $01 cmp #$ff ;and $03 as 16-bit bne onlyinc01 ;pointers inc $02 inc $04onlyinc01: inc $01 lda $01 sta $03 rts The solution uses one cell thick border around square Petri dish as uninhabited dire land. Sample output contains 3 generations of the blinker and 5 of the glider: See Conway's Game of Life/ALGOL 68 APL2 (Dialog) Example in one line APL \ 1130 example (very old APL dialect via simulator) APL1130From: APL \ 1130 Samples The following APL \ 1130 code will need APL385 font installed to display correctly.

See Download APL TT Font ∇LIFE[⎕]∇[0] NG←LIFE CG; W[1] W←CG+(¯1⊖CG)+(1⊖CG)+(¯1⌽CG)+(1⌽CG)[2] W←W+(1⊖1⌽CG)+(¯1⊖1⌽CG)+(1⊖¯1⌽CG)+(¯1⊖¯1⌽CG)[3] NG←(3=W)+(CG∧4=W) ∇ RP←5 5⍴0 0 0 0 0 0 0 1 1 0 0 1 1 0 0 0 0 1 0 0 RP0 0 0 0 00 0 1 1 00 1 1 0 00 0 1 0 00 0 0 0 0 LIFE RP0 0 0 0 00 1 1 1 00 1 0 0 00 1 1 0 00 0 0 0 0 LIFE LIFE RP0 0 1 0 00 1 1 0 01 0 0 1 00 1 1 0 00 0 0 0 0 ..................................................

One interacts with the Game of Life by creating an initial configuration and observing how it evolves.

Although you should test your implementation on more complex examples such as the glider in a larger universe, show the action of the blinker (three adjoining cells in a row all alive), over three generations, in a 3 by 3 grid.

(1,4)=TRUERETURN'' Count the number of neighbours of the point i,j' (Assume i/j +/- 1 will not fall out of world)'FUNCTION count_neighbours(i%,j%) LOCAL count%,l% count%=0 FOR l%=-1 TO 1 IF world! (i%+l%,j%+1) count%=count%+1 ENDIF NEXT l% IF world! (i%+1,j%) count%=count%+1 ENDIF RETURN count%ENDFUNC'' Update the world one step'PROCEDURE update_world LOCAL i%,j% ' compute neighbour counts and store FOR i%=1 TO 30 FOR j%=1 TO 30 ns%(i%,j%)[email protected]_neighbours(i%,j%) NEXT j% NEXT i% ' update the world cells FOR i%=1 TO 30 FOR j%=1 TO 30 IF world!

Thus, while it is somewhat verbose, it fully simulates Conway's Game of Life and is relatively simple to expand to feature different starting shapes.

Define life(pattern) = Prgm Local x,y,nt,count,save,xl,yl,xh,yh Define nt(y,x) = when(pxl Test(y,x), 1, 0) {}→save set Graph("Axes", "Off")→save[1] set Graph("Grid", "Off")→save[2] set Graph("Labels", "Off")→save[3] Fn Off Plot Off Clr Draw If pattern = "blinker" Then 36→yl 40→yh 78→xl 82→xh Pxl On 36,80 Pxl On 38,80 Pxl On 40,80 Else If pattern = "glider" Then 30→yl 40→yh 76→xl 88→xh Pxl On 38,76 Pxl On 36,78 Pxl On 36,80 Pxl On 38,80 Pxl On 40,80 Else If pattern = "r" Then 38-5*2→yl 38+5*2→yh 80-5*2→xl 80+5*2→xh Pxl On 38,78 Pxl On 36,82 Pxl On 36,80 Pxl On 38,80 Pxl On 40,80 End If While get Key() = 0 © Expand upper-left corner to whole cell For y,yl,yh,2 For x,xl,xh,2 If pxl Test(y,x) Then Pxl On y+1,x Pxl On y+1,x+1 Pxl On y, x+1 Else Pxl Off y+1,x Pxl Off y+1,x+1 Pxl Off y, x+1 End If End For End For © Compute next generation For y,yl,yh,2 For x,xl,xh,2 nt(y-1,x-1) + nt(y-1,x) + nt(y-1,x+2) + nt(y,x-1) + nt(y+1,x+2) + nt(y+2,x-1) + nt(y+2,x+1) + nt(y+2,x+2) → count If count = 3 Then Pxl On y,x Else If count ≠ 2 Then Pxl Off y,x End If End For End For End While © Restore changed options set Graph("Axes", save[1]) set Graph("Grid", save[2]) set Graph("Labels", save[3])End Prgm Also see Conway's Game of Life/C Considering that the simplest implementation in C++ would lack any use of the object-oriented paradigm, this code was specifically written to demonstrate the various object-oriented features of C++.

), Y jsr inc0103 cmp # bne clearbyte lda cmp #[[

randfill: stx $01 ;$200 for indirect ldx #$02 ;addressing stx $02randloop: lda $fe ;generate random and #$01 ;pixels on the sta ($01), Y ;screen jsr inc0103 cmp #$00 bne randloop lda $02 cmp #$06 bne randloop clearmem: lda #$df ;set $07df-$0a20 sta $01 ;to $#00 lda #$07 sta $02clearbyte: lda #$00 sta ($01), Y jsr inc0103 cmp #$20 bne clearbyte lda $02 cmp #$0a bne clearbyte starttick:copyscreen: lda #$00 ;set up source sta $01 ;pointer at sta $03 ;$01/$02 and lda #$02 ;dest pointer sta $02 ;at $03/$04 lda #$08 sta $04 ldy #$00copybyte: lda ($01), Y ;copy pixel to sta ($03), Y ;back buffer jsr inc0103 ;increment pointers cmp #$00 ;check to see bne copybyte ;if we're at $600 lda $02 ;if so, we've cmp #$06 ;copied the bne copybyte ;entire screen conway: lda #$df ;apply conway rules sta $01 ;reset the pointer sta $03 ;to $#01df/$#07df lda #$01 ;($200 - $21) sta $02 ;($800 - $21) lda #$07 sta $04onecell: lda #$00 ;process one cell ldy #$01 ;upper cell clc adc ($03), Y ldy #$41 ;lower cell clc adc ($03), Ychkleft: tax ;check to see lda $01 ;if we're at the and #$1f ;left edge tay txa cpy #$1f beq rightcellsleftcells: ldy #$00 ;upper-left cell clc adc ($03), Y ldy #$20 ;left cell clc adc ($03), Y ldy #$40 ;lower-left cell clc adc ($03), Ychkright: tax ;check to see lda $01 ;if we're at the and #$1f ;right edge tay txa cpy #$1e beq evaluaterightcells: ldy #$02 ;upper-right cell clc adc ($03), Y ldy #$22 ;right cell clc adc ($03), Y ldy #$42 ;lower-right cell clc adc ($03), Yevaluate: ldx #$01 ;evaluate total ldy #$21 ;for current cell cmp #$03 ;3 = alive beq storex ldx #$00 cmp #$02 ;2 = alive if bne storex ;c = alive lda ($03), Y and #$01 taxstorex: txa ;store to screen sta ($01), Y jsr inc0103 ;move to next cellconwayloop: cmp #$e0 ;if not last cell, bne onecell ;process next cell lda $02 cmp #$05 bne onecell jmp starttick ;run next tick inc0103: lda $01 ;increment $01 cmp #$ff ;and $03 as 16-bit bne onlyinc01 ;pointers inc $02 inc $04onlyinc01: inc $01 lda $01 sta $03 rts The solution uses one cell thick border around square Petri dish as uninhabited dire land. Sample output contains 3 generations of the blinker and 5 of the glider: See Conway's Game of Life/ALGOL 68 APL2 (Dialog) Example in one line APL \ 1130 example (very old APL dialect via simulator) APL1130From: APL \ 1130 Samples The following APL \ 1130 code will need APL385 font installed to display correctly. See Download APL TT Font ∇LIFE[⎕]∇[0] NG←LIFE CG; W[1] W←CG+(¯1⊖CG)+(1⊖CG)+(¯1⌽CG)+(1⌽CG)[2] W←W+(1⊖1⌽CG)+(¯1⊖1⌽CG)+(1⊖¯1⌽CG)+(¯1⊖¯1⌽CG)[3] NG←(3=W)+(CG∧4=W) ∇ RP←5 5⍴0 0 0 0 0 0 0 1 1 0 0 1 1 0 0 0 0 1 0 0 RP0 0 0 0 00 0 1 1 00 1 1 0 00 0 1 0 00 0 0 0 0 LIFE RP0 0 0 0 00 1 1 1 00 1 0 0 00 1 1 0 00 0 0 0 0 LIFE LIFE RP0 0 1 0 00 1 1 0 01 0 0 1 00 1 1 0 00 0 0 0 0 .................................................. One interacts with the Game of Life by creating an initial configuration and observing how it evolves. Although you should test your implementation on more complex examples such as the glider in a larger universe, show the action of the blinker (three adjoining cells in a row all alive), over three generations, in a 3 by 3 grid. (1,4)=TRUERETURN'' Count the number of neighbours of the point i,j' (Assume i/j +/- 1 will not fall out of world)'FUNCTION count_neighbours(i%,j%) LOCAL count%,l% count%=0 FOR l%=-1 TO 1 IF world! (i%+l%,j%+1) count%=count%+1 ENDIF NEXT l% IF world! (i%+1,j%) count%=count%+1 ENDIF RETURN count%ENDFUNC'' Update the world one step'PROCEDURE update_world LOCAL i%,j% ' compute neighbour counts and store FOR i%=1 TO 30 FOR j%=1 TO 30 ns%(i%,j%)[email protected]_neighbours(i%,j%) NEXT j% NEXT i% ' update the world cells FOR i%=1 TO 30 FOR j%=1 TO 30 IF world!

||

randfill: stx $01 ;$200 for indirect ldx #$02 ;addressing stx $02randloop: lda $fe ;generate random and #$01 ;pixels on the sta ($01), Y ;screen jsr inc0103 cmp #$00 bne randloop lda $02 cmp #$06 bne randloop clearmem: lda #$df ;set $07df-$0a20 sta $01 ;to $#00 lda #$07 sta $02clearbyte: lda #$00 sta ($01), Y jsr inc0103 cmp #$20 bne clearbyte lda $02 cmp #$0a bne clearbyte starttick:copyscreen: lda #$00 ;set up source sta $01 ;pointer at sta $03 ;$01/$02 and lda #$02 ;dest pointer sta $02 ;at $03/$04 lda #$08 sta $04 ldy #$00copybyte: lda ($01), Y ;copy pixel to sta ($03), Y ;back buffer jsr inc0103 ;increment pointers cmp #$00 ;check to see bne copybyte ;if we're at $600 lda $02 ;if so, we've cmp #$06 ;copied the bne copybyte ;entire screen conway: lda #$df ;apply conway rules sta $01 ;reset the pointer sta $03 ;to $#01df/$#07df lda #$01 ;($200 - $21) sta $02 ;($800 - $21) lda #$07 sta $04onecell: lda #$00 ;process one cell ldy #$01 ;upper cell clc adc ($03), Y ldy #$41 ;lower cell clc adc ($03), Ychkleft: tax ;check to see lda $01 ;if we're at the and #$1f ;left edge tay txa cpy #$1f beq rightcellsleftcells: ldy #$00 ;upper-left cell clc adc ($03), Y ldy #$20 ;left cell clc adc ($03), Y ldy #$40 ;lower-left cell clc adc ($03), Ychkright: tax ;check to see lda $01 ;if we're at the and #$1f ;right edge tay txa cpy #$1e beq evaluaterightcells: ldy #$02 ;upper-right cell clc adc ($03), Y ldy #$22 ;right cell clc adc ($03), Y ldy #$42 ;lower-right cell clc adc ($03), Yevaluate: ldx #$01 ;evaluate total ldy #$21 ;for current cell cmp #$03 ;3 = alive beq storex ldx #$00 cmp #$02 ;2 = alive if bne storex ;c = alive lda ($03), Y and #$01 taxstorex: txa ;store to screen sta ($01), Y jsr inc0103 ;move to next cellconwayloop: cmp #$e0 ;if not last cell, bne onecell ;process next cell lda $02 cmp #$05 bne onecell jmp starttick ;run next tick inc0103: lda $01 ;increment $01 cmp #$ff ;and $03 as 16-bit bne onlyinc01 ;pointers inc $02 inc $04onlyinc01: inc $01 lda $01 sta $03 rts The solution uses one cell thick border around square Petri dish as uninhabited dire land. Sample output contains 3 generations of the blinker and 5 of the glider: See Conway's Game of Life/ALGOL 68 APL2 (Dialog) Example in one line APL \ 1130 example (very old APL dialect via simulator) APL1130From: APL \ 1130 Samples The following APL \ 1130 code will need APL385 font installed to display correctly.

See Download APL TT Font ∇LIFE[⎕]∇[0] NG←LIFE CG; W[1] W←CG+(¯1⊖CG)+(1⊖CG)+(¯1⌽CG)+(1⌽CG)[2] W←W+(1⊖1⌽CG)+(¯1⊖1⌽CG)+(1⊖¯1⌽CG)+(¯1⊖¯1⌽CG)[3] NG←(3=W)+(CG∧4=W) ∇ RP←5 5⍴0 0 0 0 0 0 0 1 1 0 0 1 1 0 0 0 0 1 0 0 RP0 0 0 0 00 0 1 1 00 1 1 0 00 0 1 0 00 0 0 0 0 LIFE RP0 0 0 0 00 1 1 1 00 1 0 0 00 1 1 0 00 0 0 0 0 LIFE LIFE RP0 0 1 0 00 1 1 0 01 0 0 1 00 1 1 0 00 0 0 0 0 ..................................................

One interacts with the Game of Life by creating an initial configuration and observing how it evolves.

Although you should test your implementation on more complex examples such as the glider in a larger universe, show the action of the blinker (three adjoining cells in a row all alive), over three generations, in a 3 by 3 grid.

(1,4)=TRUERETURN'' Count the number of neighbours of the point i,j' (Assume i/j +/- 1 will not fall out of world)'FUNCTION count_neighbours(i%,j%) LOCAL count%,l% count%=0 FOR l%=-1 TO 1 IF world! (i%+l%,j%+1) count%=count%+1 ENDIF NEXT l% IF world! (i%+1,j%) count%=count%+1 ENDIF RETURN count%ENDFUNC'' Update the world one step'PROCEDURE update_world LOCAL i%,j% ' compute neighbour counts and store FOR i%=1 TO 30 FOR j%=1 TO 30 ns%(i%,j%)[email protected]_neighbours(i%,j%) NEXT j% NEXT i% ' update the world cells FOR i%=1 TO 30 FOR j%=1 TO 30 IF world!

Thus, while it is somewhat verbose, it fully simulates Conway's Game of Life and is relatively simple to expand to feature different starting shapes.

Define life(pattern) = Prgm Local x,y,nt,count,save,xl,yl,xh,yh Define nt(y,x) = when(pxl Test(y,x), 1, 0) {}→save set Graph("Axes", "Off")→save[1] set Graph("Grid", "Off")→save[2] set Graph("Labels", "Off")→save[3] Fn Off Plot Off Clr Draw If pattern = "blinker" Then 36→yl 40→yh 78→xl 82→xh Pxl On 36,80 Pxl On 38,80 Pxl On 40,80 Else If pattern = "glider" Then 30→yl 40→yh 76→xl 88→xh Pxl On 38,76 Pxl On 36,78 Pxl On 36,80 Pxl On 38,80 Pxl On 40,80 Else If pattern = "r" Then 38-5*2→yl 38+5*2→yh 80-5*2→xl 80+5*2→xh Pxl On 38,78 Pxl On 36,82 Pxl On 36,80 Pxl On 38,80 Pxl On 40,80 End If While get Key() = 0 © Expand upper-left corner to whole cell For y,yl,yh,2 For x,xl,xh,2 If pxl Test(y,x) Then Pxl On y+1,x Pxl On y+1,x+1 Pxl On y, x+1 Else Pxl Off y+1,x Pxl Off y+1,x+1 Pxl Off y, x+1 End If End For End For © Compute next generation For y,yl,yh,2 For x,xl,xh,2 nt(y-1,x-1) + nt(y-1,x) + nt(y-1,x+2) + nt(y,x-1) + nt(y+1,x+2) + nt(y+2,x-1) + nt(y+2,x+1) + nt(y+2,x+2) → count If count = 3 Then Pxl On y,x Else If count ≠ 2 Then Pxl Off y,x End If End For End For End While © Restore changed options set Graph("Axes", save[1]) set Graph("Grid", save[2]) set Graph("Labels", save[3])End Prgm Also see Conway's Game of Life/C Considering that the simplest implementation in C++ would lack any use of the object-oriented paradigm, this code was specifically written to demonstrate the various object-oriented features of C++.

]]a bne clearbyte starttick:copyscreen: lda #[[

randfill: stx $01 ;$200 for indirect ldx #$02 ;addressing stx $02randloop: lda $fe ;generate random and #$01 ;pixels on the sta ($01), Y ;screen jsr inc0103 cmp #$00 bne randloop lda $02 cmp #$06 bne randloop clearmem: lda #$df ;set $07df-$0a20 sta $01 ;to $#00 lda #$07 sta $02clearbyte: lda #$00 sta ($01), Y jsr inc0103 cmp #$20 bne clearbyte lda $02 cmp #$0a bne clearbyte starttick:copyscreen: lda #$00 ;set up source sta $01 ;pointer at sta $03 ;$01/$02 and lda #$02 ;dest pointer sta $02 ;at $03/$04 lda #$08 sta $04 ldy #$00copybyte: lda ($01), Y ;copy pixel to sta ($03), Y ;back buffer jsr inc0103 ;increment pointers cmp #$00 ;check to see bne copybyte ;if we're at $600 lda $02 ;if so, we've cmp #$06 ;copied the bne copybyte ;entire screen conway: lda #$df ;apply conway rules sta $01 ;reset the pointer sta $03 ;to $#01df/$#07df lda #$01 ;($200 - $21) sta $02 ;($800 - $21) lda #$07 sta $04onecell: lda #$00 ;process one cell ldy #$01 ;upper cell clc adc ($03), Y ldy #$41 ;lower cell clc adc ($03), Ychkleft: tax ;check to see lda $01 ;if we're at the and #$1f ;left edge tay txa cpy #$1f beq rightcellsleftcells: ldy #$00 ;upper-left cell clc adc ($03), Y ldy #$20 ;left cell clc adc ($03), Y ldy #$40 ;lower-left cell clc adc ($03), Ychkright: tax ;check to see lda $01 ;if we're at the and #$1f ;right edge tay txa cpy #$1e beq evaluaterightcells: ldy #$02 ;upper-right cell clc adc ($03), Y ldy #$22 ;right cell clc adc ($03), Y ldy #$42 ;lower-right cell clc adc ($03), Yevaluate: ldx #$01 ;evaluate total ldy #$21 ;for current cell cmp #$03 ;3 = alive beq storex ldx #$00 cmp #$02 ;2 = alive if bne storex ;c = alive lda ($03), Y and #$01 taxstorex: txa ;store to screen sta ($01), Y jsr inc0103 ;move to next cellconwayloop: cmp #$e0 ;if not last cell, bne onecell ;process next cell lda $02 cmp #$05 bne onecell jmp starttick ;run next tick inc0103: lda $01 ;increment $01 cmp #$ff ;and $03 as 16-bit bne onlyinc01 ;pointers inc $02 inc $04onlyinc01: inc $01 lda $01 sta $03 rts The solution uses one cell thick border around square Petri dish as uninhabited dire land. Sample output contains 3 generations of the blinker and 5 of the glider: See Conway's Game of Life/ALGOL 68 APL2 (Dialog) Example in one line APL \ 1130 example (very old APL dialect via simulator) APL1130From: APL \ 1130 Samples The following APL \ 1130 code will need APL385 font installed to display correctly. See Download APL TT Font ∇LIFE[⎕]∇[0] NG←LIFE CG; W[1] W←CG+(¯1⊖CG)+(1⊖CG)+(¯1⌽CG)+(1⌽CG)[2] W←W+(1⊖1⌽CG)+(¯1⊖1⌽CG)+(1⊖¯1⌽CG)+(¯1⊖¯1⌽CG)[3] NG←(3=W)+(CG∧4=W) ∇ RP←5 5⍴0 0 0 0 0 0 0 1 1 0 0 1 1 0 0 0 0 1 0 0 RP0 0 0 0 00 0 1 1 00 1 1 0 00 0 1 0 00 0 0 0 0 LIFE RP0 0 0 0 00 1 1 1 00 1 0 0 00 1 1 0 00 0 0 0 0 LIFE LIFE RP0 0 1 0 00 1 1 0 01 0 0 1 00 1 1 0 00 0 0 0 0 .................................................. One interacts with the Game of Life by creating an initial configuration and observing how it evolves. Although you should test your implementation on more complex examples such as the glider in a larger universe, show the action of the blinker (three adjoining cells in a row all alive), over three generations, in a 3 by 3 grid. (1,4)=TRUERETURN'' Count the number of neighbours of the point i,j' (Assume i/j +/- 1 will not fall out of world)'FUNCTION count_neighbours(i%,j%) LOCAL count%,l% count%=0 FOR l%=-1 TO 1 IF world! (i%+l%,j%+1) count%=count%+1 ENDIF NEXT l% IF world! (i%+1,j%) count%=count%+1 ENDIF RETURN count%ENDFUNC'' Update the world one step'PROCEDURE update_world LOCAL i%,j% ' compute neighbour counts and store FOR i%=1 TO 30 FOR j%=1 TO 30 ns%(i%,j%)[email protected]_neighbours(i%,j%) NEXT j% NEXT i% ' update the world cells FOR i%=1 TO 30 FOR j%=1 TO 30 IF world!

||

randfill: stx $01 ;$200 for indirect ldx #$02 ;addressing stx $02randloop: lda $fe ;generate random and #$01 ;pixels on the sta ($01), Y ;screen jsr inc0103 cmp #$00 bne randloop lda $02 cmp #$06 bne randloop clearmem: lda #$df ;set $07df-$0a20 sta $01 ;to $#00 lda #$07 sta $02clearbyte: lda #$00 sta ($01), Y jsr inc0103 cmp #$20 bne clearbyte lda $02 cmp #$0a bne clearbyte starttick:copyscreen: lda #$00 ;set up source sta $01 ;pointer at sta $03 ;$01/$02 and lda #$02 ;dest pointer sta $02 ;at $03/$04 lda #$08 sta $04 ldy #$00copybyte: lda ($01), Y ;copy pixel to sta ($03), Y ;back buffer jsr inc0103 ;increment pointers cmp #$00 ;check to see bne copybyte ;if we're at $600 lda $02 ;if so, we've cmp #$06 ;copied the bne copybyte ;entire screen conway: lda #$df ;apply conway rules sta $01 ;reset the pointer sta $03 ;to $#01df/$#07df lda #$01 ;($200 - $21) sta $02 ;($800 - $21) lda #$07 sta $04onecell: lda #$00 ;process one cell ldy #$01 ;upper cell clc adc ($03), Y ldy #$41 ;lower cell clc adc ($03), Ychkleft: tax ;check to see lda $01 ;if we're at the and #$1f ;left edge tay txa cpy #$1f beq rightcellsleftcells: ldy #$00 ;upper-left cell clc adc ($03), Y ldy #$20 ;left cell clc adc ($03), Y ldy #$40 ;lower-left cell clc adc ($03), Ychkright: tax ;check to see lda $01 ;if we're at the and #$1f ;right edge tay txa cpy #$1e beq evaluaterightcells: ldy #$02 ;upper-right cell clc adc ($03), Y ldy #$22 ;right cell clc adc ($03), Y ldy #$42 ;lower-right cell clc adc ($03), Yevaluate: ldx #$01 ;evaluate total ldy #$21 ;for current cell cmp #$03 ;3 = alive beq storex ldx #$00 cmp #$02 ;2 = alive if bne storex ;c = alive lda ($03), Y and #$01 taxstorex: txa ;store to screen sta ($01), Y jsr inc0103 ;move to next cellconwayloop: cmp #$e0 ;if not last cell, bne onecell ;process next cell lda $02 cmp #$05 bne onecell jmp starttick ;run next tick inc0103: lda $01 ;increment $01 cmp #$ff ;and $03 as 16-bit bne onlyinc01 ;pointers inc $02 inc $04onlyinc01: inc $01 lda $01 sta $03 rts The solution uses one cell thick border around square Petri dish as uninhabited dire land. Sample output contains 3 generations of the blinker and 5 of the glider: See Conway's Game of Life/ALGOL 68 APL2 (Dialog) Example in one line APL \ 1130 example (very old APL dialect via simulator) APL1130From: APL \ 1130 Samples The following APL \ 1130 code will need APL385 font installed to display correctly.

See Download APL TT Font ∇LIFE[⎕]∇[0] NG←LIFE CG; W[1] W←CG+(¯1⊖CG)+(1⊖CG)+(¯1⌽CG)+(1⌽CG)[2] W←W+(1⊖1⌽CG)+(¯1⊖1⌽CG)+(1⊖¯1⌽CG)+(¯1⊖¯1⌽CG)[3] NG←(3=W)+(CG∧4=W) ∇ RP←5 5⍴0 0 0 0 0 0 0 1 1 0 0 1 1 0 0 0 0 1 0 0 RP0 0 0 0 00 0 1 1 00 1 1 0 00 0 1 0 00 0 0 0 0 LIFE RP0 0 0 0 00 1 1 1 00 1 0 0 00 1 1 0 00 0 0 0 0 LIFE LIFE RP0 0 1 0 00 1 1 0 01 0 0 1 00 1 1 0 00 0 0 0 0 ..................................................

One interacts with the Game of Life by creating an initial configuration and observing how it evolves.

Although you should test your implementation on more complex examples such as the glider in a larger universe, show the action of the blinker (three adjoining cells in a row all alive), over three generations, in a 3 by 3 grid.

(1,4)=TRUERETURN'' Count the number of neighbours of the point i,j' (Assume i/j +/- 1 will not fall out of world)'FUNCTION count_neighbours(i%,j%) LOCAL count%,l% count%=0 FOR l%=-1 TO 1 IF world! (i%+l%,j%+1) count%=count%+1 ENDIF NEXT l% IF world! (i%+1,j%) count%=count%+1 ENDIF RETURN count%ENDFUNC'' Update the world one step'PROCEDURE update_world LOCAL i%,j% ' compute neighbour counts and store FOR i%=1 TO 30 FOR j%=1 TO 30 ns%(i%,j%)[email protected]_neighbours(i%,j%) NEXT j% NEXT i% ' update the world cells FOR i%=1 TO 30 FOR j%=1 TO 30 IF world!

Thus, while it is somewhat verbose, it fully simulates Conway's Game of Life and is relatively simple to expand to feature different starting shapes.

Define life(pattern) = Prgm Local x,y,nt,count,save,xl,yl,xh,yh Define nt(y,x) = when(pxl Test(y,x), 1, 0) {}→save set Graph("Axes", "Off")→save[1] set Graph("Grid", "Off")→save[2] set Graph("Labels", "Off")→save[3] Fn Off Plot Off Clr Draw If pattern = "blinker" Then 36→yl 40→yh 78→xl 82→xh Pxl On 36,80 Pxl On 38,80 Pxl On 40,80 Else If pattern = "glider" Then 30→yl 40→yh 76→xl 88→xh Pxl On 38,76 Pxl On 36,78 Pxl On 36,80 Pxl On 38,80 Pxl On 40,80 Else If pattern = "r" Then 38-5*2→yl 38+5*2→yh 80-5*2→xl 80+5*2→xh Pxl On 38,78 Pxl On 36,82 Pxl On 36,80 Pxl On 38,80 Pxl On 40,80 End If While get Key() = 0 © Expand upper-left corner to whole cell For y,yl,yh,2 For x,xl,xh,2 If pxl Test(y,x) Then Pxl On y+1,x Pxl On y+1,x+1 Pxl On y, x+1 Else Pxl Off y+1,x Pxl Off y+1,x+1 Pxl Off y, x+1 End If End For End For © Compute next generation For y,yl,yh,2 For x,xl,xh,2 nt(y-1,x-1) + nt(y-1,x) + nt(y-1,x+2) + nt(y,x-1) + nt(y+1,x+2) + nt(y+2,x-1) + nt(y+2,x+1) + nt(y+2,x+2) → count If count = 3 Then Pxl On y,x Else If count ≠ 2 Then Pxl Off y,x End If End For End For End While © Restore changed options set Graph("Axes", save[1]) set Graph("Grid", save[2]) set Graph("Labels", save[3])End Prgm Also see Conway's Game of Life/C Considering that the simplest implementation in C++ would lack any use of the object-oriented paradigm, this code was specifically written to demonstrate the various object-oriented features of C++.

]] ;set up source sta

randfill: stx $01 ;$200 for indirect ldx #$02 ;addressing stx $02randloop: lda $fe ;generate random and #$01 ;pixels on the sta ($01), Y ;screen jsr inc0103 cmp #$00 bne randloop lda $02 cmp #$06 bne randloop clearmem: lda #$df ;set $07df-$0a20 sta $01 ;to $#00 lda #$07 sta $02clearbyte: lda #$00 sta ($01), Y jsr inc0103 cmp #$20 bne clearbyte lda $02 cmp #$0a bne clearbyte starttick:copyscreen: lda #$00 ;set up source sta $01 ;pointer at sta $03 ;$01/$02 and lda #$02 ;dest pointer sta $02 ;at $03/$04 lda #$08 sta $04 ldy #$00copybyte: lda ($01), Y ;copy pixel to sta ($03), Y ;back buffer jsr inc0103 ;increment pointers cmp #$00 ;check to see bne copybyte ;if we're at $600 lda $02 ;if so, we've cmp #$06 ;copied the bne copybyte ;entire screen conway: lda #$df ;apply conway rules sta $01 ;reset the pointer sta $03 ;to $#01df/$#07df lda #$01 ;($200 - $21) sta $02 ;($800 - $21) lda #$07 sta $04onecell: lda #$00 ;process one cell ldy #$01 ;upper cell clc adc ($03), Y ldy #$41 ;lower cell clc adc ($03), Ychkleft: tax ;check to see lda $01 ;if we're at the and #$1f ;left edge tay txa cpy #$1f beq rightcellsleftcells: ldy #$00 ;upper-left cell clc adc ($03), Y ldy #$20 ;left cell clc adc ($03), Y ldy #$40 ;lower-left cell clc adc ($03), Ychkright: tax ;check to see lda $01 ;if we're at the and #$1f ;right edge tay txa cpy #$1e beq evaluaterightcells: ldy #$02 ;upper-right cell clc adc ($03), Y ldy #$22 ;right cell clc adc ($03), Y ldy #$42 ;lower-right cell clc adc ($03), Yevaluate: ldx #$01 ;evaluate total ldy #$21 ;for current cell cmp #$03 ;3 = alive beq storex ldx #$00 cmp #$02 ;2 = alive if bne storex ;c = alive lda ($03), Y and #$01 taxstorex: txa ;store to screen sta ($01), Y jsr inc0103 ;move to next cellconwayloop: cmp #$e0 ;if not last cell, bne onecell ;process next cell lda $02 cmp #$05 bne onecell jmp starttick ;run next tick inc0103: lda $01 ;increment $01 cmp #$ff ;and $03 as 16-bit bne onlyinc01 ;pointers inc $02 inc $04onlyinc01: inc $01 lda $01 sta $03 rts The solution uses one cell thick border around square Petri dish as uninhabited dire land. Sample output contains 3 generations of the blinker and 5 of the glider: See Conway's Game of Life/ALGOL 68 APL2 (Dialog) Example in one line APL \ 1130 example (very old APL dialect via simulator) APL1130From: APL \ 1130 Samples The following APL \ 1130 code will need APL385 font installed to display correctly. See Download APL TT Font ∇LIFE[⎕]∇[0] NG←LIFE CG; W[1] W←CG+(¯1⊖CG)+(1⊖CG)+(¯1⌽CG)+(1⌽CG)[2] W←W+(1⊖1⌽CG)+(¯1⊖1⌽CG)+(1⊖¯1⌽CG)+(¯1⊖¯1⌽CG)[3] NG←(3=W)+(CG∧4=W) ∇ RP←5 5⍴0 0 0 0 0 0 0 1 1 0 0 1 1 0 0 0 0 1 0 0 RP0 0 0 0 00 0 1 1 00 1 1 0 00 0 1 0 00 0 0 0 0 LIFE RP0 0 0 0 00 1 1 1 00 1 0 0 00 1 1 0 00 0 0 0 0 LIFE LIFE RP0 0 1 0 00 1 1 0 01 0 0 1 00 1 1 0 00 0 0 0 0 .................................................. One interacts with the Game of Life by creating an initial configuration and observing how it evolves. Although you should test your implementation on more complex examples such as the glider in a larger universe, show the action of the blinker (three adjoining cells in a row all alive), over three generations, in a 3 by 3 grid. (1,4)=TRUERETURN'' Count the number of neighbours of the point i,j' (Assume i/j +/- 1 will not fall out of world)'FUNCTION count_neighbours(i%,j%) LOCAL count%,l% count%=0 FOR l%=-1 TO 1 IF world! (i%+l%,j%+1) count%=count%+1 ENDIF NEXT l% IF world! (i%+1,j%) count%=count%+1 ENDIF RETURN count%ENDFUNC'' Update the world one step'PROCEDURE update_world LOCAL i%,j% ' compute neighbour counts and store FOR i%=1 TO 30 FOR j%=1 TO 30 ns%(i%,j%)[email protected]_neighbours(i%,j%) NEXT j% NEXT i% ' update the world cells FOR i%=1 TO 30 FOR j%=1 TO 30 IF world!

||

randfill: stx $01 ;$200 for indirect ldx #$02 ;addressing stx $02randloop: lda $fe ;generate random and #$01 ;pixels on the sta ($01), Y ;screen jsr inc0103 cmp #$00 bne randloop lda $02 cmp #$06 bne randloop clearmem: lda #$df ;set $07df-$0a20 sta $01 ;to $#00 lda #$07 sta $02clearbyte: lda #$00 sta ($01), Y jsr inc0103 cmp #$20 bne clearbyte lda $02 cmp #$0a bne clearbyte starttick:copyscreen: lda #$00 ;set up source sta $01 ;pointer at sta $03 ;$01/$02 and lda #$02 ;dest pointer sta $02 ;at $03/$04 lda #$08 sta $04 ldy #$00copybyte: lda ($01), Y ;copy pixel to sta ($03), Y ;back buffer jsr inc0103 ;increment pointers cmp #$00 ;check to see bne copybyte ;if we're at $600 lda $02 ;if so, we've cmp #$06 ;copied the bne copybyte ;entire screen conway: lda #$df ;apply conway rules sta $01 ;reset the pointer sta $03 ;to $#01df/$#07df lda #$01 ;($200 - $21) sta $02 ;($800 - $21) lda #$07 sta $04onecell: lda #$00 ;process one cell ldy #$01 ;upper cell clc adc ($03), Y ldy #$41 ;lower cell clc adc ($03), Ychkleft: tax ;check to see lda $01 ;if we're at the and #$1f ;left edge tay txa cpy #$1f beq rightcellsleftcells: ldy #$00 ;upper-left cell clc adc ($03), Y ldy #$20 ;left cell clc adc ($03), Y ldy #$40 ;lower-left cell clc adc ($03), Ychkright: tax ;check to see lda $01 ;if we're at the and #$1f ;right edge tay txa cpy #$1e beq evaluaterightcells: ldy #$02 ;upper-right cell clc adc ($03), Y ldy #$22 ;right cell clc adc ($03), Y ldy #$42 ;lower-right cell clc adc ($03), Yevaluate: ldx #$01 ;evaluate total ldy #$21 ;for current cell cmp #$03 ;3 = alive beq storex ldx #$00 cmp #$02 ;2 = alive if bne storex ;c = alive lda ($03), Y and #$01 taxstorex: txa ;store to screen sta ($01), Y jsr inc0103 ;move to next cellconwayloop: cmp #$e0 ;if not last cell, bne onecell ;process next cell lda $02 cmp #$05 bne onecell jmp starttick ;run next tick inc0103: lda $01 ;increment $01 cmp #$ff ;and $03 as 16-bit bne onlyinc01 ;pointers inc $02 inc $04onlyinc01: inc $01 lda $01 sta $03 rts The solution uses one cell thick border around square Petri dish as uninhabited dire land. Sample output contains 3 generations of the blinker and 5 of the glider: See Conway's Game of Life/ALGOL 68 APL2 (Dialog) Example in one line APL \ 1130 example (very old APL dialect via simulator) APL1130From: APL \ 1130 Samples The following APL \ 1130 code will need APL385 font installed to display correctly.

See Download APL TT Font ∇LIFE[⎕]∇[0] NG←LIFE CG; W[1] W←CG+(¯1⊖CG)+(1⊖CG)+(¯1⌽CG)+(1⌽CG)[2] W←W+(1⊖1⌽CG)+(¯1⊖1⌽CG)+(1⊖¯1⌽CG)+(¯1⊖¯1⌽CG)[3] NG←(3=W)+(CG∧4=W) ∇ RP←5 5⍴0 0 0 0 0 0 0 1 1 0 0 1 1 0 0 0 0 1 0 0 RP0 0 0 0 00 0 1 1 00 1 1 0 00 0 1 0 00 0 0 0 0 LIFE RP0 0 0 0 00 1 1 1 00 1 0 0 00 1 1 0 00 0 0 0 0 LIFE LIFE RP0 0 1 0 00 1 1 0 01 0 0 1 00 1 1 0 00 0 0 0 0 ..................................................

One interacts with the Game of Life by creating an initial configuration and observing how it evolves.

Although you should test your implementation on more complex examples such as the glider in a larger universe, show the action of the blinker (three adjoining cells in a row all alive), over three generations, in a 3 by 3 grid.

(1,4)=TRUERETURN'' Count the number of neighbours of the point i,j' (Assume i/j +/- 1 will not fall out of world)'FUNCTION count_neighbours(i%,j%) LOCAL count%,l% count%=0 FOR l%=-1 TO 1 IF world! (i%+l%,j%+1) count%=count%+1 ENDIF NEXT l% IF world! (i%+1,j%) count%=count%+1 ENDIF RETURN count%ENDFUNC'' Update the world one step'PROCEDURE update_world LOCAL i%,j% ' compute neighbour counts and store FOR i%=1 TO 30 FOR j%=1 TO 30 ns%(i%,j%)[email protected]_neighbours(i%,j%) NEXT j% NEXT i% ' update the world cells FOR i%=1 TO 30 FOR j%=1 TO 30 IF world!

Thus, while it is somewhat verbose, it fully simulates Conway's Game of Life and is relatively simple to expand to feature different starting shapes.

Define life(pattern) = Prgm Local x,y,nt,count,save,xl,yl,xh,yh Define nt(y,x) = when(pxl Test(y,x), 1, 0) {}→save set Graph("Axes", "Off")→save[1] set Graph("Grid", "Off")→save[2] set Graph("Labels", "Off")→save[3] Fn Off Plot Off Clr Draw If pattern = "blinker" Then 36→yl 40→yh 78→xl 82→xh Pxl On 36,80 Pxl On 38,80 Pxl On 40,80 Else If pattern = "glider" Then 30→yl 40→yh 76→xl 88→xh Pxl On 38,76 Pxl On 36,78 Pxl On 36,80 Pxl On 38,80 Pxl On 40,80 Else If pattern = "r" Then 38-5*2→yl 38+5*2→yh 80-5*2→xl 80+5*2→xh Pxl On 38,78 Pxl On 36,82 Pxl On 36,80 Pxl On 38,80 Pxl On 40,80 End If While get Key() = 0 © Expand upper-left corner to whole cell For y,yl,yh,2 For x,xl,xh,2 If pxl Test(y,x) Then Pxl On y+1,x Pxl On y+1,x+1 Pxl On y, x+1 Else Pxl Off y+1,x Pxl Off y+1,x+1 Pxl Off y, x+1 End If End For End For © Compute next generation For y,yl,yh,2 For x,xl,xh,2 nt(y-1,x-1) + nt(y-1,x) + nt(y-1,x+2) + nt(y,x-1) + nt(y+1,x+2) + nt(y+2,x-1) + nt(y+2,x+1) + nt(y+2,x+2) → count If count = 3 Then Pxl On y,x Else If count ≠ 2 Then Pxl Off y,x End If End For End For End While © Restore changed options set Graph("Axes", save[1]) set Graph("Grid", save[2]) set Graph("Labels", save[3])End Prgm Also see Conway's Game of Life/C Considering that the simplest implementation in C++ would lack any use of the object-oriented paradigm, this code was specifically written to demonstrate the various object-oriented features of C++.

;pointer at sta ;

randfill: stx $01 ;$200 for indirect ldx #$02 ;addressing stx $02randloop: lda $fe ;generate random and #$01 ;pixels on the sta ($01), Y ;screen jsr inc0103 cmp #$00 bne randloop lda $02 cmp #$06 bne randloop clearmem: lda #$df ;set $07df-$0a20 sta $01 ;to $#00 lda #$07 sta $02clearbyte: lda #$00 sta ($01), Y jsr inc0103 cmp #$20 bne clearbyte lda $02 cmp #$0a bne clearbyte starttick:copyscreen: lda #$00 ;set up source sta $01 ;pointer at sta $03 ;$01/$02 and lda #$02 ;dest pointer sta $02 ;at $03/$04 lda #$08 sta $04 ldy #$00copybyte: lda ($01), Y ;copy pixel to sta ($03), Y ;back buffer jsr inc0103 ;increment pointers cmp #$00 ;check to see bne copybyte ;if we're at $600 lda $02 ;if so, we've cmp #$06 ;copied the bne copybyte ;entire screen conway: lda #$df ;apply conway rules sta $01 ;reset the pointer sta $03 ;to $#01df/$#07df lda #$01 ;($200 - $21) sta $02 ;($800 - $21) lda #$07 sta $04onecell: lda #$00 ;process one cell ldy #$01 ;upper cell clc adc ($03), Y ldy #$41 ;lower cell clc adc ($03), Ychkleft: tax ;check to see lda $01 ;if we're at the and #$1f ;left edge tay txa cpy #$1f beq rightcellsleftcells: ldy #$00 ;upper-left cell clc adc ($03), Y ldy #$20 ;left cell clc adc ($03), Y ldy #$40 ;lower-left cell clc adc ($03), Ychkright: tax ;check to see lda $01 ;if we're at the and #$1f ;right edge tay txa cpy #$1e beq evaluaterightcells: ldy #$02 ;upper-right cell clc adc ($03), Y ldy #$22 ;right cell clc adc ($03), Y ldy #$42 ;lower-right cell clc adc ($03), Yevaluate: ldx #$01 ;evaluate total ldy #$21 ;for current cell cmp #$03 ;3 = alive beq storex ldx #$00 cmp #$02 ;2 = alive if bne storex ;c = alive lda ($03), Y and #$01 taxstorex: txa ;store to screen sta ($01), Y jsr inc0103 ;move to next cellconwayloop: cmp #$e0 ;if not last cell, bne onecell ;process next cell lda $02 cmp #$05 bne onecell jmp starttick ;run next tick inc0103: lda $01 ;increment $01 cmp #$ff ;and $03 as 16-bit bne onlyinc01 ;pointers inc $02 inc $04onlyinc01: inc $01 lda $01 sta $03 rts The solution uses one cell thick border around square Petri dish as uninhabited dire land. Sample output contains 3 generations of the blinker and 5 of the glider: See Conway's Game of Life/ALGOL 68 APL2 (Dialog) Example in one line APL \ 1130 example (very old APL dialect via simulator) APL1130From: APL \ 1130 Samples The following APL \ 1130 code will need APL385 font installed to display correctly. See Download APL TT Font ∇LIFE[⎕]∇[0] NG←LIFE CG; W[1] W←CG+(¯1⊖CG)+(1⊖CG)+(¯1⌽CG)+(1⌽CG)[2] W←W+(1⊖1⌽CG)+(¯1⊖1⌽CG)+(1⊖¯1⌽CG)+(¯1⊖¯1⌽CG)[3] NG←(3=W)+(CG∧4=W) ∇ RP←5 5⍴0 0 0 0 0 0 0 1 1 0 0 1 1 0 0 0 0 1 0 0 RP0 0 0 0 00 0 1 1 00 1 1 0 00 0 1 0 00 0 0 0 0 LIFE RP0 0 0 0 00 1 1 1 00 1 0 0 00 1 1 0 00 0 0 0 0 LIFE LIFE RP0 0 1 0 00 1 1 0 01 0 0 1 00 1 1 0 00 0 0 0 0 .................................................. One interacts with the Game of Life by creating an initial configuration and observing how it evolves. Although you should test your implementation on more complex examples such as the glider in a larger universe, show the action of the blinker (three adjoining cells in a row all alive), over three generations, in a 3 by 3 grid. (1,4)=TRUERETURN'' Count the number of neighbours of the point i,j' (Assume i/j +/- 1 will not fall out of world)'FUNCTION count_neighbours(i%,j%) LOCAL count%,l% count%=0 FOR l%=-1 TO 1 IF world! (i%+l%,j%+1) count%=count%+1 ENDIF NEXT l% IF world! (i%+1,j%) count%=count%+1 ENDIF RETURN count%ENDFUNC'' Update the world one step'PROCEDURE update_world LOCAL i%,j% ' compute neighbour counts and store FOR i%=1 TO 30 FOR j%=1 TO 30 ns%(i%,j%)[email protected]_neighbours(i%,j%) NEXT j% NEXT i% ' update the world cells FOR i%=1 TO 30 FOR j%=1 TO 30 IF world!

||

randfill: stx $01 ;$200 for indirect ldx #$02 ;addressing stx $02randloop: lda $fe ;generate random and #$01 ;pixels on the sta ($01), Y ;screen jsr inc0103 cmp #$00 bne randloop lda $02 cmp #$06 bne randloop clearmem: lda #$df ;set $07df-$0a20 sta $01 ;to $#00 lda #$07 sta $02clearbyte: lda #$00 sta ($01), Y jsr inc0103 cmp #$20 bne clearbyte lda $02 cmp #$0a bne clearbyte starttick:copyscreen: lda #$00 ;set up source sta $01 ;pointer at sta $03 ;$01/$02 and lda #$02 ;dest pointer sta $02 ;at $03/$04 lda #$08 sta $04 ldy #$00copybyte: lda ($01), Y ;copy pixel to sta ($03), Y ;back buffer jsr inc0103 ;increment pointers cmp #$00 ;check to see bne copybyte ;if we're at $600 lda $02 ;if so, we've cmp #$06 ;copied the bne copybyte ;entire screen conway: lda #$df ;apply conway rules sta $01 ;reset the pointer sta $03 ;to $#01df/$#07df lda #$01 ;($200 - $21) sta $02 ;($800 - $21) lda #$07 sta $04onecell: lda #$00 ;process one cell ldy #$01 ;upper cell clc adc ($03), Y ldy #$41 ;lower cell clc adc ($03), Ychkleft: tax ;check to see lda $01 ;if we're at the and #$1f ;left edge tay txa cpy #$1f beq rightcellsleftcells: ldy #$00 ;upper-left cell clc adc ($03), Y ldy #$20 ;left cell clc adc ($03), Y ldy #$40 ;lower-left cell clc adc ($03), Ychkright: tax ;check to see lda $01 ;if we're at the and #$1f ;right edge tay txa cpy #$1e beq evaluaterightcells: ldy #$02 ;upper-right cell clc adc ($03), Y ldy #$22 ;right cell clc adc ($03), Y ldy #$42 ;lower-right cell clc adc ($03), Yevaluate: ldx #$01 ;evaluate total ldy #$21 ;for current cell cmp #$03 ;3 = alive beq storex ldx #$00 cmp #$02 ;2 = alive if bne storex ;c = alive lda ($03), Y and #$01 taxstorex: txa ;store to screen sta ($01), Y jsr inc0103 ;move to next cellconwayloop: cmp #$e0 ;if not last cell, bne onecell ;process next cell lda $02 cmp #$05 bne onecell jmp starttick ;run next tick inc0103: lda $01 ;increment $01 cmp #$ff ;and $03 as 16-bit bne onlyinc01 ;pointers inc $02 inc $04onlyinc01: inc $01 lda $01 sta $03 rts The solution uses one cell thick border around square Petri dish as uninhabited dire land. Sample output contains 3 generations of the blinker and 5 of the glider: See Conway's Game of Life/ALGOL 68 APL2 (Dialog) Example in one line APL \ 1130 example (very old APL dialect via simulator) APL1130From: APL \ 1130 Samples The following APL \ 1130 code will need APL385 font installed to display correctly.

See Download APL TT Font ∇LIFE[⎕]∇[0] NG←LIFE CG; W[1] W←CG+(¯1⊖CG)+(1⊖CG)+(¯1⌽CG)+(1⌽CG)[2] W←W+(1⊖1⌽CG)+(¯1⊖1⌽CG)+(1⊖¯1⌽CG)+(¯1⊖¯1⌽CG)[3] NG←(3=W)+(CG∧4=W) ∇ RP←5 5⍴0 0 0 0 0 0 0 1 1 0 0 1 1 0 0 0 0 1 0 0 RP0 0 0 0 00 0 1 1 00 1 1 0 00 0 1 0 00 0 0 0 0 LIFE RP0 0 0 0 00 1 1 1 00 1 0 0 00 1 1 0 00 0 0 0 0 LIFE LIFE RP0 0 1 0 00 1 1 0 01 0 0 1 00 1 1 0 00 0 0 0 0 ..................................................

One interacts with the Game of Life by creating an initial configuration and observing how it evolves.

Although you should test your implementation on more complex examples such as the glider in a larger universe, show the action of the blinker (three adjoining cells in a row all alive), over three generations, in a 3 by 3 grid.

(1,4)=TRUERETURN'' Count the number of neighbours of the point i,j' (Assume i/j +/- 1 will not fall out of world)'FUNCTION count_neighbours(i%,j%) LOCAL count%,l% count%=0 FOR l%=-1 TO 1 IF world! (i%+l%,j%+1) count%=count%+1 ENDIF NEXT l% IF world! (i%+1,j%) count%=count%+1 ENDIF RETURN count%ENDFUNC'' Update the world one step'PROCEDURE update_world LOCAL i%,j% ' compute neighbour counts and store FOR i%=1 TO 30 FOR j%=1 TO 30 ns%(i%,j%)[email protected]_neighbours(i%,j%) NEXT j% NEXT i% ' update the world cells FOR i%=1 TO 30 FOR j%=1 TO 30 IF world!

Thus, while it is somewhat verbose, it fully simulates Conway's Game of Life and is relatively simple to expand to feature different starting shapes.

Define life(pattern) = Prgm Local x,y,nt,count,save,xl,yl,xh,yh Define nt(y,x) = when(pxl Test(y,x), 1, 0) {}→save set Graph("Axes", "Off")→save[1] set Graph("Grid", "Off")→save[2] set Graph("Labels", "Off")→save[3] Fn Off Plot Off Clr Draw If pattern = "blinker" Then 36→yl 40→yh 78→xl 82→xh Pxl On 36,80 Pxl On 38,80 Pxl On 40,80 Else If pattern = "glider" Then 30→yl 40→yh 76→xl 88→xh Pxl On 38,76 Pxl On 36,78 Pxl On 36,80 Pxl On 38,80 Pxl On 40,80 Else If pattern = "r" Then 38-5*2→yl 38+5*2→yh 80-5*2→xl 80+5*2→xh Pxl On 38,78 Pxl On 36,82 Pxl On 36,80 Pxl On 38,80 Pxl On 40,80 End If While get Key() = 0 © Expand upper-left corner to whole cell For y,yl,yh,2 For x,xl,xh,2 If pxl Test(y,x) Then Pxl On y+1,x Pxl On y+1,x+1 Pxl On y, x+1 Else Pxl Off y+1,x Pxl Off y+1,x+1 Pxl Off y, x+1 End If End For End For © Compute next generation For y,yl,yh,2 For x,xl,xh,2 nt(y-1,x-1) + nt(y-1,x) + nt(y-1,x+2) + nt(y,x-1) + nt(y+1,x+2) + nt(y+2,x-1) + nt(y+2,x+1) + nt(y+2,x+2) → count If count = 3 Then Pxl On y,x Else If count ≠ 2 Then Pxl Off y,x End If End For End For End While © Restore changed options set Graph("Axes", save[1]) set Graph("Grid", save[2]) set Graph("Labels", save[3])End Prgm Also see Conway's Game of Life/C Considering that the simplest implementation in C++ would lack any use of the object-oriented paradigm, this code was specifically written to demonstrate the various object-oriented features of C++.

/ and lda # ;dest pointer sta ;at / lda # sta ldy #[[

randfill: stx $01 ;$200 for indirect ldx #$02 ;addressing stx $02randloop: lda $fe ;generate random and #$01 ;pixels on the sta ($01), Y ;screen jsr inc0103 cmp #$00 bne randloop lda $02 cmp #$06 bne randloop clearmem: lda #$df ;set $07df-$0a20 sta $01 ;to $#00 lda #$07 sta $02clearbyte: lda #$00 sta ($01), Y jsr inc0103 cmp #$20 bne clearbyte lda $02 cmp #$0a bne clearbyte starttick:copyscreen: lda #$00 ;set up source sta $01 ;pointer at sta $03 ;$01/$02 and lda #$02 ;dest pointer sta $02 ;at $03/$04 lda #$08 sta $04 ldy #$00copybyte: lda ($01), Y ;copy pixel to sta ($03), Y ;back buffer jsr inc0103 ;increment pointers cmp #$00 ;check to see bne copybyte ;if we're at $600 lda $02 ;if so, we've cmp #$06 ;copied the bne copybyte ;entire screen conway: lda #$df ;apply conway rules sta $01 ;reset the pointer sta $03 ;to $#01df/$#07df lda #$01 ;($200 - $21) sta $02 ;($800 - $21) lda #$07 sta $04onecell: lda #$00 ;process one cell ldy #$01 ;upper cell clc adc ($03), Y ldy #$41 ;lower cell clc adc ($03), Ychkleft: tax ;check to see lda $01 ;if we're at the and #$1f ;left edge tay txa cpy #$1f beq rightcellsleftcells: ldy #$00 ;upper-left cell clc adc ($03), Y ldy #$20 ;left cell clc adc ($03), Y ldy #$40 ;lower-left cell clc adc ($03), Ychkright: tax ;check to see lda $01 ;if we're at the and #$1f ;right edge tay txa cpy #$1e beq evaluaterightcells: ldy #$02 ;upper-right cell clc adc ($03), Y ldy #$22 ;right cell clc adc ($03), Y ldy #$42 ;lower-right cell clc adc ($03), Yevaluate: ldx #$01 ;evaluate total ldy #$21 ;for current cell cmp #$03 ;3 = alive beq storex ldx #$00 cmp #$02 ;2 = alive if bne storex ;c = alive lda ($03), Y and #$01 taxstorex: txa ;store to screen sta ($01), Y jsr inc0103 ;move to next cellconwayloop: cmp #$e0 ;if not last cell, bne onecell ;process next cell lda $02 cmp #$05 bne onecell jmp starttick ;run next tick inc0103: lda $01 ;increment $01 cmp #$ff ;and $03 as 16-bit bne onlyinc01 ;pointers inc $02 inc $04onlyinc01: inc $01 lda $01 sta $03 rts The solution uses one cell thick border around square Petri dish as uninhabited dire land. Sample output contains 3 generations of the blinker and 5 of the glider: See Conway's Game of Life/ALGOL 68 APL2 (Dialog) Example in one line APL \ 1130 example (very old APL dialect via simulator) APL1130From: APL \ 1130 Samples The following APL \ 1130 code will need APL385 font installed to display correctly. See Download APL TT Font ∇LIFE[⎕]∇[0] NG←LIFE CG; W[1] W←CG+(¯1⊖CG)+(1⊖CG)+(¯1⌽CG)+(1⌽CG)[2] W←W+(1⊖1⌽CG)+(¯1⊖1⌽CG)+(1⊖¯1⌽CG)+(¯1⊖¯1⌽CG)[3] NG←(3=W)+(CG∧4=W) ∇ RP←5 5⍴0 0 0 0 0 0 0 1 1 0 0 1 1 0 0 0 0 1 0 0 RP0 0 0 0 00 0 1 1 00 1 1 0 00 0 1 0 00 0 0 0 0 LIFE RP0 0 0 0 00 1 1 1 00 1 0 0 00 1 1 0 00 0 0 0 0 LIFE LIFE RP0 0 1 0 00 1 1 0 01 0 0 1 00 1 1 0 00 0 0 0 0 .................................................. One interacts with the Game of Life by creating an initial configuration and observing how it evolves. Although you should test your implementation on more complex examples such as the glider in a larger universe, show the action of the blinker (three adjoining cells in a row all alive), over three generations, in a 3 by 3 grid. (1,4)=TRUERETURN'' Count the number of neighbours of the point i,j' (Assume i/j +/- 1 will not fall out of world)'FUNCTION count_neighbours(i%,j%) LOCAL count%,l% count%=0 FOR l%=-1 TO 1 IF world! (i%+l%,j%+1) count%=count%+1 ENDIF NEXT l% IF world! (i%+1,j%) count%=count%+1 ENDIF RETURN count%ENDFUNC'' Update the world one step'PROCEDURE update_world LOCAL i%,j% ' compute neighbour counts and store FOR i%=1 TO 30 FOR j%=1 TO 30 ns%(i%,j%)[email protected]_neighbours(i%,j%) NEXT j% NEXT i% ' update the world cells FOR i%=1 TO 30 FOR j%=1 TO 30 IF world!

||

randfill: stx $01 ;$200 for indirect ldx #$02 ;addressing stx $02randloop: lda $fe ;generate random and #$01 ;pixels on the sta ($01), Y ;screen jsr inc0103 cmp #$00 bne randloop lda $02 cmp #$06 bne randloop clearmem: lda #$df ;set $07df-$0a20 sta $01 ;to $#00 lda #$07 sta $02clearbyte: lda #$00 sta ($01), Y jsr inc0103 cmp #$20 bne clearbyte lda $02 cmp #$0a bne clearbyte starttick:copyscreen: lda #$00 ;set up source sta $01 ;pointer at sta $03 ;$01/$02 and lda #$02 ;dest pointer sta $02 ;at $03/$04 lda #$08 sta $04 ldy #$00copybyte: lda ($01), Y ;copy pixel to sta ($03), Y ;back buffer jsr inc0103 ;increment pointers cmp #$00 ;check to see bne copybyte ;if we're at $600 lda $02 ;if so, we've cmp #$06 ;copied the bne copybyte ;entire screen conway: lda #$df ;apply conway rules sta $01 ;reset the pointer sta $03 ;to $#01df/$#07df lda #$01 ;($200 - $21) sta $02 ;($800 - $21) lda #$07 sta $04onecell: lda #$00 ;process one cell ldy #$01 ;upper cell clc adc ($03), Y ldy #$41 ;lower cell clc adc ($03), Ychkleft: tax ;check to see lda $01 ;if we're at the and #$1f ;left edge tay txa cpy #$1f beq rightcellsleftcells: ldy #$00 ;upper-left cell clc adc ($03), Y ldy #$20 ;left cell clc adc ($03), Y ldy #$40 ;lower-left cell clc adc ($03), Ychkright: tax ;check to see lda $01 ;if we're at the and #$1f ;right edge tay txa cpy #$1e beq evaluaterightcells: ldy #$02 ;upper-right cell clc adc ($03), Y ldy #$22 ;right cell clc adc ($03), Y ldy #$42 ;lower-right cell clc adc ($03), Yevaluate: ldx #$01 ;evaluate total ldy #$21 ;for current cell cmp #$03 ;3 = alive beq storex ldx #$00 cmp #$02 ;2 = alive if bne storex ;c = alive lda ($03), Y and #$01 taxstorex: txa ;store to screen sta ($01), Y jsr inc0103 ;move to next cellconwayloop: cmp #$e0 ;if not last cell, bne onecell ;process next cell lda $02 cmp #$05 bne onecell jmp starttick ;run next tick inc0103: lda $01 ;increment $01 cmp #$ff ;and $03 as 16-bit bne onlyinc01 ;pointers inc $02 inc $04onlyinc01: inc $01 lda $01 sta $03 rts The solution uses one cell thick border around square Petri dish as uninhabited dire land. Sample output contains 3 generations of the blinker and 5 of the glider: See Conway's Game of Life/ALGOL 68 APL2 (Dialog) Example in one line APL \ 1130 example (very old APL dialect via simulator) APL1130From: APL \ 1130 Samples The following APL \ 1130 code will need APL385 font installed to display correctly.

See Download APL TT Font ∇LIFE[⎕]∇[0] NG←LIFE CG; W[1] W←CG+(¯1⊖CG)+(1⊖CG)+(¯1⌽CG)+(1⌽CG)[2] W←W+(1⊖1⌽CG)+(¯1⊖1⌽CG)+(1⊖¯1⌽CG)+(¯1⊖¯1⌽CG)[3] NG←(3=W)+(CG∧4=W) ∇ RP←5 5⍴0 0 0 0 0 0 0 1 1 0 0 1 1 0 0 0 0 1 0 0 RP0 0 0 0 00 0 1 1 00 1 1 0 00 0 1 0 00 0 0 0 0 LIFE RP0 0 0 0 00 1 1 1 00 1 0 0 00 1 1 0 00 0 0 0 0 LIFE LIFE RP0 0 1 0 00 1 1 0 01 0 0 1 00 1 1 0 00 0 0 0 0 ..................................................

One interacts with the Game of Life by creating an initial configuration and observing how it evolves.

Although you should test your implementation on more complex examples such as the glider in a larger universe, show the action of the blinker (three adjoining cells in a row all alive), over three generations, in a 3 by 3 grid.

(1,4)=TRUERETURN'' Count the number of neighbours of the point i,j' (Assume i/j +/- 1 will not fall out of world)'FUNCTION count_neighbours(i%,j%) LOCAL count%,l% count%=0 FOR l%=-1 TO 1 IF world! (i%+l%,j%+1) count%=count%+1 ENDIF NEXT l% IF world! (i%+1,j%) count%=count%+1 ENDIF RETURN count%ENDFUNC'' Update the world one step'PROCEDURE update_world LOCAL i%,j% ' compute neighbour counts and store FOR i%=1 TO 30 FOR j%=1 TO 30 ns%(i%,j%)[email protected]_neighbours(i%,j%) NEXT j% NEXT i% ' update the world cells FOR i%=1 TO 30 FOR j%=1 TO 30 IF world!

Thus, while it is somewhat verbose, it fully simulates Conway's Game of Life and is relatively simple to expand to feature different starting shapes.

Define life(pattern) = Prgm Local x,y,nt,count,save,xl,yl,xh,yh Define nt(y,x) = when(pxl Test(y,x), 1, 0) {}→save set Graph("Axes", "Off")→save[1] set Graph("Grid", "Off")→save[2] set Graph("Labels", "Off")→save[3] Fn Off Plot Off Clr Draw If pattern = "blinker" Then 36→yl 40→yh 78→xl 82→xh Pxl On 36,80 Pxl On 38,80 Pxl On 40,80 Else If pattern = "glider" Then 30→yl 40→yh 76→xl 88→xh Pxl On 38,76 Pxl On 36,78 Pxl On 36,80 Pxl On 38,80 Pxl On 40,80 Else If pattern = "r" Then 38-5*2→yl 38+5*2→yh 80-5*2→xl 80+5*2→xh Pxl On 38,78 Pxl On 36,82 Pxl On 36,80 Pxl On 38,80 Pxl On 40,80 End If While get Key() = 0 © Expand upper-left corner to whole cell For y,yl,yh,2 For x,xl,xh,2 If pxl Test(y,x) Then Pxl On y+1,x Pxl On y+1,x+1 Pxl On y, x+1 Else Pxl Off y+1,x Pxl Off y+1,x+1 Pxl Off y, x+1 End If End For End For © Compute next generation For y,yl,yh,2 For x,xl,xh,2 nt(y-1,x-1) + nt(y-1,x) + nt(y-1,x+2) + nt(y,x-1) + nt(y+1,x+2) + nt(y+2,x-1) + nt(y+2,x+1) + nt(y+2,x+2) → count If count = 3 Then Pxl On y,x Else If count ≠ 2 Then Pxl Off y,x End If End For End For End While © Restore changed options set Graph("Axes", save[1]) set Graph("Grid", save[2]) set Graph("Labels", save[3])End Prgm Also see Conway's Game of Life/C Considering that the simplest implementation in C++ would lack any use of the object-oriented paradigm, this code was specifically written to demonstrate the various object-oriented features of C++.

]]copybyte: lda (

randfill: stx $01 ;$200 for indirect ldx #$02 ;addressing stx $02randloop: lda $fe ;generate random and #$01 ;pixels on the sta ($01), Y ;screen jsr inc0103 cmp #$00 bne randloop lda $02 cmp #$06 bne randloop clearmem: lda #$df ;set $07df-$0a20 sta $01 ;to $#00 lda #$07 sta $02clearbyte: lda #$00 sta ($01), Y jsr inc0103 cmp #$20 bne clearbyte lda $02 cmp #$0a bne clearbyte starttick:copyscreen: lda #$00 ;set up source sta $01 ;pointer at sta $03 ;$01/$02 and lda #$02 ;dest pointer sta $02 ;at $03/$04 lda #$08 sta $04 ldy #$00copybyte: lda ($01), Y ;copy pixel to sta ($03), Y ;back buffer jsr inc0103 ;increment pointers cmp #$00 ;check to see bne copybyte ;if we're at $600 lda $02 ;if so, we've cmp #$06 ;copied the bne copybyte ;entire screen conway: lda #$df ;apply conway rules sta $01 ;reset the pointer sta $03 ;to $#01df/$#07df lda #$01 ;($200 - $21) sta $02 ;($800 - $21) lda #$07 sta $04onecell: lda #$00 ;process one cell ldy #$01 ;upper cell clc adc ($03), Y ldy #$41 ;lower cell clc adc ($03), Ychkleft: tax ;check to see lda $01 ;if we're at the and #$1f ;left edge tay txa cpy #$1f beq rightcellsleftcells: ldy #$00 ;upper-left cell clc adc ($03), Y ldy #$20 ;left cell clc adc ($03), Y ldy #$40 ;lower-left cell clc adc ($03), Ychkright: tax ;check to see lda $01 ;if we're at the and #$1f ;right edge tay txa cpy #$1e beq evaluaterightcells: ldy #$02 ;upper-right cell clc adc ($03), Y ldy #$22 ;right cell clc adc ($03), Y ldy #$42 ;lower-right cell clc adc ($03), Yevaluate: ldx #$01 ;evaluate total ldy #$21 ;for current cell cmp #$03 ;3 = alive beq storex ldx #$00 cmp #$02 ;2 = alive if bne storex ;c = alive lda ($03), Y and #$01 taxstorex: txa ;store to screen sta ($01), Y jsr inc0103 ;move to next cellconwayloop: cmp #$e0 ;if not last cell, bne onecell ;process next cell lda $02 cmp #$05 bne onecell jmp starttick ;run next tick inc0103: lda $01 ;increment $01 cmp #$ff ;and $03 as 16-bit bne onlyinc01 ;pointers inc $02 inc $04onlyinc01: inc $01 lda $01 sta $03 rts The solution uses one cell thick border around square Petri dish as uninhabited dire land. Sample output contains 3 generations of the blinker and 5 of the glider: See Conway's Game of Life/ALGOL 68 APL2 (Dialog) Example in one line APL \ 1130 example (very old APL dialect via simulator) APL1130From: APL \ 1130 Samples The following APL \ 1130 code will need APL385 font installed to display correctly. See Download APL TT Font ∇LIFE[⎕]∇[0] NG←LIFE CG; W[1] W←CG+(¯1⊖CG)+(1⊖CG)+(¯1⌽CG)+(1⌽CG)[2] W←W+(1⊖1⌽CG)+(¯1⊖1⌽CG)+(1⊖¯1⌽CG)+(¯1⊖¯1⌽CG)[3] NG←(3=W)+(CG∧4=W) ∇ RP←5 5⍴0 0 0 0 0 0 0 1 1 0 0 1 1 0 0 0 0 1 0 0 RP0 0 0 0 00 0 1 1 00 1 1 0 00 0 1 0 00 0 0 0 0 LIFE RP0 0 0 0 00 1 1 1 00 1 0 0 00 1 1 0 00 0 0 0 0 LIFE LIFE RP0 0 1 0 00 1 1 0 01 0 0 1 00 1 1 0 00 0 0 0 0 .................................................. One interacts with the Game of Life by creating an initial configuration and observing how it evolves. Although you should test your implementation on more complex examples such as the glider in a larger universe, show the action of the blinker (three adjoining cells in a row all alive), over three generations, in a 3 by 3 grid. (1,4)=TRUERETURN'' Count the number of neighbours of the point i,j' (Assume i/j +/- 1 will not fall out of world)'FUNCTION count_neighbours(i%,j%) LOCAL count%,l% count%=0 FOR l%=-1 TO 1 IF world! (i%+l%,j%+1) count%=count%+1 ENDIF NEXT l% IF world! (i%+1,j%) count%=count%+1 ENDIF RETURN count%ENDFUNC'' Update the world one step'PROCEDURE update_world LOCAL i%,j% ' compute neighbour counts and store FOR i%=1 TO 30 FOR j%=1 TO 30 ns%(i%,j%)[email protected]_neighbours(i%,j%) NEXT j% NEXT i% ' update the world cells FOR i%=1 TO 30 FOR j%=1 TO 30 IF world!

||

randfill: stx $01 ;$200 for indirect ldx #$02 ;addressing stx $02randloop: lda $fe ;generate random and #$01 ;pixels on the sta ($01), Y ;screen jsr inc0103 cmp #$00 bne randloop lda $02 cmp #$06 bne randloop clearmem: lda #$df ;set $07df-$0a20 sta $01 ;to $#00 lda #$07 sta $02clearbyte: lda #$00 sta ($01), Y jsr inc0103 cmp #$20 bne clearbyte lda $02 cmp #$0a bne clearbyte starttick:copyscreen: lda #$00 ;set up source sta $01 ;pointer at sta $03 ;$01/$02 and lda #$02 ;dest pointer sta $02 ;at $03/$04 lda #$08 sta $04 ldy #$00copybyte: lda ($01), Y ;copy pixel to sta ($03), Y ;back buffer jsr inc0103 ;increment pointers cmp #$00 ;check to see bne copybyte ;if we're at $600 lda $02 ;if so, we've cmp #$06 ;copied the bne copybyte ;entire screen conway: lda #$df ;apply conway rules sta $01 ;reset the pointer sta $03 ;to $#01df/$#07df lda #$01 ;($200 - $21) sta $02 ;($800 - $21) lda #$07 sta $04onecell: lda #$00 ;process one cell ldy #$01 ;upper cell clc adc ($03), Y ldy #$41 ;lower cell clc adc ($03), Ychkleft: tax ;check to see lda $01 ;if we're at the and #$1f ;left edge tay txa cpy #$1f beq rightcellsleftcells: ldy #$00 ;upper-left cell clc adc ($03), Y ldy #$20 ;left cell clc adc ($03), Y ldy #$40 ;lower-left cell clc adc ($03), Ychkright: tax ;check to see lda $01 ;if we're at the and #$1f ;right edge tay txa cpy #$1e beq evaluaterightcells: ldy #$02 ;upper-right cell clc adc ($03), Y ldy #$22 ;right cell clc adc ($03), Y ldy #$42 ;lower-right cell clc adc ($03), Yevaluate: ldx #$01 ;evaluate total ldy #$21 ;for current cell cmp #$03 ;3 = alive beq storex ldx #$00 cmp #$02 ;2 = alive if bne storex ;c = alive lda ($03), Y and #$01 taxstorex: txa ;store to screen sta ($01), Y jsr inc0103 ;move to next cellconwayloop: cmp #$e0 ;if not last cell, bne onecell ;process next cell lda $02 cmp #$05 bne onecell jmp starttick ;run next tick inc0103: lda $01 ;increment $01 cmp #$ff ;and $03 as 16-bit bne onlyinc01 ;pointers inc $02 inc $04onlyinc01: inc $01 lda $01 sta $03 rts The solution uses one cell thick border around square Petri dish as uninhabited dire land. Sample output contains 3 generations of the blinker and 5 of the glider: See Conway's Game of Life/ALGOL 68 APL2 (Dialog) Example in one line APL \ 1130 example (very old APL dialect via simulator) APL1130From: APL \ 1130 Samples The following APL \ 1130 code will need APL385 font installed to display correctly.

See Download APL TT Font ∇LIFE[⎕]∇[0] NG←LIFE CG; W[1] W←CG+(¯1⊖CG)+(1⊖CG)+(¯1⌽CG)+(1⌽CG)[2] W←W+(1⊖1⌽CG)+(¯1⊖1⌽CG)+(1⊖¯1⌽CG)+(¯1⊖¯1⌽CG)[3] NG←(3=W)+(CG∧4=W) ∇ RP←5 5⍴0 0 0 0 0 0 0 1 1 0 0 1 1 0 0 0 0 1 0 0 RP0 0 0 0 00 0 1 1 00 1 1 0 00 0 1 0 00 0 0 0 0 LIFE RP0 0 0 0 00 1 1 1 00 1 0 0 00 1 1 0 00 0 0 0 0 LIFE LIFE RP0 0 1 0 00 1 1 0 01 0 0 1 00 1 1 0 00 0 0 0 0 ..................................................

One interacts with the Game of Life by creating an initial configuration and observing how it evolves.

Although you should test your implementation on more complex examples such as the glider in a larger universe, show the action of the blinker (three adjoining cells in a row all alive), over three generations, in a 3 by 3 grid.

(1,4)=TRUERETURN'' Count the number of neighbours of the point i,j' (Assume i/j +/- 1 will not fall out of world)'FUNCTION count_neighbours(i%,j%) LOCAL count%,l% count%=0 FOR l%=-1 TO 1 IF world! (i%+l%,j%+1) count%=count%+1 ENDIF NEXT l% IF world! (i%+1,j%) count%=count%+1 ENDIF RETURN count%ENDFUNC'' Update the world one step'PROCEDURE update_world LOCAL i%,j% ' compute neighbour counts and store FOR i%=1 TO 30 FOR j%=1 TO 30 ns%(i%,j%)[email protected]_neighbours(i%,j%) NEXT j% NEXT i% ' update the world cells FOR i%=1 TO 30 FOR j%=1 TO 30 IF world!

Thus, while it is somewhat verbose, it fully simulates Conway's Game of Life and is relatively simple to expand to feature different starting shapes.

Define life(pattern) = Prgm Local x,y,nt,count,save,xl,yl,xh,yh Define nt(y,x) = when(pxl Test(y,x), 1, 0) {}→save set Graph("Axes", "Off")→save[1] set Graph("Grid", "Off")→save[2] set Graph("Labels", "Off")→save[3] Fn Off Plot Off Clr Draw If pattern = "blinker" Then 36→yl 40→yh 78→xl 82→xh Pxl On 36,80 Pxl On 38,80 Pxl On 40,80 Else If pattern = "glider" Then 30→yl 40→yh 76→xl 88→xh Pxl On 38,76 Pxl On 36,78 Pxl On 36,80 Pxl On 38,80 Pxl On 40,80 Else If pattern = "r" Then 38-5*2→yl 38+5*2→yh 80-5*2→xl 80+5*2→xh Pxl On 38,78 Pxl On 36,82 Pxl On 36,80 Pxl On 38,80 Pxl On 40,80 End If While get Key() = 0 © Expand upper-left corner to whole cell For y,yl,yh,2 For x,xl,xh,2 If pxl Test(y,x) Then Pxl On y+1,x Pxl On y+1,x+1 Pxl On y, x+1 Else Pxl Off y+1,x Pxl Off y+1,x+1 Pxl Off y, x+1 End If End For End For © Compute next generation For y,yl,yh,2 For x,xl,xh,2 nt(y-1,x-1) + nt(y-1,x) + nt(y-1,x+2) + nt(y,x-1) + nt(y+1,x+2) + nt(y+2,x-1) + nt(y+2,x+1) + nt(y+2,x+2) → count If count = 3 Then Pxl On y,x Else If count ≠ 2 Then Pxl Off y,x End If End For End For End While © Restore changed options set Graph("Axes", save[1]) set Graph("Grid", save[2]) set Graph("Labels", save[3])End Prgm Also see Conway's Game of Life/C Considering that the simplest implementation in C++ would lack any use of the object-oriented paradigm, this code was specifically written to demonstrate the various object-oriented features of C++.

), Y ;copy pixel to sta (), Y ;back buffer jsr inc0103 ;increment pointers cmp #[[

randfill: stx $01 ;$200 for indirect ldx #$02 ;addressing stx $02randloop: lda $fe ;generate random and #$01 ;pixels on the sta ($01), Y ;screen jsr inc0103 cmp #$00 bne randloop lda $02 cmp #$06 bne randloop clearmem: lda #$df ;set $07df-$0a20 sta $01 ;to $#00 lda #$07 sta $02clearbyte: lda #$00 sta ($01), Y jsr inc0103 cmp #$20 bne clearbyte lda $02 cmp #$0a bne clearbyte starttick:copyscreen: lda #$00 ;set up source sta $01 ;pointer at sta $03 ;$01/$02 and lda #$02 ;dest pointer sta $02 ;at $03/$04 lda #$08 sta $04 ldy #$00copybyte: lda ($01), Y ;copy pixel to sta ($03), Y ;back buffer jsr inc0103 ;increment pointers cmp #$00 ;check to see bne copybyte ;if we're at $600 lda $02 ;if so, we've cmp #$06 ;copied the bne copybyte ;entire screen conway: lda #$df ;apply conway rules sta $01 ;reset the pointer sta $03 ;to $#01df/$#07df lda #$01 ;($200 - $21) sta $02 ;($800 - $21) lda #$07 sta $04onecell: lda #$00 ;process one cell ldy #$01 ;upper cell clc adc ($03), Y ldy #$41 ;lower cell clc adc ($03), Ychkleft: tax ;check to see lda $01 ;if we're at the and #$1f ;left edge tay txa cpy #$1f beq rightcellsleftcells: ldy #$00 ;upper-left cell clc adc ($03), Y ldy #$20 ;left cell clc adc ($03), Y ldy #$40 ;lower-left cell clc adc ($03), Ychkright: tax ;check to see lda $01 ;if we're at the and #$1f ;right edge tay txa cpy #$1e beq evaluaterightcells: ldy #$02 ;upper-right cell clc adc ($03), Y ldy #$22 ;right cell clc adc ($03), Y ldy #$42 ;lower-right cell clc adc ($03), Yevaluate: ldx #$01 ;evaluate total ldy #$21 ;for current cell cmp #$03 ;3 = alive beq storex ldx #$00 cmp #$02 ;2 = alive if bne storex ;c = alive lda ($03), Y and #$01 taxstorex: txa ;store to screen sta ($01), Y jsr inc0103 ;move to next cellconwayloop: cmp #$e0 ;if not last cell, bne onecell ;process next cell lda $02 cmp #$05 bne onecell jmp starttick ;run next tick inc0103: lda $01 ;increment $01 cmp #$ff ;and $03 as 16-bit bne onlyinc01 ;pointers inc $02 inc $04onlyinc01: inc $01 lda $01 sta $03 rts The solution uses one cell thick border around square Petri dish as uninhabited dire land. Sample output contains 3 generations of the blinker and 5 of the glider: See Conway's Game of Life/ALGOL 68 APL2 (Dialog) Example in one line APL \ 1130 example (very old APL dialect via simulator) APL1130From: APL \ 1130 Samples The following APL \ 1130 code will need APL385 font installed to display correctly. See Download APL TT Font ∇LIFE[⎕]∇[0] NG←LIFE CG; W[1] W←CG+(¯1⊖CG)+(1⊖CG)+(¯1⌽CG)+(1⌽CG)[2] W←W+(1⊖1⌽CG)+(¯1⊖1⌽CG)+(1⊖¯1⌽CG)+(¯1⊖¯1⌽CG)[3] NG←(3=W)+(CG∧4=W) ∇ RP←5 5⍴0 0 0 0 0 0 0 1 1 0 0 1 1 0 0 0 0 1 0 0 RP0 0 0 0 00 0 1 1 00 1 1 0 00 0 1 0 00 0 0 0 0 LIFE RP0 0 0 0 00 1 1 1 00 1 0 0 00 1 1 0 00 0 0 0 0 LIFE LIFE RP0 0 1 0 00 1 1 0 01 0 0 1 00 1 1 0 00 0 0 0 0 .................................................. One interacts with the Game of Life by creating an initial configuration and observing how it evolves. Although you should test your implementation on more complex examples such as the glider in a larger universe, show the action of the blinker (three adjoining cells in a row all alive), over three generations, in a 3 by 3 grid. (1,4)=TRUERETURN'' Count the number of neighbours of the point i,j' (Assume i/j +/- 1 will not fall out of world)'FUNCTION count_neighbours(i%,j%) LOCAL count%,l% count%=0 FOR l%=-1 TO 1 IF world! (i%+l%,j%+1) count%=count%+1 ENDIF NEXT l% IF world! (i%+1,j%) count%=count%+1 ENDIF RETURN count%ENDFUNC'' Update the world one step'PROCEDURE update_world LOCAL i%,j% ' compute neighbour counts and store FOR i%=1 TO 30 FOR j%=1 TO 30 ns%(i%,j%)[email protected]_neighbours(i%,j%) NEXT j% NEXT i% ' update the world cells FOR i%=1 TO 30 FOR j%=1 TO 30 IF world!

||

randfill: stx $01 ;$200 for indirect ldx #$02 ;addressing stx $02randloop: lda $fe ;generate random and #$01 ;pixels on the sta ($01), Y ;screen jsr inc0103 cmp #$00 bne randloop lda $02 cmp #$06 bne randloop clearmem: lda #$df ;set $07df-$0a20 sta $01 ;to $#00 lda #$07 sta $02clearbyte: lda #$00 sta ($01), Y jsr inc0103 cmp #$20 bne clearbyte lda $02 cmp #$0a bne clearbyte starttick:copyscreen: lda #$00 ;set up source sta $01 ;pointer at sta $03 ;$01/$02 and lda #$02 ;dest pointer sta $02 ;at $03/$04 lda #$08 sta $04 ldy #$00copybyte: lda ($01), Y ;copy pixel to sta ($03), Y ;back buffer jsr inc0103 ;increment pointers cmp #$00 ;check to see bne copybyte ;if we're at $600 lda $02 ;if so, we've cmp #$06 ;copied the bne copybyte ;entire screen conway: lda #$df ;apply conway rules sta $01 ;reset the pointer sta $03 ;to $#01df/$#07df lda #$01 ;($200 - $21) sta $02 ;($800 - $21) lda #$07 sta $04onecell: lda #$00 ;process one cell ldy #$01 ;upper cell clc adc ($03), Y ldy #$41 ;lower cell clc adc ($03), Ychkleft: tax ;check to see lda $01 ;if we're at the and #$1f ;left edge tay txa cpy #$1f beq rightcellsleftcells: ldy #$00 ;upper-left cell clc adc ($03), Y ldy #$20 ;left cell clc adc ($03), Y ldy #$40 ;lower-left cell clc adc ($03), Ychkright: tax ;check to see lda $01 ;if we're at the and #$1f ;right edge tay txa cpy #$1e beq evaluaterightcells: ldy #$02 ;upper-right cell clc adc ($03), Y ldy #$22 ;right cell clc adc ($03), Y ldy #$42 ;lower-right cell clc adc ($03), Yevaluate: ldx #$01 ;evaluate total ldy #$21 ;for current cell cmp #$03 ;3 = alive beq storex ldx #$00 cmp #$02 ;2 = alive if bne storex ;c = alive lda ($03), Y and #$01 taxstorex: txa ;store to screen sta ($01), Y jsr inc0103 ;move to next cellconwayloop: cmp #$e0 ;if not last cell, bne onecell ;process next cell lda $02 cmp #$05 bne onecell jmp starttick ;run next tick inc0103: lda $01 ;increment $01 cmp #$ff ;and $03 as 16-bit bne onlyinc01 ;pointers inc $02 inc $04onlyinc01: inc $01 lda $01 sta $03 rts The solution uses one cell thick border around square Petri dish as uninhabited dire land. Sample output contains 3 generations of the blinker and 5 of the glider: See Conway's Game of Life/ALGOL 68 APL2 (Dialog) Example in one line APL \ 1130 example (very old APL dialect via simulator) APL1130From: APL \ 1130 Samples The following APL \ 1130 code will need APL385 font installed to display correctly.

See Download APL TT Font ∇LIFE[⎕]∇[0] NG←LIFE CG; W[1] W←CG+(¯1⊖CG)+(1⊖CG)+(¯1⌽CG)+(1⌽CG)[2] W←W+(1⊖1⌽CG)+(¯1⊖1⌽CG)+(1⊖¯1⌽CG)+(¯1⊖¯1⌽CG)[3] NG←(3=W)+(CG∧4=W) ∇ RP←5 5⍴0 0 0 0 0 0 0 1 1 0 0 1 1 0 0 0 0 1 0 0 RP0 0 0 0 00 0 1 1 00 1 1 0 00 0 1 0 00 0 0 0 0 LIFE RP0 0 0 0 00 1 1 1 00 1 0 0 00 1 1 0 00 0 0 0 0 LIFE LIFE RP0 0 1 0 00 1 1 0 01 0 0 1 00 1 1 0 00 0 0 0 0 ..................................................

One interacts with the Game of Life by creating an initial configuration and observing how it evolves.

Although you should test your implementation on more complex examples such as the glider in a larger universe, show the action of the blinker (three adjoining cells in a row all alive), over three generations, in a 3 by 3 grid.

(1,4)=TRUERETURN'' Count the number of neighbours of the point i,j' (Assume i/j +/- 1 will not fall out of world)'FUNCTION count_neighbours(i%,j%) LOCAL count%,l% count%=0 FOR l%=-1 TO 1 IF world! (i%+l%,j%+1) count%=count%+1 ENDIF NEXT l% IF world! (i%+1,j%) count%=count%+1 ENDIF RETURN count%ENDFUNC'' Update the world one step'PROCEDURE update_world LOCAL i%,j% ' compute neighbour counts and store FOR i%=1 TO 30 FOR j%=1 TO 30 ns%(i%,j%)[email protected]_neighbours(i%,j%) NEXT j% NEXT i% ' update the world cells FOR i%=1 TO 30 FOR j%=1 TO 30 IF world!

Thus, while it is somewhat verbose, it fully simulates Conway's Game of Life and is relatively simple to expand to feature different starting shapes.

Define life(pattern) = Prgm Local x,y,nt,count,save,xl,yl,xh,yh Define nt(y,x) = when(pxl Test(y,x), 1, 0) {}→save set Graph("Axes", "Off")→save[1] set Graph("Grid", "Off")→save[2] set Graph("Labels", "Off")→save[3] Fn Off Plot Off Clr Draw If pattern = "blinker" Then 36→yl 40→yh 78→xl 82→xh Pxl On 36,80 Pxl On 38,80 Pxl On 40,80 Else If pattern = "glider" Then 30→yl 40→yh 76→xl 88→xh Pxl On 38,76 Pxl On 36,78 Pxl On 36,80 Pxl On 38,80 Pxl On 40,80 Else If pattern = "r" Then 38-5*2→yl 38+5*2→yh 80-5*2→xl 80+5*2→xh Pxl On 38,78 Pxl On 36,82 Pxl On 36,80 Pxl On 38,80 Pxl On 40,80 End If While get Key() = 0 © Expand upper-left corner to whole cell For y,yl,yh,2 For x,xl,xh,2 If pxl Test(y,x) Then Pxl On y+1,x Pxl On y+1,x+1 Pxl On y, x+1 Else Pxl Off y+1,x Pxl Off y+1,x+1 Pxl Off y, x+1 End If End For End For © Compute next generation For y,yl,yh,2 For x,xl,xh,2 nt(y-1,x-1) + nt(y-1,x) + nt(y-1,x+2) + nt(y,x-1) + nt(y+1,x+2) + nt(y+2,x-1) + nt(y+2,x+1) + nt(y+2,x+2) → count If count = 3 Then Pxl On y,x Else If count ≠ 2 Then Pxl Off y,x End If End For End For End While © Restore changed options set Graph("Axes", save[1]) set Graph("Grid", save[2]) set Graph("Labels", save[3])End Prgm Also see Conway's Game of Life/C Considering that the simplest implementation in C++ would lack any use of the object-oriented paradigm, this code was specifically written to demonstrate the various object-oriented features of C++.

]] ;check to see bne copybyte ;if we're at 0 lda ;if so, we've cmp # ;copied the bne copybyte ;entire screen conway: lda #$df ;apply conway rules sta

randfill: stx $01 ;$200 for indirect ldx #$02 ;addressing stx $02randloop: lda $fe ;generate random and #$01 ;pixels on the sta ($01), Y ;screen jsr inc0103 cmp #$00 bne randloop lda $02 cmp #$06 bne randloop clearmem: lda #$df ;set $07df-$0a20 sta $01 ;to $#00 lda #$07 sta $02clearbyte: lda #$00 sta ($01), Y jsr inc0103 cmp #$20 bne clearbyte lda $02 cmp #$0a bne clearbyte starttick:copyscreen: lda #$00 ;set up source sta $01 ;pointer at sta $03 ;$01/$02 and lda #$02 ;dest pointer sta $02 ;at $03/$04 lda #$08 sta $04 ldy #$00copybyte: lda ($01), Y ;copy pixel to sta ($03), Y ;back buffer jsr inc0103 ;increment pointers cmp #$00 ;check to see bne copybyte ;if we're at $600 lda $02 ;if so, we've cmp #$06 ;copied the bne copybyte ;entire screen conway: lda #$df ;apply conway rules sta $01 ;reset the pointer sta $03 ;to $#01df/$#07df lda #$01 ;($200 - $21) sta $02 ;($800 - $21) lda #$07 sta $04onecell: lda #$00 ;process one cell ldy #$01 ;upper cell clc adc ($03), Y ldy #$41 ;lower cell clc adc ($03), Ychkleft: tax ;check to see lda $01 ;if we're at the and #$1f ;left edge tay txa cpy #$1f beq rightcellsleftcells: ldy #$00 ;upper-left cell clc adc ($03), Y ldy #$20 ;left cell clc adc ($03), Y ldy #$40 ;lower-left cell clc adc ($03), Ychkright: tax ;check to see lda $01 ;if we're at the and #$1f ;right edge tay txa cpy #$1e beq evaluaterightcells: ldy #$02 ;upper-right cell clc adc ($03), Y ldy #$22 ;right cell clc adc ($03), Y ldy #$42 ;lower-right cell clc adc ($03), Yevaluate: ldx #$01 ;evaluate total ldy #$21 ;for current cell cmp #$03 ;3 = alive beq storex ldx #$00 cmp #$02 ;2 = alive if bne storex ;c = alive lda ($03), Y and #$01 taxstorex: txa ;store to screen sta ($01), Y jsr inc0103 ;move to next cellconwayloop: cmp #$e0 ;if not last cell, bne onecell ;process next cell lda $02 cmp #$05 bne onecell jmp starttick ;run next tick inc0103: lda $01 ;increment $01 cmp #$ff ;and $03 as 16-bit bne onlyinc01 ;pointers inc $02 inc $04onlyinc01: inc $01 lda $01 sta $03 rts The solution uses one cell thick border around square Petri dish as uninhabited dire land. Sample output contains 3 generations of the blinker and 5 of the glider: See Conway's Game of Life/ALGOL 68 APL2 (Dialog) Example in one line APL \ 1130 example (very old APL dialect via simulator) APL1130From: APL \ 1130 Samples The following APL \ 1130 code will need APL385 font installed to display correctly. See Download APL TT Font ∇LIFE[⎕]∇[0] NG←LIFE CG; W[1] W←CG+(¯1⊖CG)+(1⊖CG)+(¯1⌽CG)+(1⌽CG)[2] W←W+(1⊖1⌽CG)+(¯1⊖1⌽CG)+(1⊖¯1⌽CG)+(¯1⊖¯1⌽CG)[3] NG←(3=W)+(CG∧4=W) ∇ RP←5 5⍴0 0 0 0 0 0 0 1 1 0 0 1 1 0 0 0 0 1 0 0 RP0 0 0 0 00 0 1 1 00 1 1 0 00 0 1 0 00 0 0 0 0 LIFE RP0 0 0 0 00 1 1 1 00 1 0 0 00 1 1 0 00 0 0 0 0 LIFE LIFE RP0 0 1 0 00 1 1 0 01 0 0 1 00 1 1 0 00 0 0 0 0 .................................................. One interacts with the Game of Life by creating an initial configuration and observing how it evolves. Although you should test your implementation on more complex examples such as the glider in a larger universe, show the action of the blinker (three adjoining cells in a row all alive), over three generations, in a 3 by 3 grid. (1,4)=TRUERETURN'' Count the number of neighbours of the point i,j' (Assume i/j +/- 1 will not fall out of world)'FUNCTION count_neighbours(i%,j%) LOCAL count%,l% count%=0 FOR l%=-1 TO 1 IF world! (i%+l%,j%+1) count%=count%+1 ENDIF NEXT l% IF world! (i%+1,j%) count%=count%+1 ENDIF RETURN count%ENDFUNC'' Update the world one step'PROCEDURE update_world LOCAL i%,j% ' compute neighbour counts and store FOR i%=1 TO 30 FOR j%=1 TO 30 ns%(i%,j%)[email protected]_neighbours(i%,j%) NEXT j% NEXT i% ' update the world cells FOR i%=1 TO 30 FOR j%=1 TO 30 IF world!

||

randfill: stx $01 ;$200 for indirect ldx #$02 ;addressing stx $02randloop: lda $fe ;generate random and #$01 ;pixels on the sta ($01), Y ;screen jsr inc0103 cmp #$00 bne randloop lda $02 cmp #$06 bne randloop clearmem: lda #$df ;set $07df-$0a20 sta $01 ;to $#00 lda #$07 sta $02clearbyte: lda #$00 sta ($01), Y jsr inc0103 cmp #$20 bne clearbyte lda $02 cmp #$0a bne clearbyte starttick:copyscreen: lda #$00 ;set up source sta $01 ;pointer at sta $03 ;$01/$02 and lda #$02 ;dest pointer sta $02 ;at $03/$04 lda #$08 sta $04 ldy #$00copybyte: lda ($01), Y ;copy pixel to sta ($03), Y ;back buffer jsr inc0103 ;increment pointers cmp #$00 ;check to see bne copybyte ;if we're at $600 lda $02 ;if so, we've cmp #$06 ;copied the bne copybyte ;entire screen conway: lda #$df ;apply conway rules sta $01 ;reset the pointer sta $03 ;to $#01df/$#07df lda #$01 ;($200 - $21) sta $02 ;($800 - $21) lda #$07 sta $04onecell: lda #$00 ;process one cell ldy #$01 ;upper cell clc adc ($03), Y ldy #$41 ;lower cell clc adc ($03), Ychkleft: tax ;check to see lda $01 ;if we're at the and #$1f ;left edge tay txa cpy #$1f beq rightcellsleftcells: ldy #$00 ;upper-left cell clc adc ($03), Y ldy #$20 ;left cell clc adc ($03), Y ldy #$40 ;lower-left cell clc adc ($03), Ychkright: tax ;check to see lda $01 ;if we're at the and #$1f ;right edge tay txa cpy #$1e beq evaluaterightcells: ldy #$02 ;upper-right cell clc adc ($03), Y ldy #$22 ;right cell clc adc ($03), Y ldy #$42 ;lower-right cell clc adc ($03), Yevaluate: ldx #$01 ;evaluate total ldy #$21 ;for current cell cmp #$03 ;3 = alive beq storex ldx #$00 cmp #$02 ;2 = alive if bne storex ;c = alive lda ($03), Y and #$01 taxstorex: txa ;store to screen sta ($01), Y jsr inc0103 ;move to next cellconwayloop: cmp #$e0 ;if not last cell, bne onecell ;process next cell lda $02 cmp #$05 bne onecell jmp starttick ;run next tick inc0103: lda $01 ;increment $01 cmp #$ff ;and $03 as 16-bit bne onlyinc01 ;pointers inc $02 inc $04onlyinc01: inc $01 lda $01 sta $03 rts The solution uses one cell thick border around square Petri dish as uninhabited dire land. Sample output contains 3 generations of the blinker and 5 of the glider: See Conway's Game of Life/ALGOL 68 APL2 (Dialog) Example in one line APL \ 1130 example (very old APL dialect via simulator) APL1130From: APL \ 1130 Samples The following APL \ 1130 code will need APL385 font installed to display correctly.

See Download APL TT Font ∇LIFE[⎕]∇[0] NG←LIFE CG; W[1] W←CG+(¯1⊖CG)+(1⊖CG)+(¯1⌽CG)+(1⌽CG)[2] W←W+(1⊖1⌽CG)+(¯1⊖1⌽CG)+(1⊖¯1⌽CG)+(¯1⊖¯1⌽CG)[3] NG←(3=W)+(CG∧4=W) ∇ RP←5 5⍴0 0 0 0 0 0 0 1 1 0 0 1 1 0 0 0 0 1 0 0 RP0 0 0 0 00 0 1 1 00 1 1 0 00 0 1 0 00 0 0 0 0 LIFE RP0 0 0 0 00 1 1 1 00 1 0 0 00 1 1 0 00 0 0 0 0 LIFE LIFE RP0 0 1 0 00 1 1 0 01 0 0 1 00 1 1 0 00 0 0 0 0 ..................................................

One interacts with the Game of Life by creating an initial configuration and observing how it evolves.

Although you should test your implementation on more complex examples such as the glider in a larger universe, show the action of the blinker (three adjoining cells in a row all alive), over three generations, in a 3 by 3 grid.

(1,4)=TRUERETURN'' Count the number of neighbours of the point i,j' (Assume i/j +/- 1 will not fall out of world)'FUNCTION count_neighbours(i%,j%) LOCAL count%,l% count%=0 FOR l%=-1 TO 1 IF world! (i%+l%,j%+1) count%=count%+1 ENDIF NEXT l% IF world! (i%+1,j%) count%=count%+1 ENDIF RETURN count%ENDFUNC'' Update the world one step'PROCEDURE update_world LOCAL i%,j% ' compute neighbour counts and store FOR i%=1 TO 30 FOR j%=1 TO 30 ns%(i%,j%)[email protected]_neighbours(i%,j%) NEXT j% NEXT i% ' update the world cells FOR i%=1 TO 30 FOR j%=1 TO 30 IF world!

Thus, while it is somewhat verbose, it fully simulates Conway's Game of Life and is relatively simple to expand to feature different starting shapes.

Define life(pattern) = Prgm Local x,y,nt,count,save,xl,yl,xh,yh Define nt(y,x) = when(pxl Test(y,x), 1, 0) {}→save set Graph("Axes", "Off")→save[1] set Graph("Grid", "Off")→save[2] set Graph("Labels", "Off")→save[3] Fn Off Plot Off Clr Draw If pattern = "blinker" Then 36→yl 40→yh 78→xl 82→xh Pxl On 36,80 Pxl On 38,80 Pxl On 40,80 Else If pattern = "glider" Then 30→yl 40→yh 76→xl 88→xh Pxl On 38,76 Pxl On 36,78 Pxl On 36,80 Pxl On 38,80 Pxl On 40,80 Else If pattern = "r" Then 38-5*2→yl 38+5*2→yh 80-5*2→xl 80+5*2→xh Pxl On 38,78 Pxl On 36,82 Pxl On 36,80 Pxl On 38,80 Pxl On 40,80 End If While get Key() = 0 © Expand upper-left corner to whole cell For y,yl,yh,2 For x,xl,xh,2 If pxl Test(y,x) Then Pxl On y+1,x Pxl On y+1,x+1 Pxl On y, x+1 Else Pxl Off y+1,x Pxl Off y+1,x+1 Pxl Off y, x+1 End If End For End For © Compute next generation For y,yl,yh,2 For x,xl,xh,2 nt(y-1,x-1) + nt(y-1,x) + nt(y-1,x+2) + nt(y,x-1) + nt(y+1,x+2) + nt(y+2,x-1) + nt(y+2,x+1) + nt(y+2,x+2) → count If count = 3 Then Pxl On y,x Else If count ≠ 2 Then Pxl Off y,x End If End For End For End While © Restore changed options set Graph("Axes", save[1]) set Graph("Grid", save[2]) set Graph("Labels", save[3])End Prgm Also see Conway's Game of Life/C Considering that the simplest implementation in C++ would lack any use of the object-oriented paradigm, this code was specifically written to demonstrate the various object-oriented features of C++.

;reset the pointer sta ;to $#01df/$#07df lda #

randfill: stx $01 ;$200 for indirect ldx #$02 ;addressing stx $02randloop: lda $fe ;generate random and #$01 ;pixels on the sta ($01), Y ;screen jsr inc0103 cmp #$00 bne randloop lda $02 cmp #$06 bne randloop clearmem: lda #$df ;set $07df-$0a20 sta $01 ;to $#00 lda #$07 sta $02clearbyte: lda #$00 sta ($01), Y jsr inc0103 cmp #$20 bne clearbyte lda $02 cmp #$0a bne clearbyte starttick:copyscreen: lda #$00 ;set up source sta $01 ;pointer at sta $03 ;$01/$02 and lda #$02 ;dest pointer sta $02 ;at $03/$04 lda #$08 sta $04 ldy #$00copybyte: lda ($01), Y ;copy pixel to sta ($03), Y ;back buffer jsr inc0103 ;increment pointers cmp #$00 ;check to see bne copybyte ;if we're at $600 lda $02 ;if so, we've cmp #$06 ;copied the bne copybyte ;entire screen conway: lda #$df ;apply conway rules sta $01 ;reset the pointer sta $03 ;to $#01df/$#07df lda #$01 ;($200 - $21) sta $02 ;($800 - $21) lda #$07 sta $04onecell: lda #$00 ;process one cell ldy #$01 ;upper cell clc adc ($03), Y ldy #$41 ;lower cell clc adc ($03), Ychkleft: tax ;check to see lda $01 ;if we're at the and #$1f ;left edge tay txa cpy #$1f beq rightcellsleftcells: ldy #$00 ;upper-left cell clc adc ($03), Y ldy #$20 ;left cell clc adc ($03), Y ldy #$40 ;lower-left cell clc adc ($03), Ychkright: tax ;check to see lda $01 ;if we're at the and #$1f ;right edge tay txa cpy #$1e beq evaluaterightcells: ldy #$02 ;upper-right cell clc adc ($03), Y ldy #$22 ;right cell clc adc ($03), Y ldy #$42 ;lower-right cell clc adc ($03), Yevaluate: ldx #$01 ;evaluate total ldy #$21 ;for current cell cmp #$03 ;3 = alive beq storex ldx #$00 cmp #$02 ;2 = alive if bne storex ;c = alive lda ($03), Y and #$01 taxstorex: txa ;store to screen sta ($01), Y jsr inc0103 ;move to next cellconwayloop: cmp #$e0 ;if not last cell, bne onecell ;process next cell lda $02 cmp #$05 bne onecell jmp starttick ;run next tick inc0103: lda $01 ;increment $01 cmp #$ff ;and $03 as 16-bit bne onlyinc01 ;pointers inc $02 inc $04onlyinc01: inc $01 lda $01 sta $03 rts The solution uses one cell thick border around square Petri dish as uninhabited dire land. Sample output contains 3 generations of the blinker and 5 of the glider: See Conway's Game of Life/ALGOL 68 APL2 (Dialog) Example in one line APL \ 1130 example (very old APL dialect via simulator) APL1130From: APL \ 1130 Samples The following APL \ 1130 code will need APL385 font installed to display correctly. See Download APL TT Font ∇LIFE[⎕]∇[0] NG←LIFE CG; W[1] W←CG+(¯1⊖CG)+(1⊖CG)+(¯1⌽CG)+(1⌽CG)[2] W←W+(1⊖1⌽CG)+(¯1⊖1⌽CG)+(1⊖¯1⌽CG)+(¯1⊖¯1⌽CG)[3] NG←(3=W)+(CG∧4=W) ∇ RP←5 5⍴0 0 0 0 0 0 0 1 1 0 0 1 1 0 0 0 0 1 0 0 RP0 0 0 0 00 0 1 1 00 1 1 0 00 0 1 0 00 0 0 0 0 LIFE RP0 0 0 0 00 1 1 1 00 1 0 0 00 1 1 0 00 0 0 0 0 LIFE LIFE RP0 0 1 0 00 1 1 0 01 0 0 1 00 1 1 0 00 0 0 0 0 .................................................. One interacts with the Game of Life by creating an initial configuration and observing how it evolves. Although you should test your implementation on more complex examples such as the glider in a larger universe, show the action of the blinker (three adjoining cells in a row all alive), over three generations, in a 3 by 3 grid. (1,4)=TRUERETURN'' Count the number of neighbours of the point i,j' (Assume i/j +/- 1 will not fall out of world)'FUNCTION count_neighbours(i%,j%) LOCAL count%,l% count%=0 FOR l%=-1 TO 1 IF world! (i%+l%,j%+1) count%=count%+1 ENDIF NEXT l% IF world! (i%+1,j%) count%=count%+1 ENDIF RETURN count%ENDFUNC'' Update the world one step'PROCEDURE update_world LOCAL i%,j% ' compute neighbour counts and store FOR i%=1 TO 30 FOR j%=1 TO 30 ns%(i%,j%)[email protected]_neighbours(i%,j%) NEXT j% NEXT i% ' update the world cells FOR i%=1 TO 30 FOR j%=1 TO 30 IF world!

||

randfill: stx $01 ;$200 for indirect ldx #$02 ;addressing stx $02randloop: lda $fe ;generate random and #$01 ;pixels on the sta ($01), Y ;screen jsr inc0103 cmp #$00 bne randloop lda $02 cmp #$06 bne randloop clearmem: lda #$df ;set $07df-$0a20 sta $01 ;to $#00 lda #$07 sta $02clearbyte: lda #$00 sta ($01), Y jsr inc0103 cmp #$20 bne clearbyte lda $02 cmp #$0a bne clearbyte starttick:copyscreen: lda #$00 ;set up source sta $01 ;pointer at sta $03 ;$01/$02 and lda #$02 ;dest pointer sta $02 ;at $03/$04 lda #$08 sta $04 ldy #$00copybyte: lda ($01), Y ;copy pixel to sta ($03), Y ;back buffer jsr inc0103 ;increment pointers cmp #$00 ;check to see bne copybyte ;if we're at $600 lda $02 ;if so, we've cmp #$06 ;copied the bne copybyte ;entire screen conway: lda #$df ;apply conway rules sta $01 ;reset the pointer sta $03 ;to $#01df/$#07df lda #$01 ;($200 - $21) sta $02 ;($800 - $21) lda #$07 sta $04onecell: lda #$00 ;process one cell ldy #$01 ;upper cell clc adc ($03), Y ldy #$41 ;lower cell clc adc ($03), Ychkleft: tax ;check to see lda $01 ;if we're at the and #$1f ;left edge tay txa cpy #$1f beq rightcellsleftcells: ldy #$00 ;upper-left cell clc adc ($03), Y ldy #$20 ;left cell clc adc ($03), Y ldy #$40 ;lower-left cell clc adc ($03), Ychkright: tax ;check to see lda $01 ;if we're at the and #$1f ;right edge tay txa cpy #$1e beq evaluaterightcells: ldy #$02 ;upper-right cell clc adc ($03), Y ldy #$22 ;right cell clc adc ($03), Y ldy #$42 ;lower-right cell clc adc ($03), Yevaluate: ldx #$01 ;evaluate total ldy #$21 ;for current cell cmp #$03 ;3 = alive beq storex ldx #$00 cmp #$02 ;2 = alive if bne storex ;c = alive lda ($03), Y and #$01 taxstorex: txa ;store to screen sta ($01), Y jsr inc0103 ;move to next cellconwayloop: cmp #$e0 ;if not last cell, bne onecell ;process next cell lda $02 cmp #$05 bne onecell jmp starttick ;run next tick inc0103: lda $01 ;increment $01 cmp #$ff ;and $03 as 16-bit bne onlyinc01 ;pointers inc $02 inc $04onlyinc01: inc $01 lda $01 sta $03 rts The solution uses one cell thick border around square Petri dish as uninhabited dire land. Sample output contains 3 generations of the blinker and 5 of the glider: See Conway's Game of Life/ALGOL 68 APL2 (Dialog) Example in one line APL \ 1130 example (very old APL dialect via simulator) APL1130From: APL \ 1130 Samples The following APL \ 1130 code will need APL385 font installed to display correctly.

See Download APL TT Font ∇LIFE[⎕]∇[0] NG←LIFE CG; W[1] W←CG+(¯1⊖CG)+(1⊖CG)+(¯1⌽CG)+(1⌽CG)[2] W←W+(1⊖1⌽CG)+(¯1⊖1⌽CG)+(1⊖¯1⌽CG)+(¯1⊖¯1⌽CG)[3] NG←(3=W)+(CG∧4=W) ∇ RP←5 5⍴0 0 0 0 0 0 0 1 1 0 0 1 1 0 0 0 0 1 0 0 RP0 0 0 0 00 0 1 1 00 1 1 0 00 0 1 0 00 0 0 0 0 LIFE RP0 0 0 0 00 1 1 1 00 1 0 0 00 1 1 0 00 0 0 0 0 LIFE LIFE RP0 0 1 0 00 1 1 0 01 0 0 1 00 1 1 0 00 0 0 0 0 ..................................................

One interacts with the Game of Life by creating an initial configuration and observing how it evolves.

Although you should test your implementation on more complex examples such as the glider in a larger universe, show the action of the blinker (three adjoining cells in a row all alive), over three generations, in a 3 by 3 grid.

(1,4)=TRUERETURN'' Count the number of neighbours of the point i,j' (Assume i/j +/- 1 will not fall out of world)'FUNCTION count_neighbours(i%,j%) LOCAL count%,l% count%=0 FOR l%=-1 TO 1 IF world! (i%+l%,j%+1) count%=count%+1 ENDIF NEXT l% IF world! (i%+1,j%) count%=count%+1 ENDIF RETURN count%ENDFUNC'' Update the world one step'PROCEDURE update_world LOCAL i%,j% ' compute neighbour counts and store FOR i%=1 TO 30 FOR j%=1 TO 30 ns%(i%,j%)[email protected]_neighbours(i%,j%) NEXT j% NEXT i% ' update the world cells FOR i%=1 TO 30 FOR j%=1 TO 30 IF world!

Thus, while it is somewhat verbose, it fully simulates Conway's Game of Life and is relatively simple to expand to feature different starting shapes.

Define life(pattern) = Prgm Local x,y,nt,count,save,xl,yl,xh,yh Define nt(y,x) = when(pxl Test(y,x), 1, 0) {}→save set Graph("Axes", "Off")→save[1] set Graph("Grid", "Off")→save[2] set Graph("Labels", "Off")→save[3] Fn Off Plot Off Clr Draw If pattern = "blinker" Then 36→yl 40→yh 78→xl 82→xh Pxl On 36,80 Pxl On 38,80 Pxl On 40,80 Else If pattern = "glider" Then 30→yl 40→yh 76→xl 88→xh Pxl On 38,76 Pxl On 36,78 Pxl On 36,80 Pxl On 38,80 Pxl On 40,80 Else If pattern = "r" Then 38-5*2→yl 38+5*2→yh 80-5*2→xl 80+5*2→xh Pxl On 38,78 Pxl On 36,82 Pxl On 36,80 Pxl On 38,80 Pxl On 40,80 End If While get Key() = 0 © Expand upper-left corner to whole cell For y,yl,yh,2 For x,xl,xh,2 If pxl Test(y,x) Then Pxl On y+1,x Pxl On y+1,x+1 Pxl On y, x+1 Else Pxl Off y+1,x Pxl Off y+1,x+1 Pxl Off y, x+1 End If End For End For © Compute next generation For y,yl,yh,2 For x,xl,xh,2 nt(y-1,x-1) + nt(y-1,x) + nt(y-1,x+2) + nt(y,x-1) + nt(y+1,x+2) + nt(y+2,x-1) + nt(y+2,x+1) + nt(y+2,x+2) → count If count = 3 Then Pxl On y,x Else If count ≠ 2 Then Pxl Off y,x End If End For End For End While © Restore changed options set Graph("Axes", save[1]) set Graph("Grid", save[2]) set Graph("Labels", save[3])End Prgm Also see Conway's Game of Life/C Considering that the simplest implementation in C++ would lack any use of the object-oriented paradigm, this code was specifically written to demonstrate the various object-oriented features of C++.

;(0 - ) sta ;(0 - ) lda # sta onecell: lda #[[

randfill: stx $01 ;$200 for indirect ldx #$02 ;addressing stx $02randloop: lda $fe ;generate random and #$01 ;pixels on the sta ($01), Y ;screen jsr inc0103 cmp #$00 bne randloop lda $02 cmp #$06 bne randloop clearmem: lda #$df ;set $07df-$0a20 sta $01 ;to $#00 lda #$07 sta $02clearbyte: lda #$00 sta ($01), Y jsr inc0103 cmp #$20 bne clearbyte lda $02 cmp #$0a bne clearbyte starttick:copyscreen: lda #$00 ;set up source sta $01 ;pointer at sta $03 ;$01/$02 and lda #$02 ;dest pointer sta $02 ;at $03/$04 lda #$08 sta $04 ldy #$00copybyte: lda ($01), Y ;copy pixel to sta ($03), Y ;back buffer jsr inc0103 ;increment pointers cmp #$00 ;check to see bne copybyte ;if we're at $600 lda $02 ;if so, we've cmp #$06 ;copied the bne copybyte ;entire screen conway: lda #$df ;apply conway rules sta $01 ;reset the pointer sta $03 ;to $#01df/$#07df lda #$01 ;($200 - $21) sta $02 ;($800 - $21) lda #$07 sta $04onecell: lda #$00 ;process one cell ldy #$01 ;upper cell clc adc ($03), Y ldy #$41 ;lower cell clc adc ($03), Ychkleft: tax ;check to see lda $01 ;if we're at the and #$1f ;left edge tay txa cpy #$1f beq rightcellsleftcells: ldy #$00 ;upper-left cell clc adc ($03), Y ldy #$20 ;left cell clc adc ($03), Y ldy #$40 ;lower-left cell clc adc ($03), Ychkright: tax ;check to see lda $01 ;if we're at the and #$1f ;right edge tay txa cpy #$1e beq evaluaterightcells: ldy #$02 ;upper-right cell clc adc ($03), Y ldy #$22 ;right cell clc adc ($03), Y ldy #$42 ;lower-right cell clc adc ($03), Yevaluate: ldx #$01 ;evaluate total ldy #$21 ;for current cell cmp #$03 ;3 = alive beq storex ldx #$00 cmp #$02 ;2 = alive if bne storex ;c = alive lda ($03), Y and #$01 taxstorex: txa ;store to screen sta ($01), Y jsr inc0103 ;move to next cellconwayloop: cmp #$e0 ;if not last cell, bne onecell ;process next cell lda $02 cmp #$05 bne onecell jmp starttick ;run next tick inc0103: lda $01 ;increment $01 cmp #$ff ;and $03 as 16-bit bne onlyinc01 ;pointers inc $02 inc $04onlyinc01: inc $01 lda $01 sta $03 rts The solution uses one cell thick border around square Petri dish as uninhabited dire land. Sample output contains 3 generations of the blinker and 5 of the glider: See Conway's Game of Life/ALGOL 68 APL2 (Dialog) Example in one line APL \ 1130 example (very old APL dialect via simulator) APL1130From: APL \ 1130 Samples The following APL \ 1130 code will need APL385 font installed to display correctly. See Download APL TT Font ∇LIFE[⎕]∇[0] NG←LIFE CG; W[1] W←CG+(¯1⊖CG)+(1⊖CG)+(¯1⌽CG)+(1⌽CG)[2] W←W+(1⊖1⌽CG)+(¯1⊖1⌽CG)+(1⊖¯1⌽CG)+(¯1⊖¯1⌽CG)[3] NG←(3=W)+(CG∧4=W) ∇ RP←5 5⍴0 0 0 0 0 0 0 1 1 0 0 1 1 0 0 0 0 1 0 0 RP0 0 0 0 00 0 1 1 00 1 1 0 00 0 1 0 00 0 0 0 0 LIFE RP0 0 0 0 00 1 1 1 00 1 0 0 00 1 1 0 00 0 0 0 0 LIFE LIFE RP0 0 1 0 00 1 1 0 01 0 0 1 00 1 1 0 00 0 0 0 0 .................................................. One interacts with the Game of Life by creating an initial configuration and observing how it evolves. Although you should test your implementation on more complex examples such as the glider in a larger universe, show the action of the blinker (three adjoining cells in a row all alive), over three generations, in a 3 by 3 grid. (1,4)=TRUERETURN'' Count the number of neighbours of the point i,j' (Assume i/j +/- 1 will not fall out of world)'FUNCTION count_neighbours(i%,j%) LOCAL count%,l% count%=0 FOR l%=-1 TO 1 IF world! (i%+l%,j%+1) count%=count%+1 ENDIF NEXT l% IF world! (i%+1,j%) count%=count%+1 ENDIF RETURN count%ENDFUNC'' Update the world one step'PROCEDURE update_world LOCAL i%,j% ' compute neighbour counts and store FOR i%=1 TO 30 FOR j%=1 TO 30 ns%(i%,j%)[email protected]_neighbours(i%,j%) NEXT j% NEXT i% ' update the world cells FOR i%=1 TO 30 FOR j%=1 TO 30 IF world!

||

randfill: stx $01 ;$200 for indirect ldx #$02 ;addressing stx $02randloop: lda $fe ;generate random and #$01 ;pixels on the sta ($01), Y ;screen jsr inc0103 cmp #$00 bne randloop lda $02 cmp #$06 bne randloop clearmem: lda #$df ;set $07df-$0a20 sta $01 ;to $#00 lda #$07 sta $02clearbyte: lda #$00 sta ($01), Y jsr inc0103 cmp #$20 bne clearbyte lda $02 cmp #$0a bne clearbyte starttick:copyscreen: lda #$00 ;set up source sta $01 ;pointer at sta $03 ;$01/$02 and lda #$02 ;dest pointer sta $02 ;at $03/$04 lda #$08 sta $04 ldy #$00copybyte: lda ($01), Y ;copy pixel to sta ($03), Y ;back buffer jsr inc0103 ;increment pointers cmp #$00 ;check to see bne copybyte ;if we're at $600 lda $02 ;if so, we've cmp #$06 ;copied the bne copybyte ;entire screen conway: lda #$df ;apply conway rules sta $01 ;reset the pointer sta $03 ;to $#01df/$#07df lda #$01 ;($200 - $21) sta $02 ;($800 - $21) lda #$07 sta $04onecell: lda #$00 ;process one cell ldy #$01 ;upper cell clc adc ($03), Y ldy #$41 ;lower cell clc adc ($03), Ychkleft: tax ;check to see lda $01 ;if we're at the and #$1f ;left edge tay txa cpy #$1f beq rightcellsleftcells: ldy #$00 ;upper-left cell clc adc ($03), Y ldy #$20 ;left cell clc adc ($03), Y ldy #$40 ;lower-left cell clc adc ($03), Ychkright: tax ;check to see lda $01 ;if we're at the and #$1f ;right edge tay txa cpy #$1e beq evaluaterightcells: ldy #$02 ;upper-right cell clc adc ($03), Y ldy #$22 ;right cell clc adc ($03), Y ldy #$42 ;lower-right cell clc adc ($03), Yevaluate: ldx #$01 ;evaluate total ldy #$21 ;for current cell cmp #$03 ;3 = alive beq storex ldx #$00 cmp #$02 ;2 = alive if bne storex ;c = alive lda ($03), Y and #$01 taxstorex: txa ;store to screen sta ($01), Y jsr inc0103 ;move to next cellconwayloop: cmp #$e0 ;if not last cell, bne onecell ;process next cell lda $02 cmp #$05 bne onecell jmp starttick ;run next tick inc0103: lda $01 ;increment $01 cmp #$ff ;and $03 as 16-bit bne onlyinc01 ;pointers inc $02 inc $04onlyinc01: inc $01 lda $01 sta $03 rts The solution uses one cell thick border around square Petri dish as uninhabited dire land. Sample output contains 3 generations of the blinker and 5 of the glider: See Conway's Game of Life/ALGOL 68 APL2 (Dialog) Example in one line APL \ 1130 example (very old APL dialect via simulator) APL1130From: APL \ 1130 Samples The following APL \ 1130 code will need APL385 font installed to display correctly.

See Download APL TT Font ∇LIFE[⎕]∇[0] NG←LIFE CG; W[1] W←CG+(¯1⊖CG)+(1⊖CG)+(¯1⌽CG)+(1⌽CG)[2] W←W+(1⊖1⌽CG)+(¯1⊖1⌽CG)+(1⊖¯1⌽CG)+(¯1⊖¯1⌽CG)[3] NG←(3=W)+(CG∧4=W) ∇ RP←5 5⍴0 0 0 0 0 0 0 1 1 0 0 1 1 0 0 0 0 1 0 0 RP0 0 0 0 00 0 1 1 00 1 1 0 00 0 1 0 00 0 0 0 0 LIFE RP0 0 0 0 00 1 1 1 00 1 0 0 00 1 1 0 00 0 0 0 0 LIFE LIFE RP0 0 1 0 00 1 1 0 01 0 0 1 00 1 1 0 00 0 0 0 0 ..................................................

One interacts with the Game of Life by creating an initial configuration and observing how it evolves.

Although you should test your implementation on more complex examples such as the glider in a larger universe, show the action of the blinker (three adjoining cells in a row all alive), over three generations, in a 3 by 3 grid.

(1,4)=TRUERETURN'' Count the number of neighbours of the point i,j' (Assume i/j +/- 1 will not fall out of world)'FUNCTION count_neighbours(i%,j%) LOCAL count%,l% count%=0 FOR l%=-1 TO 1 IF world! (i%+l%,j%+1) count%=count%+1 ENDIF NEXT l% IF world! (i%+1,j%) count%=count%+1 ENDIF RETURN count%ENDFUNC'' Update the world one step'PROCEDURE update_world LOCAL i%,j% ' compute neighbour counts and store FOR i%=1 TO 30 FOR j%=1 TO 30 ns%(i%,j%)[email protected]_neighbours(i%,j%) NEXT j% NEXT i% ' update the world cells FOR i%=1 TO 30 FOR j%=1 TO 30 IF world!

Thus, while it is somewhat verbose, it fully simulates Conway's Game of Life and is relatively simple to expand to feature different starting shapes.

Define life(pattern) = Prgm Local x,y,nt,count,save,xl,yl,xh,yh Define nt(y,x) = when(pxl Test(y,x), 1, 0) {}→save set Graph("Axes", "Off")→save[1] set Graph("Grid", "Off")→save[2] set Graph("Labels", "Off")→save[3] Fn Off Plot Off Clr Draw If pattern = "blinker" Then 36→yl 40→yh 78→xl 82→xh Pxl On 36,80 Pxl On 38,80 Pxl On 40,80 Else If pattern = "glider" Then 30→yl 40→yh 76→xl 88→xh Pxl On 38,76 Pxl On 36,78 Pxl On 36,80 Pxl On 38,80 Pxl On 40,80 Else If pattern = "r" Then 38-5*2→yl 38+5*2→yh 80-5*2→xl 80+5*2→xh Pxl On 38,78 Pxl On 36,82 Pxl On 36,80 Pxl On 38,80 Pxl On 40,80 End If While get Key() = 0 © Expand upper-left corner to whole cell For y,yl,yh,2 For x,xl,xh,2 If pxl Test(y,x) Then Pxl On y+1,x Pxl On y+1,x+1 Pxl On y, x+1 Else Pxl Off y+1,x Pxl Off y+1,x+1 Pxl Off y, x+1 End If End For End For © Compute next generation For y,yl,yh,2 For x,xl,xh,2 nt(y-1,x-1) + nt(y-1,x) + nt(y-1,x+2) + nt(y,x-1) + nt(y+1,x+2) + nt(y+2,x-1) + nt(y+2,x+1) + nt(y+2,x+2) → count If count = 3 Then Pxl On y,x Else If count ≠ 2 Then Pxl Off y,x End If End For End For End While © Restore changed options set Graph("Axes", save[1]) set Graph("Grid", save[2]) set Graph("Labels", save[3])End Prgm Also see Conway's Game of Life/C Considering that the simplest implementation in C++ would lack any use of the object-oriented paradigm, this code was specifically written to demonstrate the various object-oriented features of C++.

]] ;process one cell ldy #

randfill: stx $01 ;$200 for indirect ldx #$02 ;addressing stx $02randloop: lda $fe ;generate random and #$01 ;pixels on the sta ($01), Y ;screen jsr inc0103 cmp #$00 bne randloop lda $02 cmp #$06 bne randloop clearmem: lda #$df ;set $07df-$0a20 sta $01 ;to $#00 lda #$07 sta $02clearbyte: lda #$00 sta ($01), Y jsr inc0103 cmp #$20 bne clearbyte lda $02 cmp #$0a bne clearbyte starttick:copyscreen: lda #$00 ;set up source sta $01 ;pointer at sta $03 ;$01/$02 and lda #$02 ;dest pointer sta $02 ;at $03/$04 lda #$08 sta $04 ldy #$00copybyte: lda ($01), Y ;copy pixel to sta ($03), Y ;back buffer jsr inc0103 ;increment pointers cmp #$00 ;check to see bne copybyte ;if we're at $600 lda $02 ;if so, we've cmp #$06 ;copied the bne copybyte ;entire screen conway: lda #$df ;apply conway rules sta $01 ;reset the pointer sta $03 ;to $#01df/$#07df lda #$01 ;($200 - $21) sta $02 ;($800 - $21) lda #$07 sta $04onecell: lda #$00 ;process one cell ldy #$01 ;upper cell clc adc ($03), Y ldy #$41 ;lower cell clc adc ($03), Ychkleft: tax ;check to see lda $01 ;if we're at the and #$1f ;left edge tay txa cpy #$1f beq rightcellsleftcells: ldy #$00 ;upper-left cell clc adc ($03), Y ldy #$20 ;left cell clc adc ($03), Y ldy #$40 ;lower-left cell clc adc ($03), Ychkright: tax ;check to see lda $01 ;if we're at the and #$1f ;right edge tay txa cpy #$1e beq evaluaterightcells: ldy #$02 ;upper-right cell clc adc ($03), Y ldy #$22 ;right cell clc adc ($03), Y ldy #$42 ;lower-right cell clc adc ($03), Yevaluate: ldx #$01 ;evaluate total ldy #$21 ;for current cell cmp #$03 ;3 = alive beq storex ldx #$00 cmp #$02 ;2 = alive if bne storex ;c = alive lda ($03), Y and #$01 taxstorex: txa ;store to screen sta ($01), Y jsr inc0103 ;move to next cellconwayloop: cmp #$e0 ;if not last cell, bne onecell ;process next cell lda $02 cmp #$05 bne onecell jmp starttick ;run next tick inc0103: lda $01 ;increment $01 cmp #$ff ;and $03 as 16-bit bne onlyinc01 ;pointers inc $02 inc $04onlyinc01: inc $01 lda $01 sta $03 rts The solution uses one cell thick border around square Petri dish as uninhabited dire land. Sample output contains 3 generations of the blinker and 5 of the glider: See Conway's Game of Life/ALGOL 68 APL2 (Dialog) Example in one line APL \ 1130 example (very old APL dialect via simulator) APL1130From: APL \ 1130 Samples The following APL \ 1130 code will need APL385 font installed to display correctly. See Download APL TT Font ∇LIFE[⎕]∇[0] NG←LIFE CG; W[1] W←CG+(¯1⊖CG)+(1⊖CG)+(¯1⌽CG)+(1⌽CG)[2] W←W+(1⊖1⌽CG)+(¯1⊖1⌽CG)+(1⊖¯1⌽CG)+(¯1⊖¯1⌽CG)[3] NG←(3=W)+(CG∧4=W) ∇ RP←5 5⍴0 0 0 0 0 0 0 1 1 0 0 1 1 0 0 0 0 1 0 0 RP0 0 0 0 00 0 1 1 00 1 1 0 00 0 1 0 00 0 0 0 0 LIFE RP0 0 0 0 00 1 1 1 00 1 0 0 00 1 1 0 00 0 0 0 0 LIFE LIFE RP0 0 1 0 00 1 1 0 01 0 0 1 00 1 1 0 00 0 0 0 0 .................................................. One interacts with the Game of Life by creating an initial configuration and observing how it evolves. Although you should test your implementation on more complex examples such as the glider in a larger universe, show the action of the blinker (three adjoining cells in a row all alive), over three generations, in a 3 by 3 grid. (1,4)=TRUERETURN'' Count the number of neighbours of the point i,j' (Assume i/j +/- 1 will not fall out of world)'FUNCTION count_neighbours(i%,j%) LOCAL count%,l% count%=0 FOR l%=-1 TO 1 IF world! (i%+l%,j%+1) count%=count%+1 ENDIF NEXT l% IF world! (i%+1,j%) count%=count%+1 ENDIF RETURN count%ENDFUNC'' Update the world one step'PROCEDURE update_world LOCAL i%,j% ' compute neighbour counts and store FOR i%=1 TO 30 FOR j%=1 TO 30 ns%(i%,j%)[email protected]_neighbours(i%,j%) NEXT j% NEXT i% ' update the world cells FOR i%=1 TO 30 FOR j%=1 TO 30 IF world!

||

randfill: stx $01 ;$200 for indirect ldx #$02 ;addressing stx $02randloop: lda $fe ;generate random and #$01 ;pixels on the sta ($01), Y ;screen jsr inc0103 cmp #$00 bne randloop lda $02 cmp #$06 bne randloop clearmem: lda #$df ;set $07df-$0a20 sta $01 ;to $#00 lda #$07 sta $02clearbyte: lda #$00 sta ($01), Y jsr inc0103 cmp #$20 bne clearbyte lda $02 cmp #$0a bne clearbyte starttick:copyscreen: lda #$00 ;set up source sta $01 ;pointer at sta $03 ;$01/$02 and lda #$02 ;dest pointer sta $02 ;at $03/$04 lda #$08 sta $04 ldy #$00copybyte: lda ($01), Y ;copy pixel to sta ($03), Y ;back buffer jsr inc0103 ;increment pointers cmp #$00 ;check to see bne copybyte ;if we're at $600 lda $02 ;if so, we've cmp #$06 ;copied the bne copybyte ;entire screen conway: lda #$df ;apply conway rules sta $01 ;reset the pointer sta $03 ;to $#01df/$#07df lda #$01 ;($200 - $21) sta $02 ;($800 - $21) lda #$07 sta $04onecell: lda #$00 ;process one cell ldy #$01 ;upper cell clc adc ($03), Y ldy #$41 ;lower cell clc adc ($03), Ychkleft: tax ;check to see lda $01 ;if we're at the and #$1f ;left edge tay txa cpy #$1f beq rightcellsleftcells: ldy #$00 ;upper-left cell clc adc ($03), Y ldy #$20 ;left cell clc adc ($03), Y ldy #$40 ;lower-left cell clc adc ($03), Ychkright: tax ;check to see lda $01 ;if we're at the and #$1f ;right edge tay txa cpy #$1e beq evaluaterightcells: ldy #$02 ;upper-right cell clc adc ($03), Y ldy #$22 ;right cell clc adc ($03), Y ldy #$42 ;lower-right cell clc adc ($03), Yevaluate: ldx #$01 ;evaluate total ldy #$21 ;for current cell cmp #$03 ;3 = alive beq storex ldx #$00 cmp #$02 ;2 = alive if bne storex ;c = alive lda ($03), Y and #$01 taxstorex: txa ;store to screen sta ($01), Y jsr inc0103 ;move to next cellconwayloop: cmp #$e0 ;if not last cell, bne onecell ;process next cell lda $02 cmp #$05 bne onecell jmp starttick ;run next tick inc0103: lda $01 ;increment $01 cmp #$ff ;and $03 as 16-bit bne onlyinc01 ;pointers inc $02 inc $04onlyinc01: inc $01 lda $01 sta $03 rts The solution uses one cell thick border around square Petri dish as uninhabited dire land. Sample output contains 3 generations of the blinker and 5 of the glider: See Conway's Game of Life/ALGOL 68 APL2 (Dialog) Example in one line APL \ 1130 example (very old APL dialect via simulator) APL1130From: APL \ 1130 Samples The following APL \ 1130 code will need APL385 font installed to display correctly.

See Download APL TT Font ∇LIFE[⎕]∇[0] NG←LIFE CG; W[1] W←CG+(¯1⊖CG)+(1⊖CG)+(¯1⌽CG)+(1⌽CG)[2] W←W+(1⊖1⌽CG)+(¯1⊖1⌽CG)+(1⊖¯1⌽CG)+(¯1⊖¯1⌽CG)[3] NG←(3=W)+(CG∧4=W) ∇ RP←5 5⍴0 0 0 0 0 0 0 1 1 0 0 1 1 0 0 0 0 1 0 0 RP0 0 0 0 00 0 1 1 00 1 1 0 00 0 1 0 00 0 0 0 0 LIFE RP0 0 0 0 00 1 1 1 00 1 0 0 00 1 1 0 00 0 0 0 0 LIFE LIFE RP0 0 1 0 00 1 1 0 01 0 0 1 00 1 1 0 00 0 0 0 0 ..................................................

One interacts with the Game of Life by creating an initial configuration and observing how it evolves.

Although you should test your implementation on more complex examples such as the glider in a larger universe, show the action of the blinker (three adjoining cells in a row all alive), over three generations, in a 3 by 3 grid.

(1,4)=TRUERETURN'' Count the number of neighbours of the point i,j' (Assume i/j +/- 1 will not fall out of world)'FUNCTION count_neighbours(i%,j%) LOCAL count%,l% count%=0 FOR l%=-1 TO 1 IF world! (i%+l%,j%+1) count%=count%+1 ENDIF NEXT l% IF world! (i%+1,j%) count%=count%+1 ENDIF RETURN count%ENDFUNC'' Update the world one step'PROCEDURE update_world LOCAL i%,j% ' compute neighbour counts and store FOR i%=1 TO 30 FOR j%=1 TO 30 ns%(i%,j%)[email protected]_neighbours(i%,j%) NEXT j% NEXT i% ' update the world cells FOR i%=1 TO 30 FOR j%=1 TO 30 IF world!

Thus, while it is somewhat verbose, it fully simulates Conway's Game of Life and is relatively simple to expand to feature different starting shapes.

Define life(pattern) = Prgm Local x,y,nt,count,save,xl,yl,xh,yh Define nt(y,x) = when(pxl Test(y,x), 1, 0) {}→save set Graph("Axes", "Off")→save[1] set Graph("Grid", "Off")→save[2] set Graph("Labels", "Off")→save[3] Fn Off Plot Off Clr Draw If pattern = "blinker" Then 36→yl 40→yh 78→xl 82→xh Pxl On 36,80 Pxl On 38,80 Pxl On 40,80 Else If pattern = "glider" Then 30→yl 40→yh 76→xl 88→xh Pxl On 38,76 Pxl On 36,78 Pxl On 36,80 Pxl On 38,80 Pxl On 40,80 Else If pattern = "r" Then 38-5*2→yl 38+5*2→yh 80-5*2→xl 80+5*2→xh Pxl On 38,78 Pxl On 36,82 Pxl On 36,80 Pxl On 38,80 Pxl On 40,80 End If While get Key() = 0 © Expand upper-left corner to whole cell For y,yl,yh,2 For x,xl,xh,2 If pxl Test(y,x) Then Pxl On y+1,x Pxl On y+1,x+1 Pxl On y, x+1 Else Pxl Off y+1,x Pxl Off y+1,x+1 Pxl Off y, x+1 End If End For End For © Compute next generation For y,yl,yh,2 For x,xl,xh,2 nt(y-1,x-1) + nt(y-1,x) + nt(y-1,x+2) + nt(y,x-1) + nt(y+1,x+2) + nt(y+2,x-1) + nt(y+2,x+1) + nt(y+2,x+2) → count If count = 3 Then Pxl On y,x Else If count ≠ 2 Then Pxl Off y,x End If End For End For End While © Restore changed options set Graph("Axes", save[1]) set Graph("Grid", save[2]) set Graph("Labels", save[3])End Prgm Also see Conway's Game of Life/C Considering that the simplest implementation in C++ would lack any use of the object-oriented paradigm, this code was specifically written to demonstrate the various object-oriented features of C++.

;upper cell clc adc (), Y ldy # ;lower cell clc adc (), Ychkleft: tax ;check to see lda

randfill: stx $01 ;$200 for indirect ldx #$02 ;addressing stx $02randloop: lda $fe ;generate random and #$01 ;pixels on the sta ($01), Y ;screen jsr inc0103 cmp #$00 bne randloop lda $02 cmp #$06 bne randloop clearmem: lda #$df ;set $07df-$0a20 sta $01 ;to $#00 lda #$07 sta $02clearbyte: lda #$00 sta ($01), Y jsr inc0103 cmp #$20 bne clearbyte lda $02 cmp #$0a bne clearbyte starttick:copyscreen: lda #$00 ;set up source sta $01 ;pointer at sta $03 ;$01/$02 and lda #$02 ;dest pointer sta $02 ;at $03/$04 lda #$08 sta $04 ldy #$00copybyte: lda ($01), Y ;copy pixel to sta ($03), Y ;back buffer jsr inc0103 ;increment pointers cmp #$00 ;check to see bne copybyte ;if we're at $600 lda $02 ;if so, we've cmp #$06 ;copied the bne copybyte ;entire screen conway: lda #$df ;apply conway rules sta $01 ;reset the pointer sta $03 ;to $#01df/$#07df lda #$01 ;($200 - $21) sta $02 ;($800 - $21) lda #$07 sta $04onecell: lda #$00 ;process one cell ldy #$01 ;upper cell clc adc ($03), Y ldy #$41 ;lower cell clc adc ($03), Ychkleft: tax ;check to see lda $01 ;if we're at the and #$1f ;left edge tay txa cpy #$1f beq rightcellsleftcells: ldy #$00 ;upper-left cell clc adc ($03), Y ldy #$20 ;left cell clc adc ($03), Y ldy #$40 ;lower-left cell clc adc ($03), Ychkright: tax ;check to see lda $01 ;if we're at the and #$1f ;right edge tay txa cpy #$1e beq evaluaterightcells: ldy #$02 ;upper-right cell clc adc ($03), Y ldy #$22 ;right cell clc adc ($03), Y ldy #$42 ;lower-right cell clc adc ($03), Yevaluate: ldx #$01 ;evaluate total ldy #$21 ;for current cell cmp #$03 ;3 = alive beq storex ldx #$00 cmp #$02 ;2 = alive if bne storex ;c = alive lda ($03), Y and #$01 taxstorex: txa ;store to screen sta ($01), Y jsr inc0103 ;move to next cellconwayloop: cmp #$e0 ;if not last cell, bne onecell ;process next cell lda $02 cmp #$05 bne onecell jmp starttick ;run next tick inc0103: lda $01 ;increment $01 cmp #$ff ;and $03 as 16-bit bne onlyinc01 ;pointers inc $02 inc $04onlyinc01: inc $01 lda $01 sta $03 rts The solution uses one cell thick border around square Petri dish as uninhabited dire land. Sample output contains 3 generations of the blinker and 5 of the glider: See Conway's Game of Life/ALGOL 68 APL2 (Dialog) Example in one line APL \ 1130 example (very old APL dialect via simulator) APL1130From: APL \ 1130 Samples The following APL \ 1130 code will need APL385 font installed to display correctly. See Download APL TT Font ∇LIFE[⎕]∇[0] NG←LIFE CG; W[1] W←CG+(¯1⊖CG)+(1⊖CG)+(¯1⌽CG)+(1⌽CG)[2] W←W+(1⊖1⌽CG)+(¯1⊖1⌽CG)+(1⊖¯1⌽CG)+(¯1⊖¯1⌽CG)[3] NG←(3=W)+(CG∧4=W) ∇ RP←5 5⍴0 0 0 0 0 0 0 1 1 0 0 1 1 0 0 0 0 1 0 0 RP0 0 0 0 00 0 1 1 00 1 1 0 00 0 1 0 00 0 0 0 0 LIFE RP0 0 0 0 00 1 1 1 00 1 0 0 00 1 1 0 00 0 0 0 0 LIFE LIFE RP0 0 1 0 00 1 1 0 01 0 0 1 00 1 1 0 00 0 0 0 0 .................................................. One interacts with the Game of Life by creating an initial configuration and observing how it evolves. Although you should test your implementation on more complex examples such as the glider in a larger universe, show the action of the blinker (three adjoining cells in a row all alive), over three generations, in a 3 by 3 grid. (1,4)=TRUERETURN'' Count the number of neighbours of the point i,j' (Assume i/j +/- 1 will not fall out of world)'FUNCTION count_neighbours(i%,j%) LOCAL count%,l% count%=0 FOR l%=-1 TO 1 IF world! (i%+l%,j%+1) count%=count%+1 ENDIF NEXT l% IF world! (i%+1,j%) count%=count%+1 ENDIF RETURN count%ENDFUNC'' Update the world one step'PROCEDURE update_world LOCAL i%,j% ' compute neighbour counts and store FOR i%=1 TO 30 FOR j%=1 TO 30 ns%(i%,j%)[email protected]_neighbours(i%,j%) NEXT j% NEXT i% ' update the world cells FOR i%=1 TO 30 FOR j%=1 TO 30 IF world!

||

randfill: stx $01 ;$200 for indirect ldx #$02 ;addressing stx $02randloop: lda $fe ;generate random and #$01 ;pixels on the sta ($01), Y ;screen jsr inc0103 cmp #$00 bne randloop lda $02 cmp #$06 bne randloop clearmem: lda #$df ;set $07df-$0a20 sta $01 ;to $#00 lda #$07 sta $02clearbyte: lda #$00 sta ($01), Y jsr inc0103 cmp #$20 bne clearbyte lda $02 cmp #$0a bne clearbyte starttick:copyscreen: lda #$00 ;set up source sta $01 ;pointer at sta $03 ;$01/$02 and lda #$02 ;dest pointer sta $02 ;at $03/$04 lda #$08 sta $04 ldy #$00copybyte: lda ($01), Y ;copy pixel to sta ($03), Y ;back buffer jsr inc0103 ;increment pointers cmp #$00 ;check to see bne copybyte ;if we're at $600 lda $02 ;if so, we've cmp #$06 ;copied the bne copybyte ;entire screen conway: lda #$df ;apply conway rules sta $01 ;reset the pointer sta $03 ;to $#01df/$#07df lda #$01 ;($200 - $21) sta $02 ;($800 - $21) lda #$07 sta $04onecell: lda #$00 ;process one cell ldy #$01 ;upper cell clc adc ($03), Y ldy #$41 ;lower cell clc adc ($03), Ychkleft: tax ;check to see lda $01 ;if we're at the and #$1f ;left edge tay txa cpy #$1f beq rightcellsleftcells: ldy #$00 ;upper-left cell clc adc ($03), Y ldy #$20 ;left cell clc adc ($03), Y ldy #$40 ;lower-left cell clc adc ($03), Ychkright: tax ;check to see lda $01 ;if we're at the and #$1f ;right edge tay txa cpy #$1e beq evaluaterightcells: ldy #$02 ;upper-right cell clc adc ($03), Y ldy #$22 ;right cell clc adc ($03), Y ldy #$42 ;lower-right cell clc adc ($03), Yevaluate: ldx #$01 ;evaluate total ldy #$21 ;for current cell cmp #$03 ;3 = alive beq storex ldx #$00 cmp #$02 ;2 = alive if bne storex ;c = alive lda ($03), Y and #$01 taxstorex: txa ;store to screen sta ($01), Y jsr inc0103 ;move to next cellconwayloop: cmp #$e0 ;if not last cell, bne onecell ;process next cell lda $02 cmp #$05 bne onecell jmp starttick ;run next tick inc0103: lda $01 ;increment $01 cmp #$ff ;and $03 as 16-bit bne onlyinc01 ;pointers inc $02 inc $04onlyinc01: inc $01 lda $01 sta $03 rts The solution uses one cell thick border around square Petri dish as uninhabited dire land. Sample output contains 3 generations of the blinker and 5 of the glider: See Conway's Game of Life/ALGOL 68 APL2 (Dialog) Example in one line APL \ 1130 example (very old APL dialect via simulator) APL1130From: APL \ 1130 Samples The following APL \ 1130 code will need APL385 font installed to display correctly.

See Download APL TT Font ∇LIFE[⎕]∇[0] NG←LIFE CG; W[1] W←CG+(¯1⊖CG)+(1⊖CG)+(¯1⌽CG)+(1⌽CG)[2] W←W+(1⊖1⌽CG)+(¯1⊖1⌽CG)+(1⊖¯1⌽CG)+(¯1⊖¯1⌽CG)[3] NG←(3=W)+(CG∧4=W) ∇ RP←5 5⍴0 0 0 0 0 0 0 1 1 0 0 1 1 0 0 0 0 1 0 0 RP0 0 0 0 00 0 1 1 00 1 1 0 00 0 1 0 00 0 0 0 0 LIFE RP0 0 0 0 00 1 1 1 00 1 0 0 00 1 1 0 00 0 0 0 0 LIFE LIFE RP0 0 1 0 00 1 1 0 01 0 0 1 00 1 1 0 00 0 0 0 0 ..................................................

One interacts with the Game of Life by creating an initial configuration and observing how it evolves.

Although you should test your implementation on more complex examples such as the glider in a larger universe, show the action of the blinker (three adjoining cells in a row all alive), over three generations, in a 3 by 3 grid.

(1,4)=TRUERETURN'' Count the number of neighbours of the point i,j' (Assume i/j +/- 1 will not fall out of world)'FUNCTION count_neighbours(i%,j%) LOCAL count%,l% count%=0 FOR l%=-1 TO 1 IF world! (i%+l%,j%+1) count%=count%+1 ENDIF NEXT l% IF world! (i%+1,j%) count%=count%+1 ENDIF RETURN count%ENDFUNC'' Update the world one step'PROCEDURE update_world LOCAL i%,j% ' compute neighbour counts and store FOR i%=1 TO 30 FOR j%=1 TO 30 ns%(i%,j%)[email protected]_neighbours(i%,j%) NEXT j% NEXT i% ' update the world cells FOR i%=1 TO 30 FOR j%=1 TO 30 IF world!

Thus, while it is somewhat verbose, it fully simulates Conway's Game of Life and is relatively simple to expand to feature different starting shapes.

Define life(pattern) = Prgm Local x,y,nt,count,save,xl,yl,xh,yh Define nt(y,x) = when(pxl Test(y,x), 1, 0) {}→save set Graph("Axes", "Off")→save[1] set Graph("Grid", "Off")→save[2] set Graph("Labels", "Off")→save[3] Fn Off Plot Off Clr Draw If pattern = "blinker" Then 36→yl 40→yh 78→xl 82→xh Pxl On 36,80 Pxl On 38,80 Pxl On 40,80 Else If pattern = "glider" Then 30→yl 40→yh 76→xl 88→xh Pxl On 38,76 Pxl On 36,78 Pxl On 36,80 Pxl On 38,80 Pxl On 40,80 Else If pattern = "r" Then 38-5*2→yl 38+5*2→yh 80-5*2→xl 80+5*2→xh Pxl On 38,78 Pxl On 36,82 Pxl On 36,80 Pxl On 38,80 Pxl On 40,80 End If While get Key() = 0 © Expand upper-left corner to whole cell For y,yl,yh,2 For x,xl,xh,2 If pxl Test(y,x) Then Pxl On y+1,x Pxl On y+1,x+1 Pxl On y, x+1 Else Pxl Off y+1,x Pxl Off y+1,x+1 Pxl Off y, x+1 End If End For End For © Compute next generation For y,yl,yh,2 For x,xl,xh,2 nt(y-1,x-1) + nt(y-1,x) + nt(y-1,x+2) + nt(y,x-1) + nt(y+1,x+2) + nt(y+2,x-1) + nt(y+2,x+1) + nt(y+2,x+2) → count If count = 3 Then Pxl On y,x Else If count ≠ 2 Then Pxl Off y,x End If End For End For End While © Restore changed options set Graph("Axes", save[1]) set Graph("Grid", save[2]) set Graph("Labels", save[3])End Prgm Also see Conway's Game of Life/C Considering that the simplest implementation in C++ would lack any use of the object-oriented paradigm, this code was specifically written to demonstrate the various object-oriented features of C++.

;if we're at the and #

randfill: stx $01 ;$200 for indirect ldx #$02 ;addressing stx $02randloop: lda $fe ;generate random and #$01 ;pixels on the sta ($01), Y ;screen jsr inc0103 cmp #$00 bne randloop lda $02 cmp #$06 bne randloop clearmem: lda #$df ;set $07df-$0a20 sta $01 ;to $#00 lda #$07 sta $02clearbyte: lda #$00 sta ($01), Y jsr inc0103 cmp #$20 bne clearbyte lda $02 cmp #$0a bne clearbyte starttick:copyscreen: lda #$00 ;set up source sta $01 ;pointer at sta $03 ;$01/$02 and lda #$02 ;dest pointer sta $02 ;at $03/$04 lda #$08 sta $04 ldy #$00copybyte: lda ($01), Y ;copy pixel to sta ($03), Y ;back buffer jsr inc0103 ;increment pointers cmp #$00 ;check to see bne copybyte ;if we're at $600 lda $02 ;if so, we've cmp #$06 ;copied the bne copybyte ;entire screen conway: lda #$df ;apply conway rules sta $01 ;reset the pointer sta $03 ;to $#01df/$#07df lda #$01 ;($200 - $21) sta $02 ;($800 - $21) lda #$07 sta $04onecell: lda #$00 ;process one cell ldy #$01 ;upper cell clc adc ($03), Y ldy #$41 ;lower cell clc adc ($03), Ychkleft: tax ;check to see lda $01 ;if we're at the and #$1f ;left edge tay txa cpy #$1f beq rightcellsleftcells: ldy #$00 ;upper-left cell clc adc ($03), Y ldy #$20 ;left cell clc adc ($03), Y ldy #$40 ;lower-left cell clc adc ($03), Ychkright: tax ;check to see lda $01 ;if we're at the and #$1f ;right edge tay txa cpy #$1e beq evaluaterightcells: ldy #$02 ;upper-right cell clc adc ($03), Y ldy #$22 ;right cell clc adc ($03), Y ldy #$42 ;lower-right cell clc adc ($03), Yevaluate: ldx #$01 ;evaluate total ldy #$21 ;for current cell cmp #$03 ;3 = alive beq storex ldx #$00 cmp #$02 ;2 = alive if bne storex ;c = alive lda ($03), Y and #$01 taxstorex: txa ;store to screen sta ($01), Y jsr inc0103 ;move to next cellconwayloop: cmp #$e0 ;if not last cell, bne onecell ;process next cell lda $02 cmp #$05 bne onecell jmp starttick ;run next tick inc0103: lda $01 ;increment $01 cmp #$ff ;and $03 as 16-bit bne onlyinc01 ;pointers inc $02 inc $04onlyinc01: inc $01 lda $01 sta $03 rts The solution uses one cell thick border around square Petri dish as uninhabited dire land. Sample output contains 3 generations of the blinker and 5 of the glider: See Conway's Game of Life/ALGOL 68 APL2 (Dialog) Example in one line APL \ 1130 example (very old APL dialect via simulator) APL1130From: APL \ 1130 Samples The following APL \ 1130 code will need APL385 font installed to display correctly. See Download APL TT Font ∇LIFE[⎕]∇[0] NG←LIFE CG; W[1] W←CG+(¯1⊖CG)+(1⊖CG)+(¯1⌽CG)+(1⌽CG)[2] W←W+(1⊖1⌽CG)+(¯1⊖1⌽CG)+(1⊖¯1⌽CG)+(¯1⊖¯1⌽CG)[3] NG←(3=W)+(CG∧4=W) ∇ RP←5 5⍴0 0 0 0 0 0 0 1 1 0 0 1 1 0 0 0 0 1 0 0 RP0 0 0 0 00 0 1 1 00 1 1 0 00 0 1 0 00 0 0 0 0 LIFE RP0 0 0 0 00 1 1 1 00 1 0 0 00 1 1 0 00 0 0 0 0 LIFE LIFE RP0 0 1 0 00 1 1 0 01 0 0 1 00 1 1 0 00 0 0 0 0 .................................................. One interacts with the Game of Life by creating an initial configuration and observing how it evolves. Although you should test your implementation on more complex examples such as the glider in a larger universe, show the action of the blinker (three adjoining cells in a row all alive), over three generations, in a 3 by 3 grid. (1,4)=TRUERETURN'' Count the number of neighbours of the point i,j' (Assume i/j +/- 1 will not fall out of world)'FUNCTION count_neighbours(i%,j%) LOCAL count%,l% count%=0 FOR l%=-1 TO 1 IF world! (i%+l%,j%+1) count%=count%+1 ENDIF NEXT l% IF world! (i%+1,j%) count%=count%+1 ENDIF RETURN count%ENDFUNC'' Update the world one step'PROCEDURE update_world LOCAL i%,j% ' compute neighbour counts and store FOR i%=1 TO 30 FOR j%=1 TO 30 ns%(i%,j%)[email protected]_neighbours(i%,j%) NEXT j% NEXT i% ' update the world cells FOR i%=1 TO 30 FOR j%=1 TO 30 IF world!

||

randfill: stx $01 ;$200 for indirect ldx #$02 ;addressing stx $02randloop: lda $fe ;generate random and #$01 ;pixels on the sta ($01), Y ;screen jsr inc0103 cmp #$00 bne randloop lda $02 cmp #$06 bne randloop clearmem: lda #$df ;set $07df-$0a20 sta $01 ;to $#00 lda #$07 sta $02clearbyte: lda #$00 sta ($01), Y jsr inc0103 cmp #$20 bne clearbyte lda $02 cmp #$0a bne clearbyte starttick:copyscreen: lda #$00 ;set up source sta $01 ;pointer at sta $03 ;$01/$02 and lda #$02 ;dest pointer sta $02 ;at $03/$04 lda #$08 sta $04 ldy #$00copybyte: lda ($01), Y ;copy pixel to sta ($03), Y ;back buffer jsr inc0103 ;increment pointers cmp #$00 ;check to see bne copybyte ;if we're at $600 lda $02 ;if so, we've cmp #$06 ;copied the bne copybyte ;entire screen conway: lda #$df ;apply conway rules sta $01 ;reset the pointer sta $03 ;to $#01df/$#07df lda #$01 ;($200 - $21) sta $02 ;($800 - $21) lda #$07 sta $04onecell: lda #$00 ;process one cell ldy #$01 ;upper cell clc adc ($03), Y ldy #$41 ;lower cell clc adc ($03), Ychkleft: tax ;check to see lda $01 ;if we're at the and #$1f ;left edge tay txa cpy #$1f beq rightcellsleftcells: ldy #$00 ;upper-left cell clc adc ($03), Y ldy #$20 ;left cell clc adc ($03), Y ldy #$40 ;lower-left cell clc adc ($03), Ychkright: tax ;check to see lda $01 ;if we're at the and #$1f ;right edge tay txa cpy #$1e beq evaluaterightcells: ldy #$02 ;upper-right cell clc adc ($03), Y ldy #$22 ;right cell clc adc ($03), Y ldy #$42 ;lower-right cell clc adc ($03), Yevaluate: ldx #$01 ;evaluate total ldy #$21 ;for current cell cmp #$03 ;3 = alive beq storex ldx #$00 cmp #$02 ;2 = alive if bne storex ;c = alive lda ($03), Y and #$01 taxstorex: txa ;store to screen sta ($01), Y jsr inc0103 ;move to next cellconwayloop: cmp #$e0 ;if not last cell, bne onecell ;process next cell lda $02 cmp #$05 bne onecell jmp starttick ;run next tick inc0103: lda $01 ;increment $01 cmp #$ff ;and $03 as 16-bit bne onlyinc01 ;pointers inc $02 inc $04onlyinc01: inc $01 lda $01 sta $03 rts The solution uses one cell thick border around square Petri dish as uninhabited dire land. Sample output contains 3 generations of the blinker and 5 of the glider: See Conway's Game of Life/ALGOL 68 APL2 (Dialog) Example in one line APL \ 1130 example (very old APL dialect via simulator) APL1130From: APL \ 1130 Samples The following APL \ 1130 code will need APL385 font installed to display correctly.

See Download APL TT Font ∇LIFE[⎕]∇[0] NG←LIFE CG; W[1] W←CG+(¯1⊖CG)+(1⊖CG)+(¯1⌽CG)+(1⌽CG)[2] W←W+(1⊖1⌽CG)+(¯1⊖1⌽CG)+(1⊖¯1⌽CG)+(¯1⊖¯1⌽CG)[3] NG←(3=W)+(CG∧4=W) ∇ RP←5 5⍴0 0 0 0 0 0 0 1 1 0 0 1 1 0 0 0 0 1 0 0 RP0 0 0 0 00 0 1 1 00 1 1 0 00 0 1 0 00 0 0 0 0 LIFE RP0 0 0 0 00 1 1 1 00 1 0 0 00 1 1 0 00 0 0 0 0 LIFE LIFE RP0 0 1 0 00 1 1 0 01 0 0 1 00 1 1 0 00 0 0 0 0 ..................................................

One interacts with the Game of Life by creating an initial configuration and observing how it evolves.

Although you should test your implementation on more complex examples such as the glider in a larger universe, show the action of the blinker (three adjoining cells in a row all alive), over three generations, in a 3 by 3 grid.

(1,4)=TRUERETURN'' Count the number of neighbours of the point i,j' (Assume i/j +/- 1 will not fall out of world)'FUNCTION count_neighbours(i%,j%) LOCAL count%,l% count%=0 FOR l%=-1 TO 1 IF world! (i%+l%,j%+1) count%=count%+1 ENDIF NEXT l% IF world! (i%+1,j%) count%=count%+1 ENDIF RETURN count%ENDFUNC'' Update the world one step'PROCEDURE update_world LOCAL i%,j% ' compute neighbour counts and store FOR i%=1 TO 30 FOR j%=1 TO 30 ns%(i%,j%)[email protected]_neighbours(i%,j%) NEXT j% NEXT i% ' update the world cells FOR i%=1 TO 30 FOR j%=1 TO 30 IF world!

Thus, while it is somewhat verbose, it fully simulates Conway's Game of Life and is relatively simple to expand to feature different starting shapes.

Define life(pattern) = Prgm Local x,y,nt,count,save,xl,yl,xh,yh Define nt(y,x) = when(pxl Test(y,x), 1, 0) {}→save set Graph("Axes", "Off")→save[1] set Graph("Grid", "Off")→save[2] set Graph("Labels", "Off")→save[3] Fn Off Plot Off Clr Draw If pattern = "blinker" Then 36→yl 40→yh 78→xl 82→xh Pxl On 36,80 Pxl On 38,80 Pxl On 40,80 Else If pattern = "glider" Then 30→yl 40→yh 76→xl 88→xh Pxl On 38,76 Pxl On 36,78 Pxl On 36,80 Pxl On 38,80 Pxl On 40,80 Else If pattern = "r" Then 38-5*2→yl 38+5*2→yh 80-5*2→xl 80+5*2→xh Pxl On 38,78 Pxl On 36,82 Pxl On 36,80 Pxl On 38,80 Pxl On 40,80 End If While get Key() = 0 © Expand upper-left corner to whole cell For y,yl,yh,2 For x,xl,xh,2 If pxl Test(y,x) Then Pxl On y+1,x Pxl On y+1,x+1 Pxl On y, x+1 Else Pxl Off y+1,x Pxl Off y+1,x+1 Pxl Off y, x+1 End If End For End For © Compute next generation For y,yl,yh,2 For x,xl,xh,2 nt(y-1,x-1) + nt(y-1,x) + nt(y-1,x+2) + nt(y,x-1) + nt(y+1,x+2) + nt(y+2,x-1) + nt(y+2,x+1) + nt(y+2,x+2) → count If count = 3 Then Pxl On y,x Else If count ≠ 2 Then Pxl Off y,x End If End For End For End While © Restore changed options set Graph("Axes", save[1]) set Graph("Grid", save[2]) set Graph("Labels", save[3])End Prgm Also see Conway's Game of Life/C Considering that the simplest implementation in C++ would lack any use of the object-oriented paradigm, this code was specifically written to demonstrate the various object-oriented features of C++.

f ;left edge tay txa cpy #

randfill: stx $01 ;$200 for indirect ldx #$02 ;addressing stx $02randloop: lda $fe ;generate random and #$01 ;pixels on the sta ($01), Y ;screen jsr inc0103 cmp #$00 bne randloop lda $02 cmp #$06 bne randloop clearmem: lda #$df ;set $07df-$0a20 sta $01 ;to $#00 lda #$07 sta $02clearbyte: lda #$00 sta ($01), Y jsr inc0103 cmp #$20 bne clearbyte lda $02 cmp #$0a bne clearbyte starttick:copyscreen: lda #$00 ;set up source sta $01 ;pointer at sta $03 ;$01/$02 and lda #$02 ;dest pointer sta $02 ;at $03/$04 lda #$08 sta $04 ldy #$00copybyte: lda ($01), Y ;copy pixel to sta ($03), Y ;back buffer jsr inc0103 ;increment pointers cmp #$00 ;check to see bne copybyte ;if we're at $600 lda $02 ;if so, we've cmp #$06 ;copied the bne copybyte ;entire screen conway: lda #$df ;apply conway rules sta $01 ;reset the pointer sta $03 ;to $#01df/$#07df lda #$01 ;($200 - $21) sta $02 ;($800 - $21) lda #$07 sta $04onecell: lda #$00 ;process one cell ldy #$01 ;upper cell clc adc ($03), Y ldy #$41 ;lower cell clc adc ($03), Ychkleft: tax ;check to see lda $01 ;if we're at the and #$1f ;left edge tay txa cpy #$1f beq rightcellsleftcells: ldy #$00 ;upper-left cell clc adc ($03), Y ldy #$20 ;left cell clc adc ($03), Y ldy #$40 ;lower-left cell clc adc ($03), Ychkright: tax ;check to see lda $01 ;if we're at the and #$1f ;right edge tay txa cpy #$1e beq evaluaterightcells: ldy #$02 ;upper-right cell clc adc ($03), Y ldy #$22 ;right cell clc adc ($03), Y ldy #$42 ;lower-right cell clc adc ($03), Yevaluate: ldx #$01 ;evaluate total ldy #$21 ;for current cell cmp #$03 ;3 = alive beq storex ldx #$00 cmp #$02 ;2 = alive if bne storex ;c = alive lda ($03), Y and #$01 taxstorex: txa ;store to screen sta ($01), Y jsr inc0103 ;move to next cellconwayloop: cmp #$e0 ;if not last cell, bne onecell ;process next cell lda $02 cmp #$05 bne onecell jmp starttick ;run next tick inc0103: lda $01 ;increment $01 cmp #$ff ;and $03 as 16-bit bne onlyinc01 ;pointers inc $02 inc $04onlyinc01: inc $01 lda $01 sta $03 rts The solution uses one cell thick border around square Petri dish as uninhabited dire land. Sample output contains 3 generations of the blinker and 5 of the glider: See Conway's Game of Life/ALGOL 68 APL2 (Dialog) Example in one line APL \ 1130 example (very old APL dialect via simulator) APL1130From: APL \ 1130 Samples The following APL \ 1130 code will need APL385 font installed to display correctly. See Download APL TT Font ∇LIFE[⎕]∇[0] NG←LIFE CG; W[1] W←CG+(¯1⊖CG)+(1⊖CG)+(¯1⌽CG)+(1⌽CG)[2] W←W+(1⊖1⌽CG)+(¯1⊖1⌽CG)+(1⊖¯1⌽CG)+(¯1⊖¯1⌽CG)[3] NG←(3=W)+(CG∧4=W) ∇ RP←5 5⍴0 0 0 0 0 0 0 1 1 0 0 1 1 0 0 0 0 1 0 0 RP0 0 0 0 00 0 1 1 00 1 1 0 00 0 1 0 00 0 0 0 0 LIFE RP0 0 0 0 00 1 1 1 00 1 0 0 00 1 1 0 00 0 0 0 0 LIFE LIFE RP0 0 1 0 00 1 1 0 01 0 0 1 00 1 1 0 00 0 0 0 0 .................................................. One interacts with the Game of Life by creating an initial configuration and observing how it evolves. Although you should test your implementation on more complex examples such as the glider in a larger universe, show the action of the blinker (three adjoining cells in a row all alive), over three generations, in a 3 by 3 grid. (1,4)=TRUERETURN'' Count the number of neighbours of the point i,j' (Assume i/j +/- 1 will not fall out of world)'FUNCTION count_neighbours(i%,j%) LOCAL count%,l% count%=0 FOR l%=-1 TO 1 IF world! (i%+l%,j%+1) count%=count%+1 ENDIF NEXT l% IF world! (i%+1,j%) count%=count%+1 ENDIF RETURN count%ENDFUNC'' Update the world one step'PROCEDURE update_world LOCAL i%,j% ' compute neighbour counts and store FOR i%=1 TO 30 FOR j%=1 TO 30 ns%(i%,j%)[email protected]_neighbours(i%,j%) NEXT j% NEXT i% ' update the world cells FOR i%=1 TO 30 FOR j%=1 TO 30 IF world!

||

randfill: stx $01 ;$200 for indirect ldx #$02 ;addressing stx $02randloop: lda $fe ;generate random and #$01 ;pixels on the sta ($01), Y ;screen jsr inc0103 cmp #$00 bne randloop lda $02 cmp #$06 bne randloop clearmem: lda #$df ;set $07df-$0a20 sta $01 ;to $#00 lda #$07 sta $02clearbyte: lda #$00 sta ($01), Y jsr inc0103 cmp #$20 bne clearbyte lda $02 cmp #$0a bne clearbyte starttick:copyscreen: lda #$00 ;set up source sta $01 ;pointer at sta $03 ;$01/$02 and lda #$02 ;dest pointer sta $02 ;at $03/$04 lda #$08 sta $04 ldy #$00copybyte: lda ($01), Y ;copy pixel to sta ($03), Y ;back buffer jsr inc0103 ;increment pointers cmp #$00 ;check to see bne copybyte ;if we're at $600 lda $02 ;if so, we've cmp #$06 ;copied the bne copybyte ;entire screen conway: lda #$df ;apply conway rules sta $01 ;reset the pointer sta $03 ;to $#01df/$#07df lda #$01 ;($200 - $21) sta $02 ;($800 - $21) lda #$07 sta $04onecell: lda #$00 ;process one cell ldy #$01 ;upper cell clc adc ($03), Y ldy #$41 ;lower cell clc adc ($03), Ychkleft: tax ;check to see lda $01 ;if we're at the and #$1f ;left edge tay txa cpy #$1f beq rightcellsleftcells: ldy #$00 ;upper-left cell clc adc ($03), Y ldy #$20 ;left cell clc adc ($03), Y ldy #$40 ;lower-left cell clc adc ($03), Ychkright: tax ;check to see lda $01 ;if we're at the and #$1f ;right edge tay txa cpy #$1e beq evaluaterightcells: ldy #$02 ;upper-right cell clc adc ($03), Y ldy #$22 ;right cell clc adc ($03), Y ldy #$42 ;lower-right cell clc adc ($03), Yevaluate: ldx #$01 ;evaluate total ldy #$21 ;for current cell cmp #$03 ;3 = alive beq storex ldx #$00 cmp #$02 ;2 = alive if bne storex ;c = alive lda ($03), Y and #$01 taxstorex: txa ;store to screen sta ($01), Y jsr inc0103 ;move to next cellconwayloop: cmp #$e0 ;if not last cell, bne onecell ;process next cell lda $02 cmp #$05 bne onecell jmp starttick ;run next tick inc0103: lda $01 ;increment $01 cmp #$ff ;and $03 as 16-bit bne onlyinc01 ;pointers inc $02 inc $04onlyinc01: inc $01 lda $01 sta $03 rts The solution uses one cell thick border around square Petri dish as uninhabited dire land. Sample output contains 3 generations of the blinker and 5 of the glider: See Conway's Game of Life/ALGOL 68 APL2 (Dialog) Example in one line APL \ 1130 example (very old APL dialect via simulator) APL1130From: APL \ 1130 Samples The following APL \ 1130 code will need APL385 font installed to display correctly.

See Download APL TT Font ∇LIFE[⎕]∇[0] NG←LIFE CG; W[1] W←CG+(¯1⊖CG)+(1⊖CG)+(¯1⌽CG)+(1⌽CG)[2] W←W+(1⊖1⌽CG)+(¯1⊖1⌽CG)+(1⊖¯1⌽CG)+(¯1⊖¯1⌽CG)[3] NG←(3=W)+(CG∧4=W) ∇ RP←5 5⍴0 0 0 0 0 0 0 1 1 0 0 1 1 0 0 0 0 1 0 0 RP0 0 0 0 00 0 1 1 00 1 1 0 00 0 1 0 00 0 0 0 0 LIFE RP0 0 0 0 00 1 1 1 00 1 0 0 00 1 1 0 00 0 0 0 0 LIFE LIFE RP0 0 1 0 00 1 1 0 01 0 0 1 00 1 1 0 00 0 0 0 0 ..................................................

One interacts with the Game of Life by creating an initial configuration and observing how it evolves.

Although you should test your implementation on more complex examples such as the glider in a larger universe, show the action of the blinker (three adjoining cells in a row all alive), over three generations, in a 3 by 3 grid.

(1,4)=TRUERETURN'' Count the number of neighbours of the point i,j' (Assume i/j +/- 1 will not fall out of world)'FUNCTION count_neighbours(i%,j%) LOCAL count%,l% count%=0 FOR l%=-1 TO 1 IF world! (i%+l%,j%+1) count%=count%+1 ENDIF NEXT l% IF world! (i%+1,j%) count%=count%+1 ENDIF RETURN count%ENDFUNC'' Update the world one step'PROCEDURE update_world LOCAL i%,j% ' compute neighbour counts and store FOR i%=1 TO 30 FOR j%=1 TO 30 ns%(i%,j%)[email protected]_neighbours(i%,j%) NEXT j% NEXT i% ' update the world cells FOR i%=1 TO 30 FOR j%=1 TO 30 IF world!

Thus, while it is somewhat verbose, it fully simulates Conway's Game of Life and is relatively simple to expand to feature different starting shapes.

Define life(pattern) = Prgm Local x,y,nt,count,save,xl,yl,xh,yh Define nt(y,x) = when(pxl Test(y,x), 1, 0) {}→save set Graph("Axes", "Off")→save[1] set Graph("Grid", "Off")→save[2] set Graph("Labels", "Off")→save[3] Fn Off Plot Off Clr Draw If pattern = "blinker" Then 36→yl 40→yh 78→xl 82→xh Pxl On 36,80 Pxl On 38,80 Pxl On 40,80 Else If pattern = "glider" Then 30→yl 40→yh 76→xl 88→xh Pxl On 38,76 Pxl On 36,78 Pxl On 36,80 Pxl On 38,80 Pxl On 40,80 Else If pattern = "r" Then 38-5*2→yl 38+5*2→yh 80-5*2→xl 80+5*2→xh Pxl On 38,78 Pxl On 36,82 Pxl On 36,80 Pxl On 38,80 Pxl On 40,80 End If While get Key() = 0 © Expand upper-left corner to whole cell For y,yl,yh,2 For x,xl,xh,2 If pxl Test(y,x) Then Pxl On y+1,x Pxl On y+1,x+1 Pxl On y, x+1 Else Pxl Off y+1,x Pxl Off y+1,x+1 Pxl Off y, x+1 End If End For End For © Compute next generation For y,yl,yh,2 For x,xl,xh,2 nt(y-1,x-1) + nt(y-1,x) + nt(y-1,x+2) + nt(y,x-1) + nt(y+1,x+2) + nt(y+2,x-1) + nt(y+2,x+1) + nt(y+2,x+2) → count If count = 3 Then Pxl On y,x Else If count ≠ 2 Then Pxl Off y,x End If End For End For End While © Restore changed options set Graph("Axes", save[1]) set Graph("Grid", save[2]) set Graph("Labels", save[3])End Prgm Also see Conway's Game of Life/C Considering that the simplest implementation in C++ would lack any use of the object-oriented paradigm, this code was specifically written to demonstrate the various object-oriented features of C++.

f beq rightcellsleftcells: ldy #[[

randfill: stx $01 ;$200 for indirect ldx #$02 ;addressing stx $02randloop: lda $fe ;generate random and #$01 ;pixels on the sta ($01), Y ;screen jsr inc0103 cmp #$00 bne randloop lda $02 cmp #$06 bne randloop clearmem: lda #$df ;set $07df-$0a20 sta $01 ;to $#00 lda #$07 sta $02clearbyte: lda #$00 sta ($01), Y jsr inc0103 cmp #$20 bne clearbyte lda $02 cmp #$0a bne clearbyte starttick:copyscreen: lda #$00 ;set up source sta $01 ;pointer at sta $03 ;$01/$02 and lda #$02 ;dest pointer sta $02 ;at $03/$04 lda #$08 sta $04 ldy #$00copybyte: lda ($01), Y ;copy pixel to sta ($03), Y ;back buffer jsr inc0103 ;increment pointers cmp #$00 ;check to see bne copybyte ;if we're at $600 lda $02 ;if so, we've cmp #$06 ;copied the bne copybyte ;entire screen conway: lda #$df ;apply conway rules sta $01 ;reset the pointer sta $03 ;to $#01df/$#07df lda #$01 ;($200 - $21) sta $02 ;($800 - $21) lda #$07 sta $04onecell: lda #$00 ;process one cell ldy #$01 ;upper cell clc adc ($03), Y ldy #$41 ;lower cell clc adc ($03), Ychkleft: tax ;check to see lda $01 ;if we're at the and #$1f ;left edge tay txa cpy #$1f beq rightcellsleftcells: ldy #$00 ;upper-left cell clc adc ($03), Y ldy #$20 ;left cell clc adc ($03), Y ldy #$40 ;lower-left cell clc adc ($03), Ychkright: tax ;check to see lda $01 ;if we're at the and #$1f ;right edge tay txa cpy #$1e beq evaluaterightcells: ldy #$02 ;upper-right cell clc adc ($03), Y ldy #$22 ;right cell clc adc ($03), Y ldy #$42 ;lower-right cell clc adc ($03), Yevaluate: ldx #$01 ;evaluate total ldy #$21 ;for current cell cmp #$03 ;3 = alive beq storex ldx #$00 cmp #$02 ;2 = alive if bne storex ;c = alive lda ($03), Y and #$01 taxstorex: txa ;store to screen sta ($01), Y jsr inc0103 ;move to next cellconwayloop: cmp #$e0 ;if not last cell, bne onecell ;process next cell lda $02 cmp #$05 bne onecell jmp starttick ;run next tick inc0103: lda $01 ;increment $01 cmp #$ff ;and $03 as 16-bit bne onlyinc01 ;pointers inc $02 inc $04onlyinc01: inc $01 lda $01 sta $03 rts The solution uses one cell thick border around square Petri dish as uninhabited dire land. Sample output contains 3 generations of the blinker and 5 of the glider: See Conway's Game of Life/ALGOL 68 APL2 (Dialog) Example in one line APL \ 1130 example (very old APL dialect via simulator) APL1130From: APL \ 1130 Samples The following APL \ 1130 code will need APL385 font installed to display correctly. See Download APL TT Font ∇LIFE[⎕]∇[0] NG←LIFE CG; W[1] W←CG+(¯1⊖CG)+(1⊖CG)+(¯1⌽CG)+(1⌽CG)[2] W←W+(1⊖1⌽CG)+(¯1⊖1⌽CG)+(1⊖¯1⌽CG)+(¯1⊖¯1⌽CG)[3] NG←(3=W)+(CG∧4=W) ∇ RP←5 5⍴0 0 0 0 0 0 0 1 1 0 0 1 1 0 0 0 0 1 0 0 RP0 0 0 0 00 0 1 1 00 1 1 0 00 0 1 0 00 0 0 0 0 LIFE RP0 0 0 0 00 1 1 1 00 1 0 0 00 1 1 0 00 0 0 0 0 LIFE LIFE RP0 0 1 0 00 1 1 0 01 0 0 1 00 1 1 0 00 0 0 0 0 .................................................. One interacts with the Game of Life by creating an initial configuration and observing how it evolves. Although you should test your implementation on more complex examples such as the glider in a larger universe, show the action of the blinker (three adjoining cells in a row all alive), over three generations, in a 3 by 3 grid. (1,4)=TRUERETURN'' Count the number of neighbours of the point i,j' (Assume i/j +/- 1 will not fall out of world)'FUNCTION count_neighbours(i%,j%) LOCAL count%,l% count%=0 FOR l%=-1 TO 1 IF world! (i%+l%,j%+1) count%=count%+1 ENDIF NEXT l% IF world! (i%+1,j%) count%=count%+1 ENDIF RETURN count%ENDFUNC'' Update the world one step'PROCEDURE update_world LOCAL i%,j% ' compute neighbour counts and store FOR i%=1 TO 30 FOR j%=1 TO 30 ns%(i%,j%)[email protected]_neighbours(i%,j%) NEXT j% NEXT i% ' update the world cells FOR i%=1 TO 30 FOR j%=1 TO 30 IF world!

||

randfill: stx $01 ;$200 for indirect ldx #$02 ;addressing stx $02randloop: lda $fe ;generate random and #$01 ;pixels on the sta ($01), Y ;screen jsr inc0103 cmp #$00 bne randloop lda $02 cmp #$06 bne randloop clearmem: lda #$df ;set $07df-$0a20 sta $01 ;to $#00 lda #$07 sta $02clearbyte: lda #$00 sta ($01), Y jsr inc0103 cmp #$20 bne clearbyte lda $02 cmp #$0a bne clearbyte starttick:copyscreen: lda #$00 ;set up source sta $01 ;pointer at sta $03 ;$01/$02 and lda #$02 ;dest pointer sta $02 ;at $03/$04 lda #$08 sta $04 ldy #$00copybyte: lda ($01), Y ;copy pixel to sta ($03), Y ;back buffer jsr inc0103 ;increment pointers cmp #$00 ;check to see bne copybyte ;if we're at $600 lda $02 ;if so, we've cmp #$06 ;copied the bne copybyte ;entire screen conway: lda #$df ;apply conway rules sta $01 ;reset the pointer sta $03 ;to $#01df/$#07df lda #$01 ;($200 - $21) sta $02 ;($800 - $21) lda #$07 sta $04onecell: lda #$00 ;process one cell ldy #$01 ;upper cell clc adc ($03), Y ldy #$41 ;lower cell clc adc ($03), Ychkleft: tax ;check to see lda $01 ;if we're at the and #$1f ;left edge tay txa cpy #$1f beq rightcellsleftcells: ldy #$00 ;upper-left cell clc adc ($03), Y ldy #$20 ;left cell clc adc ($03), Y ldy #$40 ;lower-left cell clc adc ($03), Ychkright: tax ;check to see lda $01 ;if we're at the and #$1f ;right edge tay txa cpy #$1e beq evaluaterightcells: ldy #$02 ;upper-right cell clc adc ($03), Y ldy #$22 ;right cell clc adc ($03), Y ldy #$42 ;lower-right cell clc adc ($03), Yevaluate: ldx #$01 ;evaluate total ldy #$21 ;for current cell cmp #$03 ;3 = alive beq storex ldx #$00 cmp #$02 ;2 = alive if bne storex ;c = alive lda ($03), Y and #$01 taxstorex: txa ;store to screen sta ($01), Y jsr inc0103 ;move to next cellconwayloop: cmp #$e0 ;if not last cell, bne onecell ;process next cell lda $02 cmp #$05 bne onecell jmp starttick ;run next tick inc0103: lda $01 ;increment $01 cmp #$ff ;and $03 as 16-bit bne onlyinc01 ;pointers inc $02 inc $04onlyinc01: inc $01 lda $01 sta $03 rts The solution uses one cell thick border around square Petri dish as uninhabited dire land. Sample output contains 3 generations of the blinker and 5 of the glider: See Conway's Game of Life/ALGOL 68 APL2 (Dialog) Example in one line APL \ 1130 example (very old APL dialect via simulator) APL1130From: APL \ 1130 Samples The following APL \ 1130 code will need APL385 font installed to display correctly.

See Download APL TT Font ∇LIFE[⎕]∇[0] NG←LIFE CG; W[1] W←CG+(¯1⊖CG)+(1⊖CG)+(¯1⌽CG)+(1⌽CG)[2] W←W+(1⊖1⌽CG)+(¯1⊖1⌽CG)+(1⊖¯1⌽CG)+(¯1⊖¯1⌽CG)[3] NG←(3=W)+(CG∧4=W) ∇ RP←5 5⍴0 0 0 0 0 0 0 1 1 0 0 1 1 0 0 0 0 1 0 0 RP0 0 0 0 00 0 1 1 00 1 1 0 00 0 1 0 00 0 0 0 0 LIFE RP0 0 0 0 00 1 1 1 00 1 0 0 00 1 1 0 00 0 0 0 0 LIFE LIFE RP0 0 1 0 00 1 1 0 01 0 0 1 00 1 1 0 00 0 0 0 0 ..................................................

One interacts with the Game of Life by creating an initial configuration and observing how it evolves.

Although you should test your implementation on more complex examples such as the glider in a larger universe, show the action of the blinker (three adjoining cells in a row all alive), over three generations, in a 3 by 3 grid.

(1,4)=TRUERETURN'' Count the number of neighbours of the point i,j' (Assume i/j +/- 1 will not fall out of world)'FUNCTION count_neighbours(i%,j%) LOCAL count%,l% count%=0 FOR l%=-1 TO 1 IF world! (i%+l%,j%+1) count%=count%+1 ENDIF NEXT l% IF world! (i%+1,j%) count%=count%+1 ENDIF RETURN count%ENDFUNC'' Update the world one step'PROCEDURE update_world LOCAL i%,j% ' compute neighbour counts and store FOR i%=1 TO 30 FOR j%=1 TO 30 ns%(i%,j%)[email protected]_neighbours(i%,j%) NEXT j% NEXT i% ' update the world cells FOR i%=1 TO 30 FOR j%=1 TO 30 IF world!

Thus, while it is somewhat verbose, it fully simulates Conway's Game of Life and is relatively simple to expand to feature different starting shapes.

Define life(pattern) = Prgm Local x,y,nt,count,save,xl,yl,xh,yh Define nt(y,x) = when(pxl Test(y,x), 1, 0) {}→save set Graph("Axes", "Off")→save[1] set Graph("Grid", "Off")→save[2] set Graph("Labels", "Off")→save[3] Fn Off Plot Off Clr Draw If pattern = "blinker" Then 36→yl 40→yh 78→xl 82→xh Pxl On 36,80 Pxl On 38,80 Pxl On 40,80 Else If pattern = "glider" Then 30→yl 40→yh 76→xl 88→xh Pxl On 38,76 Pxl On 36,78 Pxl On 36,80 Pxl On 38,80 Pxl On 40,80 Else If pattern = "r" Then 38-5*2→yl 38+5*2→yh 80-5*2→xl 80+5*2→xh Pxl On 38,78 Pxl On 36,82 Pxl On 36,80 Pxl On 38,80 Pxl On 40,80 End If While get Key() = 0 © Expand upper-left corner to whole cell For y,yl,yh,2 For x,xl,xh,2 If pxl Test(y,x) Then Pxl On y+1,x Pxl On y+1,x+1 Pxl On y, x+1 Else Pxl Off y+1,x Pxl Off y+1,x+1 Pxl Off y, x+1 End If End For End For © Compute next generation For y,yl,yh,2 For x,xl,xh,2 nt(y-1,x-1) + nt(y-1,x) + nt(y-1,x+2) + nt(y,x-1) + nt(y+1,x+2) + nt(y+2,x-1) + nt(y+2,x+1) + nt(y+2,x+2) → count If count = 3 Then Pxl On y,x Else If count ≠ 2 Then Pxl Off y,x End If End For End For End While © Restore changed options set Graph("Axes", save[1]) set Graph("Grid", save[2]) set Graph("Labels", save[3])End Prgm Also see Conway's Game of Life/C Considering that the simplest implementation in C++ would lack any use of the object-oriented paradigm, this code was specifically written to demonstrate the various object-oriented features of C++.

]] ;upper-left cell clc adc (), Y ldy # ;left cell clc adc (), Y ldy # ;lower-left cell clc adc (), Ychkright: tax ;check to see lda

randfill: stx $01 ;$200 for indirect ldx #$02 ;addressing stx $02randloop: lda $fe ;generate random and #$01 ;pixels on the sta ($01), Y ;screen jsr inc0103 cmp #$00 bne randloop lda $02 cmp #$06 bne randloop clearmem: lda #$df ;set $07df-$0a20 sta $01 ;to $#00 lda #$07 sta $02clearbyte: lda #$00 sta ($01), Y jsr inc0103 cmp #$20 bne clearbyte lda $02 cmp #$0a bne clearbyte starttick:copyscreen: lda #$00 ;set up source sta $01 ;pointer at sta $03 ;$01/$02 and lda #$02 ;dest pointer sta $02 ;at $03/$04 lda #$08 sta $04 ldy #$00copybyte: lda ($01), Y ;copy pixel to sta ($03), Y ;back buffer jsr inc0103 ;increment pointers cmp #$00 ;check to see bne copybyte ;if we're at $600 lda $02 ;if so, we've cmp #$06 ;copied the bne copybyte ;entire screen conway: lda #$df ;apply conway rules sta $01 ;reset the pointer sta $03 ;to $#01df/$#07df lda #$01 ;($200 - $21) sta $02 ;($800 - $21) lda #$07 sta $04onecell: lda #$00 ;process one cell ldy #$01 ;upper cell clc adc ($03), Y ldy #$41 ;lower cell clc adc ($03), Ychkleft: tax ;check to see lda $01 ;if we're at the and #$1f ;left edge tay txa cpy #$1f beq rightcellsleftcells: ldy #$00 ;upper-left cell clc adc ($03), Y ldy #$20 ;left cell clc adc ($03), Y ldy #$40 ;lower-left cell clc adc ($03), Ychkright: tax ;check to see lda $01 ;if we're at the and #$1f ;right edge tay txa cpy #$1e beq evaluaterightcells: ldy #$02 ;upper-right cell clc adc ($03), Y ldy #$22 ;right cell clc adc ($03), Y ldy #$42 ;lower-right cell clc adc ($03), Yevaluate: ldx #$01 ;evaluate total ldy #$21 ;for current cell cmp #$03 ;3 = alive beq storex ldx #$00 cmp #$02 ;2 = alive if bne storex ;c = alive lda ($03), Y and #$01 taxstorex: txa ;store to screen sta ($01), Y jsr inc0103 ;move to next cellconwayloop: cmp #$e0 ;if not last cell, bne onecell ;process next cell lda $02 cmp #$05 bne onecell jmp starttick ;run next tick inc0103: lda $01 ;increment $01 cmp #$ff ;and $03 as 16-bit bne onlyinc01 ;pointers inc $02 inc $04onlyinc01: inc $01 lda $01 sta $03 rts The solution uses one cell thick border around square Petri dish as uninhabited dire land. Sample output contains 3 generations of the blinker and 5 of the glider: See Conway's Game of Life/ALGOL 68 APL2 (Dialog) Example in one line APL \ 1130 example (very old APL dialect via simulator) APL1130From: APL \ 1130 Samples The following APL \ 1130 code will need APL385 font installed to display correctly. See Download APL TT Font ∇LIFE[⎕]∇[0] NG←LIFE CG; W[1] W←CG+(¯1⊖CG)+(1⊖CG)+(¯1⌽CG)+(1⌽CG)[2] W←W+(1⊖1⌽CG)+(¯1⊖1⌽CG)+(1⊖¯1⌽CG)+(¯1⊖¯1⌽CG)[3] NG←(3=W)+(CG∧4=W) ∇ RP←5 5⍴0 0 0 0 0 0 0 1 1 0 0 1 1 0 0 0 0 1 0 0 RP0 0 0 0 00 0 1 1 00 1 1 0 00 0 1 0 00 0 0 0 0 LIFE RP0 0 0 0 00 1 1 1 00 1 0 0 00 1 1 0 00 0 0 0 0 LIFE LIFE RP0 0 1 0 00 1 1 0 01 0 0 1 00 1 1 0 00 0 0 0 0 .................................................. One interacts with the Game of Life by creating an initial configuration and observing how it evolves. Although you should test your implementation on more complex examples such as the glider in a larger universe, show the action of the blinker (three adjoining cells in a row all alive), over three generations, in a 3 by 3 grid. (1,4)=TRUERETURN'' Count the number of neighbours of the point i,j' (Assume i/j +/- 1 will not fall out of world)'FUNCTION count_neighbours(i%,j%) LOCAL count%,l% count%=0 FOR l%=-1 TO 1 IF world! (i%+l%,j%+1) count%=count%+1 ENDIF NEXT l% IF world! (i%+1,j%) count%=count%+1 ENDIF RETURN count%ENDFUNC'' Update the world one step'PROCEDURE update_world LOCAL i%,j% ' compute neighbour counts and store FOR i%=1 TO 30 FOR j%=1 TO 30 ns%(i%,j%)[email protected]_neighbours(i%,j%) NEXT j% NEXT i% ' update the world cells FOR i%=1 TO 30 FOR j%=1 TO 30 IF world!

||

randfill: stx $01 ;$200 for indirect ldx #$02 ;addressing stx $02randloop: lda $fe ;generate random and #$01 ;pixels on the sta ($01), Y ;screen jsr inc0103 cmp #$00 bne randloop lda $02 cmp #$06 bne randloop clearmem: lda #$df ;set $07df-$0a20 sta $01 ;to $#00 lda #$07 sta $02clearbyte: lda #$00 sta ($01), Y jsr inc0103 cmp #$20 bne clearbyte lda $02 cmp #$0a bne clearbyte starttick:copyscreen: lda #$00 ;set up source sta $01 ;pointer at sta $03 ;$01/$02 and lda #$02 ;dest pointer sta $02 ;at $03/$04 lda #$08 sta $04 ldy #$00copybyte: lda ($01), Y ;copy pixel to sta ($03), Y ;back buffer jsr inc0103 ;increment pointers cmp #$00 ;check to see bne copybyte ;if we're at $600 lda $02 ;if so, we've cmp #$06 ;copied the bne copybyte ;entire screen conway: lda #$df ;apply conway rules sta $01 ;reset the pointer sta $03 ;to $#01df/$#07df lda #$01 ;($200 - $21) sta $02 ;($800 - $21) lda #$07 sta $04onecell: lda #$00 ;process one cell ldy #$01 ;upper cell clc adc ($03), Y ldy #$41 ;lower cell clc adc ($03), Ychkleft: tax ;check to see lda $01 ;if we're at the and #$1f ;left edge tay txa cpy #$1f beq rightcellsleftcells: ldy #$00 ;upper-left cell clc adc ($03), Y ldy #$20 ;left cell clc adc ($03), Y ldy #$40 ;lower-left cell clc adc ($03), Ychkright: tax ;check to see lda $01 ;if we're at the and #$1f ;right edge tay txa cpy #$1e beq evaluaterightcells: ldy #$02 ;upper-right cell clc adc ($03), Y ldy #$22 ;right cell clc adc ($03), Y ldy #$42 ;lower-right cell clc adc ($03), Yevaluate: ldx #$01 ;evaluate total ldy #$21 ;for current cell cmp #$03 ;3 = alive beq storex ldx #$00 cmp #$02 ;2 = alive if bne storex ;c = alive lda ($03), Y and #$01 taxstorex: txa ;store to screen sta ($01), Y jsr inc0103 ;move to next cellconwayloop: cmp #$e0 ;if not last cell, bne onecell ;process next cell lda $02 cmp #$05 bne onecell jmp starttick ;run next tick inc0103: lda $01 ;increment $01 cmp #$ff ;and $03 as 16-bit bne onlyinc01 ;pointers inc $02 inc $04onlyinc01: inc $01 lda $01 sta $03 rts The solution uses one cell thick border around square Petri dish as uninhabited dire land. Sample output contains 3 generations of the blinker and 5 of the glider: See Conway's Game of Life/ALGOL 68 APL2 (Dialog) Example in one line APL \ 1130 example (very old APL dialect via simulator) APL1130From: APL \ 1130 Samples The following APL \ 1130 code will need APL385 font installed to display correctly.

See Download APL TT Font ∇LIFE[⎕]∇[0] NG←LIFE CG; W[1] W←CG+(¯1⊖CG)+(1⊖CG)+(¯1⌽CG)+(1⌽CG)[2] W←W+(1⊖1⌽CG)+(¯1⊖1⌽CG)+(1⊖¯1⌽CG)+(¯1⊖¯1⌽CG)[3] NG←(3=W)+(CG∧4=W) ∇ RP←5 5⍴0 0 0 0 0 0 0 1 1 0 0 1 1 0 0 0 0 1 0 0 RP0 0 0 0 00 0 1 1 00 1 1 0 00 0 1 0 00 0 0 0 0 LIFE RP0 0 0 0 00 1 1 1 00 1 0 0 00 1 1 0 00 0 0 0 0 LIFE LIFE RP0 0 1 0 00 1 1 0 01 0 0 1 00 1 1 0 00 0 0 0 0 ..................................................

One interacts with the Game of Life by creating an initial configuration and observing how it evolves.

Although you should test your implementation on more complex examples such as the glider in a larger universe, show the action of the blinker (three adjoining cells in a row all alive), over three generations, in a 3 by 3 grid.

(1,4)=TRUERETURN'' Count the number of neighbours of the point i,j' (Assume i/j +/- 1 will not fall out of world)'FUNCTION count_neighbours(i%,j%) LOCAL count%,l% count%=0 FOR l%=-1 TO 1 IF world! (i%+l%,j%+1) count%=count%+1 ENDIF NEXT l% IF world! (i%+1,j%) count%=count%+1 ENDIF RETURN count%ENDFUNC'' Update the world one step'PROCEDURE update_world LOCAL i%,j% ' compute neighbour counts and store FOR i%=1 TO 30 FOR j%=1 TO 30 ns%(i%,j%)[email protected]_neighbours(i%,j%) NEXT j% NEXT i% ' update the world cells FOR i%=1 TO 30 FOR j%=1 TO 30 IF world!

Thus, while it is somewhat verbose, it fully simulates Conway's Game of Life and is relatively simple to expand to feature different starting shapes.

Define life(pattern) = Prgm Local x,y,nt,count,save,xl,yl,xh,yh Define nt(y,x) = when(pxl Test(y,x), 1, 0) {}→save set Graph("Axes", "Off")→save[1] set Graph("Grid", "Off")→save[2] set Graph("Labels", "Off")→save[3] Fn Off Plot Off Clr Draw If pattern = "blinker" Then 36→yl 40→yh 78→xl 82→xh Pxl On 36,80 Pxl On 38,80 Pxl On 40,80 Else If pattern = "glider" Then 30→yl 40→yh 76→xl 88→xh Pxl On 38,76 Pxl On 36,78 Pxl On 36,80 Pxl On 38,80 Pxl On 40,80 Else If pattern = "r" Then 38-5*2→yl 38+5*2→yh 80-5*2→xl 80+5*2→xh Pxl On 38,78 Pxl On 36,82 Pxl On 36,80 Pxl On 38,80 Pxl On 40,80 End If While get Key() = 0 © Expand upper-left corner to whole cell For y,yl,yh,2 For x,xl,xh,2 If pxl Test(y,x) Then Pxl On y+1,x Pxl On y+1,x+1 Pxl On y, x+1 Else Pxl Off y+1,x Pxl Off y+1,x+1 Pxl Off y, x+1 End If End For End For © Compute next generation For y,yl,yh,2 For x,xl,xh,2 nt(y-1,x-1) + nt(y-1,x) + nt(y-1,x+2) + nt(y,x-1) + nt(y+1,x+2) + nt(y+2,x-1) + nt(y+2,x+1) + nt(y+2,x+2) → count If count = 3 Then Pxl On y,x Else If count ≠ 2 Then Pxl Off y,x End If End For End For End While © Restore changed options set Graph("Axes", save[1]) set Graph("Grid", save[2]) set Graph("Labels", save[3])End Prgm Also see Conway's Game of Life/C Considering that the simplest implementation in C++ would lack any use of the object-oriented paradigm, this code was specifically written to demonstrate the various object-oriented features of C++.

;if we're at the and #

randfill: stx $01 ;$200 for indirect ldx #$02 ;addressing stx $02randloop: lda $fe ;generate random and #$01 ;pixels on the sta ($01), Y ;screen jsr inc0103 cmp #$00 bne randloop lda $02 cmp #$06 bne randloop clearmem: lda #$df ;set $07df-$0a20 sta $01 ;to $#00 lda #$07 sta $02clearbyte: lda #$00 sta ($01), Y jsr inc0103 cmp #$20 bne clearbyte lda $02 cmp #$0a bne clearbyte starttick:copyscreen: lda #$00 ;set up source sta $01 ;pointer at sta $03 ;$01/$02 and lda #$02 ;dest pointer sta $02 ;at $03/$04 lda #$08 sta $04 ldy #$00copybyte: lda ($01), Y ;copy pixel to sta ($03), Y ;back buffer jsr inc0103 ;increment pointers cmp #$00 ;check to see bne copybyte ;if we're at $600 lda $02 ;if so, we've cmp #$06 ;copied the bne copybyte ;entire screen conway: lda #$df ;apply conway rules sta $01 ;reset the pointer sta $03 ;to $#01df/$#07df lda #$01 ;($200 - $21) sta $02 ;($800 - $21) lda #$07 sta $04onecell: lda #$00 ;process one cell ldy #$01 ;upper cell clc adc ($03), Y ldy #$41 ;lower cell clc adc ($03), Ychkleft: tax ;check to see lda $01 ;if we're at the and #$1f ;left edge tay txa cpy #$1f beq rightcellsleftcells: ldy #$00 ;upper-left cell clc adc ($03), Y ldy #$20 ;left cell clc adc ($03), Y ldy #$40 ;lower-left cell clc adc ($03), Ychkright: tax ;check to see lda $01 ;if we're at the and #$1f ;right edge tay txa cpy #$1e beq evaluaterightcells: ldy #$02 ;upper-right cell clc adc ($03), Y ldy #$22 ;right cell clc adc ($03), Y ldy #$42 ;lower-right cell clc adc ($03), Yevaluate: ldx #$01 ;evaluate total ldy #$21 ;for current cell cmp #$03 ;3 = alive beq storex ldx #$00 cmp #$02 ;2 = alive if bne storex ;c = alive lda ($03), Y and #$01 taxstorex: txa ;store to screen sta ($01), Y jsr inc0103 ;move to next cellconwayloop: cmp #$e0 ;if not last cell, bne onecell ;process next cell lda $02 cmp #$05 bne onecell jmp starttick ;run next tick inc0103: lda $01 ;increment $01 cmp #$ff ;and $03 as 16-bit bne onlyinc01 ;pointers inc $02 inc $04onlyinc01: inc $01 lda $01 sta $03 rts The solution uses one cell thick border around square Petri dish as uninhabited dire land. Sample output contains 3 generations of the blinker and 5 of the glider: See Conway's Game of Life/ALGOL 68 APL2 (Dialog) Example in one line APL \ 1130 example (very old APL dialect via simulator) APL1130From: APL \ 1130 Samples The following APL \ 1130 code will need APL385 font installed to display correctly. See Download APL TT Font ∇LIFE[⎕]∇[0] NG←LIFE CG; W[1] W←CG+(¯1⊖CG)+(1⊖CG)+(¯1⌽CG)+(1⌽CG)[2] W←W+(1⊖1⌽CG)+(¯1⊖1⌽CG)+(1⊖¯1⌽CG)+(¯1⊖¯1⌽CG)[3] NG←(3=W)+(CG∧4=W) ∇ RP←5 5⍴0 0 0 0 0 0 0 1 1 0 0 1 1 0 0 0 0 1 0 0 RP0 0 0 0 00 0 1 1 00 1 1 0 00 0 1 0 00 0 0 0 0 LIFE RP0 0 0 0 00 1 1 1 00 1 0 0 00 1 1 0 00 0 0 0 0 LIFE LIFE RP0 0 1 0 00 1 1 0 01 0 0 1 00 1 1 0 00 0 0 0 0 .................................................. One interacts with the Game of Life by creating an initial configuration and observing how it evolves. Although you should test your implementation on more complex examples such as the glider in a larger universe, show the action of the blinker (three adjoining cells in a row all alive), over three generations, in a 3 by 3 grid. (1,4)=TRUERETURN'' Count the number of neighbours of the point i,j' (Assume i/j +/- 1 will not fall out of world)'FUNCTION count_neighbours(i%,j%) LOCAL count%,l% count%=0 FOR l%=-1 TO 1 IF world! (i%+l%,j%+1) count%=count%+1 ENDIF NEXT l% IF world! (i%+1,j%) count%=count%+1 ENDIF RETURN count%ENDFUNC'' Update the world one step'PROCEDURE update_world LOCAL i%,j% ' compute neighbour counts and store FOR i%=1 TO 30 FOR j%=1 TO 30 ns%(i%,j%)[email protected]_neighbours(i%,j%) NEXT j% NEXT i% ' update the world cells FOR i%=1 TO 30 FOR j%=1 TO 30 IF world!

||

randfill: stx $01 ;$200 for indirect ldx #$02 ;addressing stx $02randloop: lda $fe ;generate random and #$01 ;pixels on the sta ($01), Y ;screen jsr inc0103 cmp #$00 bne randloop lda $02 cmp #$06 bne randloop clearmem: lda #$df ;set $07df-$0a20 sta $01 ;to $#00 lda #$07 sta $02clearbyte: lda #$00 sta ($01), Y jsr inc0103 cmp #$20 bne clearbyte lda $02 cmp #$0a bne clearbyte starttick:copyscreen: lda #$00 ;set up source sta $01 ;pointer at sta $03 ;$01/$02 and lda #$02 ;dest pointer sta $02 ;at $03/$04 lda #$08 sta $04 ldy #$00copybyte: lda ($01), Y ;copy pixel to sta ($03), Y ;back buffer jsr inc0103 ;increment pointers cmp #$00 ;check to see bne copybyte ;if we're at $600 lda $02 ;if so, we've cmp #$06 ;copied the bne copybyte ;entire screen conway: lda #$df ;apply conway rules sta $01 ;reset the pointer sta $03 ;to $#01df/$#07df lda #$01 ;($200 - $21) sta $02 ;($800 - $21) lda #$07 sta $04onecell: lda #$00 ;process one cell ldy #$01 ;upper cell clc adc ($03), Y ldy #$41 ;lower cell clc adc ($03), Ychkleft: tax ;check to see lda $01 ;if we're at the and #$1f ;left edge tay txa cpy #$1f beq rightcellsleftcells: ldy #$00 ;upper-left cell clc adc ($03), Y ldy #$20 ;left cell clc adc ($03), Y ldy #$40 ;lower-left cell clc adc ($03), Ychkright: tax ;check to see lda $01 ;if we're at the and #$1f ;right edge tay txa cpy #$1e beq evaluaterightcells: ldy #$02 ;upper-right cell clc adc ($03), Y ldy #$22 ;right cell clc adc ($03), Y ldy #$42 ;lower-right cell clc adc ($03), Yevaluate: ldx #$01 ;evaluate total ldy #$21 ;for current cell cmp #$03 ;3 = alive beq storex ldx #$00 cmp #$02 ;2 = alive if bne storex ;c = alive lda ($03), Y and #$01 taxstorex: txa ;store to screen sta ($01), Y jsr inc0103 ;move to next cellconwayloop: cmp #$e0 ;if not last cell, bne onecell ;process next cell lda $02 cmp #$05 bne onecell jmp starttick ;run next tick inc0103: lda $01 ;increment $01 cmp #$ff ;and $03 as 16-bit bne onlyinc01 ;pointers inc $02 inc $04onlyinc01: inc $01 lda $01 sta $03 rts The solution uses one cell thick border around square Petri dish as uninhabited dire land. Sample output contains 3 generations of the blinker and 5 of the glider: See Conway's Game of Life/ALGOL 68 APL2 (Dialog) Example in one line APL \ 1130 example (very old APL dialect via simulator) APL1130From: APL \ 1130 Samples The following APL \ 1130 code will need APL385 font installed to display correctly.

See Download APL TT Font ∇LIFE[⎕]∇[0] NG←LIFE CG; W[1] W←CG+(¯1⊖CG)+(1⊖CG)+(¯1⌽CG)+(1⌽CG)[2] W←W+(1⊖1⌽CG)+(¯1⊖1⌽CG)+(1⊖¯1⌽CG)+(¯1⊖¯1⌽CG)[3] NG←(3=W)+(CG∧4=W) ∇ RP←5 5⍴0 0 0 0 0 0 0 1 1 0 0 1 1 0 0 0 0 1 0 0 RP0 0 0 0 00 0 1 1 00 1 1 0 00 0 1 0 00 0 0 0 0 LIFE RP0 0 0 0 00 1 1 1 00 1 0 0 00 1 1 0 00 0 0 0 0 LIFE LIFE RP0 0 1 0 00 1 1 0 01 0 0 1 00 1 1 0 00 0 0 0 0 ..................................................

One interacts with the Game of Life by creating an initial configuration and observing how it evolves.

Although you should test your implementation on more complex examples such as the glider in a larger universe, show the action of the blinker (three adjoining cells in a row all alive), over three generations, in a 3 by 3 grid.

(1,4)=TRUERETURN'' Count the number of neighbours of the point i,j' (Assume i/j +/- 1 will not fall out of world)'FUNCTION count_neighbours(i%,j%) LOCAL count%,l% count%=0 FOR l%=-1 TO 1 IF world! (i%+l%,j%+1) count%=count%+1 ENDIF NEXT l% IF world! (i%+1,j%) count%=count%+1 ENDIF RETURN count%ENDFUNC'' Update the world one step'PROCEDURE update_world LOCAL i%,j% ' compute neighbour counts and store FOR i%=1 TO 30 FOR j%=1 TO 30 ns%(i%,j%)[email protected]_neighbours(i%,j%) NEXT j% NEXT i% ' update the world cells FOR i%=1 TO 30 FOR j%=1 TO 30 IF world!

Thus, while it is somewhat verbose, it fully simulates Conway's Game of Life and is relatively simple to expand to feature different starting shapes.

Define life(pattern) = Prgm Local x,y,nt,count,save,xl,yl,xh,yh Define nt(y,x) = when(pxl Test(y,x), 1, 0) {}→save set Graph("Axes", "Off")→save[1] set Graph("Grid", "Off")→save[2] set Graph("Labels", "Off")→save[3] Fn Off Plot Off Clr Draw If pattern = "blinker" Then 36→yl 40→yh 78→xl 82→xh Pxl On 36,80 Pxl On 38,80 Pxl On 40,80 Else If pattern = "glider" Then 30→yl 40→yh 76→xl 88→xh Pxl On 38,76 Pxl On 36,78 Pxl On 36,80 Pxl On 38,80 Pxl On 40,80 Else If pattern = "r" Then 38-5*2→yl 38+5*2→yh 80-5*2→xl 80+5*2→xh Pxl On 38,78 Pxl On 36,82 Pxl On 36,80 Pxl On 38,80 Pxl On 40,80 End If While get Key() = 0 © Expand upper-left corner to whole cell For y,yl,yh,2 For x,xl,xh,2 If pxl Test(y,x) Then Pxl On y+1,x Pxl On y+1,x+1 Pxl On y, x+1 Else Pxl Off y+1,x Pxl Off y+1,x+1 Pxl Off y, x+1 End If End For End For © Compute next generation For y,yl,yh,2 For x,xl,xh,2 nt(y-1,x-1) + nt(y-1,x) + nt(y-1,x+2) + nt(y,x-1) + nt(y+1,x+2) + nt(y+2,x-1) + nt(y+2,x+1) + nt(y+2,x+2) → count If count = 3 Then Pxl On y,x Else If count ≠ 2 Then Pxl Off y,x End If End For End For End While © Restore changed options set Graph("Axes", save[1]) set Graph("Grid", save[2]) set Graph("Labels", save[3])End Prgm Also see Conway's Game of Life/C Considering that the simplest implementation in C++ would lack any use of the object-oriented paradigm, this code was specifically written to demonstrate the various object-oriented features of C++.

f ;right edge tay txa cpy #

randfill: stx $01 ;$200 for indirect ldx #$02 ;addressing stx $02randloop: lda $fe ;generate random and #$01 ;pixels on the sta ($01), Y ;screen jsr inc0103 cmp #$00 bne randloop lda $02 cmp #$06 bne randloop clearmem: lda #$df ;set $07df-$0a20 sta $01 ;to $#00 lda #$07 sta $02clearbyte: lda #$00 sta ($01), Y jsr inc0103 cmp #$20 bne clearbyte lda $02 cmp #$0a bne clearbyte starttick:copyscreen: lda #$00 ;set up source sta $01 ;pointer at sta $03 ;$01/$02 and lda #$02 ;dest pointer sta $02 ;at $03/$04 lda #$08 sta $04 ldy #$00copybyte: lda ($01), Y ;copy pixel to sta ($03), Y ;back buffer jsr inc0103 ;increment pointers cmp #$00 ;check to see bne copybyte ;if we're at $600 lda $02 ;if so, we've cmp #$06 ;copied the bne copybyte ;entire screen conway: lda #$df ;apply conway rules sta $01 ;reset the pointer sta $03 ;to $#01df/$#07df lda #$01 ;($200 - $21) sta $02 ;($800 - $21) lda #$07 sta $04onecell: lda #$00 ;process one cell ldy #$01 ;upper cell clc adc ($03), Y ldy #$41 ;lower cell clc adc ($03), Ychkleft: tax ;check to see lda $01 ;if we're at the and #$1f ;left edge tay txa cpy #$1f beq rightcellsleftcells: ldy #$00 ;upper-left cell clc adc ($03), Y ldy #$20 ;left cell clc adc ($03), Y ldy #$40 ;lower-left cell clc adc ($03), Ychkright: tax ;check to see lda $01 ;if we're at the and #$1f ;right edge tay txa cpy #$1e beq evaluaterightcells: ldy #$02 ;upper-right cell clc adc ($03), Y ldy #$22 ;right cell clc adc ($03), Y ldy #$42 ;lower-right cell clc adc ($03), Yevaluate: ldx #$01 ;evaluate total ldy #$21 ;for current cell cmp #$03 ;3 = alive beq storex ldx #$00 cmp #$02 ;2 = alive if bne storex ;c = alive lda ($03), Y and #$01 taxstorex: txa ;store to screen sta ($01), Y jsr inc0103 ;move to next cellconwayloop: cmp #$e0 ;if not last cell, bne onecell ;process next cell lda $02 cmp #$05 bne onecell jmp starttick ;run next tick inc0103: lda $01 ;increment $01 cmp #$ff ;and $03 as 16-bit bne onlyinc01 ;pointers inc $02 inc $04onlyinc01: inc $01 lda $01 sta $03 rts The solution uses one cell thick border around square Petri dish as uninhabited dire land. Sample output contains 3 generations of the blinker and 5 of the glider: See Conway's Game of Life/ALGOL 68 APL2 (Dialog) Example in one line APL \ 1130 example (very old APL dialect via simulator) APL1130From: APL \ 1130 Samples The following APL \ 1130 code will need APL385 font installed to display correctly. See Download APL TT Font ∇LIFE[⎕]∇[0] NG←LIFE CG; W[1] W←CG+(¯1⊖CG)+(1⊖CG)+(¯1⌽CG)+(1⌽CG)[2] W←W+(1⊖1⌽CG)+(¯1⊖1⌽CG)+(1⊖¯1⌽CG)+(¯1⊖¯1⌽CG)[3] NG←(3=W)+(CG∧4=W) ∇ RP←5 5⍴0 0 0 0 0 0 0 1 1 0 0 1 1 0 0 0 0 1 0 0 RP0 0 0 0 00 0 1 1 00 1 1 0 00 0 1 0 00 0 0 0 0 LIFE RP0 0 0 0 00 1 1 1 00 1 0 0 00 1 1 0 00 0 0 0 0 LIFE LIFE RP0 0 1 0 00 1 1 0 01 0 0 1 00 1 1 0 00 0 0 0 0 .................................................. One interacts with the Game of Life by creating an initial configuration and observing how it evolves. Although you should test your implementation on more complex examples such as the glider in a larger universe, show the action of the blinker (three adjoining cells in a row all alive), over three generations, in a 3 by 3 grid. (1,4)=TRUERETURN'' Count the number of neighbours of the point i,j' (Assume i/j +/- 1 will not fall out of world)'FUNCTION count_neighbours(i%,j%) LOCAL count%,l% count%=0 FOR l%=-1 TO 1 IF world! (i%+l%,j%+1) count%=count%+1 ENDIF NEXT l% IF world! (i%+1,j%) count%=count%+1 ENDIF RETURN count%ENDFUNC'' Update the world one step'PROCEDURE update_world LOCAL i%,j% ' compute neighbour counts and store FOR i%=1 TO 30 FOR j%=1 TO 30 ns%(i%,j%)[email protected]_neighbours(i%,j%) NEXT j% NEXT i% ' update the world cells FOR i%=1 TO 30 FOR j%=1 TO 30 IF world!

||

randfill: stx $01 ;$200 for indirect ldx #$02 ;addressing stx $02randloop: lda $fe ;generate random and #$01 ;pixels on the sta ($01), Y ;screen jsr inc0103 cmp #$00 bne randloop lda $02 cmp #$06 bne randloop clearmem: lda #$df ;set $07df-$0a20 sta $01 ;to $#00 lda #$07 sta $02clearbyte: lda #$00 sta ($01), Y jsr inc0103 cmp #$20 bne clearbyte lda $02 cmp #$0a bne clearbyte starttick:copyscreen: lda #$00 ;set up source sta $01 ;pointer at sta $03 ;$01/$02 and lda #$02 ;dest pointer sta $02 ;at $03/$04 lda #$08 sta $04 ldy #$00copybyte: lda ($01), Y ;copy pixel to sta ($03), Y ;back buffer jsr inc0103 ;increment pointers cmp #$00 ;check to see bne copybyte ;if we're at $600 lda $02 ;if so, we've cmp #$06 ;copied the bne copybyte ;entire screen conway: lda #$df ;apply conway rules sta $01 ;reset the pointer sta $03 ;to $#01df/$#07df lda #$01 ;($200 - $21) sta $02 ;($800 - $21) lda #$07 sta $04onecell: lda #$00 ;process one cell ldy #$01 ;upper cell clc adc ($03), Y ldy #$41 ;lower cell clc adc ($03), Ychkleft: tax ;check to see lda $01 ;if we're at the and #$1f ;left edge tay txa cpy #$1f beq rightcellsleftcells: ldy #$00 ;upper-left cell clc adc ($03), Y ldy #$20 ;left cell clc adc ($03), Y ldy #$40 ;lower-left cell clc adc ($03), Ychkright: tax ;check to see lda $01 ;if we're at the and #$1f ;right edge tay txa cpy #$1e beq evaluaterightcells: ldy #$02 ;upper-right cell clc adc ($03), Y ldy #$22 ;right cell clc adc ($03), Y ldy #$42 ;lower-right cell clc adc ($03), Yevaluate: ldx #$01 ;evaluate total ldy #$21 ;for current cell cmp #$03 ;3 = alive beq storex ldx #$00 cmp #$02 ;2 = alive if bne storex ;c = alive lda ($03), Y and #$01 taxstorex: txa ;store to screen sta ($01), Y jsr inc0103 ;move to next cellconwayloop: cmp #$e0 ;if not last cell, bne onecell ;process next cell lda $02 cmp #$05 bne onecell jmp starttick ;run next tick inc0103: lda $01 ;increment $01 cmp #$ff ;and $03 as 16-bit bne onlyinc01 ;pointers inc $02 inc $04onlyinc01: inc $01 lda $01 sta $03 rts The solution uses one cell thick border around square Petri dish as uninhabited dire land. Sample output contains 3 generations of the blinker and 5 of the glider: See Conway's Game of Life/ALGOL 68 APL2 (Dialog) Example in one line APL \ 1130 example (very old APL dialect via simulator) APL1130From: APL \ 1130 Samples The following APL \ 1130 code will need APL385 font installed to display correctly.

See Download APL TT Font ∇LIFE[⎕]∇[0] NG←LIFE CG; W[1] W←CG+(¯1⊖CG)+(1⊖CG)+(¯1⌽CG)+(1⌽CG)[2] W←W+(1⊖1⌽CG)+(¯1⊖1⌽CG)+(1⊖¯1⌽CG)+(¯1⊖¯1⌽CG)[3] NG←(3=W)+(CG∧4=W) ∇ RP←5 5⍴0 0 0 0 0 0 0 1 1 0 0 1 1 0 0 0 0 1 0 0 RP0 0 0 0 00 0 1 1 00 1 1 0 00 0 1 0 00 0 0 0 0 LIFE RP0 0 0 0 00 1 1 1 00 1 0 0 00 1 1 0 00 0 0 0 0 LIFE LIFE RP0 0 1 0 00 1 1 0 01 0 0 1 00 1 1 0 00 0 0 0 0 ..................................................

One interacts with the Game of Life by creating an initial configuration and observing how it evolves.

Although you should test your implementation on more complex examples such as the glider in a larger universe, show the action of the blinker (three adjoining cells in a row all alive), over three generations, in a 3 by 3 grid.

(1,4)=TRUERETURN'' Count the number of neighbours of the point i,j' (Assume i/j +/- 1 will not fall out of world)'FUNCTION count_neighbours(i%,j%) LOCAL count%,l% count%=0 FOR l%=-1 TO 1 IF world! (i%+l%,j%+1) count%=count%+1 ENDIF NEXT l% IF world! (i%+1,j%) count%=count%+1 ENDIF RETURN count%ENDFUNC'' Update the world one step'PROCEDURE update_world LOCAL i%,j% ' compute neighbour counts and store FOR i%=1 TO 30 FOR j%=1 TO 30 ns%(i%,j%)[email protected]_neighbours(i%,j%) NEXT j% NEXT i% ' update the world cells FOR i%=1 TO 30 FOR j%=1 TO 30 IF world!

Thus, while it is somewhat verbose, it fully simulates Conway's Game of Life and is relatively simple to expand to feature different starting shapes.

Define life(pattern) = Prgm Local x,y,nt,count,save,xl,yl,xh,yh Define nt(y,x) = when(pxl Test(y,x), 1, 0) {}→save set Graph("Axes", "Off")→save[1] set Graph("Grid", "Off")→save[2] set Graph("Labels", "Off")→save[3] Fn Off Plot Off Clr Draw If pattern = "blinker" Then 36→yl 40→yh 78→xl 82→xh Pxl On 36,80 Pxl On 38,80 Pxl On 40,80 Else If pattern = "glider" Then 30→yl 40→yh 76→xl 88→xh Pxl On 38,76 Pxl On 36,78 Pxl On 36,80 Pxl On 38,80 Pxl On 40,80 Else If pattern = "r" Then 38-5*2→yl 38+5*2→yh 80-5*2→xl 80+5*2→xh Pxl On 38,78 Pxl On 36,82 Pxl On 36,80 Pxl On 38,80 Pxl On 40,80 End If While get Key() = 0 © Expand upper-left corner to whole cell For y,yl,yh,2 For x,xl,xh,2 If pxl Test(y,x) Then Pxl On y+1,x Pxl On y+1,x+1 Pxl On y, x+1 Else Pxl Off y+1,x Pxl Off y+1,x+1 Pxl Off y, x+1 End If End For End For © Compute next generation For y,yl,yh,2 For x,xl,xh,2 nt(y-1,x-1) + nt(y-1,x) + nt(y-1,x+2) + nt(y,x-1) + nt(y+1,x+2) + nt(y+2,x-1) + nt(y+2,x+1) + nt(y+2,x+2) → count If count = 3 Then Pxl On y,x Else If count ≠ 2 Then Pxl Off y,x End If End For End For End While © Restore changed options set Graph("Axes", save[1]) set Graph("Grid", save[2]) set Graph("Labels", save[3])End Prgm Also see Conway's Game of Life/C Considering that the simplest implementation in C++ would lack any use of the object-oriented paradigm, this code was specifically written to demonstrate the various object-oriented features of C++.

e beq evaluaterightcells: ldy # ;upper-right cell clc adc (), Y ldy # ;right cell clc adc (), Y ldy # ;lower-right cell clc adc (), Yevaluate: ldx #

randfill: stx $01 ;$200 for indirect ldx #$02 ;addressing stx $02randloop: lda $fe ;generate random and #$01 ;pixels on the sta ($01), Y ;screen jsr inc0103 cmp #$00 bne randloop lda $02 cmp #$06 bne randloop clearmem: lda #$df ;set $07df-$0a20 sta $01 ;to $#00 lda #$07 sta $02clearbyte: lda #$00 sta ($01), Y jsr inc0103 cmp #$20 bne clearbyte lda $02 cmp #$0a bne clearbyte starttick:copyscreen: lda #$00 ;set up source sta $01 ;pointer at sta $03 ;$01/$02 and lda #$02 ;dest pointer sta $02 ;at $03/$04 lda #$08 sta $04 ldy #$00copybyte: lda ($01), Y ;copy pixel to sta ($03), Y ;back buffer jsr inc0103 ;increment pointers cmp #$00 ;check to see bne copybyte ;if we're at $600 lda $02 ;if so, we've cmp #$06 ;copied the bne copybyte ;entire screen conway: lda #$df ;apply conway rules sta $01 ;reset the pointer sta $03 ;to $#01df/$#07df lda #$01 ;($200 - $21) sta $02 ;($800 - $21) lda #$07 sta $04onecell: lda #$00 ;process one cell ldy #$01 ;upper cell clc adc ($03), Y ldy #$41 ;lower cell clc adc ($03), Ychkleft: tax ;check to see lda $01 ;if we're at the and #$1f ;left edge tay txa cpy #$1f beq rightcellsleftcells: ldy #$00 ;upper-left cell clc adc ($03), Y ldy #$20 ;left cell clc adc ($03), Y ldy #$40 ;lower-left cell clc adc ($03), Ychkright: tax ;check to see lda $01 ;if we're at the and #$1f ;right edge tay txa cpy #$1e beq evaluaterightcells: ldy #$02 ;upper-right cell clc adc ($03), Y ldy #$22 ;right cell clc adc ($03), Y ldy #$42 ;lower-right cell clc adc ($03), Yevaluate: ldx #$01 ;evaluate total ldy #$21 ;for current cell cmp #$03 ;3 = alive beq storex ldx #$00 cmp #$02 ;2 = alive if bne storex ;c = alive lda ($03), Y and #$01 taxstorex: txa ;store to screen sta ($01), Y jsr inc0103 ;move to next cellconwayloop: cmp #$e0 ;if not last cell, bne onecell ;process next cell lda $02 cmp #$05 bne onecell jmp starttick ;run next tick inc0103: lda $01 ;increment $01 cmp #$ff ;and $03 as 16-bit bne onlyinc01 ;pointers inc $02 inc $04onlyinc01: inc $01 lda $01 sta $03 rts The solution uses one cell thick border around square Petri dish as uninhabited dire land. Sample output contains 3 generations of the blinker and 5 of the glider: See Conway's Game of Life/ALGOL 68 APL2 (Dialog) Example in one line APL \ 1130 example (very old APL dialect via simulator) APL1130From: APL \ 1130 Samples The following APL \ 1130 code will need APL385 font installed to display correctly. See Download APL TT Font ∇LIFE[⎕]∇[0] NG←LIFE CG; W[1] W←CG+(¯1⊖CG)+(1⊖CG)+(¯1⌽CG)+(1⌽CG)[2] W←W+(1⊖1⌽CG)+(¯1⊖1⌽CG)+(1⊖¯1⌽CG)+(¯1⊖¯1⌽CG)[3] NG←(3=W)+(CG∧4=W) ∇ RP←5 5⍴0 0 0 0 0 0 0 1 1 0 0 1 1 0 0 0 0 1 0 0 RP0 0 0 0 00 0 1 1 00 1 1 0 00 0 1 0 00 0 0 0 0 LIFE RP0 0 0 0 00 1 1 1 00 1 0 0 00 1 1 0 00 0 0 0 0 LIFE LIFE RP0 0 1 0 00 1 1 0 01 0 0 1 00 1 1 0 00 0 0 0 0 .................................................. One interacts with the Game of Life by creating an initial configuration and observing how it evolves. Although you should test your implementation on more complex examples such as the glider in a larger universe, show the action of the blinker (three adjoining cells in a row all alive), over three generations, in a 3 by 3 grid. (1,4)=TRUERETURN'' Count the number of neighbours of the point i,j' (Assume i/j +/- 1 will not fall out of world)'FUNCTION count_neighbours(i%,j%) LOCAL count%,l% count%=0 FOR l%=-1 TO 1 IF world! (i%+l%,j%+1) count%=count%+1 ENDIF NEXT l% IF world! (i%+1,j%) count%=count%+1 ENDIF RETURN count%ENDFUNC'' Update the world one step'PROCEDURE update_world LOCAL i%,j% ' compute neighbour counts and store FOR i%=1 TO 30 FOR j%=1 TO 30 ns%(i%,j%)[email protected]_neighbours(i%,j%) NEXT j% NEXT i% ' update the world cells FOR i%=1 TO 30 FOR j%=1 TO 30 IF world!

||

randfill: stx $01 ;$200 for indirect ldx #$02 ;addressing stx $02randloop: lda $fe ;generate random and #$01 ;pixels on the sta ($01), Y ;screen jsr inc0103 cmp #$00 bne randloop lda $02 cmp #$06 bne randloop clearmem: lda #$df ;set $07df-$0a20 sta $01 ;to $#00 lda #$07 sta $02clearbyte: lda #$00 sta ($01), Y jsr inc0103 cmp #$20 bne clearbyte lda $02 cmp #$0a bne clearbyte starttick:copyscreen: lda #$00 ;set up source sta $01 ;pointer at sta $03 ;$01/$02 and lda #$02 ;dest pointer sta $02 ;at $03/$04 lda #$08 sta $04 ldy #$00copybyte: lda ($01), Y ;copy pixel to sta ($03), Y ;back buffer jsr inc0103 ;increment pointers cmp #$00 ;check to see bne copybyte ;if we're at $600 lda $02 ;if so, we've cmp #$06 ;copied the bne copybyte ;entire screen conway: lda #$df ;apply conway rules sta $01 ;reset the pointer sta $03 ;to $#01df/$#07df lda #$01 ;($200 - $21) sta $02 ;($800 - $21) lda #$07 sta $04onecell: lda #$00 ;process one cell ldy #$01 ;upper cell clc adc ($03), Y ldy #$41 ;lower cell clc adc ($03), Ychkleft: tax ;check to see lda $01 ;if we're at the and #$1f ;left edge tay txa cpy #$1f beq rightcellsleftcells: ldy #$00 ;upper-left cell clc adc ($03), Y ldy #$20 ;left cell clc adc ($03), Y ldy #$40 ;lower-left cell clc adc ($03), Ychkright: tax ;check to see lda $01 ;if we're at the and #$1f ;right edge tay txa cpy #$1e beq evaluaterightcells: ldy #$02 ;upper-right cell clc adc ($03), Y ldy #$22 ;right cell clc adc ($03), Y ldy #$42 ;lower-right cell clc adc ($03), Yevaluate: ldx #$01 ;evaluate total ldy #$21 ;for current cell cmp #$03 ;3 = alive beq storex ldx #$00 cmp #$02 ;2 = alive if bne storex ;c = alive lda ($03), Y and #$01 taxstorex: txa ;store to screen sta ($01), Y jsr inc0103 ;move to next cellconwayloop: cmp #$e0 ;if not last cell, bne onecell ;process next cell lda $02 cmp #$05 bne onecell jmp starttick ;run next tick inc0103: lda $01 ;increment $01 cmp #$ff ;and $03 as 16-bit bne onlyinc01 ;pointers inc $02 inc $04onlyinc01: inc $01 lda $01 sta $03 rts The solution uses one cell thick border around square Petri dish as uninhabited dire land. Sample output contains 3 generations of the blinker and 5 of the glider: See Conway's Game of Life/ALGOL 68 APL2 (Dialog) Example in one line APL \ 1130 example (very old APL dialect via simulator) APL1130From: APL \ 1130 Samples The following APL \ 1130 code will need APL385 font installed to display correctly.

See Download APL TT Font ∇LIFE[⎕]∇[0] NG←LIFE CG; W[1] W←CG+(¯1⊖CG)+(1⊖CG)+(¯1⌽CG)+(1⌽CG)[2] W←W+(1⊖1⌽CG)+(¯1⊖1⌽CG)+(1⊖¯1⌽CG)+(¯1⊖¯1⌽CG)[3] NG←(3=W)+(CG∧4=W) ∇ RP←5 5⍴0 0 0 0 0 0 0 1 1 0 0 1 1 0 0 0 0 1 0 0 RP0 0 0 0 00 0 1 1 00 1 1 0 00 0 1 0 00 0 0 0 0 LIFE RP0 0 0 0 00 1 1 1 00 1 0 0 00 1 1 0 00 0 0 0 0 LIFE LIFE RP0 0 1 0 00 1 1 0 01 0 0 1 00 1 1 0 00 0 0 0 0 ..................................................

One interacts with the Game of Life by creating an initial configuration and observing how it evolves.

Although you should test your implementation on more complex examples such as the glider in a larger universe, show the action of the blinker (three adjoining cells in a row all alive), over three generations, in a 3 by 3 grid.

(1,4)=TRUERETURN'' Count the number of neighbours of the point i,j' (Assume i/j +/- 1 will not fall out of world)'FUNCTION count_neighbours(i%,j%) LOCAL count%,l% count%=0 FOR l%=-1 TO 1 IF world! (i%+l%,j%+1) count%=count%+1 ENDIF NEXT l% IF world! (i%+1,j%) count%=count%+1 ENDIF RETURN count%ENDFUNC'' Update the world one step'PROCEDURE update_world LOCAL i%,j% ' compute neighbour counts and store FOR i%=1 TO 30 FOR j%=1 TO 30 ns%(i%,j%)[email protected]_neighbours(i%,j%) NEXT j% NEXT i% ' update the world cells FOR i%=1 TO 30 FOR j%=1 TO 30 IF world!

Thus, while it is somewhat verbose, it fully simulates Conway's Game of Life and is relatively simple to expand to feature different starting shapes.

Define life(pattern) = Prgm Local x,y,nt,count,save,xl,yl,xh,yh Define nt(y,x) = when(pxl Test(y,x), 1, 0) {}→save set Graph("Axes", "Off")→save[1] set Graph("Grid", "Off")→save[2] set Graph("Labels", "Off")→save[3] Fn Off Plot Off Clr Draw If pattern = "blinker" Then 36→yl 40→yh 78→xl 82→xh Pxl On 36,80 Pxl On 38,80 Pxl On 40,80 Else If pattern = "glider" Then 30→yl 40→yh 76→xl 88→xh Pxl On 38,76 Pxl On 36,78 Pxl On 36,80 Pxl On 38,80 Pxl On 40,80 Else If pattern = "r" Then 38-5*2→yl 38+5*2→yh 80-5*2→xl 80+5*2→xh Pxl On 38,78 Pxl On 36,82 Pxl On 36,80 Pxl On 38,80 Pxl On 40,80 End If While get Key() = 0 © Expand upper-left corner to whole cell For y,yl,yh,2 For x,xl,xh,2 If pxl Test(y,x) Then Pxl On y+1,x Pxl On y+1,x+1 Pxl On y, x+1 Else Pxl Off y+1,x Pxl Off y+1,x+1 Pxl Off y, x+1 End If End For End For © Compute next generation For y,yl,yh,2 For x,xl,xh,2 nt(y-1,x-1) + nt(y-1,x) + nt(y-1,x+2) + nt(y,x-1) + nt(y+1,x+2) + nt(y+2,x-1) + nt(y+2,x+1) + nt(y+2,x+2) → count If count = 3 Then Pxl On y,x Else If count ≠ 2 Then Pxl Off y,x End If End For End For End While © Restore changed options set Graph("Axes", save[1]) set Graph("Grid", save[2]) set Graph("Labels", save[3])End Prgm Also see Conway's Game of Life/C Considering that the simplest implementation in C++ would lack any use of the object-oriented paradigm, this code was specifically written to demonstrate the various object-oriented features of C++.

;evaluate total ldy # ;for current cell cmp # ;3 = alive beq storex ldx #[[

randfill: stx $01 ;$200 for indirect ldx #$02 ;addressing stx $02randloop: lda $fe ;generate random and #$01 ;pixels on the sta ($01), Y ;screen jsr inc0103 cmp #$00 bne randloop lda $02 cmp #$06 bne randloop clearmem: lda #$df ;set $07df-$0a20 sta $01 ;to $#00 lda #$07 sta $02clearbyte: lda #$00 sta ($01), Y jsr inc0103 cmp #$20 bne clearbyte lda $02 cmp #$0a bne clearbyte starttick:copyscreen: lda #$00 ;set up source sta $01 ;pointer at sta $03 ;$01/$02 and lda #$02 ;dest pointer sta $02 ;at $03/$04 lda #$08 sta $04 ldy #$00copybyte: lda ($01), Y ;copy pixel to sta ($03), Y ;back buffer jsr inc0103 ;increment pointers cmp #$00 ;check to see bne copybyte ;if we're at $600 lda $02 ;if so, we've cmp #$06 ;copied the bne copybyte ;entire screen conway: lda #$df ;apply conway rules sta $01 ;reset the pointer sta $03 ;to $#01df/$#07df lda #$01 ;($200 - $21) sta $02 ;($800 - $21) lda #$07 sta $04onecell: lda #$00 ;process one cell ldy #$01 ;upper cell clc adc ($03), Y ldy #$41 ;lower cell clc adc ($03), Ychkleft: tax ;check to see lda $01 ;if we're at the and #$1f ;left edge tay txa cpy #$1f beq rightcellsleftcells: ldy #$00 ;upper-left cell clc adc ($03), Y ldy #$20 ;left cell clc adc ($03), Y ldy #$40 ;lower-left cell clc adc ($03), Ychkright: tax ;check to see lda $01 ;if we're at the and #$1f ;right edge tay txa cpy #$1e beq evaluaterightcells: ldy #$02 ;upper-right cell clc adc ($03), Y ldy #$22 ;right cell clc adc ($03), Y ldy #$42 ;lower-right cell clc adc ($03), Yevaluate: ldx #$01 ;evaluate total ldy #$21 ;for current cell cmp #$03 ;3 = alive beq storex ldx #$00 cmp #$02 ;2 = alive if bne storex ;c = alive lda ($03), Y and #$01 taxstorex: txa ;store to screen sta ($01), Y jsr inc0103 ;move to next cellconwayloop: cmp #$e0 ;if not last cell, bne onecell ;process next cell lda $02 cmp #$05 bne onecell jmp starttick ;run next tick inc0103: lda $01 ;increment $01 cmp #$ff ;and $03 as 16-bit bne onlyinc01 ;pointers inc $02 inc $04onlyinc01: inc $01 lda $01 sta $03 rts The solution uses one cell thick border around square Petri dish as uninhabited dire land. Sample output contains 3 generations of the blinker and 5 of the glider: See Conway's Game of Life/ALGOL 68 APL2 (Dialog) Example in one line APL \ 1130 example (very old APL dialect via simulator) APL1130From: APL \ 1130 Samples The following APL \ 1130 code will need APL385 font installed to display correctly. See Download APL TT Font ∇LIFE[⎕]∇[0] NG←LIFE CG; W[1] W←CG+(¯1⊖CG)+(1⊖CG)+(¯1⌽CG)+(1⌽CG)[2] W←W+(1⊖1⌽CG)+(¯1⊖1⌽CG)+(1⊖¯1⌽CG)+(¯1⊖¯1⌽CG)[3] NG←(3=W)+(CG∧4=W) ∇ RP←5 5⍴0 0 0 0 0 0 0 1 1 0 0 1 1 0 0 0 0 1 0 0 RP0 0 0 0 00 0 1 1 00 1 1 0 00 0 1 0 00 0 0 0 0 LIFE RP0 0 0 0 00 1 1 1 00 1 0 0 00 1 1 0 00 0 0 0 0 LIFE LIFE RP0 0 1 0 00 1 1 0 01 0 0 1 00 1 1 0 00 0 0 0 0 .................................................. One interacts with the Game of Life by creating an initial configuration and observing how it evolves. Although you should test your implementation on more complex examples such as the glider in a larger universe, show the action of the blinker (three adjoining cells in a row all alive), over three generations, in a 3 by 3 grid. (1,4)=TRUERETURN'' Count the number of neighbours of the point i,j' (Assume i/j +/- 1 will not fall out of world)'FUNCTION count_neighbours(i%,j%) LOCAL count%,l% count%=0 FOR l%=-1 TO 1 IF world! (i%+l%,j%+1) count%=count%+1 ENDIF NEXT l% IF world! (i%+1,j%) count%=count%+1 ENDIF RETURN count%ENDFUNC'' Update the world one step'PROCEDURE update_world LOCAL i%,j% ' compute neighbour counts and store FOR i%=1 TO 30 FOR j%=1 TO 30 ns%(i%,j%)[email protected]_neighbours(i%,j%) NEXT j% NEXT i% ' update the world cells FOR i%=1 TO 30 FOR j%=1 TO 30 IF world!

||

randfill: stx $01 ;$200 for indirect ldx #$02 ;addressing stx $02randloop: lda $fe ;generate random and #$01 ;pixels on the sta ($01), Y ;screen jsr inc0103 cmp #$00 bne randloop lda $02 cmp #$06 bne randloop clearmem: lda #$df ;set $07df-$0a20 sta $01 ;to $#00 lda #$07 sta $02clearbyte: lda #$00 sta ($01), Y jsr inc0103 cmp #$20 bne clearbyte lda $02 cmp #$0a bne clearbyte starttick:copyscreen: lda #$00 ;set up source sta $01 ;pointer at sta $03 ;$01/$02 and lda #$02 ;dest pointer sta $02 ;at $03/$04 lda #$08 sta $04 ldy #$00copybyte: lda ($01), Y ;copy pixel to sta ($03), Y ;back buffer jsr inc0103 ;increment pointers cmp #$00 ;check to see bne copybyte ;if we're at $600 lda $02 ;if so, we've cmp #$06 ;copied the bne copybyte ;entire screen conway: lda #$df ;apply conway rules sta $01 ;reset the pointer sta $03 ;to $#01df/$#07df lda #$01 ;($200 - $21) sta $02 ;($800 - $21) lda #$07 sta $04onecell: lda #$00 ;process one cell ldy #$01 ;upper cell clc adc ($03), Y ldy #$41 ;lower cell clc adc ($03), Ychkleft: tax ;check to see lda $01 ;if we're at the and #$1f ;left edge tay txa cpy #$1f beq rightcellsleftcells: ldy #$00 ;upper-left cell clc adc ($03), Y ldy #$20 ;left cell clc adc ($03), Y ldy #$40 ;lower-left cell clc adc ($03), Ychkright: tax ;check to see lda $01 ;if we're at the and #$1f ;right edge tay txa cpy #$1e beq evaluaterightcells: ldy #$02 ;upper-right cell clc adc ($03), Y ldy #$22 ;right cell clc adc ($03), Y ldy #$42 ;lower-right cell clc adc ($03), Yevaluate: ldx #$01 ;evaluate total ldy #$21 ;for current cell cmp #$03 ;3 = alive beq storex ldx #$00 cmp #$02 ;2 = alive if bne storex ;c = alive lda ($03), Y and #$01 taxstorex: txa ;store to screen sta ($01), Y jsr inc0103 ;move to next cellconwayloop: cmp #$e0 ;if not last cell, bne onecell ;process next cell lda $02 cmp #$05 bne onecell jmp starttick ;run next tick inc0103: lda $01 ;increment $01 cmp #$ff ;and $03 as 16-bit bne onlyinc01 ;pointers inc $02 inc $04onlyinc01: inc $01 lda $01 sta $03 rts The solution uses one cell thick border around square Petri dish as uninhabited dire land. Sample output contains 3 generations of the blinker and 5 of the glider: See Conway's Game of Life/ALGOL 68 APL2 (Dialog) Example in one line APL \ 1130 example (very old APL dialect via simulator) APL1130From: APL \ 1130 Samples The following APL \ 1130 code will need APL385 font installed to display correctly.

See Download APL TT Font ∇LIFE[⎕]∇[0] NG←LIFE CG; W[1] W←CG+(¯1⊖CG)+(1⊖CG)+(¯1⌽CG)+(1⌽CG)[2] W←W+(1⊖1⌽CG)+(¯1⊖1⌽CG)+(1⊖¯1⌽CG)+(¯1⊖¯1⌽CG)[3] NG←(3=W)+(CG∧4=W) ∇ RP←5 5⍴0 0 0 0 0 0 0 1 1 0 0 1 1 0 0 0 0 1 0 0 RP0 0 0 0 00 0 1 1 00 1 1 0 00 0 1 0 00 0 0 0 0 LIFE RP0 0 0 0 00 1 1 1 00 1 0 0 00 1 1 0 00 0 0 0 0 LIFE LIFE RP0 0 1 0 00 1 1 0 01 0 0 1 00 1 1 0 00 0 0 0 0 ..................................................

One interacts with the Game of Life by creating an initial configuration and observing how it evolves.

Although you should test your implementation on more complex examples such as the glider in a larger universe, show the action of the blinker (three adjoining cells in a row all alive), over three generations, in a 3 by 3 grid.

(1,4)=TRUERETURN'' Count the number of neighbours of the point i,j' (Assume i/j +/- 1 will not fall out of world)'FUNCTION count_neighbours(i%,j%) LOCAL count%,l% count%=0 FOR l%=-1 TO 1 IF world! (i%+l%,j%+1) count%=count%+1 ENDIF NEXT l% IF world! (i%+1,j%) count%=count%+1 ENDIF RETURN count%ENDFUNC'' Update the world one step'PROCEDURE update_world LOCAL i%,j% ' compute neighbour counts and store FOR i%=1 TO 30 FOR j%=1 TO 30 ns%(i%,j%)[email protected]_neighbours(i%,j%) NEXT j% NEXT i% ' update the world cells FOR i%=1 TO 30 FOR j%=1 TO 30 IF world!

Thus, while it is somewhat verbose, it fully simulates Conway's Game of Life and is relatively simple to expand to feature different starting shapes.

Define life(pattern) = Prgm Local x,y,nt,count,save,xl,yl,xh,yh Define nt(y,x) = when(pxl Test(y,x), 1, 0) {}→save set Graph("Axes", "Off")→save[1] set Graph("Grid", "Off")→save[2] set Graph("Labels", "Off")→save[3] Fn Off Plot Off Clr Draw If pattern = "blinker" Then 36→yl 40→yh 78→xl 82→xh Pxl On 36,80 Pxl On 38,80 Pxl On 40,80 Else If pattern = "glider" Then 30→yl 40→yh 76→xl 88→xh Pxl On 38,76 Pxl On 36,78 Pxl On 36,80 Pxl On 38,80 Pxl On 40,80 Else If pattern = "r" Then 38-5*2→yl 38+5*2→yh 80-5*2→xl 80+5*2→xh Pxl On 38,78 Pxl On 36,82 Pxl On 36,80 Pxl On 38,80 Pxl On 40,80 End If While get Key() = 0 © Expand upper-left corner to whole cell For y,yl,yh,2 For x,xl,xh,2 If pxl Test(y,x) Then Pxl On y+1,x Pxl On y+1,x+1 Pxl On y, x+1 Else Pxl Off y+1,x Pxl Off y+1,x+1 Pxl Off y, x+1 End If End For End For © Compute next generation For y,yl,yh,2 For x,xl,xh,2 nt(y-1,x-1) + nt(y-1,x) + nt(y-1,x+2) + nt(y,x-1) + nt(y+1,x+2) + nt(y+2,x-1) + nt(y+2,x+1) + nt(y+2,x+2) → count If count = 3 Then Pxl On y,x Else If count ≠ 2 Then Pxl Off y,x End If End For End For End While © Restore changed options set Graph("Axes", save[1]) set Graph("Grid", save[2]) set Graph("Labels", save[3])End Prgm Also see Conway's Game of Life/C Considering that the simplest implementation in C++ would lack any use of the object-oriented paradigm, this code was specifically written to demonstrate the various object-oriented features of C++.

]] cmp # ;2 = alive if bne storex ;c = alive lda (), Y and #

randfill: stx $01 ;$200 for indirect ldx #$02 ;addressing stx $02randloop: lda $fe ;generate random and #$01 ;pixels on the sta ($01), Y ;screen jsr inc0103 cmp #$00 bne randloop lda $02 cmp #$06 bne randloop clearmem: lda #$df ;set $07df-$0a20 sta $01 ;to $#00 lda #$07 sta $02clearbyte: lda #$00 sta ($01), Y jsr inc0103 cmp #$20 bne clearbyte lda $02 cmp #$0a bne clearbyte starttick:copyscreen: lda #$00 ;set up source sta $01 ;pointer at sta $03 ;$01/$02 and lda #$02 ;dest pointer sta $02 ;at $03/$04 lda #$08 sta $04 ldy #$00copybyte: lda ($01), Y ;copy pixel to sta ($03), Y ;back buffer jsr inc0103 ;increment pointers cmp #$00 ;check to see bne copybyte ;if we're at $600 lda $02 ;if so, we've cmp #$06 ;copied the bne copybyte ;entire screen conway: lda #$df ;apply conway rules sta $01 ;reset the pointer sta $03 ;to $#01df/$#07df lda #$01 ;($200 - $21) sta $02 ;($800 - $21) lda #$07 sta $04onecell: lda #$00 ;process one cell ldy #$01 ;upper cell clc adc ($03), Y ldy #$41 ;lower cell clc adc ($03), Ychkleft: tax ;check to see lda $01 ;if we're at the and #$1f ;left edge tay txa cpy #$1f beq rightcellsleftcells: ldy #$00 ;upper-left cell clc adc ($03), Y ldy #$20 ;left cell clc adc ($03), Y ldy #$40 ;lower-left cell clc adc ($03), Ychkright: tax ;check to see lda $01 ;if we're at the and #$1f ;right edge tay txa cpy #$1e beq evaluaterightcells: ldy #$02 ;upper-right cell clc adc ($03), Y ldy #$22 ;right cell clc adc ($03), Y ldy #$42 ;lower-right cell clc adc ($03), Yevaluate: ldx #$01 ;evaluate total ldy #$21 ;for current cell cmp #$03 ;3 = alive beq storex ldx #$00 cmp #$02 ;2 = alive if bne storex ;c = alive lda ($03), Y and #$01 taxstorex: txa ;store to screen sta ($01), Y jsr inc0103 ;move to next cellconwayloop: cmp #$e0 ;if not last cell, bne onecell ;process next cell lda $02 cmp #$05 bne onecell jmp starttick ;run next tick inc0103: lda $01 ;increment $01 cmp #$ff ;and $03 as 16-bit bne onlyinc01 ;pointers inc $02 inc $04onlyinc01: inc $01 lda $01 sta $03 rts The solution uses one cell thick border around square Petri dish as uninhabited dire land. Sample output contains 3 generations of the blinker and 5 of the glider: See Conway's Game of Life/ALGOL 68 APL2 (Dialog) Example in one line APL \ 1130 example (very old APL dialect via simulator) APL1130From: APL \ 1130 Samples The following APL \ 1130 code will need APL385 font installed to display correctly. See Download APL TT Font ∇LIFE[⎕]∇[0] NG←LIFE CG; W[1] W←CG+(¯1⊖CG)+(1⊖CG)+(¯1⌽CG)+(1⌽CG)[2] W←W+(1⊖1⌽CG)+(¯1⊖1⌽CG)+(1⊖¯1⌽CG)+(¯1⊖¯1⌽CG)[3] NG←(3=W)+(CG∧4=W) ∇ RP←5 5⍴0 0 0 0 0 0 0 1 1 0 0 1 1 0 0 0 0 1 0 0 RP0 0 0 0 00 0 1 1 00 1 1 0 00 0 1 0 00 0 0 0 0 LIFE RP0 0 0 0 00 1 1 1 00 1 0 0 00 1 1 0 00 0 0 0 0 LIFE LIFE RP0 0 1 0 00 1 1 0 01 0 0 1 00 1 1 0 00 0 0 0 0 .................................................. One interacts with the Game of Life by creating an initial configuration and observing how it evolves. Although you should test your implementation on more complex examples such as the glider in a larger universe, show the action of the blinker (three adjoining cells in a row all alive), over three generations, in a 3 by 3 grid. (1,4)=TRUERETURN'' Count the number of neighbours of the point i,j' (Assume i/j +/- 1 will not fall out of world)'FUNCTION count_neighbours(i%,j%) LOCAL count%,l% count%=0 FOR l%=-1 TO 1 IF world! (i%+l%,j%+1) count%=count%+1 ENDIF NEXT l% IF world! (i%+1,j%) count%=count%+1 ENDIF RETURN count%ENDFUNC'' Update the world one step'PROCEDURE update_world LOCAL i%,j% ' compute neighbour counts and store FOR i%=1 TO 30 FOR j%=1 TO 30 ns%(i%,j%)[email protected]_neighbours(i%,j%) NEXT j% NEXT i% ' update the world cells FOR i%=1 TO 30 FOR j%=1 TO 30 IF world!

||

randfill: stx $01 ;$200 for indirect ldx #$02 ;addressing stx $02randloop: lda $fe ;generate random and #$01 ;pixels on the sta ($01), Y ;screen jsr inc0103 cmp #$00 bne randloop lda $02 cmp #$06 bne randloop clearmem: lda #$df ;set $07df-$0a20 sta $01 ;to $#00 lda #$07 sta $02clearbyte: lda #$00 sta ($01), Y jsr inc0103 cmp #$20 bne clearbyte lda $02 cmp #$0a bne clearbyte starttick:copyscreen: lda #$00 ;set up source sta $01 ;pointer at sta $03 ;$01/$02 and lda #$02 ;dest pointer sta $02 ;at $03/$04 lda #$08 sta $04 ldy #$00copybyte: lda ($01), Y ;copy pixel to sta ($03), Y ;back buffer jsr inc0103 ;increment pointers cmp #$00 ;check to see bne copybyte ;if we're at $600 lda $02 ;if so, we've cmp #$06 ;copied the bne copybyte ;entire screen conway: lda #$df ;apply conway rules sta $01 ;reset the pointer sta $03 ;to $#01df/$#07df lda #$01 ;($200 - $21) sta $02 ;($800 - $21) lda #$07 sta $04onecell: lda #$00 ;process one cell ldy #$01 ;upper cell clc adc ($03), Y ldy #$41 ;lower cell clc adc ($03), Ychkleft: tax ;check to see lda $01 ;if we're at the and #$1f ;left edge tay txa cpy #$1f beq rightcellsleftcells: ldy #$00 ;upper-left cell clc adc ($03), Y ldy #$20 ;left cell clc adc ($03), Y ldy #$40 ;lower-left cell clc adc ($03), Ychkright: tax ;check to see lda $01 ;if we're at the and #$1f ;right edge tay txa cpy #$1e beq evaluaterightcells: ldy #$02 ;upper-right cell clc adc ($03), Y ldy #$22 ;right cell clc adc ($03), Y ldy #$42 ;lower-right cell clc adc ($03), Yevaluate: ldx #$01 ;evaluate total ldy #$21 ;for current cell cmp #$03 ;3 = alive beq storex ldx #$00 cmp #$02 ;2 = alive if bne storex ;c = alive lda ($03), Y and #$01 taxstorex: txa ;store to screen sta ($01), Y jsr inc0103 ;move to next cellconwayloop: cmp #$e0 ;if not last cell, bne onecell ;process next cell lda $02 cmp #$05 bne onecell jmp starttick ;run next tick inc0103: lda $01 ;increment $01 cmp #$ff ;and $03 as 16-bit bne onlyinc01 ;pointers inc $02 inc $04onlyinc01: inc $01 lda $01 sta $03 rts The solution uses one cell thick border around square Petri dish as uninhabited dire land. Sample output contains 3 generations of the blinker and 5 of the glider: See Conway's Game of Life/ALGOL 68 APL2 (Dialog) Example in one line APL \ 1130 example (very old APL dialect via simulator) APL1130From: APL \ 1130 Samples The following APL \ 1130 code will need APL385 font installed to display correctly.

See Download APL TT Font ∇LIFE[⎕]∇[0] NG←LIFE CG; W[1] W←CG+(¯1⊖CG)+(1⊖CG)+(¯1⌽CG)+(1⌽CG)[2] W←W+(1⊖1⌽CG)+(¯1⊖1⌽CG)+(1⊖¯1⌽CG)+(¯1⊖¯1⌽CG)[3] NG←(3=W)+(CG∧4=W) ∇ RP←5 5⍴0 0 0 0 0 0 0 1 1 0 0 1 1 0 0 0 0 1 0 0 RP0 0 0 0 00 0 1 1 00 1 1 0 00 0 1 0 00 0 0 0 0 LIFE RP0 0 0 0 00 1 1 1 00 1 0 0 00 1 1 0 00 0 0 0 0 LIFE LIFE RP0 0 1 0 00 1 1 0 01 0 0 1 00 1 1 0 00 0 0 0 0 ..................................................

One interacts with the Game of Life by creating an initial configuration and observing how it evolves.

Although you should test your implementation on more complex examples such as the glider in a larger universe, show the action of the blinker (three adjoining cells in a row all alive), over three generations, in a 3 by 3 grid.

(1,4)=TRUERETURN'' Count the number of neighbours of the point i,j' (Assume i/j +/- 1 will not fall out of world)'FUNCTION count_neighbours(i%,j%) LOCAL count%,l% count%=0 FOR l%=-1 TO 1 IF world! (i%+l%,j%+1) count%=count%+1 ENDIF NEXT l% IF world! (i%+1,j%) count%=count%+1 ENDIF RETURN count%ENDFUNC'' Update the world one step'PROCEDURE update_world LOCAL i%,j% ' compute neighbour counts and store FOR i%=1 TO 30 FOR j%=1 TO 30 ns%(i%,j%)[email protected]_neighbours(i%,j%) NEXT j% NEXT i% ' update the world cells FOR i%=1 TO 30 FOR j%=1 TO 30 IF world!

Thus, while it is somewhat verbose, it fully simulates Conway's Game of Life and is relatively simple to expand to feature different starting shapes.

Define life(pattern) = Prgm Local x,y,nt,count,save,xl,yl,xh,yh Define nt(y,x) = when(pxl Test(y,x), 1, 0) {}→save set Graph("Axes", "Off")→save[1] set Graph("Grid", "Off")→save[2] set Graph("Labels", "Off")→save[3] Fn Off Plot Off Clr Draw If pattern = "blinker" Then 36→yl 40→yh 78→xl 82→xh Pxl On 36,80 Pxl On 38,80 Pxl On 40,80 Else If pattern = "glider" Then 30→yl 40→yh 76→xl 88→xh Pxl On 38,76 Pxl On 36,78 Pxl On 36,80 Pxl On 38,80 Pxl On 40,80 Else If pattern = "r" Then 38-5*2→yl 38+5*2→yh 80-5*2→xl 80+5*2→xh Pxl On 38,78 Pxl On 36,82 Pxl On 36,80 Pxl On 38,80 Pxl On 40,80 End If While get Key() = 0 © Expand upper-left corner to whole cell For y,yl,yh,2 For x,xl,xh,2 If pxl Test(y,x) Then Pxl On y+1,x Pxl On y+1,x+1 Pxl On y, x+1 Else Pxl Off y+1,x Pxl Off y+1,x+1 Pxl Off y, x+1 End If End For End For © Compute next generation For y,yl,yh,2 For x,xl,xh,2 nt(y-1,x-1) + nt(y-1,x) + nt(y-1,x+2) + nt(y,x-1) + nt(y+1,x+2) + nt(y+2,x-1) + nt(y+2,x+1) + nt(y+2,x+2) → count If count = 3 Then Pxl On y,x Else If count ≠ 2 Then Pxl Off y,x End If End For End For End While © Restore changed options set Graph("Axes", save[1]) set Graph("Grid", save[2]) set Graph("Labels", save[3])End Prgm Also see Conway's Game of Life/C Considering that the simplest implementation in C++ would lack any use of the object-oriented paradigm, this code was specifically written to demonstrate the various object-oriented features of C++.

taxstorex: txa ;store to screen sta (

randfill: stx $01 ;$200 for indirect ldx #$02 ;addressing stx $02randloop: lda $fe ;generate random and #$01 ;pixels on the sta ($01), Y ;screen jsr inc0103 cmp #$00 bne randloop lda $02 cmp #$06 bne randloop clearmem: lda #$df ;set $07df-$0a20 sta $01 ;to $#00 lda #$07 sta $02clearbyte: lda #$00 sta ($01), Y jsr inc0103 cmp #$20 bne clearbyte lda $02 cmp #$0a bne clearbyte starttick:copyscreen: lda #$00 ;set up source sta $01 ;pointer at sta $03 ;$01/$02 and lda #$02 ;dest pointer sta $02 ;at $03/$04 lda #$08 sta $04 ldy #$00copybyte: lda ($01), Y ;copy pixel to sta ($03), Y ;back buffer jsr inc0103 ;increment pointers cmp #$00 ;check to see bne copybyte ;if we're at $600 lda $02 ;if so, we've cmp #$06 ;copied the bne copybyte ;entire screen conway: lda #$df ;apply conway rules sta $01 ;reset the pointer sta $03 ;to $#01df/$#07df lda #$01 ;($200 - $21) sta $02 ;($800 - $21) lda #$07 sta $04onecell: lda #$00 ;process one cell ldy #$01 ;upper cell clc adc ($03), Y ldy #$41 ;lower cell clc adc ($03), Ychkleft: tax ;check to see lda $01 ;if we're at the and #$1f ;left edge tay txa cpy #$1f beq rightcellsleftcells: ldy #$00 ;upper-left cell clc adc ($03), Y ldy #$20 ;left cell clc adc ($03), Y ldy #$40 ;lower-left cell clc adc ($03), Ychkright: tax ;check to see lda $01 ;if we're at the and #$1f ;right edge tay txa cpy #$1e beq evaluaterightcells: ldy #$02 ;upper-right cell clc adc ($03), Y ldy #$22 ;right cell clc adc ($03), Y ldy #$42 ;lower-right cell clc adc ($03), Yevaluate: ldx #$01 ;evaluate total ldy #$21 ;for current cell cmp #$03 ;3 = alive beq storex ldx #$00 cmp #$02 ;2 = alive if bne storex ;c = alive lda ($03), Y and #$01 taxstorex: txa ;store to screen sta ($01), Y jsr inc0103 ;move to next cellconwayloop: cmp #$e0 ;if not last cell, bne onecell ;process next cell lda $02 cmp #$05 bne onecell jmp starttick ;run next tick inc0103: lda $01 ;increment $01 cmp #$ff ;and $03 as 16-bit bne onlyinc01 ;pointers inc $02 inc $04onlyinc01: inc $01 lda $01 sta $03 rts The solution uses one cell thick border around square Petri dish as uninhabited dire land. Sample output contains 3 generations of the blinker and 5 of the glider: See Conway's Game of Life/ALGOL 68 APL2 (Dialog) Example in one line APL \ 1130 example (very old APL dialect via simulator) APL1130From: APL \ 1130 Samples The following APL \ 1130 code will need APL385 font installed to display correctly. See Download APL TT Font ∇LIFE[⎕]∇[0] NG←LIFE CG; W[1] W←CG+(¯1⊖CG)+(1⊖CG)+(¯1⌽CG)+(1⌽CG)[2] W←W+(1⊖1⌽CG)+(¯1⊖1⌽CG)+(1⊖¯1⌽CG)+(¯1⊖¯1⌽CG)[3] NG←(3=W)+(CG∧4=W) ∇ RP←5 5⍴0 0 0 0 0 0 0 1 1 0 0 1 1 0 0 0 0 1 0 0 RP0 0 0 0 00 0 1 1 00 1 1 0 00 0 1 0 00 0 0 0 0 LIFE RP0 0 0 0 00 1 1 1 00 1 0 0 00 1 1 0 00 0 0 0 0 LIFE LIFE RP0 0 1 0 00 1 1 0 01 0 0 1 00 1 1 0 00 0 0 0 0 .................................................. One interacts with the Game of Life by creating an initial configuration and observing how it evolves. Although you should test your implementation on more complex examples such as the glider in a larger universe, show the action of the blinker (three adjoining cells in a row all alive), over three generations, in a 3 by 3 grid. (1,4)=TRUERETURN'' Count the number of neighbours of the point i,j' (Assume i/j +/- 1 will not fall out of world)'FUNCTION count_neighbours(i%,j%) LOCAL count%,l% count%=0 FOR l%=-1 TO 1 IF world! (i%+l%,j%+1) count%=count%+1 ENDIF NEXT l% IF world! (i%+1,j%) count%=count%+1 ENDIF RETURN count%ENDFUNC'' Update the world one step'PROCEDURE update_world LOCAL i%,j% ' compute neighbour counts and store FOR i%=1 TO 30 FOR j%=1 TO 30 ns%(i%,j%)[email protected]_neighbours(i%,j%) NEXT j% NEXT i% ' update the world cells FOR i%=1 TO 30 FOR j%=1 TO 30 IF world!

||

randfill: stx $01 ;$200 for indirect ldx #$02 ;addressing stx $02randloop: lda $fe ;generate random and #$01 ;pixels on the sta ($01), Y ;screen jsr inc0103 cmp #$00 bne randloop lda $02 cmp #$06 bne randloop clearmem: lda #$df ;set $07df-$0a20 sta $01 ;to $#00 lda #$07 sta $02clearbyte: lda #$00 sta ($01), Y jsr inc0103 cmp #$20 bne clearbyte lda $02 cmp #$0a bne clearbyte starttick:copyscreen: lda #$00 ;set up source sta $01 ;pointer at sta $03 ;$01/$02 and lda #$02 ;dest pointer sta $02 ;at $03/$04 lda #$08 sta $04 ldy #$00copybyte: lda ($01), Y ;copy pixel to sta ($03), Y ;back buffer jsr inc0103 ;increment pointers cmp #$00 ;check to see bne copybyte ;if we're at $600 lda $02 ;if so, we've cmp #$06 ;copied the bne copybyte ;entire screen conway: lda #$df ;apply conway rules sta $01 ;reset the pointer sta $03 ;to $#01df/$#07df lda #$01 ;($200 - $21) sta $02 ;($800 - $21) lda #$07 sta $04onecell: lda #$00 ;process one cell ldy #$01 ;upper cell clc adc ($03), Y ldy #$41 ;lower cell clc adc ($03), Ychkleft: tax ;check to see lda $01 ;if we're at the and #$1f ;left edge tay txa cpy #$1f beq rightcellsleftcells: ldy #$00 ;upper-left cell clc adc ($03), Y ldy #$20 ;left cell clc adc ($03), Y ldy #$40 ;lower-left cell clc adc ($03), Ychkright: tax ;check to see lda $01 ;if we're at the and #$1f ;right edge tay txa cpy #$1e beq evaluaterightcells: ldy #$02 ;upper-right cell clc adc ($03), Y ldy #$22 ;right cell clc adc ($03), Y ldy #$42 ;lower-right cell clc adc ($03), Yevaluate: ldx #$01 ;evaluate total ldy #$21 ;for current cell cmp #$03 ;3 = alive beq storex ldx #$00 cmp #$02 ;2 = alive if bne storex ;c = alive lda ($03), Y and #$01 taxstorex: txa ;store to screen sta ($01), Y jsr inc0103 ;move to next cellconwayloop: cmp #$e0 ;if not last cell, bne onecell ;process next cell lda $02 cmp #$05 bne onecell jmp starttick ;run next tick inc0103: lda $01 ;increment $01 cmp #$ff ;and $03 as 16-bit bne onlyinc01 ;pointers inc $02 inc $04onlyinc01: inc $01 lda $01 sta $03 rts The solution uses one cell thick border around square Petri dish as uninhabited dire land. Sample output contains 3 generations of the blinker and 5 of the glider: See Conway's Game of Life/ALGOL 68 APL2 (Dialog) Example in one line APL \ 1130 example (very old APL dialect via simulator) APL1130From: APL \ 1130 Samples The following APL \ 1130 code will need APL385 font installed to display correctly.

See Download APL TT Font ∇LIFE[⎕]∇[0] NG←LIFE CG; W[1] W←CG+(¯1⊖CG)+(1⊖CG)+(¯1⌽CG)+(1⌽CG)[2] W←W+(1⊖1⌽CG)+(¯1⊖1⌽CG)+(1⊖¯1⌽CG)+(¯1⊖¯1⌽CG)[3] NG←(3=W)+(CG∧4=W) ∇ RP←5 5⍴0 0 0 0 0 0 0 1 1 0 0 1 1 0 0 0 0 1 0 0 RP0 0 0 0 00 0 1 1 00 1 1 0 00 0 1 0 00 0 0 0 0 LIFE RP0 0 0 0 00 1 1 1 00 1 0 0 00 1 1 0 00 0 0 0 0 LIFE LIFE RP0 0 1 0 00 1 1 0 01 0 0 1 00 1 1 0 00 0 0 0 0 ..................................................

One interacts with the Game of Life by creating an initial configuration and observing how it evolves.

Although you should test your implementation on more complex examples such as the glider in a larger universe, show the action of the blinker (three adjoining cells in a row all alive), over three generations, in a 3 by 3 grid.

(1,4)=TRUERETURN'' Count the number of neighbours of the point i,j' (Assume i/j +/- 1 will not fall out of world)'FUNCTION count_neighbours(i%,j%) LOCAL count%,l% count%=0 FOR l%=-1 TO 1 IF world! (i%+l%,j%+1) count%=count%+1 ENDIF NEXT l% IF world! (i%+1,j%) count%=count%+1 ENDIF RETURN count%ENDFUNC'' Update the world one step'PROCEDURE update_world LOCAL i%,j% ' compute neighbour counts and store FOR i%=1 TO 30 FOR j%=1 TO 30 ns%(i%,j%)[email protected]_neighbours(i%,j%) NEXT j% NEXT i% ' update the world cells FOR i%=1 TO 30 FOR j%=1 TO 30 IF world!

Thus, while it is somewhat verbose, it fully simulates Conway's Game of Life and is relatively simple to expand to feature different starting shapes.

Define life(pattern) = Prgm Local x,y,nt,count,save,xl,yl,xh,yh Define nt(y,x) = when(pxl Test(y,x), 1, 0) {}→save set Graph("Axes", "Off")→save[1] set Graph("Grid", "Off")→save[2] set Graph("Labels", "Off")→save[3] Fn Off Plot Off Clr Draw If pattern = "blinker" Then 36→yl 40→yh 78→xl 82→xh Pxl On 36,80 Pxl On 38,80 Pxl On 40,80 Else If pattern = "glider" Then 30→yl 40→yh 76→xl 88→xh Pxl On 38,76 Pxl On 36,78 Pxl On 36,80 Pxl On 38,80 Pxl On 40,80 Else If pattern = "r" Then 38-5*2→yl 38+5*2→yh 80-5*2→xl 80+5*2→xh Pxl On 38,78 Pxl On 36,82 Pxl On 36,80 Pxl On 38,80 Pxl On 40,80 End If While get Key() = 0 © Expand upper-left corner to whole cell For y,yl,yh,2 For x,xl,xh,2 If pxl Test(y,x) Then Pxl On y+1,x Pxl On y+1,x+1 Pxl On y, x+1 Else Pxl Off y+1,x Pxl Off y+1,x+1 Pxl Off y, x+1 End If End For End For © Compute next generation For y,yl,yh,2 For x,xl,xh,2 nt(y-1,x-1) + nt(y-1,x) + nt(y-1,x+2) + nt(y,x-1) + nt(y+1,x+2) + nt(y+2,x-1) + nt(y+2,x+1) + nt(y+2,x+2) → count If count = 3 Then Pxl On y,x Else If count ≠ 2 Then Pxl Off y,x End If End For End For End While © Restore changed options set Graph("Axes", save[1]) set Graph("Grid", save[2]) set Graph("Labels", save[3])End Prgm Also see Conway's Game of Life/C Considering that the simplest implementation in C++ would lack any use of the object-oriented paradigm, this code was specifically written to demonstrate the various object-oriented features of C++.

), Y jsr inc0103 ;move to next cellconwayloop: cmp #$e0 ;if not last cell, bne onecell ;process next cell lda cmp # bne onecell jmp starttick ;run next tick inc0103: lda

randfill: stx $01 ;$200 for indirect ldx #$02 ;addressing stx $02randloop: lda $fe ;generate random and #$01 ;pixels on the sta ($01), Y ;screen jsr inc0103 cmp #$00 bne randloop lda $02 cmp #$06 bne randloop clearmem: lda #$df ;set $07df-$0a20 sta $01 ;to $#00 lda #$07 sta $02clearbyte: lda #$00 sta ($01), Y jsr inc0103 cmp #$20 bne clearbyte lda $02 cmp #$0a bne clearbyte starttick:copyscreen: lda #$00 ;set up source sta $01 ;pointer at sta $03 ;$01/$02 and lda #$02 ;dest pointer sta $02 ;at $03/$04 lda #$08 sta $04 ldy #$00copybyte: lda ($01), Y ;copy pixel to sta ($03), Y ;back buffer jsr inc0103 ;increment pointers cmp #$00 ;check to see bne copybyte ;if we're at $600 lda $02 ;if so, we've cmp #$06 ;copied the bne copybyte ;entire screen conway: lda #$df ;apply conway rules sta $01 ;reset the pointer sta $03 ;to $#01df/$#07df lda #$01 ;($200 - $21) sta $02 ;($800 - $21) lda #$07 sta $04onecell: lda #$00 ;process one cell ldy #$01 ;upper cell clc adc ($03), Y ldy #$41 ;lower cell clc adc ($03), Ychkleft: tax ;check to see lda $01 ;if we're at the and #$1f ;left edge tay txa cpy #$1f beq rightcellsleftcells: ldy #$00 ;upper-left cell clc adc ($03), Y ldy #$20 ;left cell clc adc ($03), Y ldy #$40 ;lower-left cell clc adc ($03), Ychkright: tax ;check to see lda $01 ;if we're at the and #$1f ;right edge tay txa cpy #$1e beq evaluaterightcells: ldy #$02 ;upper-right cell clc adc ($03), Y ldy #$22 ;right cell clc adc ($03), Y ldy #$42 ;lower-right cell clc adc ($03), Yevaluate: ldx #$01 ;evaluate total ldy #$21 ;for current cell cmp #$03 ;3 = alive beq storex ldx #$00 cmp #$02 ;2 = alive if bne storex ;c = alive lda ($03), Y and #$01 taxstorex: txa ;store to screen sta ($01), Y jsr inc0103 ;move to next cellconwayloop: cmp #$e0 ;if not last cell, bne onecell ;process next cell lda $02 cmp #$05 bne onecell jmp starttick ;run next tick inc0103: lda $01 ;increment $01 cmp #$ff ;and $03 as 16-bit bne onlyinc01 ;pointers inc $02 inc $04onlyinc01: inc $01 lda $01 sta $03 rts The solution uses one cell thick border around square Petri dish as uninhabited dire land. Sample output contains 3 generations of the blinker and 5 of the glider: See Conway's Game of Life/ALGOL 68 APL2 (Dialog) Example in one line APL \ 1130 example (very old APL dialect via simulator) APL1130From: APL \ 1130 Samples The following APL \ 1130 code will need APL385 font installed to display correctly. See Download APL TT Font ∇LIFE[⎕]∇[0] NG←LIFE CG; W[1] W←CG+(¯1⊖CG)+(1⊖CG)+(¯1⌽CG)+(1⌽CG)[2] W←W+(1⊖1⌽CG)+(¯1⊖1⌽CG)+(1⊖¯1⌽CG)+(¯1⊖¯1⌽CG)[3] NG←(3=W)+(CG∧4=W) ∇ RP←5 5⍴0 0 0 0 0 0 0 1 1 0 0 1 1 0 0 0 0 1 0 0 RP0 0 0 0 00 0 1 1 00 1 1 0 00 0 1 0 00 0 0 0 0 LIFE RP0 0 0 0 00 1 1 1 00 1 0 0 00 1 1 0 00 0 0 0 0 LIFE LIFE RP0 0 1 0 00 1 1 0 01 0 0 1 00 1 1 0 00 0 0 0 0 .................................................. One interacts with the Game of Life by creating an initial configuration and observing how it evolves. Although you should test your implementation on more complex examples such as the glider in a larger universe, show the action of the blinker (three adjoining cells in a row all alive), over three generations, in a 3 by 3 grid. (1,4)=TRUERETURN'' Count the number of neighbours of the point i,j' (Assume i/j +/- 1 will not fall out of world)'FUNCTION count_neighbours(i%,j%) LOCAL count%,l% count%=0 FOR l%=-1 TO 1 IF world! (i%+l%,j%+1) count%=count%+1 ENDIF NEXT l% IF world! (i%+1,j%) count%=count%+1 ENDIF RETURN count%ENDFUNC'' Update the world one step'PROCEDURE update_world LOCAL i%,j% ' compute neighbour counts and store FOR i%=1 TO 30 FOR j%=1 TO 30 ns%(i%,j%)[email protected]_neighbours(i%,j%) NEXT j% NEXT i% ' update the world cells FOR i%=1 TO 30 FOR j%=1 TO 30 IF world!

||

randfill: stx $01 ;$200 for indirect ldx #$02 ;addressing stx $02randloop: lda $fe ;generate random and #$01 ;pixels on the sta ($01), Y ;screen jsr inc0103 cmp #$00 bne randloop lda $02 cmp #$06 bne randloop clearmem: lda #$df ;set $07df-$0a20 sta $01 ;to $#00 lda #$07 sta $02clearbyte: lda #$00 sta ($01), Y jsr inc0103 cmp #$20 bne clearbyte lda $02 cmp #$0a bne clearbyte starttick:copyscreen: lda #$00 ;set up source sta $01 ;pointer at sta $03 ;$01/$02 and lda #$02 ;dest pointer sta $02 ;at $03/$04 lda #$08 sta $04 ldy #$00copybyte: lda ($01), Y ;copy pixel to sta ($03), Y ;back buffer jsr inc0103 ;increment pointers cmp #$00 ;check to see bne copybyte ;if we're at $600 lda $02 ;if so, we've cmp #$06 ;copied the bne copybyte ;entire screen conway: lda #$df ;apply conway rules sta $01 ;reset the pointer sta $03 ;to $#01df/$#07df lda #$01 ;($200 - $21) sta $02 ;($800 - $21) lda #$07 sta $04onecell: lda #$00 ;process one cell ldy #$01 ;upper cell clc adc ($03), Y ldy #$41 ;lower cell clc adc ($03), Ychkleft: tax ;check to see lda $01 ;if we're at the and #$1f ;left edge tay txa cpy #$1f beq rightcellsleftcells: ldy #$00 ;upper-left cell clc adc ($03), Y ldy #$20 ;left cell clc adc ($03), Y ldy #$40 ;lower-left cell clc adc ($03), Ychkright: tax ;check to see lda $01 ;if we're at the and #$1f ;right edge tay txa cpy #$1e beq evaluaterightcells: ldy #$02 ;upper-right cell clc adc ($03), Y ldy #$22 ;right cell clc adc ($03), Y ldy #$42 ;lower-right cell clc adc ($03), Yevaluate: ldx #$01 ;evaluate total ldy #$21 ;for current cell cmp #$03 ;3 = alive beq storex ldx #$00 cmp #$02 ;2 = alive if bne storex ;c = alive lda ($03), Y and #$01 taxstorex: txa ;store to screen sta ($01), Y jsr inc0103 ;move to next cellconwayloop: cmp #$e0 ;if not last cell, bne onecell ;process next cell lda $02 cmp #$05 bne onecell jmp starttick ;run next tick inc0103: lda $01 ;increment $01 cmp #$ff ;and $03 as 16-bit bne onlyinc01 ;pointers inc $02 inc $04onlyinc01: inc $01 lda $01 sta $03 rts The solution uses one cell thick border around square Petri dish as uninhabited dire land. Sample output contains 3 generations of the blinker and 5 of the glider: See Conway's Game of Life/ALGOL 68 APL2 (Dialog) Example in one line APL \ 1130 example (very old APL dialect via simulator) APL1130From: APL \ 1130 Samples The following APL \ 1130 code will need APL385 font installed to display correctly.

See Download APL TT Font ∇LIFE[⎕]∇[0] NG←LIFE CG; W[1] W←CG+(¯1⊖CG)+(1⊖CG)+(¯1⌽CG)+(1⌽CG)[2] W←W+(1⊖1⌽CG)+(¯1⊖1⌽CG)+(1⊖¯1⌽CG)+(¯1⊖¯1⌽CG)[3] NG←(3=W)+(CG∧4=W) ∇ RP←5 5⍴0 0 0 0 0 0 0 1 1 0 0 1 1 0 0 0 0 1 0 0 RP0 0 0 0 00 0 1 1 00 1 1 0 00 0 1 0 00 0 0 0 0 LIFE RP0 0 0 0 00 1 1 1 00 1 0 0 00 1 1 0 00 0 0 0 0 LIFE LIFE RP0 0 1 0 00 1 1 0 01 0 0 1 00 1 1 0 00 0 0 0 0 ..................................................

One interacts with the Game of Life by creating an initial configuration and observing how it evolves.

Although you should test your implementation on more complex examples such as the glider in a larger universe, show the action of the blinker (three adjoining cells in a row all alive), over three generations, in a 3 by 3 grid.

(1,4)=TRUERETURN'' Count the number of neighbours of the point i,j' (Assume i/j +/- 1 will not fall out of world)'FUNCTION count_neighbours(i%,j%) LOCAL count%,l% count%=0 FOR l%=-1 TO 1 IF world! (i%+l%,j%+1) count%=count%+1 ENDIF NEXT l% IF world! (i%+1,j%) count%=count%+1 ENDIF RETURN count%ENDFUNC'' Update the world one step'PROCEDURE update_world LOCAL i%,j% ' compute neighbour counts and store FOR i%=1 TO 30 FOR j%=1 TO 30 ns%(i%,j%)[email protected]_neighbours(i%,j%) NEXT j% NEXT i% ' update the world cells FOR i%=1 TO 30 FOR j%=1 TO 30 IF world!

Thus, while it is somewhat verbose, it fully simulates Conway's Game of Life and is relatively simple to expand to feature different starting shapes.

Define life(pattern) = Prgm Local x,y,nt,count,save,xl,yl,xh,yh Define nt(y,x) = when(pxl Test(y,x), 1, 0) {}→save set Graph("Axes", "Off")→save[1] set Graph("Grid", "Off")→save[2] set Graph("Labels", "Off")→save[3] Fn Off Plot Off Clr Draw If pattern = "blinker" Then 36→yl 40→yh 78→xl 82→xh Pxl On 36,80 Pxl On 38,80 Pxl On 40,80 Else If pattern = "glider" Then 30→yl 40→yh 76→xl 88→xh Pxl On 38,76 Pxl On 36,78 Pxl On 36,80 Pxl On 38,80 Pxl On 40,80 Else If pattern = "r" Then 38-5*2→yl 38+5*2→yh 80-5*2→xl 80+5*2→xh Pxl On 38,78 Pxl On 36,82 Pxl On 36,80 Pxl On 38,80 Pxl On 40,80 End If While get Key() = 0 © Expand upper-left corner to whole cell For y,yl,yh,2 For x,xl,xh,2 If pxl Test(y,x) Then Pxl On y+1,x Pxl On y+1,x+1 Pxl On y, x+1 Else Pxl Off y+1,x Pxl Off y+1,x+1 Pxl Off y, x+1 End If End For End For © Compute next generation For y,yl,yh,2 For x,xl,xh,2 nt(y-1,x-1) + nt(y-1,x) + nt(y-1,x+2) + nt(y,x-1) + nt(y+1,x+2) + nt(y+2,x-1) + nt(y+2,x+1) + nt(y+2,x+2) → count If count = 3 Then Pxl On y,x Else If count ≠ 2 Then Pxl Off y,x End If End For End For End While © Restore changed options set Graph("Axes", save[1]) set Graph("Grid", save[2]) set Graph("Labels", save[3])End Prgm Also see Conway's Game of Life/C Considering that the simplest implementation in C++ would lack any use of the object-oriented paradigm, this code was specifically written to demonstrate the various object-oriented features of C++.

;increment

randfill: stx $01 ;$200 for indirect ldx #$02 ;addressing stx $02randloop: lda $fe ;generate random and #$01 ;pixels on the sta ($01), Y ;screen jsr inc0103 cmp #$00 bne randloop lda $02 cmp #$06 bne randloop clearmem: lda #$df ;set $07df-$0a20 sta $01 ;to $#00 lda #$07 sta $02clearbyte: lda #$00 sta ($01), Y jsr inc0103 cmp #$20 bne clearbyte lda $02 cmp #$0a bne clearbyte starttick:copyscreen: lda #$00 ;set up source sta $01 ;pointer at sta $03 ;$01/$02 and lda #$02 ;dest pointer sta $02 ;at $03/$04 lda #$08 sta $04 ldy #$00copybyte: lda ($01), Y ;copy pixel to sta ($03), Y ;back buffer jsr inc0103 ;increment pointers cmp #$00 ;check to see bne copybyte ;if we're at $600 lda $02 ;if so, we've cmp #$06 ;copied the bne copybyte ;entire screen conway: lda #$df ;apply conway rules sta $01 ;reset the pointer sta $03 ;to $#01df/$#07df lda #$01 ;($200 - $21) sta $02 ;($800 - $21) lda #$07 sta $04onecell: lda #$00 ;process one cell ldy #$01 ;upper cell clc adc ($03), Y ldy #$41 ;lower cell clc adc ($03), Ychkleft: tax ;check to see lda $01 ;if we're at the and #$1f ;left edge tay txa cpy #$1f beq rightcellsleftcells: ldy #$00 ;upper-left cell clc adc ($03), Y ldy #$20 ;left cell clc adc ($03), Y ldy #$40 ;lower-left cell clc adc ($03), Ychkright: tax ;check to see lda $01 ;if we're at the and #$1f ;right edge tay txa cpy #$1e beq evaluaterightcells: ldy #$02 ;upper-right cell clc adc ($03), Y ldy #$22 ;right cell clc adc ($03), Y ldy #$42 ;lower-right cell clc adc ($03), Yevaluate: ldx #$01 ;evaluate total ldy #$21 ;for current cell cmp #$03 ;3 = alive beq storex ldx #$00 cmp #$02 ;2 = alive if bne storex ;c = alive lda ($03), Y and #$01 taxstorex: txa ;store to screen sta ($01), Y jsr inc0103 ;move to next cellconwayloop: cmp #$e0 ;if not last cell, bne onecell ;process next cell lda $02 cmp #$05 bne onecell jmp starttick ;run next tick inc0103: lda $01 ;increment $01 cmp #$ff ;and $03 as 16-bit bne onlyinc01 ;pointers inc $02 inc $04onlyinc01: inc $01 lda $01 sta $03 rts The solution uses one cell thick border around square Petri dish as uninhabited dire land. Sample output contains 3 generations of the blinker and 5 of the glider: See Conway's Game of Life/ALGOL 68 APL2 (Dialog) Example in one line APL \ 1130 example (very old APL dialect via simulator) APL1130From: APL \ 1130 Samples The following APL \ 1130 code will need APL385 font installed to display correctly. See Download APL TT Font ∇LIFE[⎕]∇[0] NG←LIFE CG; W[1] W←CG+(¯1⊖CG)+(1⊖CG)+(¯1⌽CG)+(1⌽CG)[2] W←W+(1⊖1⌽CG)+(¯1⊖1⌽CG)+(1⊖¯1⌽CG)+(¯1⊖¯1⌽CG)[3] NG←(3=W)+(CG∧4=W) ∇ RP←5 5⍴0 0 0 0 0 0 0 1 1 0 0 1 1 0 0 0 0 1 0 0 RP0 0 0 0 00 0 1 1 00 1 1 0 00 0 1 0 00 0 0 0 0 LIFE RP0 0 0 0 00 1 1 1 00 1 0 0 00 1 1 0 00 0 0 0 0 LIFE LIFE RP0 0 1 0 00 1 1 0 01 0 0 1 00 1 1 0 00 0 0 0 0 .................................................. One interacts with the Game of Life by creating an initial configuration and observing how it evolves. Although you should test your implementation on more complex examples such as the glider in a larger universe, show the action of the blinker (three adjoining cells in a row all alive), over three generations, in a 3 by 3 grid. (1,4)=TRUERETURN'' Count the number of neighbours of the point i,j' (Assume i/j +/- 1 will not fall out of world)'FUNCTION count_neighbours(i%,j%) LOCAL count%,l% count%=0 FOR l%=-1 TO 1 IF world! (i%+l%,j%+1) count%=count%+1 ENDIF NEXT l% IF world! (i%+1,j%) count%=count%+1 ENDIF RETURN count%ENDFUNC'' Update the world one step'PROCEDURE update_world LOCAL i%,j% ' compute neighbour counts and store FOR i%=1 TO 30 FOR j%=1 TO 30 ns%(i%,j%)[email protected]_neighbours(i%,j%) NEXT j% NEXT i% ' update the world cells FOR i%=1 TO 30 FOR j%=1 TO 30 IF world!

||

randfill: stx $01 ;$200 for indirect ldx #$02 ;addressing stx $02randloop: lda $fe ;generate random and #$01 ;pixels on the sta ($01), Y ;screen jsr inc0103 cmp #$00 bne randloop lda $02 cmp #$06 bne randloop clearmem: lda #$df ;set $07df-$0a20 sta $01 ;to $#00 lda #$07 sta $02clearbyte: lda #$00 sta ($01), Y jsr inc0103 cmp #$20 bne clearbyte lda $02 cmp #$0a bne clearbyte starttick:copyscreen: lda #$00 ;set up source sta $01 ;pointer at sta $03 ;$01/$02 and lda #$02 ;dest pointer sta $02 ;at $03/$04 lda #$08 sta $04 ldy #$00copybyte: lda ($01), Y ;copy pixel to sta ($03), Y ;back buffer jsr inc0103 ;increment pointers cmp #$00 ;check to see bne copybyte ;if we're at $600 lda $02 ;if so, we've cmp #$06 ;copied the bne copybyte ;entire screen conway: lda #$df ;apply conway rules sta $01 ;reset the pointer sta $03 ;to $#01df/$#07df lda #$01 ;($200 - $21) sta $02 ;($800 - $21) lda #$07 sta $04onecell: lda #$00 ;process one cell ldy #$01 ;upper cell clc adc ($03), Y ldy #$41 ;lower cell clc adc ($03), Ychkleft: tax ;check to see lda $01 ;if we're at the and #$1f ;left edge tay txa cpy #$1f beq rightcellsleftcells: ldy #$00 ;upper-left cell clc adc ($03), Y ldy #$20 ;left cell clc adc ($03), Y ldy #$40 ;lower-left cell clc adc ($03), Ychkright: tax ;check to see lda $01 ;if we're at the and #$1f ;right edge tay txa cpy #$1e beq evaluaterightcells: ldy #$02 ;upper-right cell clc adc ($03), Y ldy #$22 ;right cell clc adc ($03), Y ldy #$42 ;lower-right cell clc adc ($03), Yevaluate: ldx #$01 ;evaluate total ldy #$21 ;for current cell cmp #$03 ;3 = alive beq storex ldx #$00 cmp #$02 ;2 = alive if bne storex ;c = alive lda ($03), Y and #$01 taxstorex: txa ;store to screen sta ($01), Y jsr inc0103 ;move to next cellconwayloop: cmp #$e0 ;if not last cell, bne onecell ;process next cell lda $02 cmp #$05 bne onecell jmp starttick ;run next tick inc0103: lda $01 ;increment $01 cmp #$ff ;and $03 as 16-bit bne onlyinc01 ;pointers inc $02 inc $04onlyinc01: inc $01 lda $01 sta $03 rts The solution uses one cell thick border around square Petri dish as uninhabited dire land. Sample output contains 3 generations of the blinker and 5 of the glider: See Conway's Game of Life/ALGOL 68 APL2 (Dialog) Example in one line APL \ 1130 example (very old APL dialect via simulator) APL1130From: APL \ 1130 Samples The following APL \ 1130 code will need APL385 font installed to display correctly.

See Download APL TT Font ∇LIFE[⎕]∇[0] NG←LIFE CG; W[1] W←CG+(¯1⊖CG)+(1⊖CG)+(¯1⌽CG)+(1⌽CG)[2] W←W+(1⊖1⌽CG)+(¯1⊖1⌽CG)+(1⊖¯1⌽CG)+(¯1⊖¯1⌽CG)[3] NG←(3=W)+(CG∧4=W) ∇ RP←5 5⍴0 0 0 0 0 0 0 1 1 0 0 1 1 0 0 0 0 1 0 0 RP0 0 0 0 00 0 1 1 00 1 1 0 00 0 1 0 00 0 0 0 0 LIFE RP0 0 0 0 00 1 1 1 00 1 0 0 00 1 1 0 00 0 0 0 0 LIFE LIFE RP0 0 1 0 00 1 1 0 01 0 0 1 00 1 1 0 00 0 0 0 0 ..................................................

One interacts with the Game of Life by creating an initial configuration and observing how it evolves.

Although you should test your implementation on more complex examples such as the glider in a larger universe, show the action of the blinker (three adjoining cells in a row all alive), over three generations, in a 3 by 3 grid.

(1,4)=TRUERETURN'' Count the number of neighbours of the point i,j' (Assume i/j +/- 1 will not fall out of world)'FUNCTION count_neighbours(i%,j%) LOCAL count%,l% count%=0 FOR l%=-1 TO 1 IF world! (i%+l%,j%+1) count%=count%+1 ENDIF NEXT l% IF world! (i%+1,j%) count%=count%+1 ENDIF RETURN count%ENDFUNC'' Update the world one step'PROCEDURE update_world LOCAL i%,j% ' compute neighbour counts and store FOR i%=1 TO 30 FOR j%=1 TO 30 ns%(i%,j%)[email protected]_neighbours(i%,j%) NEXT j% NEXT i% ' update the world cells FOR i%=1 TO 30 FOR j%=1 TO 30 IF world!

Thus, while it is somewhat verbose, it fully simulates Conway's Game of Life and is relatively simple to expand to feature different starting shapes.

Define life(pattern) = Prgm Local x,y,nt,count,save,xl,yl,xh,yh Define nt(y,x) = when(pxl Test(y,x), 1, 0) {}→save set Graph("Axes", "Off")→save[1] set Graph("Grid", "Off")→save[2] set Graph("Labels", "Off")→save[3] Fn Off Plot Off Clr Draw If pattern = "blinker" Then 36→yl 40→yh 78→xl 82→xh Pxl On 36,80 Pxl On 38,80 Pxl On 40,80 Else If pattern = "glider" Then 30→yl 40→yh 76→xl 88→xh Pxl On 38,76 Pxl On 36,78 Pxl On 36,80 Pxl On 38,80 Pxl On 40,80 Else If pattern = "r" Then 38-5*2→yl 38+5*2→yh 80-5*2→xl 80+5*2→xh Pxl On 38,78 Pxl On 36,82 Pxl On 36,80 Pxl On 38,80 Pxl On 40,80 End If While get Key() = 0 © Expand upper-left corner to whole cell For y,yl,yh,2 For x,xl,xh,2 If pxl Test(y,x) Then Pxl On y+1,x Pxl On y+1,x+1 Pxl On y, x+1 Else Pxl Off y+1,x Pxl Off y+1,x+1 Pxl Off y, x+1 End If End For End For © Compute next generation For y,yl,yh,2 For x,xl,xh,2 nt(y-1,x-1) + nt(y-1,x) + nt(y-1,x+2) + nt(y,x-1) + nt(y+1,x+2) + nt(y+2,x-1) + nt(y+2,x+1) + nt(y+2,x+2) → count If count = 3 Then Pxl On y,x Else If count ≠ 2 Then Pxl Off y,x End If End For End For End While © Restore changed options set Graph("Axes", save[1]) set Graph("Grid", save[2]) set Graph("Labels", save[3])End Prgm Also see Conway's Game of Life/C Considering that the simplest implementation in C++ would lack any use of the object-oriented paradigm, this code was specifically written to demonstrate the various object-oriented features of C++.

cmp #$ff ;and as 16-bit bne onlyinc01 ;pointers inc inc onlyinc01: inc

randfill: stx $01 ;$200 for indirect ldx #$02 ;addressing stx $02randloop: lda $fe ;generate random and #$01 ;pixels on the sta ($01), Y ;screen jsr inc0103 cmp #$00 bne randloop lda $02 cmp #$06 bne randloop clearmem: lda #$df ;set $07df-$0a20 sta $01 ;to $#00 lda #$07 sta $02clearbyte: lda #$00 sta ($01), Y jsr inc0103 cmp #$20 bne clearbyte lda $02 cmp #$0a bne clearbyte starttick:copyscreen: lda #$00 ;set up source sta $01 ;pointer at sta $03 ;$01/$02 and lda #$02 ;dest pointer sta $02 ;at $03/$04 lda #$08 sta $04 ldy #$00copybyte: lda ($01), Y ;copy pixel to sta ($03), Y ;back buffer jsr inc0103 ;increment pointers cmp #$00 ;check to see bne copybyte ;if we're at $600 lda $02 ;if so, we've cmp #$06 ;copied the bne copybyte ;entire screen conway: lda #$df ;apply conway rules sta $01 ;reset the pointer sta $03 ;to $#01df/$#07df lda #$01 ;($200 - $21) sta $02 ;($800 - $21) lda #$07 sta $04onecell: lda #$00 ;process one cell ldy #$01 ;upper cell clc adc ($03), Y ldy #$41 ;lower cell clc adc ($03), Ychkleft: tax ;check to see lda $01 ;if we're at the and #$1f ;left edge tay txa cpy #$1f beq rightcellsleftcells: ldy #$00 ;upper-left cell clc adc ($03), Y ldy #$20 ;left cell clc adc ($03), Y ldy #$40 ;lower-left cell clc adc ($03), Ychkright: tax ;check to see lda $01 ;if we're at the and #$1f ;right edge tay txa cpy #$1e beq evaluaterightcells: ldy #$02 ;upper-right cell clc adc ($03), Y ldy #$22 ;right cell clc adc ($03), Y ldy #$42 ;lower-right cell clc adc ($03), Yevaluate: ldx #$01 ;evaluate total ldy #$21 ;for current cell cmp #$03 ;3 = alive beq storex ldx #$00 cmp #$02 ;2 = alive if bne storex ;c = alive lda ($03), Y and #$01 taxstorex: txa ;store to screen sta ($01), Y jsr inc0103 ;move to next cellconwayloop: cmp #$e0 ;if not last cell, bne onecell ;process next cell lda $02 cmp #$05 bne onecell jmp starttick ;run next tick inc0103: lda $01 ;increment $01 cmp #$ff ;and $03 as 16-bit bne onlyinc01 ;pointers inc $02 inc $04onlyinc01: inc $01 lda $01 sta $03 rts The solution uses one cell thick border around square Petri dish as uninhabited dire land. Sample output contains 3 generations of the blinker and 5 of the glider: See Conway's Game of Life/ALGOL 68 APL2 (Dialog) Example in one line APL \ 1130 example (very old APL dialect via simulator) APL1130From: APL \ 1130 Samples The following APL \ 1130 code will need APL385 font installed to display correctly. See Download APL TT Font ∇LIFE[⎕]∇[0] NG←LIFE CG; W[1] W←CG+(¯1⊖CG)+(1⊖CG)+(¯1⌽CG)+(1⌽CG)[2] W←W+(1⊖1⌽CG)+(¯1⊖1⌽CG)+(1⊖¯1⌽CG)+(¯1⊖¯1⌽CG)[3] NG←(3=W)+(CG∧4=W) ∇ RP←5 5⍴0 0 0 0 0 0 0 1 1 0 0 1 1 0 0 0 0 1 0 0 RP0 0 0 0 00 0 1 1 00 1 1 0 00 0 1 0 00 0 0 0 0 LIFE RP0 0 0 0 00 1 1 1 00 1 0 0 00 1 1 0 00 0 0 0 0 LIFE LIFE RP0 0 1 0 00 1 1 0 01 0 0 1 00 1 1 0 00 0 0 0 0 .................................................. One interacts with the Game of Life by creating an initial configuration and observing how it evolves. Although you should test your implementation on more complex examples such as the glider in a larger universe, show the action of the blinker (three adjoining cells in a row all alive), over three generations, in a 3 by 3 grid. (1,4)=TRUERETURN'' Count the number of neighbours of the point i,j' (Assume i/j +/- 1 will not fall out of world)'FUNCTION count_neighbours(i%,j%) LOCAL count%,l% count%=0 FOR l%=-1 TO 1 IF world! (i%+l%,j%+1) count%=count%+1 ENDIF NEXT l% IF world! (i%+1,j%) count%=count%+1 ENDIF RETURN count%ENDFUNC'' Update the world one step'PROCEDURE update_world LOCAL i%,j% ' compute neighbour counts and store FOR i%=1 TO 30 FOR j%=1 TO 30 ns%(i%,j%)[email protected]_neighbours(i%,j%) NEXT j% NEXT i% ' update the world cells FOR i%=1 TO 30 FOR j%=1 TO 30 IF world!

||

randfill: stx $01 ;$200 for indirect ldx #$02 ;addressing stx $02randloop: lda $fe ;generate random and #$01 ;pixels on the sta ($01), Y ;screen jsr inc0103 cmp #$00 bne randloop lda $02 cmp #$06 bne randloop clearmem: lda #$df ;set $07df-$0a20 sta $01 ;to $#00 lda #$07 sta $02clearbyte: lda #$00 sta ($01), Y jsr inc0103 cmp #$20 bne clearbyte lda $02 cmp #$0a bne clearbyte starttick:copyscreen: lda #$00 ;set up source sta $01 ;pointer at sta $03 ;$01/$02 and lda #$02 ;dest pointer sta $02 ;at $03/$04 lda #$08 sta $04 ldy #$00copybyte: lda ($01), Y ;copy pixel to sta ($03), Y ;back buffer jsr inc0103 ;increment pointers cmp #$00 ;check to see bne copybyte ;if we're at $600 lda $02 ;if so, we've cmp #$06 ;copied the bne copybyte ;entire screen conway: lda #$df ;apply conway rules sta $01 ;reset the pointer sta $03 ;to $#01df/$#07df lda #$01 ;($200 - $21) sta $02 ;($800 - $21) lda #$07 sta $04onecell: lda #$00 ;process one cell ldy #$01 ;upper cell clc adc ($03), Y ldy #$41 ;lower cell clc adc ($03), Ychkleft: tax ;check to see lda $01 ;if we're at the and #$1f ;left edge tay txa cpy #$1f beq rightcellsleftcells: ldy #$00 ;upper-left cell clc adc ($03), Y ldy #$20 ;left cell clc adc ($03), Y ldy #$40 ;lower-left cell clc adc ($03), Ychkright: tax ;check to see lda $01 ;if we're at the and #$1f ;right edge tay txa cpy #$1e beq evaluaterightcells: ldy #$02 ;upper-right cell clc adc ($03), Y ldy #$22 ;right cell clc adc ($03), Y ldy #$42 ;lower-right cell clc adc ($03), Yevaluate: ldx #$01 ;evaluate total ldy #$21 ;for current cell cmp #$03 ;3 = alive beq storex ldx #$00 cmp #$02 ;2 = alive if bne storex ;c = alive lda ($03), Y and #$01 taxstorex: txa ;store to screen sta ($01), Y jsr inc0103 ;move to next cellconwayloop: cmp #$e0 ;if not last cell, bne onecell ;process next cell lda $02 cmp #$05 bne onecell jmp starttick ;run next tick inc0103: lda $01 ;increment $01 cmp #$ff ;and $03 as 16-bit bne onlyinc01 ;pointers inc $02 inc $04onlyinc01: inc $01 lda $01 sta $03 rts The solution uses one cell thick border around square Petri dish as uninhabited dire land. Sample output contains 3 generations of the blinker and 5 of the glider: See Conway's Game of Life/ALGOL 68 APL2 (Dialog) Example in one line APL \ 1130 example (very old APL dialect via simulator) APL1130From: APL \ 1130 Samples The following APL \ 1130 code will need APL385 font installed to display correctly.

See Download APL TT Font ∇LIFE[⎕]∇[0] NG←LIFE CG; W[1] W←CG+(¯1⊖CG)+(1⊖CG)+(¯1⌽CG)+(1⌽CG)[2] W←W+(1⊖1⌽CG)+(¯1⊖1⌽CG)+(1⊖¯1⌽CG)+(¯1⊖¯1⌽CG)[3] NG←(3=W)+(CG∧4=W) ∇ RP←5 5⍴0 0 0 0 0 0 0 1 1 0 0 1 1 0 0 0 0 1 0 0 RP0 0 0 0 00 0 1 1 00 1 1 0 00 0 1 0 00 0 0 0 0 LIFE RP0 0 0 0 00 1 1 1 00 1 0 0 00 1 1 0 00 0 0 0 0 LIFE LIFE RP0 0 1 0 00 1 1 0 01 0 0 1 00 1 1 0 00 0 0 0 0 ..................................................

One interacts with the Game of Life by creating an initial configuration and observing how it evolves.

Although you should test your implementation on more complex examples such as the glider in a larger universe, show the action of the blinker (three adjoining cells in a row all alive), over three generations, in a 3 by 3 grid.

(1,4)=TRUERETURN'' Count the number of neighbours of the point i,j' (Assume i/j +/- 1 will not fall out of world)'FUNCTION count_neighbours(i%,j%) LOCAL count%,l% count%=0 FOR l%=-1 TO 1 IF world! (i%+l%,j%+1) count%=count%+1 ENDIF NEXT l% IF world! (i%+1,j%) count%=count%+1 ENDIF RETURN count%ENDFUNC'' Update the world one step'PROCEDURE update_world LOCAL i%,j% ' compute neighbour counts and store FOR i%=1 TO 30 FOR j%=1 TO 30 ns%(i%,j%)[email protected]_neighbours(i%,j%) NEXT j% NEXT i% ' update the world cells FOR i%=1 TO 30 FOR j%=1 TO 30 IF world!

Thus, while it is somewhat verbose, it fully simulates Conway's Game of Life and is relatively simple to expand to feature different starting shapes.

Define life(pattern) = Prgm Local x,y,nt,count,save,xl,yl,xh,yh Define nt(y,x) = when(pxl Test(y,x), 1, 0) {}→save set Graph("Axes", "Off")→save[1] set Graph("Grid", "Off")→save[2] set Graph("Labels", "Off")→save[3] Fn Off Plot Off Clr Draw If pattern = "blinker" Then 36→yl 40→yh 78→xl 82→xh Pxl On 36,80 Pxl On 38,80 Pxl On 40,80 Else If pattern = "glider" Then 30→yl 40→yh 76→xl 88→xh Pxl On 38,76 Pxl On 36,78 Pxl On 36,80 Pxl On 38,80 Pxl On 40,80 Else If pattern = "r" Then 38-5*2→yl 38+5*2→yh 80-5*2→xl 80+5*2→xh Pxl On 38,78 Pxl On 36,82 Pxl On 36,80 Pxl On 38,80 Pxl On 40,80 End If While get Key() = 0 © Expand upper-left corner to whole cell For y,yl,yh,2 For x,xl,xh,2 If pxl Test(y,x) Then Pxl On y+1,x Pxl On y+1,x+1 Pxl On y, x+1 Else Pxl Off y+1,x Pxl Off y+1,x+1 Pxl Off y, x+1 End If End For End For © Compute next generation For y,yl,yh,2 For x,xl,xh,2 nt(y-1,x-1) + nt(y-1,x) + nt(y-1,x+2) + nt(y,x-1) + nt(y+1,x+2) + nt(y+2,x-1) + nt(y+2,x+1) + nt(y+2,x+2) → count If count = 3 Then Pxl On y,x Else If count ≠ 2 Then Pxl Off y,x End If End For End For End While © Restore changed options set Graph("Axes", save[1]) set Graph("Grid", save[2]) set Graph("Labels", save[3])End Prgm Also see Conway's Game of Life/C Considering that the simplest implementation in C++ would lack any use of the object-oriented paradigm, this code was specifically written to demonstrate the various object-oriented features of C++.

lda

randfill: stx $01 ;$200 for indirect ldx #$02 ;addressing stx $02randloop: lda $fe ;generate random and #$01 ;pixels on the sta ($01), Y ;screen jsr inc0103 cmp #$00 bne randloop lda $02 cmp #$06 bne randloop clearmem: lda #$df ;set $07df-$0a20 sta $01 ;to $#00 lda #$07 sta $02clearbyte: lda #$00 sta ($01), Y jsr inc0103 cmp #$20 bne clearbyte lda $02 cmp #$0a bne clearbyte starttick:copyscreen: lda #$00 ;set up source sta $01 ;pointer at sta $03 ;$01/$02 and lda #$02 ;dest pointer sta $02 ;at $03/$04 lda #$08 sta $04 ldy #$00copybyte: lda ($01), Y ;copy pixel to sta ($03), Y ;back buffer jsr inc0103 ;increment pointers cmp #$00 ;check to see bne copybyte ;if we're at $600 lda $02 ;if so, we've cmp #$06 ;copied the bne copybyte ;entire screen conway: lda #$df ;apply conway rules sta $01 ;reset the pointer sta $03 ;to $#01df/$#07df lda #$01 ;($200 - $21) sta $02 ;($800 - $21) lda #$07 sta $04onecell: lda #$00 ;process one cell ldy #$01 ;upper cell clc adc ($03), Y ldy #$41 ;lower cell clc adc ($03), Ychkleft: tax ;check to see lda $01 ;if we're at the and #$1f ;left edge tay txa cpy #$1f beq rightcellsleftcells: ldy #$00 ;upper-left cell clc adc ($03), Y ldy #$20 ;left cell clc adc ($03), Y ldy #$40 ;lower-left cell clc adc ($03), Ychkright: tax ;check to see lda $01 ;if we're at the and #$1f ;right edge tay txa cpy #$1e beq evaluaterightcells: ldy #$02 ;upper-right cell clc adc ($03), Y ldy #$22 ;right cell clc adc ($03), Y ldy #$42 ;lower-right cell clc adc ($03), Yevaluate: ldx #$01 ;evaluate total ldy #$21 ;for current cell cmp #$03 ;3 = alive beq storex ldx #$00 cmp #$02 ;2 = alive if bne storex ;c = alive lda ($03), Y and #$01 taxstorex: txa ;store to screen sta ($01), Y jsr inc0103 ;move to next cellconwayloop: cmp #$e0 ;if not last cell, bne onecell ;process next cell lda $02 cmp #$05 bne onecell jmp starttick ;run next tick inc0103: lda $01 ;increment $01 cmp #$ff ;and $03 as 16-bit bne onlyinc01 ;pointers inc $02 inc $04onlyinc01: inc $01 lda $01 sta $03 rts The solution uses one cell thick border around square Petri dish as uninhabited dire land. Sample output contains 3 generations of the blinker and 5 of the glider: See Conway's Game of Life/ALGOL 68 APL2 (Dialog) Example in one line APL \ 1130 example (very old APL dialect via simulator) APL1130From: APL \ 1130 Samples The following APL \ 1130 code will need APL385 font installed to display correctly. See Download APL TT Font ∇LIFE[⎕]∇[0] NG←LIFE CG; W[1] W←CG+(¯1⊖CG)+(1⊖CG)+(¯1⌽CG)+(1⌽CG)[2] W←W+(1⊖1⌽CG)+(¯1⊖1⌽CG)+(1⊖¯1⌽CG)+(¯1⊖¯1⌽CG)[3] NG←(3=W)+(CG∧4=W) ∇ RP←5 5⍴0 0 0 0 0 0 0 1 1 0 0 1 1 0 0 0 0 1 0 0 RP0 0 0 0 00 0 1 1 00 1 1 0 00 0 1 0 00 0 0 0 0 LIFE RP0 0 0 0 00 1 1 1 00 1 0 0 00 1 1 0 00 0 0 0 0 LIFE LIFE RP0 0 1 0 00 1 1 0 01 0 0 1 00 1 1 0 00 0 0 0 0 .................................................. One interacts with the Game of Life by creating an initial configuration and observing how it evolves. Although you should test your implementation on more complex examples such as the glider in a larger universe, show the action of the blinker (three adjoining cells in a row all alive), over three generations, in a 3 by 3 grid. (1,4)=TRUERETURN'' Count the number of neighbours of the point i,j' (Assume i/j +/- 1 will not fall out of world)'FUNCTION count_neighbours(i%,j%) LOCAL count%,l% count%=0 FOR l%=-1 TO 1 IF world! (i%+l%,j%+1) count%=count%+1 ENDIF NEXT l% IF world! (i%+1,j%) count%=count%+1 ENDIF RETURN count%ENDFUNC'' Update the world one step'PROCEDURE update_world LOCAL i%,j% ' compute neighbour counts and store FOR i%=1 TO 30 FOR j%=1 TO 30 ns%(i%,j%)[email protected]_neighbours(i%,j%) NEXT j% NEXT i% ' update the world cells FOR i%=1 TO 30 FOR j%=1 TO 30 IF world!

||

randfill: stx $01 ;$200 for indirect ldx #$02 ;addressing stx $02randloop: lda $fe ;generate random and #$01 ;pixels on the sta ($01), Y ;screen jsr inc0103 cmp #$00 bne randloop lda $02 cmp #$06 bne randloop clearmem: lda #$df ;set $07df-$0a20 sta $01 ;to $#00 lda #$07 sta $02clearbyte: lda #$00 sta ($01), Y jsr inc0103 cmp #$20 bne clearbyte lda $02 cmp #$0a bne clearbyte starttick:copyscreen: lda #$00 ;set up source sta $01 ;pointer at sta $03 ;$01/$02 and lda #$02 ;dest pointer sta $02 ;at $03/$04 lda #$08 sta $04 ldy #$00copybyte: lda ($01), Y ;copy pixel to sta ($03), Y ;back buffer jsr inc0103 ;increment pointers cmp #$00 ;check to see bne copybyte ;if we're at $600 lda $02 ;if so, we've cmp #$06 ;copied the bne copybyte ;entire screen conway: lda #$df ;apply conway rules sta $01 ;reset the pointer sta $03 ;to $#01df/$#07df lda #$01 ;($200 - $21) sta $02 ;($800 - $21) lda #$07 sta $04onecell: lda #$00 ;process one cell ldy #$01 ;upper cell clc adc ($03), Y ldy #$41 ;lower cell clc adc ($03), Ychkleft: tax ;check to see lda $01 ;if we're at the and #$1f ;left edge tay txa cpy #$1f beq rightcellsleftcells: ldy #$00 ;upper-left cell clc adc ($03), Y ldy #$20 ;left cell clc adc ($03), Y ldy #$40 ;lower-left cell clc adc ($03), Ychkright: tax ;check to see lda $01 ;if we're at the and #$1f ;right edge tay txa cpy #$1e beq evaluaterightcells: ldy #$02 ;upper-right cell clc adc ($03), Y ldy #$22 ;right cell clc adc ($03), Y ldy #$42 ;lower-right cell clc adc ($03), Yevaluate: ldx #$01 ;evaluate total ldy #$21 ;for current cell cmp #$03 ;3 = alive beq storex ldx #$00 cmp #$02 ;2 = alive if bne storex ;c = alive lda ($03), Y and #$01 taxstorex: txa ;store to screen sta ($01), Y jsr inc0103 ;move to next cellconwayloop: cmp #$e0 ;if not last cell, bne onecell ;process next cell lda $02 cmp #$05 bne onecell jmp starttick ;run next tick inc0103: lda $01 ;increment $01 cmp #$ff ;and $03 as 16-bit bne onlyinc01 ;pointers inc $02 inc $04onlyinc01: inc $01 lda $01 sta $03 rts The solution uses one cell thick border around square Petri dish as uninhabited dire land. Sample output contains 3 generations of the blinker and 5 of the glider: See Conway's Game of Life/ALGOL 68 APL2 (Dialog) Example in one line APL \ 1130 example (very old APL dialect via simulator) APL1130From: APL \ 1130 Samples The following APL \ 1130 code will need APL385 font installed to display correctly.

See Download APL TT Font ∇LIFE[⎕]∇[0] NG←LIFE CG; W[1] W←CG+(¯1⊖CG)+(1⊖CG)+(¯1⌽CG)+(1⌽CG)[2] W←W+(1⊖1⌽CG)+(¯1⊖1⌽CG)+(1⊖¯1⌽CG)+(¯1⊖¯1⌽CG)[3] NG←(3=W)+(CG∧4=W) ∇ RP←5 5⍴0 0 0 0 0 0 0 1 1 0 0 1 1 0 0 0 0 1 0 0 RP0 0 0 0 00 0 1 1 00 1 1 0 00 0 1 0 00 0 0 0 0 LIFE RP0 0 0 0 00 1 1 1 00 1 0 0 00 1 1 0 00 0 0 0 0 LIFE LIFE RP0 0 1 0 00 1 1 0 01 0 0 1 00 1 1 0 00 0 0 0 0 ..................................................

One interacts with the Game of Life by creating an initial configuration and observing how it evolves.

Although you should test your implementation on more complex examples such as the glider in a larger universe, show the action of the blinker (three adjoining cells in a row all alive), over three generations, in a 3 by 3 grid.

(1,4)=TRUERETURN'' Count the number of neighbours of the point i,j' (Assume i/j +/- 1 will not fall out of world)'FUNCTION count_neighbours(i%,j%) LOCAL count%,l% count%=0 FOR l%=-1 TO 1 IF world! (i%+l%,j%+1) count%=count%+1 ENDIF NEXT l% IF world! (i%+1,j%) count%=count%+1 ENDIF RETURN count%ENDFUNC'' Update the world one step'PROCEDURE update_world LOCAL i%,j% ' compute neighbour counts and store FOR i%=1 TO 30 FOR j%=1 TO 30 ns%(i%,j%)[email protected]_neighbours(i%,j%) NEXT j% NEXT i% ' update the world cells FOR i%=1 TO 30 FOR j%=1 TO 30 IF world!

Thus, while it is somewhat verbose, it fully simulates Conway's Game of Life and is relatively simple to expand to feature different starting shapes.

Define life(pattern) = Prgm Local x,y,nt,count,save,xl,yl,xh,yh Define nt(y,x) = when(pxl Test(y,x), 1, 0) {}→save set Graph("Axes", "Off")→save[1] set Graph("Grid", "Off")→save[2] set Graph("Labels", "Off")→save[3] Fn Off Plot Off Clr Draw If pattern = "blinker" Then 36→yl 40→yh 78→xl 82→xh Pxl On 36,80 Pxl On 38,80 Pxl On 40,80 Else If pattern = "glider" Then 30→yl 40→yh 76→xl 88→xh Pxl On 38,76 Pxl On 36,78 Pxl On 36,80 Pxl On 38,80 Pxl On 40,80 Else If pattern = "r" Then 38-5*2→yl 38+5*2→yh 80-5*2→xl 80+5*2→xh Pxl On 38,78 Pxl On 36,82 Pxl On 36,80 Pxl On 38,80 Pxl On 40,80 End If While get Key() = 0 © Expand upper-left corner to whole cell For y,yl,yh,2 For x,xl,xh,2 If pxl Test(y,x) Then Pxl On y+1,x Pxl On y+1,x+1 Pxl On y, x+1 Else Pxl Off y+1,x Pxl Off y+1,x+1 Pxl Off y, x+1 End If End For End For © Compute next generation For y,yl,yh,2 For x,xl,xh,2 nt(y-1,x-1) + nt(y-1,x) + nt(y-1,x+2) + nt(y,x-1) + nt(y+1,x+2) + nt(y+2,x-1) + nt(y+2,x+1) + nt(y+2,x+2) → count If count = 3 Then Pxl On y,x Else If count ≠ 2 Then Pxl Off y,x End If End For End For End While © Restore changed options set Graph("Axes", save[1]) set Graph("Grid", save[2]) set Graph("Labels", save[3])End Prgm Also see Conway's Game of Life/C Considering that the simplest implementation in C++ would lack any use of the object-oriented paradigm, this code was specifically written to demonstrate the various object-oriented features of C++.

sta rts The solution uses one cell thick border around square Petri dish as uninhabited dire land. Sample output contains 3 generations of the blinker and 5 of the glider: See Conway's Game of Life/ALGOL 68 APL2 (Dialog) Example in one line APL \ 1130 example (very old APL dialect via simulator) APL1130From: APL \ 1130 Samples The following APL \ 1130 code will need APL385 font installed to display correctly.

See Download APL TT Font ∇LIFE[⎕]∇[0] NG←LIFE CG; W[1] W←CG+(¯1⊖CG)+(1⊖CG)+(¯1⌽CG)+(1⌽CG)[2] W←W+(1⊖1⌽CG)+(¯1⊖1⌽CG)+(1⊖¯1⌽CG)+(¯1⊖¯1⌽CG)[3] NG←(3=W)+(CG∧4=W) ∇ RP←5 5⍴0 0 0 0 0 0 0 1 1 0 0 1 1 0 0 0 0 1 0 0 RP0 0 0 0 00 0 1 1 00 1 1 0 00 0 1 0 00 0 0 0 0 LIFE RP0 0 0 0 00 1 1 1 00 1 0 0 00 1 1 0 00 0 0 0 0 LIFE LIFE RP0 0 1 0 00 1 1 0 01 0 0 1 00 1 1 0 00 0 0 0 0 ..................................................

One interacts with the Game of Life by creating an initial configuration and observing how it evolves.

Although you should test your implementation on more complex examples such as the glider in a larger universe, show the action of the blinker (three adjoining cells in a row all alive), over three generations, in a 3 by 3 grid.

(1,4)=TRUERETURN'' Count the number of neighbours of the point i,j' (Assume i/j +/- 1 will not fall out of world)'FUNCTION count_neighbours(i%,j%) LOCAL count%,l% count%=0 FOR l%=-1 TO 1 IF world! (i%+l%,j%+1) count%=count%+1 ENDIF NEXT l% IF world! (i%+1,j%) count%=count%+1 ENDIF RETURN count%ENDFUNC'' Update the world one step'PROCEDURE update_world LOCAL i%,j% ' compute neighbour counts and store FOR i%=1 TO 30 FOR j%=1 TO 30 ns%(i%,j%)[email protected]_neighbours(i%,j%) NEXT j% NEXT i% ' update the world cells FOR i%=1 TO 30 FOR j%=1 TO 30 IF world!

Thus, while it is somewhat verbose, it fully simulates Conway's Game of Life and is relatively simple to expand to feature different starting shapes.

Define life(pattern) = Prgm Local x,y,nt,count,save,xl,yl,xh,yh Define nt(y,x) = when(pxl Test(y,x), 1, 0) {}→save set Graph("Axes", "Off")→save[1] set Graph("Grid", "Off")→save[2] set Graph("Labels", "Off")→save[3] Fn Off Plot Off Clr Draw If pattern = "blinker" Then 36→yl 40→yh 78→xl 82→xh Pxl On 36,80 Pxl On 38,80 Pxl On 40,80 Else If pattern = "glider" Then 30→yl 40→yh 76→xl 88→xh Pxl On 38,76 Pxl On 36,78 Pxl On 36,80 Pxl On 38,80 Pxl On 40,80 Else If pattern = "r" Then 38-5*2→yl 38+5*2→yh 80-5*2→xl 80+5*2→xh Pxl On 38,78 Pxl On 36,82 Pxl On 36,80 Pxl On 38,80 Pxl On 40,80 End If While get Key() = 0 © Expand upper-left corner to whole cell For y,yl,yh,2 For x,xl,xh,2 If pxl Test(y,x) Then Pxl On y+1,x Pxl On y+1,x+1 Pxl On y, x+1 Else Pxl Off y+1,x Pxl Off y+1,x+1 Pxl Off y, x+1 End If End For End For © Compute next generation For y,yl,yh,2 For x,xl,xh,2 nt(y-1,x-1) + nt(y-1,x) + nt(y-1,x+2) + nt(y,x-1) + nt(y+1,x+2) + nt(y+2,x-1) + nt(y+2,x+1) + nt(y+2,x+2) → count If count = 3 Then Pxl On y,x Else If count ≠ 2 Then Pxl Off y,x End If End For End For End While © Restore changed options set Graph("Axes", save[1]) set Graph("Grid", save[2]) set Graph("Labels", save[3])End Prgm Also see Conway's Game of Life/C Considering that the simplest implementation in C++ would lack any use of the object-oriented paradigm, this code was specifically written to demonstrate the various object-oriented features of C++.

bne randloop lda cmp # bne randloop clearmem: lda #$df ;set df-[[

randfill: stx $01 ;$200 for indirect ldx #$02 ;addressing stx $02randloop: lda $fe ;generate random and #$01 ;pixels on the sta ($01), Y ;screen jsr inc0103 cmp #$00 bne randloop lda $02 cmp #$06 bne randloop clearmem: lda #$df ;set $07df-$0a20 sta $01 ;to $#00 lda #$07 sta $02clearbyte: lda #$00 sta ($01), Y jsr inc0103 cmp #$20 bne clearbyte lda $02 cmp #$0a bne clearbyte starttick:copyscreen: lda #$00 ;set up source sta $01 ;pointer at sta $03 ;$01/$02 and lda #$02 ;dest pointer sta $02 ;at $03/$04 lda #$08 sta $04 ldy #$00copybyte: lda ($01), Y ;copy pixel to sta ($03), Y ;back buffer jsr inc0103 ;increment pointers cmp #$00 ;check to see bne copybyte ;if we're at $600 lda $02 ;if so, we've cmp #$06 ;copied the bne copybyte ;entire screen conway: lda #$df ;apply conway rules sta $01 ;reset the pointer sta $03 ;to $#01df/$#07df lda #$01 ;($200 - $21) sta $02 ;($800 - $21) lda #$07 sta $04onecell: lda #$00 ;process one cell ldy #$01 ;upper cell clc adc ($03), Y ldy #$41 ;lower cell clc adc ($03), Ychkleft: tax ;check to see lda $01 ;if we're at the and #$1f ;left edge tay txa cpy #$1f beq rightcellsleftcells: ldy #$00 ;upper-left cell clc adc ($03), Y ldy #$20 ;left cell clc adc ($03), Y ldy #$40 ;lower-left cell clc adc ($03), Ychkright: tax ;check to see lda $01 ;if we're at the and #$1f ;right edge tay txa cpy #$1e beq evaluaterightcells: ldy #$02 ;upper-right cell clc adc ($03), Y ldy #$22 ;right cell clc adc ($03), Y ldy #$42 ;lower-right cell clc adc ($03), Yevaluate: ldx #$01 ;evaluate total ldy #$21 ;for current cell cmp #$03 ;3 = alive beq storex ldx #$00 cmp #$02 ;2 = alive if bne storex ;c = alive lda ($03), Y and #$01 taxstorex: txa ;store to screen sta ($01), Y jsr inc0103 ;move to next cellconwayloop: cmp #$e0 ;if not last cell, bne onecell ;process next cell lda $02 cmp #$05 bne onecell jmp starttick ;run next tick inc0103: lda $01 ;increment $01 cmp #$ff ;and $03 as 16-bit bne onlyinc01 ;pointers inc $02 inc $04onlyinc01: inc $01 lda $01 sta $03 rts The solution uses one cell thick border around square Petri dish as uninhabited dire land. Sample output contains 3 generations of the blinker and 5 of the glider: See Conway's Game of Life/ALGOL 68 APL2 (Dialog) Example in one line APL \ 1130 example (very old APL dialect via simulator) APL1130From: APL \ 1130 Samples The following APL \ 1130 code will need APL385 font installed to display correctly. See Download APL TT Font ∇LIFE[⎕]∇[0] NG←LIFE CG; W[1] W←CG+(¯1⊖CG)+(1⊖CG)+(¯1⌽CG)+(1⌽CG)[2] W←W+(1⊖1⌽CG)+(¯1⊖1⌽CG)+(1⊖¯1⌽CG)+(¯1⊖¯1⌽CG)[3] NG←(3=W)+(CG∧4=W) ∇ RP←5 5⍴0 0 0 0 0 0 0 1 1 0 0 1 1 0 0 0 0 1 0 0 RP0 0 0 0 00 0 1 1 00 1 1 0 00 0 1 0 00 0 0 0 0 LIFE RP0 0 0 0 00 1 1 1 00 1 0 0 00 1 1 0 00 0 0 0 0 LIFE LIFE RP0 0 1 0 00 1 1 0 01 0 0 1 00 1 1 0 00 0 0 0 0 .................................................. One interacts with the Game of Life by creating an initial configuration and observing how it evolves. Although you should test your implementation on more complex examples such as the glider in a larger universe, show the action of the blinker (three adjoining cells in a row all alive), over three generations, in a 3 by 3 grid. (1,4)=TRUERETURN'' Count the number of neighbours of the point i,j' (Assume i/j +/- 1 will not fall out of world)'FUNCTION count_neighbours(i%,j%) LOCAL count%,l% count%=0 FOR l%=-1 TO 1 IF world! (i%+l%,j%+1) count%=count%+1 ENDIF NEXT l% IF world! (i%+1,j%) count%=count%+1 ENDIF RETURN count%ENDFUNC'' Update the world one step'PROCEDURE update_world LOCAL i%,j% ' compute neighbour counts and store FOR i%=1 TO 30 FOR j%=1 TO 30 ns%(i%,j%)[email protected]_neighbours(i%,j%) NEXT j% NEXT i% ' update the world cells FOR i%=1 TO 30 FOR j%=1 TO 30 IF world!

||

randfill: stx $01 ;$200 for indirect ldx #$02 ;addressing stx $02randloop: lda $fe ;generate random and #$01 ;pixels on the sta ($01), Y ;screen jsr inc0103 cmp #$00 bne randloop lda $02 cmp #$06 bne randloop clearmem: lda #$df ;set $07df-$0a20 sta $01 ;to $#00 lda #$07 sta $02clearbyte: lda #$00 sta ($01), Y jsr inc0103 cmp #$20 bne clearbyte lda $02 cmp #$0a bne clearbyte starttick:copyscreen: lda #$00 ;set up source sta $01 ;pointer at sta $03 ;$01/$02 and lda #$02 ;dest pointer sta $02 ;at $03/$04 lda #$08 sta $04 ldy #$00copybyte: lda ($01), Y ;copy pixel to sta ($03), Y ;back buffer jsr inc0103 ;increment pointers cmp #$00 ;check to see bne copybyte ;if we're at $600 lda $02 ;if so, we've cmp #$06 ;copied the bne copybyte ;entire screen conway: lda #$df ;apply conway rules sta $01 ;reset the pointer sta $03 ;to $#01df/$#07df lda #$01 ;($200 - $21) sta $02 ;($800 - $21) lda #$07 sta $04onecell: lda #$00 ;process one cell ldy #$01 ;upper cell clc adc ($03), Y ldy #$41 ;lower cell clc adc ($03), Ychkleft: tax ;check to see lda $01 ;if we're at the and #$1f ;left edge tay txa cpy #$1f beq rightcellsleftcells: ldy #$00 ;upper-left cell clc adc ($03), Y ldy #$20 ;left cell clc adc ($03), Y ldy #$40 ;lower-left cell clc adc ($03), Ychkright: tax ;check to see lda $01 ;if we're at the and #$1f ;right edge tay txa cpy #$1e beq evaluaterightcells: ldy #$02 ;upper-right cell clc adc ($03), Y ldy #$22 ;right cell clc adc ($03), Y ldy #$42 ;lower-right cell clc adc ($03), Yevaluate: ldx #$01 ;evaluate total ldy #$21 ;for current cell cmp #$03 ;3 = alive beq storex ldx #$00 cmp #$02 ;2 = alive if bne storex ;c = alive lda ($03), Y and #$01 taxstorex: txa ;store to screen sta ($01), Y jsr inc0103 ;move to next cellconwayloop: cmp #$e0 ;if not last cell, bne onecell ;process next cell lda $02 cmp #$05 bne onecell jmp starttick ;run next tick inc0103: lda $01 ;increment $01 cmp #$ff ;and $03 as 16-bit bne onlyinc01 ;pointers inc $02 inc $04onlyinc01: inc $01 lda $01 sta $03 rts The solution uses one cell thick border around square Petri dish as uninhabited dire land. Sample output contains 3 generations of the blinker and 5 of the glider: See Conway's Game of Life/ALGOL 68 APL2 (Dialog) Example in one line APL \ 1130 example (very old APL dialect via simulator) APL1130From: APL \ 1130 Samples The following APL \ 1130 code will need APL385 font installed to display correctly.

See Download APL TT Font ∇LIFE[⎕]∇[0] NG←LIFE CG; W[1] W←CG+(¯1⊖CG)+(1⊖CG)+(¯1⌽CG)+(1⌽CG)[2] W←W+(1⊖1⌽CG)+(¯1⊖1⌽CG)+(1⊖¯1⌽CG)+(¯1⊖¯1⌽CG)[3] NG←(3=W)+(CG∧4=W) ∇ RP←5 5⍴0 0 0 0 0 0 0 1 1 0 0 1 1 0 0 0 0 1 0 0 RP0 0 0 0 00 0 1 1 00 1 1 0 00 0 1 0 00 0 0 0 0 LIFE RP0 0 0 0 00 1 1 1 00 1 0 0 00 1 1 0 00 0 0 0 0 LIFE LIFE RP0 0 1 0 00 1 1 0 01 0 0 1 00 1 1 0 00 0 0 0 0 ..................................................

One interacts with the Game of Life by creating an initial configuration and observing how it evolves.

Although you should test your implementation on more complex examples such as the glider in a larger universe, show the action of the blinker (three adjoining cells in a row all alive), over three generations, in a 3 by 3 grid.

(1,4)=TRUERETURN'' Count the number of neighbours of the point i,j' (Assume i/j +/- 1 will not fall out of world)'FUNCTION count_neighbours(i%,j%) LOCAL count%,l% count%=0 FOR l%=-1 TO 1 IF world! (i%+l%,j%+1) count%=count%+1 ENDIF NEXT l% IF world! (i%+1,j%) count%=count%+1 ENDIF RETURN count%ENDFUNC'' Update the world one step'PROCEDURE update_world LOCAL i%,j% ' compute neighbour counts and store FOR i%=1 TO 30 FOR j%=1 TO 30 ns%(i%,j%)[email protected]_neighbours(i%,j%) NEXT j% NEXT i% ' update the world cells FOR i%=1 TO 30 FOR j%=1 TO 30 IF world!

Thus, while it is somewhat verbose, it fully simulates Conway's Game of Life and is relatively simple to expand to feature different starting shapes.

Define life(pattern) = Prgm Local x,y,nt,count,save,xl,yl,xh,yh Define nt(y,x) = when(pxl Test(y,x), 1, 0) {}→save set Graph("Axes", "Off")→save[1] set Graph("Grid", "Off")→save[2] set Graph("Labels", "Off")→save[3] Fn Off Plot Off Clr Draw If pattern = "blinker" Then 36→yl 40→yh 78→xl 82→xh Pxl On 36,80 Pxl On 38,80 Pxl On 40,80 Else If pattern = "glider" Then 30→yl 40→yh 76→xl 88→xh Pxl On 38,76 Pxl On 36,78 Pxl On 36,80 Pxl On 38,80 Pxl On 40,80 Else If pattern = "r" Then 38-5*2→yl 38+5*2→yh 80-5*2→xl 80+5*2→xh Pxl On 38,78 Pxl On 36,82 Pxl On 36,80 Pxl On 38,80 Pxl On 40,80 End If While get Key() = 0 © Expand upper-left corner to whole cell For y,yl,yh,2 For x,xl,xh,2 If pxl Test(y,x) Then Pxl On y+1,x Pxl On y+1,x+1 Pxl On y, x+1 Else Pxl Off y+1,x Pxl Off y+1,x+1 Pxl Off y, x+1 End If End For End For © Compute next generation For y,yl,yh,2 For x,xl,xh,2 nt(y-1,x-1) + nt(y-1,x) + nt(y-1,x+2) + nt(y,x-1) + nt(y+1,x+2) + nt(y+2,x-1) + nt(y+2,x+1) + nt(y+2,x+2) → count If count = 3 Then Pxl On y,x Else If count ≠ 2 Then Pxl Off y,x End If End For End For End While © Restore changed options set Graph("Axes", save[1]) set Graph("Grid", save[2]) set Graph("Labels", save[3])End Prgm Also see Conway's Game of Life/C Considering that the simplest implementation in C++ would lack any use of the object-oriented paradigm, this code was specifically written to demonstrate the various object-oriented features of C++.

]]a20 sta

randfill: stx $01 ;$200 for indirect ldx #$02 ;addressing stx $02randloop: lda $fe ;generate random and #$01 ;pixels on the sta ($01), Y ;screen jsr inc0103 cmp #$00 bne randloop lda $02 cmp #$06 bne randloop clearmem: lda #$df ;set $07df-$0a20 sta $01 ;to $#00 lda #$07 sta $02clearbyte: lda #$00 sta ($01), Y jsr inc0103 cmp #$20 bne clearbyte lda $02 cmp #$0a bne clearbyte starttick:copyscreen: lda #$00 ;set up source sta $01 ;pointer at sta $03 ;$01/$02 and lda #$02 ;dest pointer sta $02 ;at $03/$04 lda #$08 sta $04 ldy #$00copybyte: lda ($01), Y ;copy pixel to sta ($03), Y ;back buffer jsr inc0103 ;increment pointers cmp #$00 ;check to see bne copybyte ;if we're at $600 lda $02 ;if so, we've cmp #$06 ;copied the bne copybyte ;entire screen conway: lda #$df ;apply conway rules sta $01 ;reset the pointer sta $03 ;to $#01df/$#07df lda #$01 ;($200 - $21) sta $02 ;($800 - $21) lda #$07 sta $04onecell: lda #$00 ;process one cell ldy #$01 ;upper cell clc adc ($03), Y ldy #$41 ;lower cell clc adc ($03), Ychkleft: tax ;check to see lda $01 ;if we're at the and #$1f ;left edge tay txa cpy #$1f beq rightcellsleftcells: ldy #$00 ;upper-left cell clc adc ($03), Y ldy #$20 ;left cell clc adc ($03), Y ldy #$40 ;lower-left cell clc adc ($03), Ychkright: tax ;check to see lda $01 ;if we're at the and #$1f ;right edge tay txa cpy #$1e beq evaluaterightcells: ldy #$02 ;upper-right cell clc adc ($03), Y ldy #$22 ;right cell clc adc ($03), Y ldy #$42 ;lower-right cell clc adc ($03), Yevaluate: ldx #$01 ;evaluate total ldy #$21 ;for current cell cmp #$03 ;3 = alive beq storex ldx #$00 cmp #$02 ;2 = alive if bne storex ;c = alive lda ($03), Y and #$01 taxstorex: txa ;store to screen sta ($01), Y jsr inc0103 ;move to next cellconwayloop: cmp #$e0 ;if not last cell, bne onecell ;process next cell lda $02 cmp #$05 bne onecell jmp starttick ;run next tick inc0103: lda $01 ;increment $01 cmp #$ff ;and $03 as 16-bit bne onlyinc01 ;pointers inc $02 inc $04onlyinc01: inc $01 lda $01 sta $03 rts The solution uses one cell thick border around square Petri dish as uninhabited dire land. Sample output contains 3 generations of the blinker and 5 of the glider: See Conway's Game of Life/ALGOL 68 APL2 (Dialog) Example in one line APL \ 1130 example (very old APL dialect via simulator) APL1130From: APL \ 1130 Samples The following APL \ 1130 code will need APL385 font installed to display correctly. See Download APL TT Font ∇LIFE[⎕]∇[0] NG←LIFE CG; W[1] W←CG+(¯1⊖CG)+(1⊖CG)+(¯1⌽CG)+(1⌽CG)[2] W←W+(1⊖1⌽CG)+(¯1⊖1⌽CG)+(1⊖¯1⌽CG)+(¯1⊖¯1⌽CG)[3] NG←(3=W)+(CG∧4=W) ∇ RP←5 5⍴0 0 0 0 0 0 0 1 1 0 0 1 1 0 0 0 0 1 0 0 RP0 0 0 0 00 0 1 1 00 1 1 0 00 0 1 0 00 0 0 0 0 LIFE RP0 0 0 0 00 1 1 1 00 1 0 0 00 1 1 0 00 0 0 0 0 LIFE LIFE RP0 0 1 0 00 1 1 0 01 0 0 1 00 1 1 0 00 0 0 0 0 .................................................. One interacts with the Game of Life by creating an initial configuration and observing how it evolves. Although you should test your implementation on more complex examples such as the glider in a larger universe, show the action of the blinker (three adjoining cells in a row all alive), over three generations, in a 3 by 3 grid. (1,4)=TRUERETURN'' Count the number of neighbours of the point i,j' (Assume i/j +/- 1 will not fall out of world)'FUNCTION count_neighbours(i%,j%) LOCAL count%,l% count%=0 FOR l%=-1 TO 1 IF world! (i%+l%,j%+1) count%=count%+1 ENDIF NEXT l% IF world! (i%+1,j%) count%=count%+1 ENDIF RETURN count%ENDFUNC'' Update the world one step'PROCEDURE update_world LOCAL i%,j% ' compute neighbour counts and store FOR i%=1 TO 30 FOR j%=1 TO 30 ns%(i%,j%)[email protected]_neighbours(i%,j%) NEXT j% NEXT i% ' update the world cells FOR i%=1 TO 30 FOR j%=1 TO 30 IF world!

||

randfill: stx $01 ;$200 for indirect ldx #$02 ;addressing stx $02randloop: lda $fe ;generate random and #$01 ;pixels on the sta ($01), Y ;screen jsr inc0103 cmp #$00 bne randloop lda $02 cmp #$06 bne randloop clearmem: lda #$df ;set $07df-$0a20 sta $01 ;to $#00 lda #$07 sta $02clearbyte: lda #$00 sta ($01), Y jsr inc0103 cmp #$20 bne clearbyte lda $02 cmp #$0a bne clearbyte starttick:copyscreen: lda #$00 ;set up source sta $01 ;pointer at sta $03 ;$01/$02 and lda #$02 ;dest pointer sta $02 ;at $03/$04 lda #$08 sta $04 ldy #$00copybyte: lda ($01), Y ;copy pixel to sta ($03), Y ;back buffer jsr inc0103 ;increment pointers cmp #$00 ;check to see bne copybyte ;if we're at $600 lda $02 ;if so, we've cmp #$06 ;copied the bne copybyte ;entire screen conway: lda #$df ;apply conway rules sta $01 ;reset the pointer sta $03 ;to $#01df/$#07df lda #$01 ;($200 - $21) sta $02 ;($800 - $21) lda #$07 sta $04onecell: lda #$00 ;process one cell ldy #$01 ;upper cell clc adc ($03), Y ldy #$41 ;lower cell clc adc ($03), Ychkleft: tax ;check to see lda $01 ;if we're at the and #$1f ;left edge tay txa cpy #$1f beq rightcellsleftcells: ldy #$00 ;upper-left cell clc adc ($03), Y ldy #$20 ;left cell clc adc ($03), Y ldy #$40 ;lower-left cell clc adc ($03), Ychkright: tax ;check to see lda $01 ;if we're at the and #$1f ;right edge tay txa cpy #$1e beq evaluaterightcells: ldy #$02 ;upper-right cell clc adc ($03), Y ldy #$22 ;right cell clc adc ($03), Y ldy #$42 ;lower-right cell clc adc ($03), Yevaluate: ldx #$01 ;evaluate total ldy #$21 ;for current cell cmp #$03 ;3 = alive beq storex ldx #$00 cmp #$02 ;2 = alive if bne storex ;c = alive lda ($03), Y and #$01 taxstorex: txa ;store to screen sta ($01), Y jsr inc0103 ;move to next cellconwayloop: cmp #$e0 ;if not last cell, bne onecell ;process next cell lda $02 cmp #$05 bne onecell jmp starttick ;run next tick inc0103: lda $01 ;increment $01 cmp #$ff ;and $03 as 16-bit bne onlyinc01 ;pointers inc $02 inc $04onlyinc01: inc $01 lda $01 sta $03 rts The solution uses one cell thick border around square Petri dish as uninhabited dire land. Sample output contains 3 generations of the blinker and 5 of the glider: See Conway's Game of Life/ALGOL 68 APL2 (Dialog) Example in one line APL \ 1130 example (very old APL dialect via simulator) APL1130From: APL \ 1130 Samples The following APL \ 1130 code will need APL385 font installed to display correctly.

See Download APL TT Font ∇LIFE[⎕]∇[0] NG←LIFE CG; W[1] W←CG+(¯1⊖CG)+(1⊖CG)+(¯1⌽CG)+(1⌽CG)[2] W←W+(1⊖1⌽CG)+(¯1⊖1⌽CG)+(1⊖¯1⌽CG)+(¯1⊖¯1⌽CG)[3] NG←(3=W)+(CG∧4=W) ∇ RP←5 5⍴0 0 0 0 0 0 0 1 1 0 0 1 1 0 0 0 0 1 0 0 RP0 0 0 0 00 0 1 1 00 1 1 0 00 0 1 0 00 0 0 0 0 LIFE RP0 0 0 0 00 1 1 1 00 1 0 0 00 1 1 0 00 0 0 0 0 LIFE LIFE RP0 0 1 0 00 1 1 0 01 0 0 1 00 1 1 0 00 0 0 0 0 ..................................................

One interacts with the Game of Life by creating an initial configuration and observing how it evolves.

Although you should test your implementation on more complex examples such as the glider in a larger universe, show the action of the blinker (three adjoining cells in a row all alive), over three generations, in a 3 by 3 grid.

(1,4)=TRUERETURN'' Count the number of neighbours of the point i,j' (Assume i/j +/- 1 will not fall out of world)'FUNCTION count_neighbours(i%,j%) LOCAL count%,l% count%=0 FOR l%=-1 TO 1 IF world! (i%+l%,j%+1) count%=count%+1 ENDIF NEXT l% IF world! (i%+1,j%) count%=count%+1 ENDIF RETURN count%ENDFUNC'' Update the world one step'PROCEDURE update_world LOCAL i%,j% ' compute neighbour counts and store FOR i%=1 TO 30 FOR j%=1 TO 30 ns%(i%,j%)[email protected]_neighbours(i%,j%) NEXT j% NEXT i% ' update the world cells FOR i%=1 TO 30 FOR j%=1 TO 30 IF world!

Thus, while it is somewhat verbose, it fully simulates Conway's Game of Life and is relatively simple to expand to feature different starting shapes.

Define life(pattern) = Prgm Local x,y,nt,count,save,xl,yl,xh,yh Define nt(y,x) = when(pxl Test(y,x), 1, 0) {}→save set Graph("Axes", "Off")→save[1] set Graph("Grid", "Off")→save[2] set Graph("Labels", "Off")→save[3] Fn Off Plot Off Clr Draw If pattern = "blinker" Then 36→yl 40→yh 78→xl 82→xh Pxl On 36,80 Pxl On 38,80 Pxl On 40,80 Else If pattern = "glider" Then 30→yl 40→yh 76→xl 88→xh Pxl On 38,76 Pxl On 36,78 Pxl On 36,80 Pxl On 38,80 Pxl On 40,80 Else If pattern = "r" Then 38-5*2→yl 38+5*2→yh 80-5*2→xl 80+5*2→xh Pxl On 38,78 Pxl On 36,82 Pxl On 36,80 Pxl On 38,80 Pxl On 40,80 End If While get Key() = 0 © Expand upper-left corner to whole cell For y,yl,yh,2 For x,xl,xh,2 If pxl Test(y,x) Then Pxl On y+1,x Pxl On y+1,x+1 Pxl On y, x+1 Else Pxl Off y+1,x Pxl Off y+1,x+1 Pxl Off y, x+1 End If End For End For © Compute next generation For y,yl,yh,2 For x,xl,xh,2 nt(y-1,x-1) + nt(y-1,x) + nt(y-1,x+2) + nt(y,x-1) + nt(y+1,x+2) + nt(y+2,x-1) + nt(y+2,x+1) + nt(y+2,x+2) → count If count = 3 Then Pxl On y,x Else If count ≠ 2 Then Pxl Off y,x End If End For End For End While © Restore changed options set Graph("Axes", save[1]) set Graph("Grid", save[2]) set Graph("Labels", save[3])End Prgm Also see Conway's Game of Life/C Considering that the simplest implementation in C++ would lack any use of the object-oriented paradigm, this code was specifically written to demonstrate the various object-oriented features of C++.

;to $#00 lda # sta clearbyte: lda #[[

randfill: stx $01 ;$200 for indirect ldx #$02 ;addressing stx $02randloop: lda $fe ;generate random and #$01 ;pixels on the sta ($01), Y ;screen jsr inc0103 cmp #$00 bne randloop lda $02 cmp #$06 bne randloop clearmem: lda #$df ;set $07df-$0a20 sta $01 ;to $#00 lda #$07 sta $02clearbyte: lda #$00 sta ($01), Y jsr inc0103 cmp #$20 bne clearbyte lda $02 cmp #$0a bne clearbyte starttick:copyscreen: lda #$00 ;set up source sta $01 ;pointer at sta $03 ;$01/$02 and lda #$02 ;dest pointer sta $02 ;at $03/$04 lda #$08 sta $04 ldy #$00copybyte: lda ($01), Y ;copy pixel to sta ($03), Y ;back buffer jsr inc0103 ;increment pointers cmp #$00 ;check to see bne copybyte ;if we're at $600 lda $02 ;if so, we've cmp #$06 ;copied the bne copybyte ;entire screen conway: lda #$df ;apply conway rules sta $01 ;reset the pointer sta $03 ;to $#01df/$#07df lda #$01 ;($200 - $21) sta $02 ;($800 - $21) lda #$07 sta $04onecell: lda #$00 ;process one cell ldy #$01 ;upper cell clc adc ($03), Y ldy #$41 ;lower cell clc adc ($03), Ychkleft: tax ;check to see lda $01 ;if we're at the and #$1f ;left edge tay txa cpy #$1f beq rightcellsleftcells: ldy #$00 ;upper-left cell clc adc ($03), Y ldy #$20 ;left cell clc adc ($03), Y ldy #$40 ;lower-left cell clc adc ($03), Ychkright: tax ;check to see lda $01 ;if we're at the and #$1f ;right edge tay txa cpy #$1e beq evaluaterightcells: ldy #$02 ;upper-right cell clc adc ($03), Y ldy #$22 ;right cell clc adc ($03), Y ldy #$42 ;lower-right cell clc adc ($03), Yevaluate: ldx #$01 ;evaluate total ldy #$21 ;for current cell cmp #$03 ;3 = alive beq storex ldx #$00 cmp #$02 ;2 = alive if bne storex ;c = alive lda ($03), Y and #$01 taxstorex: txa ;store to screen sta ($01), Y jsr inc0103 ;move to next cellconwayloop: cmp #$e0 ;if not last cell, bne onecell ;process next cell lda $02 cmp #$05 bne onecell jmp starttick ;run next tick inc0103: lda $01 ;increment $01 cmp #$ff ;and $03 as 16-bit bne onlyinc01 ;pointers inc $02 inc $04onlyinc01: inc $01 lda $01 sta $03 rts The solution uses one cell thick border around square Petri dish as uninhabited dire land. Sample output contains 3 generations of the blinker and 5 of the glider: See Conway's Game of Life/ALGOL 68 APL2 (Dialog) Example in one line APL \ 1130 example (very old APL dialect via simulator) APL1130From: APL \ 1130 Samples The following APL \ 1130 code will need APL385 font installed to display correctly. See Download APL TT Font ∇LIFE[⎕]∇[0] NG←LIFE CG; W[1] W←CG+(¯1⊖CG)+(1⊖CG)+(¯1⌽CG)+(1⌽CG)[2] W←W+(1⊖1⌽CG)+(¯1⊖1⌽CG)+(1⊖¯1⌽CG)+(¯1⊖¯1⌽CG)[3] NG←(3=W)+(CG∧4=W) ∇ RP←5 5⍴0 0 0 0 0 0 0 1 1 0 0 1 1 0 0 0 0 1 0 0 RP0 0 0 0 00 0 1 1 00 1 1 0 00 0 1 0 00 0 0 0 0 LIFE RP0 0 0 0 00 1 1 1 00 1 0 0 00 1 1 0 00 0 0 0 0 LIFE LIFE RP0 0 1 0 00 1 1 0 01 0 0 1 00 1 1 0 00 0 0 0 0 .................................................. One interacts with the Game of Life by creating an initial configuration and observing how it evolves. Although you should test your implementation on more complex examples such as the glider in a larger universe, show the action of the blinker (three adjoining cells in a row all alive), over three generations, in a 3 by 3 grid. (1,4)=TRUERETURN'' Count the number of neighbours of the point i,j' (Assume i/j +/- 1 will not fall out of world)'FUNCTION count_neighbours(i%,j%) LOCAL count%,l% count%=0 FOR l%=-1 TO 1 IF world! (i%+l%,j%+1) count%=count%+1 ENDIF NEXT l% IF world! (i%+1,j%) count%=count%+1 ENDIF RETURN count%ENDFUNC'' Update the world one step'PROCEDURE update_world LOCAL i%,j% ' compute neighbour counts and store FOR i%=1 TO 30 FOR j%=1 TO 30 ns%(i%,j%)[email protected]_neighbours(i%,j%) NEXT j% NEXT i% ' update the world cells FOR i%=1 TO 30 FOR j%=1 TO 30 IF world!

||

randfill: stx $01 ;$200 for indirect ldx #$02 ;addressing stx $02randloop: lda $fe ;generate random and #$01 ;pixels on the sta ($01), Y ;screen jsr inc0103 cmp #$00 bne randloop lda $02 cmp #$06 bne randloop clearmem: lda #$df ;set $07df-$0a20 sta $01 ;to $#00 lda #$07 sta $02clearbyte: lda #$00 sta ($01), Y jsr inc0103 cmp #$20 bne clearbyte lda $02 cmp #$0a bne clearbyte starttick:copyscreen: lda #$00 ;set up source sta $01 ;pointer at sta $03 ;$01/$02 and lda #$02 ;dest pointer sta $02 ;at $03/$04 lda #$08 sta $04 ldy #$00copybyte: lda ($01), Y ;copy pixel to sta ($03), Y ;back buffer jsr inc0103 ;increment pointers cmp #$00 ;check to see bne copybyte ;if we're at $600 lda $02 ;if so, we've cmp #$06 ;copied the bne copybyte ;entire screen conway: lda #$df ;apply conway rules sta $01 ;reset the pointer sta $03 ;to $#01df/$#07df lda #$01 ;($200 - $21) sta $02 ;($800 - $21) lda #$07 sta $04onecell: lda #$00 ;process one cell ldy #$01 ;upper cell clc adc ($03), Y ldy #$41 ;lower cell clc adc ($03), Ychkleft: tax ;check to see lda $01 ;if we're at the and #$1f ;left edge tay txa cpy #$1f beq rightcellsleftcells: ldy #$00 ;upper-left cell clc adc ($03), Y ldy #$20 ;left cell clc adc ($03), Y ldy #$40 ;lower-left cell clc adc ($03), Ychkright: tax ;check to see lda $01 ;if we're at the and #$1f ;right edge tay txa cpy #$1e beq evaluaterightcells: ldy #$02 ;upper-right cell clc adc ($03), Y ldy #$22 ;right cell clc adc ($03), Y ldy #$42 ;lower-right cell clc adc ($03), Yevaluate: ldx #$01 ;evaluate total ldy #$21 ;for current cell cmp #$03 ;3 = alive beq storex ldx #$00 cmp #$02 ;2 = alive if bne storex ;c = alive lda ($03), Y and #$01 taxstorex: txa ;store to screen sta ($01), Y jsr inc0103 ;move to next cellconwayloop: cmp #$e0 ;if not last cell, bne onecell ;process next cell lda $02 cmp #$05 bne onecell jmp starttick ;run next tick inc0103: lda $01 ;increment $01 cmp #$ff ;and $03 as 16-bit bne onlyinc01 ;pointers inc $02 inc $04onlyinc01: inc $01 lda $01 sta $03 rts The solution uses one cell thick border around square Petri dish as uninhabited dire land. Sample output contains 3 generations of the blinker and 5 of the glider: See Conway's Game of Life/ALGOL 68 APL2 (Dialog) Example in one line APL \ 1130 example (very old APL dialect via simulator) APL1130From: APL \ 1130 Samples The following APL \ 1130 code will need APL385 font installed to display correctly.

See Download APL TT Font ∇LIFE[⎕]∇[0] NG←LIFE CG; W[1] W←CG+(¯1⊖CG)+(1⊖CG)+(¯1⌽CG)+(1⌽CG)[2] W←W+(1⊖1⌽CG)+(¯1⊖1⌽CG)+(1⊖¯1⌽CG)+(¯1⊖¯1⌽CG)[3] NG←(3=W)+(CG∧4=W) ∇ RP←5 5⍴0 0 0 0 0 0 0 1 1 0 0 1 1 0 0 0 0 1 0 0 RP0 0 0 0 00 0 1 1 00 1 1 0 00 0 1 0 00 0 0 0 0 LIFE RP0 0 0 0 00 1 1 1 00 1 0 0 00 1 1 0 00 0 0 0 0 LIFE LIFE RP0 0 1 0 00 1 1 0 01 0 0 1 00 1 1 0 00 0 0 0 0 ..................................................

One interacts with the Game of Life by creating an initial configuration and observing how it evolves.

Although you should test your implementation on more complex examples such as the glider in a larger universe, show the action of the blinker (three adjoining cells in a row all alive), over three generations, in a 3 by 3 grid.

(1,4)=TRUERETURN'' Count the number of neighbours of the point i,j' (Assume i/j +/- 1 will not fall out of world)'FUNCTION count_neighbours(i%,j%) LOCAL count%,l% count%=0 FOR l%=-1 TO 1 IF world! (i%+l%,j%+1) count%=count%+1 ENDIF NEXT l% IF world! (i%+1,j%) count%=count%+1 ENDIF RETURN count%ENDFUNC'' Update the world one step'PROCEDURE update_world LOCAL i%,j% ' compute neighbour counts and store FOR i%=1 TO 30 FOR j%=1 TO 30 ns%(i%,j%)[email protected]_neighbours(i%,j%) NEXT j% NEXT i% ' update the world cells FOR i%=1 TO 30 FOR j%=1 TO 30 IF world!

Thus, while it is somewhat verbose, it fully simulates Conway's Game of Life and is relatively simple to expand to feature different starting shapes.

Define life(pattern) = Prgm Local x,y,nt,count,save,xl,yl,xh,yh Define nt(y,x) = when(pxl Test(y,x), 1, 0) {}→save set Graph("Axes", "Off")→save[1] set Graph("Grid", "Off")→save[2] set Graph("Labels", "Off")→save[3] Fn Off Plot Off Clr Draw If pattern = "blinker" Then 36→yl 40→yh 78→xl 82→xh Pxl On 36,80 Pxl On 38,80 Pxl On 40,80 Else If pattern = "glider" Then 30→yl 40→yh 76→xl 88→xh Pxl On 38,76 Pxl On 36,78 Pxl On 36,80 Pxl On 38,80 Pxl On 40,80 Else If pattern = "r" Then 38-5*2→yl 38+5*2→yh 80-5*2→xl 80+5*2→xh Pxl On 38,78 Pxl On 36,82 Pxl On 36,80 Pxl On 38,80 Pxl On 40,80 End If While get Key() = 0 © Expand upper-left corner to whole cell For y,yl,yh,2 For x,xl,xh,2 If pxl Test(y,x) Then Pxl On y+1,x Pxl On y+1,x+1 Pxl On y, x+1 Else Pxl Off y+1,x Pxl Off y+1,x+1 Pxl Off y, x+1 End If End For End For © Compute next generation For y,yl,yh,2 For x,xl,xh,2 nt(y-1,x-1) + nt(y-1,x) + nt(y-1,x+2) + nt(y,x-1) + nt(y+1,x+2) + nt(y+2,x-1) + nt(y+2,x+1) + nt(y+2,x+2) → count If count = 3 Then Pxl On y,x Else If count ≠ 2 Then Pxl Off y,x End If End For End For End While © Restore changed options set Graph("Axes", save[1]) set Graph("Grid", save[2]) set Graph("Labels", save[3])End Prgm Also see Conway's Game of Life/C Considering that the simplest implementation in C++ would lack any use of the object-oriented paradigm, this code was specifically written to demonstrate the various object-oriented features of C++.

]] sta (

randfill: stx $01 ;$200 for indirect ldx #$02 ;addressing stx $02randloop: lda $fe ;generate random and #$01 ;pixels on the sta ($01), Y ;screen jsr inc0103 cmp #$00 bne randloop lda $02 cmp #$06 bne randloop clearmem: lda #$df ;set $07df-$0a20 sta $01 ;to $#00 lda #$07 sta $02clearbyte: lda #$00 sta ($01), Y jsr inc0103 cmp #$20 bne clearbyte lda $02 cmp #$0a bne clearbyte starttick:copyscreen: lda #$00 ;set up source sta $01 ;pointer at sta $03 ;$01/$02 and lda #$02 ;dest pointer sta $02 ;at $03/$04 lda #$08 sta $04 ldy #$00copybyte: lda ($01), Y ;copy pixel to sta ($03), Y ;back buffer jsr inc0103 ;increment pointers cmp #$00 ;check to see bne copybyte ;if we're at $600 lda $02 ;if so, we've cmp #$06 ;copied the bne copybyte ;entire screen conway: lda #$df ;apply conway rules sta $01 ;reset the pointer sta $03 ;to $#01df/$#07df lda #$01 ;($200 - $21) sta $02 ;($800 - $21) lda #$07 sta $04onecell: lda #$00 ;process one cell ldy #$01 ;upper cell clc adc ($03), Y ldy #$41 ;lower cell clc adc ($03), Ychkleft: tax ;check to see lda $01 ;if we're at the and #$1f ;left edge tay txa cpy #$1f beq rightcellsleftcells: ldy #$00 ;upper-left cell clc adc ($03), Y ldy #$20 ;left cell clc adc ($03), Y ldy #$40 ;lower-left cell clc adc ($03), Ychkright: tax ;check to see lda $01 ;if we're at the and #$1f ;right edge tay txa cpy #$1e beq evaluaterightcells: ldy #$02 ;upper-right cell clc adc ($03), Y ldy #$22 ;right cell clc adc ($03), Y ldy #$42 ;lower-right cell clc adc ($03), Yevaluate: ldx #$01 ;evaluate total ldy #$21 ;for current cell cmp #$03 ;3 = alive beq storex ldx #$00 cmp #$02 ;2 = alive if bne storex ;c = alive lda ($03), Y and #$01 taxstorex: txa ;store to screen sta ($01), Y jsr inc0103 ;move to next cellconwayloop: cmp #$e0 ;if not last cell, bne onecell ;process next cell lda $02 cmp #$05 bne onecell jmp starttick ;run next tick inc0103: lda $01 ;increment $01 cmp #$ff ;and $03 as 16-bit bne onlyinc01 ;pointers inc $02 inc $04onlyinc01: inc $01 lda $01 sta $03 rts The solution uses one cell thick border around square Petri dish as uninhabited dire land. Sample output contains 3 generations of the blinker and 5 of the glider: See Conway's Game of Life/ALGOL 68 APL2 (Dialog) Example in one line APL \ 1130 example (very old APL dialect via simulator) APL1130From: APL \ 1130 Samples The following APL \ 1130 code will need APL385 font installed to display correctly. See Download APL TT Font ∇LIFE[⎕]∇[0] NG←LIFE CG; W[1] W←CG+(¯1⊖CG)+(1⊖CG)+(¯1⌽CG)+(1⌽CG)[2] W←W+(1⊖1⌽CG)+(¯1⊖1⌽CG)+(1⊖¯1⌽CG)+(¯1⊖¯1⌽CG)[3] NG←(3=W)+(CG∧4=W) ∇ RP←5 5⍴0 0 0 0 0 0 0 1 1 0 0 1 1 0 0 0 0 1 0 0 RP0 0 0 0 00 0 1 1 00 1 1 0 00 0 1 0 00 0 0 0 0 LIFE RP0 0 0 0 00 1 1 1 00 1 0 0 00 1 1 0 00 0 0 0 0 LIFE LIFE RP0 0 1 0 00 1 1 0 01 0 0 1 00 1 1 0 00 0 0 0 0 .................................................. One interacts with the Game of Life by creating an initial configuration and observing how it evolves. Although you should test your implementation on more complex examples such as the glider in a larger universe, show the action of the blinker (three adjoining cells in a row all alive), over three generations, in a 3 by 3 grid. (1,4)=TRUERETURN'' Count the number of neighbours of the point i,j' (Assume i/j +/- 1 will not fall out of world)'FUNCTION count_neighbours(i%,j%) LOCAL count%,l% count%=0 FOR l%=-1 TO 1 IF world! (i%+l%,j%+1) count%=count%+1 ENDIF NEXT l% IF world! (i%+1,j%) count%=count%+1 ENDIF RETURN count%ENDFUNC'' Update the world one step'PROCEDURE update_world LOCAL i%,j% ' compute neighbour counts and store FOR i%=1 TO 30 FOR j%=1 TO 30 ns%(i%,j%)[email protected]_neighbours(i%,j%) NEXT j% NEXT i% ' update the world cells FOR i%=1 TO 30 FOR j%=1 TO 30 IF world!

||

randfill: stx $01 ;$200 for indirect ldx #$02 ;addressing stx $02randloop: lda $fe ;generate random and #$01 ;pixels on the sta ($01), Y ;screen jsr inc0103 cmp #$00 bne randloop lda $02 cmp #$06 bne randloop clearmem: lda #$df ;set $07df-$0a20 sta $01 ;to $#00 lda #$07 sta $02clearbyte: lda #$00 sta ($01), Y jsr inc0103 cmp #$20 bne clearbyte lda $02 cmp #$0a bne clearbyte starttick:copyscreen: lda #$00 ;set up source sta $01 ;pointer at sta $03 ;$01/$02 and lda #$02 ;dest pointer sta $02 ;at $03/$04 lda #$08 sta $04 ldy #$00copybyte: lda ($01), Y ;copy pixel to sta ($03), Y ;back buffer jsr inc0103 ;increment pointers cmp #$00 ;check to see bne copybyte ;if we're at $600 lda $02 ;if so, we've cmp #$06 ;copied the bne copybyte ;entire screen conway: lda #$df ;apply conway rules sta $01 ;reset the pointer sta $03 ;to $#01df/$#07df lda #$01 ;($200 - $21) sta $02 ;($800 - $21) lda #$07 sta $04onecell: lda #$00 ;process one cell ldy #$01 ;upper cell clc adc ($03), Y ldy #$41 ;lower cell clc adc ($03), Ychkleft: tax ;check to see lda $01 ;if we're at the and #$1f ;left edge tay txa cpy #$1f beq rightcellsleftcells: ldy #$00 ;upper-left cell clc adc ($03), Y ldy #$20 ;left cell clc adc ($03), Y ldy #$40 ;lower-left cell clc adc ($03), Ychkright: tax ;check to see lda $01 ;if we're at the and #$1f ;right edge tay txa cpy #$1e beq evaluaterightcells: ldy #$02 ;upper-right cell clc adc ($03), Y ldy #$22 ;right cell clc adc ($03), Y ldy #$42 ;lower-right cell clc adc ($03), Yevaluate: ldx #$01 ;evaluate total ldy #$21 ;for current cell cmp #$03 ;3 = alive beq storex ldx #$00 cmp #$02 ;2 = alive if bne storex ;c = alive lda ($03), Y and #$01 taxstorex: txa ;store to screen sta ($01), Y jsr inc0103 ;move to next cellconwayloop: cmp #$e0 ;if not last cell, bne onecell ;process next cell lda $02 cmp #$05 bne onecell jmp starttick ;run next tick inc0103: lda $01 ;increment $01 cmp #$ff ;and $03 as 16-bit bne onlyinc01 ;pointers inc $02 inc $04onlyinc01: inc $01 lda $01 sta $03 rts The solution uses one cell thick border around square Petri dish as uninhabited dire land. Sample output contains 3 generations of the blinker and 5 of the glider: See Conway's Game of Life/ALGOL 68 APL2 (Dialog) Example in one line APL \ 1130 example (very old APL dialect via simulator) APL1130From: APL \ 1130 Samples The following APL \ 1130 code will need APL385 font installed to display correctly.

See Download APL TT Font ∇LIFE[⎕]∇[0] NG←LIFE CG; W[1] W←CG+(¯1⊖CG)+(1⊖CG)+(¯1⌽CG)+(1⌽CG)[2] W←W+(1⊖1⌽CG)+(¯1⊖1⌽CG)+(1⊖¯1⌽CG)+(¯1⊖¯1⌽CG)[3] NG←(3=W)+(CG∧4=W) ∇ RP←5 5⍴0 0 0 0 0 0 0 1 1 0 0 1 1 0 0 0 0 1 0 0 RP0 0 0 0 00 0 1 1 00 1 1 0 00 0 1 0 00 0 0 0 0 LIFE RP0 0 0 0 00 1 1 1 00 1 0 0 00 1 1 0 00 0 0 0 0 LIFE LIFE RP0 0 1 0 00 1 1 0 01 0 0 1 00 1 1 0 00 0 0 0 0 ..................................................

One interacts with the Game of Life by creating an initial configuration and observing how it evolves.

Although you should test your implementation on more complex examples such as the glider in a larger universe, show the action of the blinker (three adjoining cells in a row all alive), over three generations, in a 3 by 3 grid.

(1,4)=TRUERETURN'' Count the number of neighbours of the point i,j' (Assume i/j +/- 1 will not fall out of world)'FUNCTION count_neighbours(i%,j%) LOCAL count%,l% count%=0 FOR l%=-1 TO 1 IF world! (i%+l%,j%+1) count%=count%+1 ENDIF NEXT l% IF world! (i%+1,j%) count%=count%+1 ENDIF RETURN count%ENDFUNC'' Update the world one step'PROCEDURE update_world LOCAL i%,j% ' compute neighbour counts and store FOR i%=1 TO 30 FOR j%=1 TO 30 ns%(i%,j%)[email protected]_neighbours(i%,j%) NEXT j% NEXT i% ' update the world cells FOR i%=1 TO 30 FOR j%=1 TO 30 IF world!

Thus, while it is somewhat verbose, it fully simulates Conway's Game of Life and is relatively simple to expand to feature different starting shapes.

Define life(pattern) = Prgm Local x,y,nt,count,save,xl,yl,xh,yh Define nt(y,x) = when(pxl Test(y,x), 1, 0) {}→save set Graph("Axes", "Off")→save[1] set Graph("Grid", "Off")→save[2] set Graph("Labels", "Off")→save[3] Fn Off Plot Off Clr Draw If pattern = "blinker" Then 36→yl 40→yh 78→xl 82→xh Pxl On 36,80 Pxl On 38,80 Pxl On 40,80 Else If pattern = "glider" Then 30→yl 40→yh 76→xl 88→xh Pxl On 38,76 Pxl On 36,78 Pxl On 36,80 Pxl On 38,80 Pxl On 40,80 Else If pattern = "r" Then 38-5*2→yl 38+5*2→yh 80-5*2→xl 80+5*2→xh Pxl On 38,78 Pxl On 36,82 Pxl On 36,80 Pxl On 38,80 Pxl On 40,80 End If While get Key() = 0 © Expand upper-left corner to whole cell For y,yl,yh,2 For x,xl,xh,2 If pxl Test(y,x) Then Pxl On y+1,x Pxl On y+1,x+1 Pxl On y, x+1 Else Pxl Off y+1,x Pxl Off y+1,x+1 Pxl Off y, x+1 End If End For End For © Compute next generation For y,yl,yh,2 For x,xl,xh,2 nt(y-1,x-1) + nt(y-1,x) + nt(y-1,x+2) + nt(y,x-1) + nt(y+1,x+2) + nt(y+2,x-1) + nt(y+2,x+1) + nt(y+2,x+2) → count If count = 3 Then Pxl On y,x Else If count ≠ 2 Then Pxl Off y,x End If End For End For End While © Restore changed options set Graph("Axes", save[1]) set Graph("Grid", save[2]) set Graph("Labels", save[3])End Prgm Also see Conway's Game of Life/C Considering that the simplest implementation in C++ would lack any use of the object-oriented paradigm, this code was specifically written to demonstrate the various object-oriented features of C++.

), Y jsr inc0103 cmp # bne clearbyte lda cmp #[[

randfill: stx $01 ;$200 for indirect ldx #$02 ;addressing stx $02randloop: lda $fe ;generate random and #$01 ;pixels on the sta ($01), Y ;screen jsr inc0103 cmp #$00 bne randloop lda $02 cmp #$06 bne randloop clearmem: lda #$df ;set $07df-$0a20 sta $01 ;to $#00 lda #$07 sta $02clearbyte: lda #$00 sta ($01), Y jsr inc0103 cmp #$20 bne clearbyte lda $02 cmp #$0a bne clearbyte starttick:copyscreen: lda #$00 ;set up source sta $01 ;pointer at sta $03 ;$01/$02 and lda #$02 ;dest pointer sta $02 ;at $03/$04 lda #$08 sta $04 ldy #$00copybyte: lda ($01), Y ;copy pixel to sta ($03), Y ;back buffer jsr inc0103 ;increment pointers cmp #$00 ;check to see bne copybyte ;if we're at $600 lda $02 ;if so, we've cmp #$06 ;copied the bne copybyte ;entire screen conway: lda #$df ;apply conway rules sta $01 ;reset the pointer sta $03 ;to $#01df/$#07df lda #$01 ;($200 - $21) sta $02 ;($800 - $21) lda #$07 sta $04onecell: lda #$00 ;process one cell ldy #$01 ;upper cell clc adc ($03), Y ldy #$41 ;lower cell clc adc ($03), Ychkleft: tax ;check to see lda $01 ;if we're at the and #$1f ;left edge tay txa cpy #$1f beq rightcellsleftcells: ldy #$00 ;upper-left cell clc adc ($03), Y ldy #$20 ;left cell clc adc ($03), Y ldy #$40 ;lower-left cell clc adc ($03), Ychkright: tax ;check to see lda $01 ;if we're at the and #$1f ;right edge tay txa cpy #$1e beq evaluaterightcells: ldy #$02 ;upper-right cell clc adc ($03), Y ldy #$22 ;right cell clc adc ($03), Y ldy #$42 ;lower-right cell clc adc ($03), Yevaluate: ldx #$01 ;evaluate total ldy #$21 ;for current cell cmp #$03 ;3 = alive beq storex ldx #$00 cmp #$02 ;2 = alive if bne storex ;c = alive lda ($03), Y and #$01 taxstorex: txa ;store to screen sta ($01), Y jsr inc0103 ;move to next cellconwayloop: cmp #$e0 ;if not last cell, bne onecell ;process next cell lda $02 cmp #$05 bne onecell jmp starttick ;run next tick inc0103: lda $01 ;increment $01 cmp #$ff ;and $03 as 16-bit bne onlyinc01 ;pointers inc $02 inc $04onlyinc01: inc $01 lda $01 sta $03 rts The solution uses one cell thick border around square Petri dish as uninhabited dire land. Sample output contains 3 generations of the blinker and 5 of the glider: See Conway's Game of Life/ALGOL 68 APL2 (Dialog) Example in one line APL \ 1130 example (very old APL dialect via simulator) APL1130From: APL \ 1130 Samples The following APL \ 1130 code will need APL385 font installed to display correctly. See Download APL TT Font ∇LIFE[⎕]∇[0] NG←LIFE CG; W[1] W←CG+(¯1⊖CG)+(1⊖CG)+(¯1⌽CG)+(1⌽CG)[2] W←W+(1⊖1⌽CG)+(¯1⊖1⌽CG)+(1⊖¯1⌽CG)+(¯1⊖¯1⌽CG)[3] NG←(3=W)+(CG∧4=W) ∇ RP←5 5⍴0 0 0 0 0 0 0 1 1 0 0 1 1 0 0 0 0 1 0 0 RP0 0 0 0 00 0 1 1 00 1 1 0 00 0 1 0 00 0 0 0 0 LIFE RP0 0 0 0 00 1 1 1 00 1 0 0 00 1 1 0 00 0 0 0 0 LIFE LIFE RP0 0 1 0 00 1 1 0 01 0 0 1 00 1 1 0 00 0 0 0 0 .................................................. One interacts with the Game of Life by creating an initial configuration and observing how it evolves. Although you should test your implementation on more complex examples such as the glider in a larger universe, show the action of the blinker (three adjoining cells in a row all alive), over three generations, in a 3 by 3 grid. (1,4)=TRUERETURN'' Count the number of neighbours of the point i,j' (Assume i/j +/- 1 will not fall out of world)'FUNCTION count_neighbours(i%,j%) LOCAL count%,l% count%=0 FOR l%=-1 TO 1 IF world! (i%+l%,j%+1) count%=count%+1 ENDIF NEXT l% IF world! (i%+1,j%) count%=count%+1 ENDIF RETURN count%ENDFUNC'' Update the world one step'PROCEDURE update_world LOCAL i%,j% ' compute neighbour counts and store FOR i%=1 TO 30 FOR j%=1 TO 30 ns%(i%,j%)[email protected]_neighbours(i%,j%) NEXT j% NEXT i% ' update the world cells FOR i%=1 TO 30 FOR j%=1 TO 30 IF world!

||

randfill: stx $01 ;$200 for indirect ldx #$02 ;addressing stx $02randloop: lda $fe ;generate random and #$01 ;pixels on the sta ($01), Y ;screen jsr inc0103 cmp #$00 bne randloop lda $02 cmp #$06 bne randloop clearmem: lda #$df ;set $07df-$0a20 sta $01 ;to $#00 lda #$07 sta $02clearbyte: lda #$00 sta ($01), Y jsr inc0103 cmp #$20 bne clearbyte lda $02 cmp #$0a bne clearbyte starttick:copyscreen: lda #$00 ;set up source sta $01 ;pointer at sta $03 ;$01/$02 and lda #$02 ;dest pointer sta $02 ;at $03/$04 lda #$08 sta $04 ldy #$00copybyte: lda ($01), Y ;copy pixel to sta ($03), Y ;back buffer jsr inc0103 ;increment pointers cmp #$00 ;check to see bne copybyte ;if we're at $600 lda $02 ;if so, we've cmp #$06 ;copied the bne copybyte ;entire screen conway: lda #$df ;apply conway rules sta $01 ;reset the pointer sta $03 ;to $#01df/$#07df lda #$01 ;($200 - $21) sta $02 ;($800 - $21) lda #$07 sta $04onecell: lda #$00 ;process one cell ldy #$01 ;upper cell clc adc ($03), Y ldy #$41 ;lower cell clc adc ($03), Ychkleft: tax ;check to see lda $01 ;if we're at the and #$1f ;left edge tay txa cpy #$1f beq rightcellsleftcells: ldy #$00 ;upper-left cell clc adc ($03), Y ldy #$20 ;left cell clc adc ($03), Y ldy #$40 ;lower-left cell clc adc ($03), Ychkright: tax ;check to see lda $01 ;if we're at the and #$1f ;right edge tay txa cpy #$1e beq evaluaterightcells: ldy #$02 ;upper-right cell clc adc ($03), Y ldy #$22 ;right cell clc adc ($03), Y ldy #$42 ;lower-right cell clc adc ($03), Yevaluate: ldx #$01 ;evaluate total ldy #$21 ;for current cell cmp #$03 ;3 = alive beq storex ldx #$00 cmp #$02 ;2 = alive if bne storex ;c = alive lda ($03), Y and #$01 taxstorex: txa ;store to screen sta ($01), Y jsr inc0103 ;move to next cellconwayloop: cmp #$e0 ;if not last cell, bne onecell ;process next cell lda $02 cmp #$05 bne onecell jmp starttick ;run next tick inc0103: lda $01 ;increment $01 cmp #$ff ;and $03 as 16-bit bne onlyinc01 ;pointers inc $02 inc $04onlyinc01: inc $01 lda $01 sta $03 rts The solution uses one cell thick border around square Petri dish as uninhabited dire land. Sample output contains 3 generations of the blinker and 5 of the glider: See Conway's Game of Life/ALGOL 68 APL2 (Dialog) Example in one line APL \ 1130 example (very old APL dialect via simulator) APL1130From: APL \ 1130 Samples The following APL \ 1130 code will need APL385 font installed to display correctly.

See Download APL TT Font ∇LIFE[⎕]∇[0] NG←LIFE CG; W[1] W←CG+(¯1⊖CG)+(1⊖CG)+(¯1⌽CG)+(1⌽CG)[2] W←W+(1⊖1⌽CG)+(¯1⊖1⌽CG)+(1⊖¯1⌽CG)+(¯1⊖¯1⌽CG)[3] NG←(3=W)+(CG∧4=W) ∇ RP←5 5⍴0 0 0 0 0 0 0 1 1 0 0 1 1 0 0 0 0 1 0 0 RP0 0 0 0 00 0 1 1 00 1 1 0 00 0 1 0 00 0 0 0 0 LIFE RP0 0 0 0 00 1 1 1 00 1 0 0 00 1 1 0 00 0 0 0 0 LIFE LIFE RP0 0 1 0 00 1 1 0 01 0 0 1 00 1 1 0 00 0 0 0 0 ..................................................

One interacts with the Game of Life by creating an initial configuration and observing how it evolves.

Although you should test your implementation on more complex examples such as the glider in a larger universe, show the action of the blinker (three adjoining cells in a row all alive), over three generations, in a 3 by 3 grid.

(1,4)=TRUERETURN'' Count the number of neighbours of the point i,j' (Assume i/j +/- 1 will not fall out of world)'FUNCTION count_neighbours(i%,j%) LOCAL count%,l% count%=0 FOR l%=-1 TO 1 IF world! (i%+l%,j%+1) count%=count%+1 ENDIF NEXT l% IF world! (i%+1,j%) count%=count%+1 ENDIF RETURN count%ENDFUNC'' Update the world one step'PROCEDURE update_world LOCAL i%,j% ' compute neighbour counts and store FOR i%=1 TO 30 FOR j%=1 TO 30 ns%(i%,j%)[email protected]_neighbours(i%,j%) NEXT j% NEXT i% ' update the world cells FOR i%=1 TO 30 FOR j%=1 TO 30 IF world!

Thus, while it is somewhat verbose, it fully simulates Conway's Game of Life and is relatively simple to expand to feature different starting shapes.

Define life(pattern) = Prgm Local x,y,nt,count,save,xl,yl,xh,yh Define nt(y,x) = when(pxl Test(y,x), 1, 0) {}→save set Graph("Axes", "Off")→save[1] set Graph("Grid", "Off")→save[2] set Graph("Labels", "Off")→save[3] Fn Off Plot Off Clr Draw If pattern = "blinker" Then 36→yl 40→yh 78→xl 82→xh Pxl On 36,80 Pxl On 38,80 Pxl On 40,80 Else If pattern = "glider" Then 30→yl 40→yh 76→xl 88→xh Pxl On 38,76 Pxl On 36,78 Pxl On 36,80 Pxl On 38,80 Pxl On 40,80 Else If pattern = "r" Then 38-5*2→yl 38+5*2→yh 80-5*2→xl 80+5*2→xh Pxl On 38,78 Pxl On 36,82 Pxl On 36,80 Pxl On 38,80 Pxl On 40,80 End If While get Key() = 0 © Expand upper-left corner to whole cell For y,yl,yh,2 For x,xl,xh,2 If pxl Test(y,x) Then Pxl On y+1,x Pxl On y+1,x+1 Pxl On y, x+1 Else Pxl Off y+1,x Pxl Off y+1,x+1 Pxl Off y, x+1 End If End For End For © Compute next generation For y,yl,yh,2 For x,xl,xh,2 nt(y-1,x-1) + nt(y-1,x) + nt(y-1,x+2) + nt(y,x-1) + nt(y+1,x+2) + nt(y+2,x-1) + nt(y+2,x+1) + nt(y+2,x+2) → count If count = 3 Then Pxl On y,x Else If count ≠ 2 Then Pxl Off y,x End If End For End For End While © Restore changed options set Graph("Axes", save[1]) set Graph("Grid", save[2]) set Graph("Labels", save[3])End Prgm Also see Conway's Game of Life/C Considering that the simplest implementation in C++ would lack any use of the object-oriented paradigm, this code was specifically written to demonstrate the various object-oriented features of C++.

]]a bne clearbyte starttick:copyscreen: lda #[[

randfill: stx $01 ;$200 for indirect ldx #$02 ;addressing stx $02randloop: lda $fe ;generate random and #$01 ;pixels on the sta ($01), Y ;screen jsr inc0103 cmp #$00 bne randloop lda $02 cmp #$06 bne randloop clearmem: lda #$df ;set $07df-$0a20 sta $01 ;to $#00 lda #$07 sta $02clearbyte: lda #$00 sta ($01), Y jsr inc0103 cmp #$20 bne clearbyte lda $02 cmp #$0a bne clearbyte starttick:copyscreen: lda #$00 ;set up source sta $01 ;pointer at sta $03 ;$01/$02 and lda #$02 ;dest pointer sta $02 ;at $03/$04 lda #$08 sta $04 ldy #$00copybyte: lda ($01), Y ;copy pixel to sta ($03), Y ;back buffer jsr inc0103 ;increment pointers cmp #$00 ;check to see bne copybyte ;if we're at $600 lda $02 ;if so, we've cmp #$06 ;copied the bne copybyte ;entire screen conway: lda #$df ;apply conway rules sta $01 ;reset the pointer sta $03 ;to $#01df/$#07df lda #$01 ;($200 - $21) sta $02 ;($800 - $21) lda #$07 sta $04onecell: lda #$00 ;process one cell ldy #$01 ;upper cell clc adc ($03), Y ldy #$41 ;lower cell clc adc ($03), Ychkleft: tax ;check to see lda $01 ;if we're at the and #$1f ;left edge tay txa cpy #$1f beq rightcellsleftcells: ldy #$00 ;upper-left cell clc adc ($03), Y ldy #$20 ;left cell clc adc ($03), Y ldy #$40 ;lower-left cell clc adc ($03), Ychkright: tax ;check to see lda $01 ;if we're at the and #$1f ;right edge tay txa cpy #$1e beq evaluaterightcells: ldy #$02 ;upper-right cell clc adc ($03), Y ldy #$22 ;right cell clc adc ($03), Y ldy #$42 ;lower-right cell clc adc ($03), Yevaluate: ldx #$01 ;evaluate total ldy #$21 ;for current cell cmp #$03 ;3 = alive beq storex ldx #$00 cmp #$02 ;2 = alive if bne storex ;c = alive lda ($03), Y and #$01 taxstorex: txa ;store to screen sta ($01), Y jsr inc0103 ;move to next cellconwayloop: cmp #$e0 ;if not last cell, bne onecell ;process next cell lda $02 cmp #$05 bne onecell jmp starttick ;run next tick inc0103: lda $01 ;increment $01 cmp #$ff ;and $03 as 16-bit bne onlyinc01 ;pointers inc $02 inc $04onlyinc01: inc $01 lda $01 sta $03 rts The solution uses one cell thick border around square Petri dish as uninhabited dire land. Sample output contains 3 generations of the blinker and 5 of the glider: See Conway's Game of Life/ALGOL 68 APL2 (Dialog) Example in one line APL \ 1130 example (very old APL dialect via simulator) APL1130From: APL \ 1130 Samples The following APL \ 1130 code will need APL385 font installed to display correctly. See Download APL TT Font ∇LIFE[⎕]∇[0] NG←LIFE CG; W[1] W←CG+(¯1⊖CG)+(1⊖CG)+(¯1⌽CG)+(1⌽CG)[2] W←W+(1⊖1⌽CG)+(¯1⊖1⌽CG)+(1⊖¯1⌽CG)+(¯1⊖¯1⌽CG)[3] NG←(3=W)+(CG∧4=W) ∇ RP←5 5⍴0 0 0 0 0 0 0 1 1 0 0 1 1 0 0 0 0 1 0 0 RP0 0 0 0 00 0 1 1 00 1 1 0 00 0 1 0 00 0 0 0 0 LIFE RP0 0 0 0 00 1 1 1 00 1 0 0 00 1 1 0 00 0 0 0 0 LIFE LIFE RP0 0 1 0 00 1 1 0 01 0 0 1 00 1 1 0 00 0 0 0 0 .................................................. One interacts with the Game of Life by creating an initial configuration and observing how it evolves. Although you should test your implementation on more complex examples such as the glider in a larger universe, show the action of the blinker (three adjoining cells in a row all alive), over three generations, in a 3 by 3 grid. (1,4)=TRUERETURN'' Count the number of neighbours of the point i,j' (Assume i/j +/- 1 will not fall out of world)'FUNCTION count_neighbours(i%,j%) LOCAL count%,l% count%=0 FOR l%=-1 TO 1 IF world! (i%+l%,j%+1) count%=count%+1 ENDIF NEXT l% IF world! (i%+1,j%) count%=count%+1 ENDIF RETURN count%ENDFUNC'' Update the world one step'PROCEDURE update_world LOCAL i%,j% ' compute neighbour counts and store FOR i%=1 TO 30 FOR j%=1 TO 30 ns%(i%,j%)[email protected]_neighbours(i%,j%) NEXT j% NEXT i% ' update the world cells FOR i%=1 TO 30 FOR j%=1 TO 30 IF world!

||

randfill: stx $01 ;$200 for indirect ldx #$02 ;addressing stx $02randloop: lda $fe ;generate random and #$01 ;pixels on the sta ($01), Y ;screen jsr inc0103 cmp #$00 bne randloop lda $02 cmp #$06 bne randloop clearmem: lda #$df ;set $07df-$0a20 sta $01 ;to $#00 lda #$07 sta $02clearbyte: lda #$00 sta ($01), Y jsr inc0103 cmp #$20 bne clearbyte lda $02 cmp #$0a bne clearbyte starttick:copyscreen: lda #$00 ;set up source sta $01 ;pointer at sta $03 ;$01/$02 and lda #$02 ;dest pointer sta $02 ;at $03/$04 lda #$08 sta $04 ldy #$00copybyte: lda ($01), Y ;copy pixel to sta ($03), Y ;back buffer jsr inc0103 ;increment pointers cmp #$00 ;check to see bne copybyte ;if we're at $600 lda $02 ;if so, we've cmp #$06 ;copied the bne copybyte ;entire screen conway: lda #$df ;apply conway rules sta $01 ;reset the pointer sta $03 ;to $#01df/$#07df lda #$01 ;($200 - $21) sta $02 ;($800 - $21) lda #$07 sta $04onecell: lda #$00 ;process one cell ldy #$01 ;upper cell clc adc ($03), Y ldy #$41 ;lower cell clc adc ($03), Ychkleft: tax ;check to see lda $01 ;if we're at the and #$1f ;left edge tay txa cpy #$1f beq rightcellsleftcells: ldy #$00 ;upper-left cell clc adc ($03), Y ldy #$20 ;left cell clc adc ($03), Y ldy #$40 ;lower-left cell clc adc ($03), Ychkright: tax ;check to see lda $01 ;if we're at the and #$1f ;right edge tay txa cpy #$1e beq evaluaterightcells: ldy #$02 ;upper-right cell clc adc ($03), Y ldy #$22 ;right cell clc adc ($03), Y ldy #$42 ;lower-right cell clc adc ($03), Yevaluate: ldx #$01 ;evaluate total ldy #$21 ;for current cell cmp #$03 ;3 = alive beq storex ldx #$00 cmp #$02 ;2 = alive if bne storex ;c = alive lda ($03), Y and #$01 taxstorex: txa ;store to screen sta ($01), Y jsr inc0103 ;move to next cellconwayloop: cmp #$e0 ;if not last cell, bne onecell ;process next cell lda $02 cmp #$05 bne onecell jmp starttick ;run next tick inc0103: lda $01 ;increment $01 cmp #$ff ;and $03 as 16-bit bne onlyinc01 ;pointers inc $02 inc $04onlyinc01: inc $01 lda $01 sta $03 rts The solution uses one cell thick border around square Petri dish as uninhabited dire land. Sample output contains 3 generations of the blinker and 5 of the glider: See Conway's Game of Life/ALGOL 68 APL2 (Dialog) Example in one line APL \ 1130 example (very old APL dialect via simulator) APL1130From: APL \ 1130 Samples The following APL \ 1130 code will need APL385 font installed to display correctly.

See Download APL TT Font ∇LIFE[⎕]∇[0] NG←LIFE CG; W[1] W←CG+(¯1⊖CG)+(1⊖CG)+(¯1⌽CG)+(1⌽CG)[2] W←W+(1⊖1⌽CG)+(¯1⊖1⌽CG)+(1⊖¯1⌽CG)+(¯1⊖¯1⌽CG)[3] NG←(3=W)+(CG∧4=W) ∇ RP←5 5⍴0 0 0 0 0 0 0 1 1 0 0 1 1 0 0 0 0 1 0 0 RP0 0 0 0 00 0 1 1 00 1 1 0 00 0 1 0 00 0 0 0 0 LIFE RP0 0 0 0 00 1 1 1 00 1 0 0 00 1 1 0 00 0 0 0 0 LIFE LIFE RP0 0 1 0 00 1 1 0 01 0 0 1 00 1 1 0 00 0 0 0 0 ..................................................

One interacts with the Game of Life by creating an initial configuration and observing how it evolves.

Although you should test your implementation on more complex examples such as the glider in a larger universe, show the action of the blinker (three adjoining cells in a row all alive), over three generations, in a 3 by 3 grid.

(1,4)=TRUERETURN'' Count the number of neighbours of the point i,j' (Assume i/j +/- 1 will not fall out of world)'FUNCTION count_neighbours(i%,j%) LOCAL count%,l% count%=0 FOR l%=-1 TO 1 IF world! (i%+l%,j%+1) count%=count%+1 ENDIF NEXT l% IF world! (i%+1,j%) count%=count%+1 ENDIF RETURN count%ENDFUNC'' Update the world one step'PROCEDURE update_world LOCAL i%,j% ' compute neighbour counts and store FOR i%=1 TO 30 FOR j%=1 TO 30 ns%(i%,j%)[email protected]_neighbours(i%,j%) NEXT j% NEXT i% ' update the world cells FOR i%=1 TO 30 FOR j%=1 TO 30 IF world!

Thus, while it is somewhat verbose, it fully simulates Conway's Game of Life and is relatively simple to expand to feature different starting shapes.

Define life(pattern) = Prgm Local x,y,nt,count,save,xl,yl,xh,yh Define nt(y,x) = when(pxl Test(y,x), 1, 0) {}→save set Graph("Axes", "Off")→save[1] set Graph("Grid", "Off")→save[2] set Graph("Labels", "Off")→save[3] Fn Off Plot Off Clr Draw If pattern = "blinker" Then 36→yl 40→yh 78→xl 82→xh Pxl On 36,80 Pxl On 38,80 Pxl On 40,80 Else If pattern = "glider" Then 30→yl 40→yh 76→xl 88→xh Pxl On 38,76 Pxl On 36,78 Pxl On 36,80 Pxl On 38,80 Pxl On 40,80 Else If pattern = "r" Then 38-5*2→yl 38+5*2→yh 80-5*2→xl 80+5*2→xh Pxl On 38,78 Pxl On 36,82 Pxl On 36,80 Pxl On 38,80 Pxl On 40,80 End If While get Key() = 0 © Expand upper-left corner to whole cell For y,yl,yh,2 For x,xl,xh,2 If pxl Test(y,x) Then Pxl On y+1,x Pxl On y+1,x+1 Pxl On y, x+1 Else Pxl Off y+1,x Pxl Off y+1,x+1 Pxl Off y, x+1 End If End For End For © Compute next generation For y,yl,yh,2 For x,xl,xh,2 nt(y-1,x-1) + nt(y-1,x) + nt(y-1,x+2) + nt(y,x-1) + nt(y+1,x+2) + nt(y+2,x-1) + nt(y+2,x+1) + nt(y+2,x+2) → count If count = 3 Then Pxl On y,x Else If count ≠ 2 Then Pxl Off y,x End If End For End For End While © Restore changed options set Graph("Axes", save[1]) set Graph("Grid", save[2]) set Graph("Labels", save[3])End Prgm Also see Conway's Game of Life/C Considering that the simplest implementation in C++ would lack any use of the object-oriented paradigm, this code was specifically written to demonstrate the various object-oriented features of C++.

]] ;set up source sta

randfill: stx $01 ;$200 for indirect ldx #$02 ;addressing stx $02randloop: lda $fe ;generate random and #$01 ;pixels on the sta ($01), Y ;screen jsr inc0103 cmp #$00 bne randloop lda $02 cmp #$06 bne randloop clearmem: lda #$df ;set $07df-$0a20 sta $01 ;to $#00 lda #$07 sta $02clearbyte: lda #$00 sta ($01), Y jsr inc0103 cmp #$20 bne clearbyte lda $02 cmp #$0a bne clearbyte starttick:copyscreen: lda #$00 ;set up source sta $01 ;pointer at sta $03 ;$01/$02 and lda #$02 ;dest pointer sta $02 ;at $03/$04 lda #$08 sta $04 ldy #$00copybyte: lda ($01), Y ;copy pixel to sta ($03), Y ;back buffer jsr inc0103 ;increment pointers cmp #$00 ;check to see bne copybyte ;if we're at $600 lda $02 ;if so, we've cmp #$06 ;copied the bne copybyte ;entire screen conway: lda #$df ;apply conway rules sta $01 ;reset the pointer sta $03 ;to $#01df/$#07df lda #$01 ;($200 - $21) sta $02 ;($800 - $21) lda #$07 sta $04onecell: lda #$00 ;process one cell ldy #$01 ;upper cell clc adc ($03), Y ldy #$41 ;lower cell clc adc ($03), Ychkleft: tax ;check to see lda $01 ;if we're at the and #$1f ;left edge tay txa cpy #$1f beq rightcellsleftcells: ldy #$00 ;upper-left cell clc adc ($03), Y ldy #$20 ;left cell clc adc ($03), Y ldy #$40 ;lower-left cell clc adc ($03), Ychkright: tax ;check to see lda $01 ;if we're at the and #$1f ;right edge tay txa cpy #$1e beq evaluaterightcells: ldy #$02 ;upper-right cell clc adc ($03), Y ldy #$22 ;right cell clc adc ($03), Y ldy #$42 ;lower-right cell clc adc ($03), Yevaluate: ldx #$01 ;evaluate total ldy #$21 ;for current cell cmp #$03 ;3 = alive beq storex ldx #$00 cmp #$02 ;2 = alive if bne storex ;c = alive lda ($03), Y and #$01 taxstorex: txa ;store to screen sta ($01), Y jsr inc0103 ;move to next cellconwayloop: cmp #$e0 ;if not last cell, bne onecell ;process next cell lda $02 cmp #$05 bne onecell jmp starttick ;run next tick inc0103: lda $01 ;increment $01 cmp #$ff ;and $03 as 16-bit bne onlyinc01 ;pointers inc $02 inc $04onlyinc01: inc $01 lda $01 sta $03 rts The solution uses one cell thick border around square Petri dish as uninhabited dire land. Sample output contains 3 generations of the blinker and 5 of the glider: See Conway's Game of Life/ALGOL 68 APL2 (Dialog) Example in one line APL \ 1130 example (very old APL dialect via simulator) APL1130From: APL \ 1130 Samples The following APL \ 1130 code will need APL385 font installed to display correctly. See Download APL TT Font ∇LIFE[⎕]∇[0] NG←LIFE CG; W[1] W←CG+(¯1⊖CG)+(1⊖CG)+(¯1⌽CG)+(1⌽CG)[2] W←W+(1⊖1⌽CG)+(¯1⊖1⌽CG)+(1⊖¯1⌽CG)+(¯1⊖¯1⌽CG)[3] NG←(3=W)+(CG∧4=W) ∇ RP←5 5⍴0 0 0 0 0 0 0 1 1 0 0 1 1 0 0 0 0 1 0 0 RP0 0 0 0 00 0 1 1 00 1 1 0 00 0 1 0 00 0 0 0 0 LIFE RP0 0 0 0 00 1 1 1 00 1 0 0 00 1 1 0 00 0 0 0 0 LIFE LIFE RP0 0 1 0 00 1 1 0 01 0 0 1 00 1 1 0 00 0 0 0 0 .................................................. One interacts with the Game of Life by creating an initial configuration and observing how it evolves. Although you should test your implementation on more complex examples such as the glider in a larger universe, show the action of the blinker (three adjoining cells in a row all alive), over three generations, in a 3 by 3 grid. (1,4)=TRUERETURN'' Count the number of neighbours of the point i,j' (Assume i/j +/- 1 will not fall out of world)'FUNCTION count_neighbours(i%,j%) LOCAL count%,l% count%=0 FOR l%=-1 TO 1 IF world! (i%+l%,j%+1) count%=count%+1 ENDIF NEXT l% IF world! (i%+1,j%) count%=count%+1 ENDIF RETURN count%ENDFUNC'' Update the world one step'PROCEDURE update_world LOCAL i%,j% ' compute neighbour counts and store FOR i%=1 TO 30 FOR j%=1 TO 30 ns%(i%,j%)[email protected]_neighbours(i%,j%) NEXT j% NEXT i% ' update the world cells FOR i%=1 TO 30 FOR j%=1 TO 30 IF world!

||

randfill: stx $01 ;$200 for indirect ldx #$02 ;addressing stx $02randloop: lda $fe ;generate random and #$01 ;pixels on the sta ($01), Y ;screen jsr inc0103 cmp #$00 bne randloop lda $02 cmp #$06 bne randloop clearmem: lda #$df ;set $07df-$0a20 sta $01 ;to $#00 lda #$07 sta $02clearbyte: lda #$00 sta ($01), Y jsr inc0103 cmp #$20 bne clearbyte lda $02 cmp #$0a bne clearbyte starttick:copyscreen: lda #$00 ;set up source sta $01 ;pointer at sta $03 ;$01/$02 and lda #$02 ;dest pointer sta $02 ;at $03/$04 lda #$08 sta $04 ldy #$00copybyte: lda ($01), Y ;copy pixel to sta ($03), Y ;back buffer jsr inc0103 ;increment pointers cmp #$00 ;check to see bne copybyte ;if we're at $600 lda $02 ;if so, we've cmp #$06 ;copied the bne copybyte ;entire screen conway: lda #$df ;apply conway rules sta $01 ;reset the pointer sta $03 ;to $#01df/$#07df lda #$01 ;($200 - $21) sta $02 ;($800 - $21) lda #$07 sta $04onecell: lda #$00 ;process one cell ldy #$01 ;upper cell clc adc ($03), Y ldy #$41 ;lower cell clc adc ($03), Ychkleft: tax ;check to see lda $01 ;if we're at the and #$1f ;left edge tay txa cpy #$1f beq rightcellsleftcells: ldy #$00 ;upper-left cell clc adc ($03), Y ldy #$20 ;left cell clc adc ($03), Y ldy #$40 ;lower-left cell clc adc ($03), Ychkright: tax ;check to see lda $01 ;if we're at the and #$1f ;right edge tay txa cpy #$1e beq evaluaterightcells: ldy #$02 ;upper-right cell clc adc ($03), Y ldy #$22 ;right cell clc adc ($03), Y ldy #$42 ;lower-right cell clc adc ($03), Yevaluate: ldx #$01 ;evaluate total ldy #$21 ;for current cell cmp #$03 ;3 = alive beq storex ldx #$00 cmp #$02 ;2 = alive if bne storex ;c = alive lda ($03), Y and #$01 taxstorex: txa ;store to screen sta ($01), Y jsr inc0103 ;move to next cellconwayloop: cmp #$e0 ;if not last cell, bne onecell ;process next cell lda $02 cmp #$05 bne onecell jmp starttick ;run next tick inc0103: lda $01 ;increment $01 cmp #$ff ;and $03 as 16-bit bne onlyinc01 ;pointers inc $02 inc $04onlyinc01: inc $01 lda $01 sta $03 rts The solution uses one cell thick border around square Petri dish as uninhabited dire land. Sample output contains 3 generations of the blinker and 5 of the glider: See Conway's Game of Life/ALGOL 68 APL2 (Dialog) Example in one line APL \ 1130 example (very old APL dialect via simulator) APL1130From: APL \ 1130 Samples The following APL \ 1130 code will need APL385 font installed to display correctly.

See Download APL TT Font ∇LIFE[⎕]∇[0] NG←LIFE CG; W[1] W←CG+(¯1⊖CG)+(1⊖CG)+(¯1⌽CG)+(1⌽CG)[2] W←W+(1⊖1⌽CG)+(¯1⊖1⌽CG)+(1⊖¯1⌽CG)+(¯1⊖¯1⌽CG)[3] NG←(3=W)+(CG∧4=W) ∇ RP←5 5⍴0 0 0 0 0 0 0 1 1 0 0 1 1 0 0 0 0 1 0 0 RP0 0 0 0 00 0 1 1 00 1 1 0 00 0 1 0 00 0 0 0 0 LIFE RP0 0 0 0 00 1 1 1 00 1 0 0 00 1 1 0 00 0 0 0 0 LIFE LIFE RP0 0 1 0 00 1 1 0 01 0 0 1 00 1 1 0 00 0 0 0 0 ..................................................

One interacts with the Game of Life by creating an initial configuration and observing how it evolves.

Although you should test your implementation on more complex examples such as the glider in a larger universe, show the action of the blinker (three adjoining cells in a row all alive), over three generations, in a 3 by 3 grid.

(1,4)=TRUERETURN'' Count the number of neighbours of the point i,j' (Assume i/j +/- 1 will not fall out of world)'FUNCTION count_neighbours(i%,j%) LOCAL count%,l% count%=0 FOR l%=-1 TO 1 IF world! (i%+l%,j%+1) count%=count%+1 ENDIF NEXT l% IF world! (i%+1,j%) count%=count%+1 ENDIF RETURN count%ENDFUNC'' Update the world one step'PROCEDURE update_world LOCAL i%,j% ' compute neighbour counts and store FOR i%=1 TO 30 FOR j%=1 TO 30 ns%(i%,j%)[email protected]_neighbours(i%,j%) NEXT j% NEXT i% ' update the world cells FOR i%=1 TO 30 FOR j%=1 TO 30 IF world!

Thus, while it is somewhat verbose, it fully simulates Conway's Game of Life and is relatively simple to expand to feature different starting shapes.

Define life(pattern) = Prgm Local x,y,nt,count,save,xl,yl,xh,yh Define nt(y,x) = when(pxl Test(y,x), 1, 0) {}→save set Graph("Axes", "Off")→save[1] set Graph("Grid", "Off")→save[2] set Graph("Labels", "Off")→save[3] Fn Off Plot Off Clr Draw If pattern = "blinker" Then 36→yl 40→yh 78→xl 82→xh Pxl On 36,80 Pxl On 38,80 Pxl On 40,80 Else If pattern = "glider" Then 30→yl 40→yh 76→xl 88→xh Pxl On 38,76 Pxl On 36,78 Pxl On 36,80 Pxl On 38,80 Pxl On 40,80 Else If pattern = "r" Then 38-5*2→yl 38+5*2→yh 80-5*2→xl 80+5*2→xh Pxl On 38,78 Pxl On 36,82 Pxl On 36,80 Pxl On 38,80 Pxl On 40,80 End If While get Key() = 0 © Expand upper-left corner to whole cell For y,yl,yh,2 For x,xl,xh,2 If pxl Test(y,x) Then Pxl On y+1,x Pxl On y+1,x+1 Pxl On y, x+1 Else Pxl Off y+1,x Pxl Off y+1,x+1 Pxl Off y, x+1 End If End For End For © Compute next generation For y,yl,yh,2 For x,xl,xh,2 nt(y-1,x-1) + nt(y-1,x) + nt(y-1,x+2) + nt(y,x-1) + nt(y+1,x+2) + nt(y+2,x-1) + nt(y+2,x+1) + nt(y+2,x+2) → count If count = 3 Then Pxl On y,x Else If count ≠ 2 Then Pxl Off y,x End If End For End For End While © Restore changed options set Graph("Axes", save[1]) set Graph("Grid", save[2]) set Graph("Labels", save[3])End Prgm Also see Conway's Game of Life/C Considering that the simplest implementation in C++ would lack any use of the object-oriented paradigm, this code was specifically written to demonstrate the various object-oriented features of C++.

;pointer at sta ;

randfill: stx $01 ;$200 for indirect ldx #$02 ;addressing stx $02randloop: lda $fe ;generate random and #$01 ;pixels on the sta ($01), Y ;screen jsr inc0103 cmp #$00 bne randloop lda $02 cmp #$06 bne randloop clearmem: lda #$df ;set $07df-$0a20 sta $01 ;to $#00 lda #$07 sta $02clearbyte: lda #$00 sta ($01), Y jsr inc0103 cmp #$20 bne clearbyte lda $02 cmp #$0a bne clearbyte starttick:copyscreen: lda #$00 ;set up source sta $01 ;pointer at sta $03 ;$01/$02 and lda #$02 ;dest pointer sta $02 ;at $03/$04 lda #$08 sta $04 ldy #$00copybyte: lda ($01), Y ;copy pixel to sta ($03), Y ;back buffer jsr inc0103 ;increment pointers cmp #$00 ;check to see bne copybyte ;if we're at $600 lda $02 ;if so, we've cmp #$06 ;copied the bne copybyte ;entire screen conway: lda #$df ;apply conway rules sta $01 ;reset the pointer sta $03 ;to $#01df/$#07df lda #$01 ;($200 - $21) sta $02 ;($800 - $21) lda #$07 sta $04onecell: lda #$00 ;process one cell ldy #$01 ;upper cell clc adc ($03), Y ldy #$41 ;lower cell clc adc ($03), Ychkleft: tax ;check to see lda $01 ;if we're at the and #$1f ;left edge tay txa cpy #$1f beq rightcellsleftcells: ldy #$00 ;upper-left cell clc adc ($03), Y ldy #$20 ;left cell clc adc ($03), Y ldy #$40 ;lower-left cell clc adc ($03), Ychkright: tax ;check to see lda $01 ;if we're at the and #$1f ;right edge tay txa cpy #$1e beq evaluaterightcells: ldy #$02 ;upper-right cell clc adc ($03), Y ldy #$22 ;right cell clc adc ($03), Y ldy #$42 ;lower-right cell clc adc ($03), Yevaluate: ldx #$01 ;evaluate total ldy #$21 ;for current cell cmp #$03 ;3 = alive beq storex ldx #$00 cmp #$02 ;2 = alive if bne storex ;c = alive lda ($03), Y and #$01 taxstorex: txa ;store to screen sta ($01), Y jsr inc0103 ;move to next cellconwayloop: cmp #$e0 ;if not last cell, bne onecell ;process next cell lda $02 cmp #$05 bne onecell jmp starttick ;run next tick inc0103: lda $01 ;increment $01 cmp #$ff ;and $03 as 16-bit bne onlyinc01 ;pointers inc $02 inc $04onlyinc01: inc $01 lda $01 sta $03 rts The solution uses one cell thick border around square Petri dish as uninhabited dire land. Sample output contains 3 generations of the blinker and 5 of the glider: See Conway's Game of Life/ALGOL 68 APL2 (Dialog) Example in one line APL \ 1130 example (very old APL dialect via simulator) APL1130From: APL \ 1130 Samples The following APL \ 1130 code will need APL385 font installed to display correctly. See Download APL TT Font ∇LIFE[⎕]∇[0] NG←LIFE CG; W[1] W←CG+(¯1⊖CG)+(1⊖CG)+(¯1⌽CG)+(1⌽CG)[2] W←W+(1⊖1⌽CG)+(¯1⊖1⌽CG)+(1⊖¯1⌽CG)+(¯1⊖¯1⌽CG)[3] NG←(3=W)+(CG∧4=W) ∇ RP←5 5⍴0 0 0 0 0 0 0 1 1 0 0 1 1 0 0 0 0 1 0 0 RP0 0 0 0 00 0 1 1 00 1 1 0 00 0 1 0 00 0 0 0 0 LIFE RP0 0 0 0 00 1 1 1 00 1 0 0 00 1 1 0 00 0 0 0 0 LIFE LIFE RP0 0 1 0 00 1 1 0 01 0 0 1 00 1 1 0 00 0 0 0 0 .................................................. One interacts with the Game of Life by creating an initial configuration and observing how it evolves. Although you should test your implementation on more complex examples such as the glider in a larger universe, show the action of the blinker (three adjoining cells in a row all alive), over three generations, in a 3 by 3 grid. (1,4)=TRUERETURN'' Count the number of neighbours of the point i,j' (Assume i/j +/- 1 will not fall out of world)'FUNCTION count_neighbours(i%,j%) LOCAL count%,l% count%=0 FOR l%=-1 TO 1 IF world! (i%+l%,j%+1) count%=count%+1 ENDIF NEXT l% IF world! (i%+1,j%) count%=count%+1 ENDIF RETURN count%ENDFUNC'' Update the world one step'PROCEDURE update_world LOCAL i%,j% ' compute neighbour counts and store FOR i%=1 TO 30 FOR j%=1 TO 30 ns%(i%,j%)[email protected]_neighbours(i%,j%) NEXT j% NEXT i% ' update the world cells FOR i%=1 TO 30 FOR j%=1 TO 30 IF world!

||

randfill: stx $01 ;$200 for indirect ldx #$02 ;addressing stx $02randloop: lda $fe ;generate random and #$01 ;pixels on the sta ($01), Y ;screen jsr inc0103 cmp #$00 bne randloop lda $02 cmp #$06 bne randloop clearmem: lda #$df ;set $07df-$0a20 sta $01 ;to $#00 lda #$07 sta $02clearbyte: lda #$00 sta ($01), Y jsr inc0103 cmp #$20 bne clearbyte lda $02 cmp #$0a bne clearbyte starttick:copyscreen: lda #$00 ;set up source sta $01 ;pointer at sta $03 ;$01/$02 and lda #$02 ;dest pointer sta $02 ;at $03/$04 lda #$08 sta $04 ldy #$00copybyte: lda ($01), Y ;copy pixel to sta ($03), Y ;back buffer jsr inc0103 ;increment pointers cmp #$00 ;check to see bne copybyte ;if we're at $600 lda $02 ;if so, we've cmp #$06 ;copied the bne copybyte ;entire screen conway: lda #$df ;apply conway rules sta $01 ;reset the pointer sta $03 ;to $#01df/$#07df lda #$01 ;($200 - $21) sta $02 ;($800 - $21) lda #$07 sta $04onecell: lda #$00 ;process one cell ldy #$01 ;upper cell clc adc ($03), Y ldy #$41 ;lower cell clc adc ($03), Ychkleft: tax ;check to see lda $01 ;if we're at the and #$1f ;left edge tay txa cpy #$1f beq rightcellsleftcells: ldy #$00 ;upper-left cell clc adc ($03), Y ldy #$20 ;left cell clc adc ($03), Y ldy #$40 ;lower-left cell clc adc ($03), Ychkright: tax ;check to see lda $01 ;if we're at the and #$1f ;right edge tay txa cpy #$1e beq evaluaterightcells: ldy #$02 ;upper-right cell clc adc ($03), Y ldy #$22 ;right cell clc adc ($03), Y ldy #$42 ;lower-right cell clc adc ($03), Yevaluate: ldx #$01 ;evaluate total ldy #$21 ;for current cell cmp #$03 ;3 = alive beq storex ldx #$00 cmp #$02 ;2 = alive if bne storex ;c = alive lda ($03), Y and #$01 taxstorex: txa ;store to screen sta ($01), Y jsr inc0103 ;move to next cellconwayloop: cmp #$e0 ;if not last cell, bne onecell ;process next cell lda $02 cmp #$05 bne onecell jmp starttick ;run next tick inc0103: lda $01 ;increment $01 cmp #$ff ;and $03 as 16-bit bne onlyinc01 ;pointers inc $02 inc $04onlyinc01: inc $01 lda $01 sta $03 rts The solution uses one cell thick border around square Petri dish as uninhabited dire land. Sample output contains 3 generations of the blinker and 5 of the glider: See Conway's Game of Life/ALGOL 68 APL2 (Dialog) Example in one line APL \ 1130 example (very old APL dialect via simulator) APL1130From: APL \ 1130 Samples The following APL \ 1130 code will need APL385 font installed to display correctly.

See Download APL TT Font ∇LIFE[⎕]∇[0] NG←LIFE CG; W[1] W←CG+(¯1⊖CG)+(1⊖CG)+(¯1⌽CG)+(1⌽CG)[2] W←W+(1⊖1⌽CG)+(¯1⊖1⌽CG)+(1⊖¯1⌽CG)+(¯1⊖¯1⌽CG)[3] NG←(3=W)+(CG∧4=W) ∇ RP←5 5⍴0 0 0 0 0 0 0 1 1 0 0 1 1 0 0 0 0 1 0 0 RP0 0 0 0 00 0 1 1 00 1 1 0 00 0 1 0 00 0 0 0 0 LIFE RP0 0 0 0 00 1 1 1 00 1 0 0 00 1 1 0 00 0 0 0 0 LIFE LIFE RP0 0 1 0 00 1 1 0 01 0 0 1 00 1 1 0 00 0 0 0 0 ..................................................

One interacts with the Game of Life by creating an initial configuration and observing how it evolves.

Although you should test your implementation on more complex examples such as the glider in a larger universe, show the action of the blinker (three adjoining cells in a row all alive), over three generations, in a 3 by 3 grid.

(1,4)=TRUERETURN'' Count the number of neighbours of the point i,j' (Assume i/j +/- 1 will not fall out of world)'FUNCTION count_neighbours(i%,j%) LOCAL count%,l% count%=0 FOR l%=-1 TO 1 IF world! (i%+l%,j%+1) count%=count%+1 ENDIF NEXT l% IF world! (i%+1,j%) count%=count%+1 ENDIF RETURN count%ENDFUNC'' Update the world one step'PROCEDURE update_world LOCAL i%,j% ' compute neighbour counts and store FOR i%=1 TO 30 FOR j%=1 TO 30 ns%(i%,j%)[email protected]_neighbours(i%,j%) NEXT j% NEXT i% ' update the world cells FOR i%=1 TO 30 FOR j%=1 TO 30 IF world!

Thus, while it is somewhat verbose, it fully simulates Conway's Game of Life and is relatively simple to expand to feature different starting shapes.

Define life(pattern) = Prgm Local x,y,nt,count,save,xl,yl,xh,yh Define nt(y,x) = when(pxl Test(y,x), 1, 0) {}→save set Graph("Axes", "Off")→save[1] set Graph("Grid", "Off")→save[2] set Graph("Labels", "Off")→save[3] Fn Off Plot Off Clr Draw If pattern = "blinker" Then 36→yl 40→yh 78→xl 82→xh Pxl On 36,80 Pxl On 38,80 Pxl On 40,80 Else If pattern = "glider" Then 30→yl 40→yh 76→xl 88→xh Pxl On 38,76 Pxl On 36,78 Pxl On 36,80 Pxl On 38,80 Pxl On 40,80 Else If pattern = "r" Then 38-5*2→yl 38+5*2→yh 80-5*2→xl 80+5*2→xh Pxl On 38,78 Pxl On 36,82 Pxl On 36,80 Pxl On 38,80 Pxl On 40,80 End If While get Key() = 0 © Expand upper-left corner to whole cell For y,yl,yh,2 For x,xl,xh,2 If pxl Test(y,x) Then Pxl On y+1,x Pxl On y+1,x+1 Pxl On y, x+1 Else Pxl Off y+1,x Pxl Off y+1,x+1 Pxl Off y, x+1 End If End For End For © Compute next generation For y,yl,yh,2 For x,xl,xh,2 nt(y-1,x-1) + nt(y-1,x) + nt(y-1,x+2) + nt(y,x-1) + nt(y+1,x+2) + nt(y+2,x-1) + nt(y+2,x+1) + nt(y+2,x+2) → count If count = 3 Then Pxl On y,x Else If count ≠ 2 Then Pxl Off y,x End If End For End For End While © Restore changed options set Graph("Axes", save[1]) set Graph("Grid", save[2]) set Graph("Labels", save[3])End Prgm Also see Conway's Game of Life/C Considering that the simplest implementation in C++ would lack any use of the object-oriented paradigm, this code was specifically written to demonstrate the various object-oriented features of C++.

/ and lda # ;dest pointer sta ;at / lda # sta ldy #[[

randfill: stx $01 ;$200 for indirect ldx #$02 ;addressing stx $02randloop: lda $fe ;generate random and #$01 ;pixels on the sta ($01), Y ;screen jsr inc0103 cmp #$00 bne randloop lda $02 cmp #$06 bne randloop clearmem: lda #$df ;set $07df-$0a20 sta $01 ;to $#00 lda #$07 sta $02clearbyte: lda #$00 sta ($01), Y jsr inc0103 cmp #$20 bne clearbyte lda $02 cmp #$0a bne clearbyte starttick:copyscreen: lda #$00 ;set up source sta $01 ;pointer at sta $03 ;$01/$02 and lda #$02 ;dest pointer sta $02 ;at $03/$04 lda #$08 sta $04 ldy #$00copybyte: lda ($01), Y ;copy pixel to sta ($03), Y ;back buffer jsr inc0103 ;increment pointers cmp #$00 ;check to see bne copybyte ;if we're at $600 lda $02 ;if so, we've cmp #$06 ;copied the bne copybyte ;entire screen conway: lda #$df ;apply conway rules sta $01 ;reset the pointer sta $03 ;to $#01df/$#07df lda #$01 ;($200 - $21) sta $02 ;($800 - $21) lda #$07 sta $04onecell: lda #$00 ;process one cell ldy #$01 ;upper cell clc adc ($03), Y ldy #$41 ;lower cell clc adc ($03), Ychkleft: tax ;check to see lda $01 ;if we're at the and #$1f ;left edge tay txa cpy #$1f beq rightcellsleftcells: ldy #$00 ;upper-left cell clc adc ($03), Y ldy #$20 ;left cell clc adc ($03), Y ldy #$40 ;lower-left cell clc adc ($03), Ychkright: tax ;check to see lda $01 ;if we're at the and #$1f ;right edge tay txa cpy #$1e beq evaluaterightcells: ldy #$02 ;upper-right cell clc adc ($03), Y ldy #$22 ;right cell clc adc ($03), Y ldy #$42 ;lower-right cell clc adc ($03), Yevaluate: ldx #$01 ;evaluate total ldy #$21 ;for current cell cmp #$03 ;3 = alive beq storex ldx #$00 cmp #$02 ;2 = alive if bne storex ;c = alive lda ($03), Y and #$01 taxstorex: txa ;store to screen sta ($01), Y jsr inc0103 ;move to next cellconwayloop: cmp #$e0 ;if not last cell, bne onecell ;process next cell lda $02 cmp #$05 bne onecell jmp starttick ;run next tick inc0103: lda $01 ;increment $01 cmp #$ff ;and $03 as 16-bit bne onlyinc01 ;pointers inc $02 inc $04onlyinc01: inc $01 lda $01 sta $03 rts The solution uses one cell thick border around square Petri dish as uninhabited dire land. Sample output contains 3 generations of the blinker and 5 of the glider: See Conway's Game of Life/ALGOL 68 APL2 (Dialog) Example in one line APL \ 1130 example (very old APL dialect via simulator) APL1130From: APL \ 1130 Samples The following APL \ 1130 code will need APL385 font installed to display correctly. See Download APL TT Font ∇LIFE[⎕]∇[0] NG←LIFE CG; W[1] W←CG+(¯1⊖CG)+(1⊖CG)+(¯1⌽CG)+(1⌽CG)[2] W←W+(1⊖1⌽CG)+(¯1⊖1⌽CG)+(1⊖¯1⌽CG)+(¯1⊖¯1⌽CG)[3] NG←(3=W)+(CG∧4=W) ∇ RP←5 5⍴0 0 0 0 0 0 0 1 1 0 0 1 1 0 0 0 0 1 0 0 RP0 0 0 0 00 0 1 1 00 1 1 0 00 0 1 0 00 0 0 0 0 LIFE RP0 0 0 0 00 1 1 1 00 1 0 0 00 1 1 0 00 0 0 0 0 LIFE LIFE RP0 0 1 0 00 1 1 0 01 0 0 1 00 1 1 0 00 0 0 0 0 .................................................. One interacts with the Game of Life by creating an initial configuration and observing how it evolves. Although you should test your implementation on more complex examples such as the glider in a larger universe, show the action of the blinker (three adjoining cells in a row all alive), over three generations, in a 3 by 3 grid. (1,4)=TRUERETURN'' Count the number of neighbours of the point i,j' (Assume i/j +/- 1 will not fall out of world)'FUNCTION count_neighbours(i%,j%) LOCAL count%,l% count%=0 FOR l%=-1 TO 1 IF world! (i%+l%,j%+1) count%=count%+1 ENDIF NEXT l% IF world! (i%+1,j%) count%=count%+1 ENDIF RETURN count%ENDFUNC'' Update the world one step'PROCEDURE update_world LOCAL i%,j% ' compute neighbour counts and store FOR i%=1 TO 30 FOR j%=1 TO 30 ns%(i%,j%)[email protected]_neighbours(i%,j%) NEXT j% NEXT i% ' update the world cells FOR i%=1 TO 30 FOR j%=1 TO 30 IF world!

||

randfill: stx $01 ;$200 for indirect ldx #$02 ;addressing stx $02randloop: lda $fe ;generate random and #$01 ;pixels on the sta ($01), Y ;screen jsr inc0103 cmp #$00 bne randloop lda $02 cmp #$06 bne randloop clearmem: lda #$df ;set $07df-$0a20 sta $01 ;to $#00 lda #$07 sta $02clearbyte: lda #$00 sta ($01), Y jsr inc0103 cmp #$20 bne clearbyte lda $02 cmp #$0a bne clearbyte starttick:copyscreen: lda #$00 ;set up source sta $01 ;pointer at sta $03 ;$01/$02 and lda #$02 ;dest pointer sta $02 ;at $03/$04 lda #$08 sta $04 ldy #$00copybyte: lda ($01), Y ;copy pixel to sta ($03), Y ;back buffer jsr inc0103 ;increment pointers cmp #$00 ;check to see bne copybyte ;if we're at $600 lda $02 ;if so, we've cmp #$06 ;copied the bne copybyte ;entire screen conway: lda #$df ;apply conway rules sta $01 ;reset the pointer sta $03 ;to $#01df/$#07df lda #$01 ;($200 - $21) sta $02 ;($800 - $21) lda #$07 sta $04onecell: lda #$00 ;process one cell ldy #$01 ;upper cell clc adc ($03), Y ldy #$41 ;lower cell clc adc ($03), Ychkleft: tax ;check to see lda $01 ;if we're at the and #$1f ;left edge tay txa cpy #$1f beq rightcellsleftcells: ldy #$00 ;upper-left cell clc adc ($03), Y ldy #$20 ;left cell clc adc ($03), Y ldy #$40 ;lower-left cell clc adc ($03), Ychkright: tax ;check to see lda $01 ;if we're at the and #$1f ;right edge tay txa cpy #$1e beq evaluaterightcells: ldy #$02 ;upper-right cell clc adc ($03), Y ldy #$22 ;right cell clc adc ($03), Y ldy #$42 ;lower-right cell clc adc ($03), Yevaluate: ldx #$01 ;evaluate total ldy #$21 ;for current cell cmp #$03 ;3 = alive beq storex ldx #$00 cmp #$02 ;2 = alive if bne storex ;c = alive lda ($03), Y and #$01 taxstorex: txa ;store to screen sta ($01), Y jsr inc0103 ;move to next cellconwayloop: cmp #$e0 ;if not last cell, bne onecell ;process next cell lda $02 cmp #$05 bne onecell jmp starttick ;run next tick inc0103: lda $01 ;increment $01 cmp #$ff ;and $03 as 16-bit bne onlyinc01 ;pointers inc $02 inc $04onlyinc01: inc $01 lda $01 sta $03 rts The solution uses one cell thick border around square Petri dish as uninhabited dire land. Sample output contains 3 generations of the blinker and 5 of the glider: See Conway's Game of Life/ALGOL 68 APL2 (Dialog) Example in one line APL \ 1130 example (very old APL dialect via simulator) APL1130From: APL \ 1130 Samples The following APL \ 1130 code will need APL385 font installed to display correctly.

See Download APL TT Font ∇LIFE[⎕]∇[0] NG←LIFE CG; W[1] W←CG+(¯1⊖CG)+(1⊖CG)+(¯1⌽CG)+(1⌽CG)[2] W←W+(1⊖1⌽CG)+(¯1⊖1⌽CG)+(1⊖¯1⌽CG)+(¯1⊖¯1⌽CG)[3] NG←(3=W)+(CG∧4=W) ∇ RP←5 5⍴0 0 0 0 0 0 0 1 1 0 0 1 1 0 0 0 0 1 0 0 RP0 0 0 0 00 0 1 1 00 1 1 0 00 0 1 0 00 0 0 0 0 LIFE RP0 0 0 0 00 1 1 1 00 1 0 0 00 1 1 0 00 0 0 0 0 LIFE LIFE RP0 0 1 0 00 1 1 0 01 0 0 1 00 1 1 0 00 0 0 0 0 ..................................................

One interacts with the Game of Life by creating an initial configuration and observing how it evolves.

Although you should test your implementation on more complex examples such as the glider in a larger universe, show the action of the blinker (three adjoining cells in a row all alive), over three generations, in a 3 by 3 grid.

(1,4)=TRUERETURN'' Count the number of neighbours of the point i,j' (Assume i/j +/- 1 will not fall out of world)'FUNCTION count_neighbours(i%,j%) LOCAL count%,l% count%=0 FOR l%=-1 TO 1 IF world! (i%+l%,j%+1) count%=count%+1 ENDIF NEXT l% IF world! (i%+1,j%) count%=count%+1 ENDIF RETURN count%ENDFUNC'' Update the world one step'PROCEDURE update_world LOCAL i%,j% ' compute neighbour counts and store FOR i%=1 TO 30 FOR j%=1 TO 30 ns%(i%,j%)[email protected]_neighbours(i%,j%) NEXT j% NEXT i% ' update the world cells FOR i%=1 TO 30 FOR j%=1 TO 30 IF world!

Thus, while it is somewhat verbose, it fully simulates Conway's Game of Life and is relatively simple to expand to feature different starting shapes.

Define life(pattern) = Prgm Local x,y,nt,count,save,xl,yl,xh,yh Define nt(y,x) = when(pxl Test(y,x), 1, 0) {}→save set Graph("Axes", "Off")→save[1] set Graph("Grid", "Off")→save[2] set Graph("Labels", "Off")→save[3] Fn Off Plot Off Clr Draw If pattern = "blinker" Then 36→yl 40→yh 78→xl 82→xh Pxl On 36,80 Pxl On 38,80 Pxl On 40,80 Else If pattern = "glider" Then 30→yl 40→yh 76→xl 88→xh Pxl On 38,76 Pxl On 36,78 Pxl On 36,80 Pxl On 38,80 Pxl On 40,80 Else If pattern = "r" Then 38-5*2→yl 38+5*2→yh 80-5*2→xl 80+5*2→xh Pxl On 38,78 Pxl On 36,82 Pxl On 36,80 Pxl On 38,80 Pxl On 40,80 End If While get Key() = 0 © Expand upper-left corner to whole cell For y,yl,yh,2 For x,xl,xh,2 If pxl Test(y,x) Then Pxl On y+1,x Pxl On y+1,x+1 Pxl On y, x+1 Else Pxl Off y+1,x Pxl Off y+1,x+1 Pxl Off y, x+1 End If End For End For © Compute next generation For y,yl,yh,2 For x,xl,xh,2 nt(y-1,x-1) + nt(y-1,x) + nt(y-1,x+2) + nt(y,x-1) + nt(y+1,x+2) + nt(y+2,x-1) + nt(y+2,x+1) + nt(y+2,x+2) → count If count = 3 Then Pxl On y,x Else If count ≠ 2 Then Pxl Off y,x End If End For End For End While © Restore changed options set Graph("Axes", save[1]) set Graph("Grid", save[2]) set Graph("Labels", save[3])End Prgm Also see Conway's Game of Life/C Considering that the simplest implementation in C++ would lack any use of the object-oriented paradigm, this code was specifically written to demonstrate the various object-oriented features of C++.

]]copybyte: lda (

randfill: stx $01 ;$200 for indirect ldx #$02 ;addressing stx $02randloop: lda $fe ;generate random and #$01 ;pixels on the sta ($01), Y ;screen jsr inc0103 cmp #$00 bne randloop lda $02 cmp #$06 bne randloop clearmem: lda #$df ;set $07df-$0a20 sta $01 ;to $#00 lda #$07 sta $02clearbyte: lda #$00 sta ($01), Y jsr inc0103 cmp #$20 bne clearbyte lda $02 cmp #$0a bne clearbyte starttick:copyscreen: lda #$00 ;set up source sta $01 ;pointer at sta $03 ;$01/$02 and lda #$02 ;dest pointer sta $02 ;at $03/$04 lda #$08 sta $04 ldy #$00copybyte: lda ($01), Y ;copy pixel to sta ($03), Y ;back buffer jsr inc0103 ;increment pointers cmp #$00 ;check to see bne copybyte ;if we're at $600 lda $02 ;if so, we've cmp #$06 ;copied the bne copybyte ;entire screen conway: lda #$df ;apply conway rules sta $01 ;reset the pointer sta $03 ;to $#01df/$#07df lda #$01 ;($200 - $21) sta $02 ;($800 - $21) lda #$07 sta $04onecell: lda #$00 ;process one cell ldy #$01 ;upper cell clc adc ($03), Y ldy #$41 ;lower cell clc adc ($03), Ychkleft: tax ;check to see lda $01 ;if we're at the and #$1f ;left edge tay txa cpy #$1f beq rightcellsleftcells: ldy #$00 ;upper-left cell clc adc ($03), Y ldy #$20 ;left cell clc adc ($03), Y ldy #$40 ;lower-left cell clc adc ($03), Ychkright: tax ;check to see lda $01 ;if we're at the and #$1f ;right edge tay txa cpy #$1e beq evaluaterightcells: ldy #$02 ;upper-right cell clc adc ($03), Y ldy #$22 ;right cell clc adc ($03), Y ldy #$42 ;lower-right cell clc adc ($03), Yevaluate: ldx #$01 ;evaluate total ldy #$21 ;for current cell cmp #$03 ;3 = alive beq storex ldx #$00 cmp #$02 ;2 = alive if bne storex ;c = alive lda ($03), Y and #$01 taxstorex: txa ;store to screen sta ($01), Y jsr inc0103 ;move to next cellconwayloop: cmp #$e0 ;if not last cell, bne onecell ;process next cell lda $02 cmp #$05 bne onecell jmp starttick ;run next tick inc0103: lda $01 ;increment $01 cmp #$ff ;and $03 as 16-bit bne onlyinc01 ;pointers inc $02 inc $04onlyinc01: inc $01 lda $01 sta $03 rts The solution uses one cell thick border around square Petri dish as uninhabited dire land. Sample output contains 3 generations of the blinker and 5 of the glider: See Conway's Game of Life/ALGOL 68 APL2 (Dialog) Example in one line APL \ 1130 example (very old APL dialect via simulator) APL1130From: APL \ 1130 Samples The following APL \ 1130 code will need APL385 font installed to display correctly. See Download APL TT Font ∇LIFE[⎕]∇[0] NG←LIFE CG; W[1] W←CG+(¯1⊖CG)+(1⊖CG)+(¯1⌽CG)+(1⌽CG)[2] W←W+(1⊖1⌽CG)+(¯1⊖1⌽CG)+(1⊖¯1⌽CG)+(¯1⊖¯1⌽CG)[3] NG←(3=W)+(CG∧4=W) ∇ RP←5 5⍴0 0 0 0 0 0 0 1 1 0 0 1 1 0 0 0 0 1 0 0 RP0 0 0 0 00 0 1 1 00 1 1 0 00 0 1 0 00 0 0 0 0 LIFE RP0 0 0 0 00 1 1 1 00 1 0 0 00 1 1 0 00 0 0 0 0 LIFE LIFE RP0 0 1 0 00 1 1 0 01 0 0 1 00 1 1 0 00 0 0 0 0 .................................................. One interacts with the Game of Life by creating an initial configuration and observing how it evolves. Although you should test your implementation on more complex examples such as the glider in a larger universe, show the action of the blinker (three adjoining cells in a row all alive), over three generations, in a 3 by 3 grid. (1,4)=TRUERETURN'' Count the number of neighbours of the point i,j' (Assume i/j +/- 1 will not fall out of world)'FUNCTION count_neighbours(i%,j%) LOCAL count%,l% count%=0 FOR l%=-1 TO 1 IF world! (i%+l%,j%+1) count%=count%+1 ENDIF NEXT l% IF world! (i%+1,j%) count%=count%+1 ENDIF RETURN count%ENDFUNC'' Update the world one step'PROCEDURE update_world LOCAL i%,j% ' compute neighbour counts and store FOR i%=1 TO 30 FOR j%=1 TO 30 ns%(i%,j%)[email protected]_neighbours(i%,j%) NEXT j% NEXT i% ' update the world cells FOR i%=1 TO 30 FOR j%=1 TO 30 IF world!

||

randfill: stx $01 ;$200 for indirect ldx #$02 ;addressing stx $02randloop: lda $fe ;generate random and #$01 ;pixels on the sta ($01), Y ;screen jsr inc0103 cmp #$00 bne randloop lda $02 cmp #$06 bne randloop clearmem: lda #$df ;set $07df-$0a20 sta $01 ;to $#00 lda #$07 sta $02clearbyte: lda #$00 sta ($01), Y jsr inc0103 cmp #$20 bne clearbyte lda $02 cmp #$0a bne clearbyte starttick:copyscreen: lda #$00 ;set up source sta $01 ;pointer at sta $03 ;$01/$02 and lda #$02 ;dest pointer sta $02 ;at $03/$04 lda #$08 sta $04 ldy #$00copybyte: lda ($01), Y ;copy pixel to sta ($03), Y ;back buffer jsr inc0103 ;increment pointers cmp #$00 ;check to see bne copybyte ;if we're at $600 lda $02 ;if so, we've cmp #$06 ;copied the bne copybyte ;entire screen conway: lda #$df ;apply conway rules sta $01 ;reset the pointer sta $03 ;to $#01df/$#07df lda #$01 ;($200 - $21) sta $02 ;($800 - $21) lda #$07 sta $04onecell: lda #$00 ;process one cell ldy #$01 ;upper cell clc adc ($03), Y ldy #$41 ;lower cell clc adc ($03), Ychkleft: tax ;check to see lda $01 ;if we're at the and #$1f ;left edge tay txa cpy #$1f beq rightcellsleftcells: ldy #$00 ;upper-left cell clc adc ($03), Y ldy #$20 ;left cell clc adc ($03), Y ldy #$40 ;lower-left cell clc adc ($03), Ychkright: tax ;check to see lda $01 ;if we're at the and #$1f ;right edge tay txa cpy #$1e beq evaluaterightcells: ldy #$02 ;upper-right cell clc adc ($03), Y ldy #$22 ;right cell clc adc ($03), Y ldy #$42 ;lower-right cell clc adc ($03), Yevaluate: ldx #$01 ;evaluate total ldy #$21 ;for current cell cmp #$03 ;3 = alive beq storex ldx #$00 cmp #$02 ;2 = alive if bne storex ;c = alive lda ($03), Y and #$01 taxstorex: txa ;store to screen sta ($01), Y jsr inc0103 ;move to next cellconwayloop: cmp #$e0 ;if not last cell, bne onecell ;process next cell lda $02 cmp #$05 bne onecell jmp starttick ;run next tick inc0103: lda $01 ;increment $01 cmp #$ff ;and $03 as 16-bit bne onlyinc01 ;pointers inc $02 inc $04onlyinc01: inc $01 lda $01 sta $03 rts The solution uses one cell thick border around square Petri dish as uninhabited dire land. Sample output contains 3 generations of the blinker and 5 of the glider: See Conway's Game of Life/ALGOL 68 APL2 (Dialog) Example in one line APL \ 1130 example (very old APL dialect via simulator) APL1130From: APL \ 1130 Samples The following APL \ 1130 code will need APL385 font installed to display correctly.

See Download APL TT Font ∇LIFE[⎕]∇[0] NG←LIFE CG; W[1] W←CG+(¯1⊖CG)+(1⊖CG)+(¯1⌽CG)+(1⌽CG)[2] W←W+(1⊖1⌽CG)+(¯1⊖1⌽CG)+(1⊖¯1⌽CG)+(¯1⊖¯1⌽CG)[3] NG←(3=W)+(CG∧4=W) ∇ RP←5 5⍴0 0 0 0 0 0 0 1 1 0 0 1 1 0 0 0 0 1 0 0 RP0 0 0 0 00 0 1 1 00 1 1 0 00 0 1 0 00 0 0 0 0 LIFE RP0 0 0 0 00 1 1 1 00 1 0 0 00 1 1 0 00 0 0 0 0 LIFE LIFE RP0 0 1 0 00 1 1 0 01 0 0 1 00 1 1 0 00 0 0 0 0 ..................................................

One interacts with the Game of Life by creating an initial configuration and observing how it evolves.

Although you should test your implementation on more complex examples such as the glider in a larger universe, show the action of the blinker (three adjoining cells in a row all alive), over three generations, in a 3 by 3 grid.

(1,4)=TRUERETURN'' Count the number of neighbours of the point i,j' (Assume i/j +/- 1 will not fall out of world)'FUNCTION count_neighbours(i%,j%) LOCAL count%,l% count%=0 FOR l%=-1 TO 1 IF world! (i%+l%,j%+1) count%=count%+1 ENDIF NEXT l% IF world! (i%+1,j%) count%=count%+1 ENDIF RETURN count%ENDFUNC'' Update the world one step'PROCEDURE update_world LOCAL i%,j% ' compute neighbour counts and store FOR i%=1 TO 30 FOR j%=1 TO 30 ns%(i%,j%)[email protected]_neighbours(i%,j%) NEXT j% NEXT i% ' update the world cells FOR i%=1 TO 30 FOR j%=1 TO 30 IF world!

Thus, while it is somewhat verbose, it fully simulates Conway's Game of Life and is relatively simple to expand to feature different starting shapes.

Define life(pattern) = Prgm Local x,y,nt,count,save,xl,yl,xh,yh Define nt(y,x) = when(pxl Test(y,x), 1, 0) {}→save set Graph("Axes", "Off")→save[1] set Graph("Grid", "Off")→save[2] set Graph("Labels", "Off")→save[3] Fn Off Plot Off Clr Draw If pattern = "blinker" Then 36→yl 40→yh 78→xl 82→xh Pxl On 36,80 Pxl On 38,80 Pxl On 40,80 Else If pattern = "glider" Then 30→yl 40→yh 76→xl 88→xh Pxl On 38,76 Pxl On 36,78 Pxl On 36,80 Pxl On 38,80 Pxl On 40,80 Else If pattern = "r" Then 38-5*2→yl 38+5*2→yh 80-5*2→xl 80+5*2→xh Pxl On 38,78 Pxl On 36,82 Pxl On 36,80 Pxl On 38,80 Pxl On 40,80 End If While get Key() = 0 © Expand upper-left corner to whole cell For y,yl,yh,2 For x,xl,xh,2 If pxl Test(y,x) Then Pxl On y+1,x Pxl On y+1,x+1 Pxl On y, x+1 Else Pxl Off y+1,x Pxl Off y+1,x+1 Pxl Off y, x+1 End If End For End For © Compute next generation For y,yl,yh,2 For x,xl,xh,2 nt(y-1,x-1) + nt(y-1,x) + nt(y-1,x+2) + nt(y,x-1) + nt(y+1,x+2) + nt(y+2,x-1) + nt(y+2,x+1) + nt(y+2,x+2) → count If count = 3 Then Pxl On y,x Else If count ≠ 2 Then Pxl Off y,x End If End For End For End While © Restore changed options set Graph("Axes", save[1]) set Graph("Grid", save[2]) set Graph("Labels", save[3])End Prgm Also see Conway's Game of Life/C Considering that the simplest implementation in C++ would lack any use of the object-oriented paradigm, this code was specifically written to demonstrate the various object-oriented features of C++.

), Y ;copy pixel to sta (), Y ;back buffer jsr inc0103 ;increment pointers cmp #[[

randfill: stx $01 ;$200 for indirect ldx #$02 ;addressing stx $02randloop: lda $fe ;generate random and #$01 ;pixels on the sta ($01), Y ;screen jsr inc0103 cmp #$00 bne randloop lda $02 cmp #$06 bne randloop clearmem: lda #$df ;set $07df-$0a20 sta $01 ;to $#00 lda #$07 sta $02clearbyte: lda #$00 sta ($01), Y jsr inc0103 cmp #$20 bne clearbyte lda $02 cmp #$0a bne clearbyte starttick:copyscreen: lda #$00 ;set up source sta $01 ;pointer at sta $03 ;$01/$02 and lda #$02 ;dest pointer sta $02 ;at $03/$04 lda #$08 sta $04 ldy #$00copybyte: lda ($01), Y ;copy pixel to sta ($03), Y ;back buffer jsr inc0103 ;increment pointers cmp #$00 ;check to see bne copybyte ;if we're at $600 lda $02 ;if so, we've cmp #$06 ;copied the bne copybyte ;entire screen conway: lda #$df ;apply conway rules sta $01 ;reset the pointer sta $03 ;to $#01df/$#07df lda #$01 ;($200 - $21) sta $02 ;($800 - $21) lda #$07 sta $04onecell: lda #$00 ;process one cell ldy #$01 ;upper cell clc adc ($03), Y ldy #$41 ;lower cell clc adc ($03), Ychkleft: tax ;check to see lda $01 ;if we're at the and #$1f ;left edge tay txa cpy #$1f beq rightcellsleftcells: ldy #$00 ;upper-left cell clc adc ($03), Y ldy #$20 ;left cell clc adc ($03), Y ldy #$40 ;lower-left cell clc adc ($03), Ychkright: tax ;check to see lda $01 ;if we're at the and #$1f ;right edge tay txa cpy #$1e beq evaluaterightcells: ldy #$02 ;upper-right cell clc adc ($03), Y ldy #$22 ;right cell clc adc ($03), Y ldy #$42 ;lower-right cell clc adc ($03), Yevaluate: ldx #$01 ;evaluate total ldy #$21 ;for current cell cmp #$03 ;3 = alive beq storex ldx #$00 cmp #$02 ;2 = alive if bne storex ;c = alive lda ($03), Y and #$01 taxstorex: txa ;store to screen sta ($01), Y jsr inc0103 ;move to next cellconwayloop: cmp #$e0 ;if not last cell, bne onecell ;process next cell lda $02 cmp #$05 bne onecell jmp starttick ;run next tick inc0103: lda $01 ;increment $01 cmp #$ff ;and $03 as 16-bit bne onlyinc01 ;pointers inc $02 inc $04onlyinc01: inc $01 lda $01 sta $03 rts The solution uses one cell thick border around square Petri dish as uninhabited dire land. Sample output contains 3 generations of the blinker and 5 of the glider: See Conway's Game of Life/ALGOL 68 APL2 (Dialog) Example in one line APL \ 1130 example (very old APL dialect via simulator) APL1130From: APL \ 1130 Samples The following APL \ 1130 code will need APL385 font installed to display correctly. See Download APL TT Font ∇LIFE[⎕]∇[0] NG←LIFE CG; W[1] W←CG+(¯1⊖CG)+(1⊖CG)+(¯1⌽CG)+(1⌽CG)[2] W←W+(1⊖1⌽CG)+(¯1⊖1⌽CG)+(1⊖¯1⌽CG)+(¯1⊖¯1⌽CG)[3] NG←(3=W)+(CG∧4=W) ∇ RP←5 5⍴0 0 0 0 0 0 0 1 1 0 0 1 1 0 0 0 0 1 0 0 RP0 0 0 0 00 0 1 1 00 1 1 0 00 0 1 0 00 0 0 0 0 LIFE RP0 0 0 0 00 1 1 1 00 1 0 0 00 1 1 0 00 0 0 0 0 LIFE LIFE RP0 0 1 0 00 1 1 0 01 0 0 1 00 1 1 0 00 0 0 0 0 .................................................. One interacts with the Game of Life by creating an initial configuration and observing how it evolves. Although you should test your implementation on more complex examples such as the glider in a larger universe, show the action of the blinker (three adjoining cells in a row all alive), over three generations, in a 3 by 3 grid. (1,4)=TRUERETURN'' Count the number of neighbours of the point i,j' (Assume i/j +/- 1 will not fall out of world)'FUNCTION count_neighbours(i%,j%) LOCAL count%,l% count%=0 FOR l%=-1 TO 1 IF world! (i%+l%,j%+1) count%=count%+1 ENDIF NEXT l% IF world! (i%+1,j%) count%=count%+1 ENDIF RETURN count%ENDFUNC'' Update the world one step'PROCEDURE update_world LOCAL i%,j% ' compute neighbour counts and store FOR i%=1 TO 30 FOR j%=1 TO 30 ns%(i%,j%)[email protected]_neighbours(i%,j%) NEXT j% NEXT i% ' update the world cells FOR i%=1 TO 30 FOR j%=1 TO 30 IF world!

||

randfill: stx $01 ;$200 for indirect ldx #$02 ;addressing stx $02randloop: lda $fe ;generate random and #$01 ;pixels on the sta ($01), Y ;screen jsr inc0103 cmp #$00 bne randloop lda $02 cmp #$06 bne randloop clearmem: lda #$df ;set $07df-$0a20 sta $01 ;to $#00 lda #$07 sta $02clearbyte: lda #$00 sta ($01), Y jsr inc0103 cmp #$20 bne clearbyte lda $02 cmp #$0a bne clearbyte starttick:copyscreen: lda #$00 ;set up source sta $01 ;pointer at sta $03 ;$01/$02 and lda #$02 ;dest pointer sta $02 ;at $03/$04 lda #$08 sta $04 ldy #$00copybyte: lda ($01), Y ;copy pixel to sta ($03), Y ;back buffer jsr inc0103 ;increment pointers cmp #$00 ;check to see bne copybyte ;if we're at $600 lda $02 ;if so, we've cmp #$06 ;copied the bne copybyte ;entire screen conway: lda #$df ;apply conway rules sta $01 ;reset the pointer sta $03 ;to $#01df/$#07df lda #$01 ;($200 - $21) sta $02 ;($800 - $21) lda #$07 sta $04onecell: lda #$00 ;process one cell ldy #$01 ;upper cell clc adc ($03), Y ldy #$41 ;lower cell clc adc ($03), Ychkleft: tax ;check to see lda $01 ;if we're at the and #$1f ;left edge tay txa cpy #$1f beq rightcellsleftcells: ldy #$00 ;upper-left cell clc adc ($03), Y ldy #$20 ;left cell clc adc ($03), Y ldy #$40 ;lower-left cell clc adc ($03), Ychkright: tax ;check to see lda $01 ;if we're at the and #$1f ;right edge tay txa cpy #$1e beq evaluaterightcells: ldy #$02 ;upper-right cell clc adc ($03), Y ldy #$22 ;right cell clc adc ($03), Y ldy #$42 ;lower-right cell clc adc ($03), Yevaluate: ldx #$01 ;evaluate total ldy #$21 ;for current cell cmp #$03 ;3 = alive beq storex ldx #$00 cmp #$02 ;2 = alive if bne storex ;c = alive lda ($03), Y and #$01 taxstorex: txa ;store to screen sta ($01), Y jsr inc0103 ;move to next cellconwayloop: cmp #$e0 ;if not last cell, bne onecell ;process next cell lda $02 cmp #$05 bne onecell jmp starttick ;run next tick inc0103: lda $01 ;increment $01 cmp #$ff ;and $03 as 16-bit bne onlyinc01 ;pointers inc $02 inc $04onlyinc01: inc $01 lda $01 sta $03 rts The solution uses one cell thick border around square Petri dish as uninhabited dire land. Sample output contains 3 generations of the blinker and 5 of the glider: See Conway's Game of Life/ALGOL 68 APL2 (Dialog) Example in one line APL \ 1130 example (very old APL dialect via simulator) APL1130From: APL \ 1130 Samples The following APL \ 1130 code will need APL385 font installed to display correctly.

See Download APL TT Font ∇LIFE[⎕]∇[0] NG←LIFE CG; W[1] W←CG+(¯1⊖CG)+(1⊖CG)+(¯1⌽CG)+(1⌽CG)[2] W←W+(1⊖1⌽CG)+(¯1⊖1⌽CG)+(1⊖¯1⌽CG)+(¯1⊖¯1⌽CG)[3] NG←(3=W)+(CG∧4=W) ∇ RP←5 5⍴0 0 0 0 0 0 0 1 1 0 0 1 1 0 0 0 0 1 0 0 RP0 0 0 0 00 0 1 1 00 1 1 0 00 0 1 0 00 0 0 0 0 LIFE RP0 0 0 0 00 1 1 1 00 1 0 0 00 1 1 0 00 0 0 0 0 LIFE LIFE RP0 0 1 0 00 1 1 0 01 0 0 1 00 1 1 0 00 0 0 0 0 ..................................................

One interacts with the Game of Life by creating an initial configuration and observing how it evolves.

Although you should test your implementation on more complex examples such as the glider in a larger universe, show the action of the blinker (three adjoining cells in a row all alive), over three generations, in a 3 by 3 grid.

(1,4)=TRUERETURN'' Count the number of neighbours of the point i,j' (Assume i/j +/- 1 will not fall out of world)'FUNCTION count_neighbours(i%,j%) LOCAL count%,l% count%=0 FOR l%=-1 TO 1 IF world! (i%+l%,j%+1) count%=count%+1 ENDIF NEXT l% IF world! (i%+1,j%) count%=count%+1 ENDIF RETURN count%ENDFUNC'' Update the world one step'PROCEDURE update_world LOCAL i%,j% ' compute neighbour counts and store FOR i%=1 TO 30 FOR j%=1 TO 30 ns%(i%,j%)[email protected]_neighbours(i%,j%) NEXT j% NEXT i% ' update the world cells FOR i%=1 TO 30 FOR j%=1 TO 30 IF world!

Thus, while it is somewhat verbose, it fully simulates Conway's Game of Life and is relatively simple to expand to feature different starting shapes.

Define life(pattern) = Prgm Local x,y,nt,count,save,xl,yl,xh,yh Define nt(y,x) = when(pxl Test(y,x), 1, 0) {}→save set Graph("Axes", "Off")→save[1] set Graph("Grid", "Off")→save[2] set Graph("Labels", "Off")→save[3] Fn Off Plot Off Clr Draw If pattern = "blinker" Then 36→yl 40→yh 78→xl 82→xh Pxl On 36,80 Pxl On 38,80 Pxl On 40,80 Else If pattern = "glider" Then 30→yl 40→yh 76→xl 88→xh Pxl On 38,76 Pxl On 36,78 Pxl On 36,80 Pxl On 38,80 Pxl On 40,80 Else If pattern = "r" Then 38-5*2→yl 38+5*2→yh 80-5*2→xl 80+5*2→xh Pxl On 38,78 Pxl On 36,82 Pxl On 36,80 Pxl On 38,80 Pxl On 40,80 End If While get Key() = 0 © Expand upper-left corner to whole cell For y,yl,yh,2 For x,xl,xh,2 If pxl Test(y,x) Then Pxl On y+1,x Pxl On y+1,x+1 Pxl On y, x+1 Else Pxl Off y+1,x Pxl Off y+1,x+1 Pxl Off y, x+1 End If End For End For © Compute next generation For y,yl,yh,2 For x,xl,xh,2 nt(y-1,x-1) + nt(y-1,x) + nt(y-1,x+2) + nt(y,x-1) + nt(y+1,x+2) + nt(y+2,x-1) + nt(y+2,x+1) + nt(y+2,x+2) → count If count = 3 Then Pxl On y,x Else If count ≠ 2 Then Pxl Off y,x End If End For End For End While © Restore changed options set Graph("Axes", save[1]) set Graph("Grid", save[2]) set Graph("Labels", save[3])End Prgm Also see Conway's Game of Life/C Considering that the simplest implementation in C++ would lack any use of the object-oriented paradigm, this code was specifically written to demonstrate the various object-oriented features of C++.

]] ;check to see bne copybyte ;if we're at 0 lda ;if so, we've cmp # ;copied the bne copybyte ;entire screen conway: lda #$df ;apply conway rules sta

randfill: stx $01 ;$200 for indirect ldx #$02 ;addressing stx $02randloop: lda $fe ;generate random and #$01 ;pixels on the sta ($01), Y ;screen jsr inc0103 cmp #$00 bne randloop lda $02 cmp #$06 bne randloop clearmem: lda #$df ;set $07df-$0a20 sta $01 ;to $#00 lda #$07 sta $02clearbyte: lda #$00 sta ($01), Y jsr inc0103 cmp #$20 bne clearbyte lda $02 cmp #$0a bne clearbyte starttick:copyscreen: lda #$00 ;set up source sta $01 ;pointer at sta $03 ;$01/$02 and lda #$02 ;dest pointer sta $02 ;at $03/$04 lda #$08 sta $04 ldy #$00copybyte: lda ($01), Y ;copy pixel to sta ($03), Y ;back buffer jsr inc0103 ;increment pointers cmp #$00 ;check to see bne copybyte ;if we're at $600 lda $02 ;if so, we've cmp #$06 ;copied the bne copybyte ;entire screen conway: lda #$df ;apply conway rules sta $01 ;reset the pointer sta $03 ;to $#01df/$#07df lda #$01 ;($200 - $21) sta $02 ;($800 - $21) lda #$07 sta $04onecell: lda #$00 ;process one cell ldy #$01 ;upper cell clc adc ($03), Y ldy #$41 ;lower cell clc adc ($03), Ychkleft: tax ;check to see lda $01 ;if we're at the and #$1f ;left edge tay txa cpy #$1f beq rightcellsleftcells: ldy #$00 ;upper-left cell clc adc ($03), Y ldy #$20 ;left cell clc adc ($03), Y ldy #$40 ;lower-left cell clc adc ($03), Ychkright: tax ;check to see lda $01 ;if we're at the and #$1f ;right edge tay txa cpy #$1e beq evaluaterightcells: ldy #$02 ;upper-right cell clc adc ($03), Y ldy #$22 ;right cell clc adc ($03), Y ldy #$42 ;lower-right cell clc adc ($03), Yevaluate: ldx #$01 ;evaluate total ldy #$21 ;for current cell cmp #$03 ;3 = alive beq storex ldx #$00 cmp #$02 ;2 = alive if bne storex ;c = alive lda ($03), Y and #$01 taxstorex: txa ;store to screen sta ($01), Y jsr inc0103 ;move to next cellconwayloop: cmp #$e0 ;if not last cell, bne onecell ;process next cell lda $02 cmp #$05 bne onecell jmp starttick ;run next tick inc0103: lda $01 ;increment $01 cmp #$ff ;and $03 as 16-bit bne onlyinc01 ;pointers inc $02 inc $04onlyinc01: inc $01 lda $01 sta $03 rts The solution uses one cell thick border around square Petri dish as uninhabited dire land. Sample output contains 3 generations of the blinker and 5 of the glider: See Conway's Game of Life/ALGOL 68 APL2 (Dialog) Example in one line APL \ 1130 example (very old APL dialect via simulator) APL1130From: APL \ 1130 Samples The following APL \ 1130 code will need APL385 font installed to display correctly. See Download APL TT Font ∇LIFE[⎕]∇[0] NG←LIFE CG; W[1] W←CG+(¯1⊖CG)+(1⊖CG)+(¯1⌽CG)+(1⌽CG)[2] W←W+(1⊖1⌽CG)+(¯1⊖1⌽CG)+(1⊖¯1⌽CG)+(¯1⊖¯1⌽CG)[3] NG←(3=W)+(CG∧4=W) ∇ RP←5 5⍴0 0 0 0 0 0 0 1 1 0 0 1 1 0 0 0 0 1 0 0 RP0 0 0 0 00 0 1 1 00 1 1 0 00 0 1 0 00 0 0 0 0 LIFE RP0 0 0 0 00 1 1 1 00 1 0 0 00 1 1 0 00 0 0 0 0 LIFE LIFE RP0 0 1 0 00 1 1 0 01 0 0 1 00 1 1 0 00 0 0 0 0 .................................................. One interacts with the Game of Life by creating an initial configuration and observing how it evolves. Although you should test your implementation on more complex examples such as the glider in a larger universe, show the action of the blinker (three adjoining cells in a row all alive), over three generations, in a 3 by 3 grid. (1,4)=TRUERETURN'' Count the number of neighbours of the point i,j' (Assume i/j +/- 1 will not fall out of world)'FUNCTION count_neighbours(i%,j%) LOCAL count%,l% count%=0 FOR l%=-1 TO 1 IF world! (i%+l%,j%+1) count%=count%+1 ENDIF NEXT l% IF world! (i%+1,j%) count%=count%+1 ENDIF RETURN count%ENDFUNC'' Update the world one step'PROCEDURE update_world LOCAL i%,j% ' compute neighbour counts and store FOR i%=1 TO 30 FOR j%=1 TO 30 ns%(i%,j%)[email protected]_neighbours(i%,j%) NEXT j% NEXT i% ' update the world cells FOR i%=1 TO 30 FOR j%=1 TO 30 IF world!

||

randfill: stx $01 ;$200 for indirect ldx #$02 ;addressing stx $02randloop: lda $fe ;generate random and #$01 ;pixels on the sta ($01), Y ;screen jsr inc0103 cmp #$00 bne randloop lda $02 cmp #$06 bne randloop clearmem: lda #$df ;set $07df-$0a20 sta $01 ;to $#00 lda #$07 sta $02clearbyte: lda #$00 sta ($01), Y jsr inc0103 cmp #$20 bne clearbyte lda $02 cmp #$0a bne clearbyte starttick:copyscreen: lda #$00 ;set up source sta $01 ;pointer at sta $03 ;$01/$02 and lda #$02 ;dest pointer sta $02 ;at $03/$04 lda #$08 sta $04 ldy #$00copybyte: lda ($01), Y ;copy pixel to sta ($03), Y ;back buffer jsr inc0103 ;increment pointers cmp #$00 ;check to see bne copybyte ;if we're at $600 lda $02 ;if so, we've cmp #$06 ;copied the bne copybyte ;entire screen conway: lda #$df ;apply conway rules sta $01 ;reset the pointer sta $03 ;to $#01df/$#07df lda #$01 ;($200 - $21) sta $02 ;($800 - $21) lda #$07 sta $04onecell: lda #$00 ;process one cell ldy #$01 ;upper cell clc adc ($03), Y ldy #$41 ;lower cell clc adc ($03), Ychkleft: tax ;check to see lda $01 ;if we're at the and #$1f ;left edge tay txa cpy #$1f beq rightcellsleftcells: ldy #$00 ;upper-left cell clc adc ($03), Y ldy #$20 ;left cell clc adc ($03), Y ldy #$40 ;lower-left cell clc adc ($03), Ychkright: tax ;check to see lda $01 ;if we're at the and #$1f ;right edge tay txa cpy #$1e beq evaluaterightcells: ldy #$02 ;upper-right cell clc adc ($03), Y ldy #$22 ;right cell clc adc ($03), Y ldy #$42 ;lower-right cell clc adc ($03), Yevaluate: ldx #$01 ;evaluate total ldy #$21 ;for current cell cmp #$03 ;3 = alive beq storex ldx #$00 cmp #$02 ;2 = alive if bne storex ;c = alive lda ($03), Y and #$01 taxstorex: txa ;store to screen sta ($01), Y jsr inc0103 ;move to next cellconwayloop: cmp #$e0 ;if not last cell, bne onecell ;process next cell lda $02 cmp #$05 bne onecell jmp starttick ;run next tick inc0103: lda $01 ;increment $01 cmp #$ff ;and $03 as 16-bit bne onlyinc01 ;pointers inc $02 inc $04onlyinc01: inc $01 lda $01 sta $03 rts The solution uses one cell thick border around square Petri dish as uninhabited dire land. Sample output contains 3 generations of the blinker and 5 of the glider: See Conway's Game of Life/ALGOL 68 APL2 (Dialog) Example in one line APL \ 1130 example (very old APL dialect via simulator) APL1130From: APL \ 1130 Samples The following APL \ 1130 code will need APL385 font installed to display correctly.

See Download APL TT Font ∇LIFE[⎕]∇[0] NG←LIFE CG; W[1] W←CG+(¯1⊖CG)+(1⊖CG)+(¯1⌽CG)+(1⌽CG)[2] W←W+(1⊖1⌽CG)+(¯1⊖1⌽CG)+(1⊖¯1⌽CG)+(¯1⊖¯1⌽CG)[3] NG←(3=W)+(CG∧4=W) ∇ RP←5 5⍴0 0 0 0 0 0 0 1 1 0 0 1 1 0 0 0 0 1 0 0 RP0 0 0 0 00 0 1 1 00 1 1 0 00 0 1 0 00 0 0 0 0 LIFE RP0 0 0 0 00 1 1 1 00 1 0 0 00 1 1 0 00 0 0 0 0 LIFE LIFE RP0 0 1 0 00 1 1 0 01 0 0 1 00 1 1 0 00 0 0 0 0 ..................................................

One interacts with the Game of Life by creating an initial configuration and observing how it evolves.

Although you should test your implementation on more complex examples such as the glider in a larger universe, show the action of the blinker (three adjoining cells in a row all alive), over three generations, in a 3 by 3 grid.

(1,4)=TRUERETURN'' Count the number of neighbours of the point i,j' (Assume i/j +/- 1 will not fall out of world)'FUNCTION count_neighbours(i%,j%) LOCAL count%,l% count%=0 FOR l%=-1 TO 1 IF world! (i%+l%,j%+1) count%=count%+1 ENDIF NEXT l% IF world! (i%+1,j%) count%=count%+1 ENDIF RETURN count%ENDFUNC'' Update the world one step'PROCEDURE update_world LOCAL i%,j% ' compute neighbour counts and store FOR i%=1 TO 30 FOR j%=1 TO 30 ns%(i%,j%)[email protected]_neighbours(i%,j%) NEXT j% NEXT i% ' update the world cells FOR i%=1 TO 30 FOR j%=1 TO 30 IF world!

Thus, while it is somewhat verbose, it fully simulates Conway's Game of Life and is relatively simple to expand to feature different starting shapes.

Define life(pattern) = Prgm Local x,y,nt,count,save,xl,yl,xh,yh Define nt(y,x) = when(pxl Test(y,x), 1, 0) {}→save set Graph("Axes", "Off")→save[1] set Graph("Grid", "Off")→save[2] set Graph("Labels", "Off")→save[3] Fn Off Plot Off Clr Draw If pattern = "blinker" Then 36→yl 40→yh 78→xl 82→xh Pxl On 36,80 Pxl On 38,80 Pxl On 40,80 Else If pattern = "glider" Then 30→yl 40→yh 76→xl 88→xh Pxl On 38,76 Pxl On 36,78 Pxl On 36,80 Pxl On 38,80 Pxl On 40,80 Else If pattern = "r" Then 38-5*2→yl 38+5*2→yh 80-5*2→xl 80+5*2→xh Pxl On 38,78 Pxl On 36,82 Pxl On 36,80 Pxl On 38,80 Pxl On 40,80 End If While get Key() = 0 © Expand upper-left corner to whole cell For y,yl,yh,2 For x,xl,xh,2 If pxl Test(y,x) Then Pxl On y+1,x Pxl On y+1,x+1 Pxl On y, x+1 Else Pxl Off y+1,x Pxl Off y+1,x+1 Pxl Off y, x+1 End If End For End For © Compute next generation For y,yl,yh,2 For x,xl,xh,2 nt(y-1,x-1) + nt(y-1,x) + nt(y-1,x+2) + nt(y,x-1) + nt(y+1,x+2) + nt(y+2,x-1) + nt(y+2,x+1) + nt(y+2,x+2) → count If count = 3 Then Pxl On y,x Else If count ≠ 2 Then Pxl Off y,x End If End For End For End While © Restore changed options set Graph("Axes", save[1]) set Graph("Grid", save[2]) set Graph("Labels", save[3])End Prgm Also see Conway's Game of Life/C Considering that the simplest implementation in C++ would lack any use of the object-oriented paradigm, this code was specifically written to demonstrate the various object-oriented features of C++.

;reset the pointer sta ;to $#01df/$#07df lda #

randfill: stx $01 ;$200 for indirect ldx #$02 ;addressing stx $02randloop: lda $fe ;generate random and #$01 ;pixels on the sta ($01), Y ;screen jsr inc0103 cmp #$00 bne randloop lda $02 cmp #$06 bne randloop clearmem: lda #$df ;set $07df-$0a20 sta $01 ;to $#00 lda #$07 sta $02clearbyte: lda #$00 sta ($01), Y jsr inc0103 cmp #$20 bne clearbyte lda $02 cmp #$0a bne clearbyte starttick:copyscreen: lda #$00 ;set up source sta $01 ;pointer at sta $03 ;$01/$02 and lda #$02 ;dest pointer sta $02 ;at $03/$04 lda #$08 sta $04 ldy #$00copybyte: lda ($01), Y ;copy pixel to sta ($03), Y ;back buffer jsr inc0103 ;increment pointers cmp #$00 ;check to see bne copybyte ;if we're at $600 lda $02 ;if so, we've cmp #$06 ;copied the bne copybyte ;entire screen conway: lda #$df ;apply conway rules sta $01 ;reset the pointer sta $03 ;to $#01df/$#07df lda #$01 ;($200 - $21) sta $02 ;($800 - $21) lda #$07 sta $04onecell: lda #$00 ;process one cell ldy #$01 ;upper cell clc adc ($03), Y ldy #$41 ;lower cell clc adc ($03), Ychkleft: tax ;check to see lda $01 ;if we're at the and #$1f ;left edge tay txa cpy #$1f beq rightcellsleftcells: ldy #$00 ;upper-left cell clc adc ($03), Y ldy #$20 ;left cell clc adc ($03), Y ldy #$40 ;lower-left cell clc adc ($03), Ychkright: tax ;check to see lda $01 ;if we're at the and #$1f ;right edge tay txa cpy #$1e beq evaluaterightcells: ldy #$02 ;upper-right cell clc adc ($03), Y ldy #$22 ;right cell clc adc ($03), Y ldy #$42 ;lower-right cell clc adc ($03), Yevaluate: ldx #$01 ;evaluate total ldy #$21 ;for current cell cmp #$03 ;3 = alive beq storex ldx #$00 cmp #$02 ;2 = alive if bne storex ;c = alive lda ($03), Y and #$01 taxstorex: txa ;store to screen sta ($01), Y jsr inc0103 ;move to next cellconwayloop: cmp #$e0 ;if not last cell, bne onecell ;process next cell lda $02 cmp #$05 bne onecell jmp starttick ;run next tick inc0103: lda $01 ;increment $01 cmp #$ff ;and $03 as 16-bit bne onlyinc01 ;pointers inc $02 inc $04onlyinc01: inc $01 lda $01 sta $03 rts The solution uses one cell thick border around square Petri dish as uninhabited dire land. Sample output contains 3 generations of the blinker and 5 of the glider: See Conway's Game of Life/ALGOL 68 APL2 (Dialog) Example in one line APL \ 1130 example (very old APL dialect via simulator) APL1130From: APL \ 1130 Samples The following APL \ 1130 code will need APL385 font installed to display correctly. See Download APL TT Font ∇LIFE[⎕]∇[0] NG←LIFE CG; W[1] W←CG+(¯1⊖CG)+(1⊖CG)+(¯1⌽CG)+(1⌽CG)[2] W←W+(1⊖1⌽CG)+(¯1⊖1⌽CG)+(1⊖¯1⌽CG)+(¯1⊖¯1⌽CG)[3] NG←(3=W)+(CG∧4=W) ∇ RP←5 5⍴0 0 0 0 0 0 0 1 1 0 0 1 1 0 0 0 0 1 0 0 RP0 0 0 0 00 0 1 1 00 1 1 0 00 0 1 0 00 0 0 0 0 LIFE RP0 0 0 0 00 1 1 1 00 1 0 0 00 1 1 0 00 0 0 0 0 LIFE LIFE RP0 0 1 0 00 1 1 0 01 0 0 1 00 1 1 0 00 0 0 0 0 .................................................. One interacts with the Game of Life by creating an initial configuration and observing how it evolves. Although you should test your implementation on more complex examples such as the glider in a larger universe, show the action of the blinker (three adjoining cells in a row all alive), over three generations, in a 3 by 3 grid. (1,4)=TRUERETURN'' Count the number of neighbours of the point i,j' (Assume i/j +/- 1 will not fall out of world)'FUNCTION count_neighbours(i%,j%) LOCAL count%,l% count%=0 FOR l%=-1 TO 1 IF world! (i%+l%,j%+1) count%=count%+1 ENDIF NEXT l% IF world! (i%+1,j%) count%=count%+1 ENDIF RETURN count%ENDFUNC'' Update the world one step'PROCEDURE update_world LOCAL i%,j% ' compute neighbour counts and store FOR i%=1 TO 30 FOR j%=1 TO 30 ns%(i%,j%)[email protected]_neighbours(i%,j%) NEXT j% NEXT i% ' update the world cells FOR i%=1 TO 30 FOR j%=1 TO 30 IF world!

||

randfill: stx $01 ;$200 for indirect ldx #$02 ;addressing stx $02randloop: lda $fe ;generate random and #$01 ;pixels on the sta ($01), Y ;screen jsr inc0103 cmp #$00 bne randloop lda $02 cmp #$06 bne randloop clearmem: lda #$df ;set $07df-$0a20 sta $01 ;to $#00 lda #$07 sta $02clearbyte: lda #$00 sta ($01), Y jsr inc0103 cmp #$20 bne clearbyte lda $02 cmp #$0a bne clearbyte starttick:copyscreen: lda #$00 ;set up source sta $01 ;pointer at sta $03 ;$01/$02 and lda #$02 ;dest pointer sta $02 ;at $03/$04 lda #$08 sta $04 ldy #$00copybyte: lda ($01), Y ;copy pixel to sta ($03), Y ;back buffer jsr inc0103 ;increment pointers cmp #$00 ;check to see bne copybyte ;if we're at $600 lda $02 ;if so, we've cmp #$06 ;copied the bne copybyte ;entire screen conway: lda #$df ;apply conway rules sta $01 ;reset the pointer sta $03 ;to $#01df/$#07df lda #$01 ;($200 - $21) sta $02 ;($800 - $21) lda #$07 sta $04onecell: lda #$00 ;process one cell ldy #$01 ;upper cell clc adc ($03), Y ldy #$41 ;lower cell clc adc ($03), Ychkleft: tax ;check to see lda $01 ;if we're at the and #$1f ;left edge tay txa cpy #$1f beq rightcellsleftcells: ldy #$00 ;upper-left cell clc adc ($03), Y ldy #$20 ;left cell clc adc ($03), Y ldy #$40 ;lower-left cell clc adc ($03), Ychkright: tax ;check to see lda $01 ;if we're at the and #$1f ;right edge tay txa cpy #$1e beq evaluaterightcells: ldy #$02 ;upper-right cell clc adc ($03), Y ldy #$22 ;right cell clc adc ($03), Y ldy #$42 ;lower-right cell clc adc ($03), Yevaluate: ldx #$01 ;evaluate total ldy #$21 ;for current cell cmp #$03 ;3 = alive beq storex ldx #$00 cmp #$02 ;2 = alive if bne storex ;c = alive lda ($03), Y and #$01 taxstorex: txa ;store to screen sta ($01), Y jsr inc0103 ;move to next cellconwayloop: cmp #$e0 ;if not last cell, bne onecell ;process next cell lda $02 cmp #$05 bne onecell jmp starttick ;run next tick inc0103: lda $01 ;increment $01 cmp #$ff ;and $03 as 16-bit bne onlyinc01 ;pointers inc $02 inc $04onlyinc01: inc $01 lda $01 sta $03 rts The solution uses one cell thick border around square Petri dish as uninhabited dire land. Sample output contains 3 generations of the blinker and 5 of the glider: See Conway's Game of Life/ALGOL 68 APL2 (Dialog) Example in one line APL \ 1130 example (very old APL dialect via simulator) APL1130From: APL \ 1130 Samples The following APL \ 1130 code will need APL385 font installed to display correctly.

See Download APL TT Font ∇LIFE[⎕]∇[0] NG←LIFE CG; W[1] W←CG+(¯1⊖CG)+(1⊖CG)+(¯1⌽CG)+(1⌽CG)[2] W←W+(1⊖1⌽CG)+(¯1⊖1⌽CG)+(1⊖¯1⌽CG)+(¯1⊖¯1⌽CG)[3] NG←(3=W)+(CG∧4=W) ∇ RP←5 5⍴0 0 0 0 0 0 0 1 1 0 0 1 1 0 0 0 0 1 0 0 RP0 0 0 0 00 0 1 1 00 1 1 0 00 0 1 0 00 0 0 0 0 LIFE RP0 0 0 0 00 1 1 1 00 1 0 0 00 1 1 0 00 0 0 0 0 LIFE LIFE RP0 0 1 0 00 1 1 0 01 0 0 1 00 1 1 0 00 0 0 0 0 ..................................................

One interacts with the Game of Life by creating an initial configuration and observing how it evolves.

Although you should test your implementation on more complex examples such as the glider in a larger universe, show the action of the blinker (three adjoining cells in a row all alive), over three generations, in a 3 by 3 grid.

(1,4)=TRUERETURN'' Count the number of neighbours of the point i,j' (Assume i/j +/- 1 will not fall out of world)'FUNCTION count_neighbours(i%,j%) LOCAL count%,l% count%=0 FOR l%=-1 TO 1 IF world! (i%+l%,j%+1) count%=count%+1 ENDIF NEXT l% IF world! (i%+1,j%) count%=count%+1 ENDIF RETURN count%ENDFUNC'' Update the world one step'PROCEDURE update_world LOCAL i%,j% ' compute neighbour counts and store FOR i%=1 TO 30 FOR j%=1 TO 30 ns%(i%,j%)[email protected]_neighbours(i%,j%) NEXT j% NEXT i% ' update the world cells FOR i%=1 TO 30 FOR j%=1 TO 30 IF world!

Thus, while it is somewhat verbose, it fully simulates Conway's Game of Life and is relatively simple to expand to feature different starting shapes.

Define life(pattern) = Prgm Local x,y,nt,count,save,xl,yl,xh,yh Define nt(y,x) = when(pxl Test(y,x), 1, 0) {}→save set Graph("Axes", "Off")→save[1] set Graph("Grid", "Off")→save[2] set Graph("Labels", "Off")→save[3] Fn Off Plot Off Clr Draw If pattern = "blinker" Then 36→yl 40→yh 78→xl 82→xh Pxl On 36,80 Pxl On 38,80 Pxl On 40,80 Else If pattern = "glider" Then 30→yl 40→yh 76→xl 88→xh Pxl On 38,76 Pxl On 36,78 Pxl On 36,80 Pxl On 38,80 Pxl On 40,80 Else If pattern = "r" Then 38-5*2→yl 38+5*2→yh 80-5*2→xl 80+5*2→xh Pxl On 38,78 Pxl On 36,82 Pxl On 36,80 Pxl On 38,80 Pxl On 40,80 End If While get Key() = 0 © Expand upper-left corner to whole cell For y,yl,yh,2 For x,xl,xh,2 If pxl Test(y,x) Then Pxl On y+1,x Pxl On y+1,x+1 Pxl On y, x+1 Else Pxl Off y+1,x Pxl Off y+1,x+1 Pxl Off y, x+1 End If End For End For © Compute next generation For y,yl,yh,2 For x,xl,xh,2 nt(y-1,x-1) + nt(y-1,x) + nt(y-1,x+2) + nt(y,x-1) + nt(y+1,x+2) + nt(y+2,x-1) + nt(y+2,x+1) + nt(y+2,x+2) → count If count = 3 Then Pxl On y,x Else If count ≠ 2 Then Pxl Off y,x End If End For End For End While © Restore changed options set Graph("Axes", save[1]) set Graph("Grid", save[2]) set Graph("Labels", save[3])End Prgm Also see Conway's Game of Life/C Considering that the simplest implementation in C++ would lack any use of the object-oriented paradigm, this code was specifically written to demonstrate the various object-oriented features of C++.

;(0 - ) sta ;(0 - ) lda # sta onecell: lda #[[

randfill: stx $01 ;$200 for indirect ldx #$02 ;addressing stx $02randloop: lda $fe ;generate random and #$01 ;pixels on the sta ($01), Y ;screen jsr inc0103 cmp #$00 bne randloop lda $02 cmp #$06 bne randloop clearmem: lda #$df ;set $07df-$0a20 sta $01 ;to $#00 lda #$07 sta $02clearbyte: lda #$00 sta ($01), Y jsr inc0103 cmp #$20 bne clearbyte lda $02 cmp #$0a bne clearbyte starttick:copyscreen: lda #$00 ;set up source sta $01 ;pointer at sta $03 ;$01/$02 and lda #$02 ;dest pointer sta $02 ;at $03/$04 lda #$08 sta $04 ldy #$00copybyte: lda ($01), Y ;copy pixel to sta ($03), Y ;back buffer jsr inc0103 ;increment pointers cmp #$00 ;check to see bne copybyte ;if we're at $600 lda $02 ;if so, we've cmp #$06 ;copied the bne copybyte ;entire screen conway: lda #$df ;apply conway rules sta $01 ;reset the pointer sta $03 ;to $#01df/$#07df lda #$01 ;($200 - $21) sta $02 ;($800 - $21) lda #$07 sta $04onecell: lda #$00 ;process one cell ldy #$01 ;upper cell clc adc ($03), Y ldy #$41 ;lower cell clc adc ($03), Ychkleft: tax ;check to see lda $01 ;if we're at the and #$1f ;left edge tay txa cpy #$1f beq rightcellsleftcells: ldy #$00 ;upper-left cell clc adc ($03), Y ldy #$20 ;left cell clc adc ($03), Y ldy #$40 ;lower-left cell clc adc ($03), Ychkright: tax ;check to see lda $01 ;if we're at the and #$1f ;right edge tay txa cpy #$1e beq evaluaterightcells: ldy #$02 ;upper-right cell clc adc ($03), Y ldy #$22 ;right cell clc adc ($03), Y ldy #$42 ;lower-right cell clc adc ($03), Yevaluate: ldx #$01 ;evaluate total ldy #$21 ;for current cell cmp #$03 ;3 = alive beq storex ldx #$00 cmp #$02 ;2 = alive if bne storex ;c = alive lda ($03), Y and #$01 taxstorex: txa ;store to screen sta ($01), Y jsr inc0103 ;move to next cellconwayloop: cmp #$e0 ;if not last cell, bne onecell ;process next cell lda $02 cmp #$05 bne onecell jmp starttick ;run next tick inc0103: lda $01 ;increment $01 cmp #$ff ;and $03 as 16-bit bne onlyinc01 ;pointers inc $02 inc $04onlyinc01: inc $01 lda $01 sta $03 rts The solution uses one cell thick border around square Petri dish as uninhabited dire land. Sample output contains 3 generations of the blinker and 5 of the glider: See Conway's Game of Life/ALGOL 68 APL2 (Dialog) Example in one line APL \ 1130 example (very old APL dialect via simulator) APL1130From: APL \ 1130 Samples The following APL \ 1130 code will need APL385 font installed to display correctly. See Download APL TT Font ∇LIFE[⎕]∇[0] NG←LIFE CG; W[1] W←CG+(¯1⊖CG)+(1⊖CG)+(¯1⌽CG)+(1⌽CG)[2] W←W+(1⊖1⌽CG)+(¯1⊖1⌽CG)+(1⊖¯1⌽CG)+(¯1⊖¯1⌽CG)[3] NG←(3=W)+(CG∧4=W) ∇ RP←5 5⍴0 0 0 0 0 0 0 1 1 0 0 1 1 0 0 0 0 1 0 0 RP0 0 0 0 00 0 1 1 00 1 1 0 00 0 1 0 00 0 0 0 0 LIFE RP0 0 0 0 00 1 1 1 00 1 0 0 00 1 1 0 00 0 0 0 0 LIFE LIFE RP0 0 1 0 00 1 1 0 01 0 0 1 00 1 1 0 00 0 0 0 0 .................................................. One interacts with the Game of Life by creating an initial configuration and observing how it evolves. Although you should test your implementation on more complex examples such as the glider in a larger universe, show the action of the blinker (three adjoining cells in a row all alive), over three generations, in a 3 by 3 grid. (1,4)=TRUERETURN'' Count the number of neighbours of the point i,j' (Assume i/j +/- 1 will not fall out of world)'FUNCTION count_neighbours(i%,j%) LOCAL count%,l% count%=0 FOR l%=-1 TO 1 IF world! (i%+l%,j%+1) count%=count%+1 ENDIF NEXT l% IF world! (i%+1,j%) count%=count%+1 ENDIF RETURN count%ENDFUNC'' Update the world one step'PROCEDURE update_world LOCAL i%,j% ' compute neighbour counts and store FOR i%=1 TO 30 FOR j%=1 TO 30 ns%(i%,j%)[email protected]_neighbours(i%,j%) NEXT j% NEXT i% ' update the world cells FOR i%=1 TO 30 FOR j%=1 TO 30 IF world!

||

randfill: stx $01 ;$200 for indirect ldx #$02 ;addressing stx $02randloop: lda $fe ;generate random and #$01 ;pixels on the sta ($01), Y ;screen jsr inc0103 cmp #$00 bne randloop lda $02 cmp #$06 bne randloop clearmem: lda #$df ;set $07df-$0a20 sta $01 ;to $#00 lda #$07 sta $02clearbyte: lda #$00 sta ($01), Y jsr inc0103 cmp #$20 bne clearbyte lda $02 cmp #$0a bne clearbyte starttick:copyscreen: lda #$00 ;set up source sta $01 ;pointer at sta $03 ;$01/$02 and lda #$02 ;dest pointer sta $02 ;at $03/$04 lda #$08 sta $04 ldy #$00copybyte: lda ($01), Y ;copy pixel to sta ($03), Y ;back buffer jsr inc0103 ;increment pointers cmp #$00 ;check to see bne copybyte ;if we're at $600 lda $02 ;if so, we've cmp #$06 ;copied the bne copybyte ;entire screen conway: lda #$df ;apply conway rules sta $01 ;reset the pointer sta $03 ;to $#01df/$#07df lda #$01 ;($200 - $21) sta $02 ;($800 - $21) lda #$07 sta $04onecell: lda #$00 ;process one cell ldy #$01 ;upper cell clc adc ($03), Y ldy #$41 ;lower cell clc adc ($03), Ychkleft: tax ;check to see lda $01 ;if we're at the and #$1f ;left edge tay txa cpy #$1f beq rightcellsleftcells: ldy #$00 ;upper-left cell clc adc ($03), Y ldy #$20 ;left cell clc adc ($03), Y ldy #$40 ;lower-left cell clc adc ($03), Ychkright: tax ;check to see lda $01 ;if we're at the and #$1f ;right edge tay txa cpy #$1e beq evaluaterightcells: ldy #$02 ;upper-right cell clc adc ($03), Y ldy #$22 ;right cell clc adc ($03), Y ldy #$42 ;lower-right cell clc adc ($03), Yevaluate: ldx #$01 ;evaluate total ldy #$21 ;for current cell cmp #$03 ;3 = alive beq storex ldx #$00 cmp #$02 ;2 = alive if bne storex ;c = alive lda ($03), Y and #$01 taxstorex: txa ;store to screen sta ($01), Y jsr inc0103 ;move to next cellconwayloop: cmp #$e0 ;if not last cell, bne onecell ;process next cell lda $02 cmp #$05 bne onecell jmp starttick ;run next tick inc0103: lda $01 ;increment $01 cmp #$ff ;and $03 as 16-bit bne onlyinc01 ;pointers inc $02 inc $04onlyinc01: inc $01 lda $01 sta $03 rts The solution uses one cell thick border around square Petri dish as uninhabited dire land. Sample output contains 3 generations of the blinker and 5 of the glider: See Conway's Game of Life/ALGOL 68 APL2 (Dialog) Example in one line APL \ 1130 example (very old APL dialect via simulator) APL1130From: APL \ 1130 Samples The following APL \ 1130 code will need APL385 font installed to display correctly.

See Download APL TT Font ∇LIFE[⎕]∇[0] NG←LIFE CG; W[1] W←CG+(¯1⊖CG)+(1⊖CG)+(¯1⌽CG)+(1⌽CG)[2] W←W+(1⊖1⌽CG)+(¯1⊖1⌽CG)+(1⊖¯1⌽CG)+(¯1⊖¯1⌽CG)[3] NG←(3=W)+(CG∧4=W) ∇ RP←5 5⍴0 0 0 0 0 0 0 1 1 0 0 1 1 0 0 0 0 1 0 0 RP0 0 0 0 00 0 1 1 00 1 1 0 00 0 1 0 00 0 0 0 0 LIFE RP0 0 0 0 00 1 1 1 00 1 0 0 00 1 1 0 00 0 0 0 0 LIFE LIFE RP0 0 1 0 00 1 1 0 01 0 0 1 00 1 1 0 00 0 0 0 0 ..................................................

One interacts with the Game of Life by creating an initial configuration and observing how it evolves.

Although you should test your implementation on more complex examples such as the glider in a larger universe, show the action of the blinker (three adjoining cells in a row all alive), over three generations, in a 3 by 3 grid.

(1,4)=TRUERETURN'' Count the number of neighbours of the point i,j' (Assume i/j +/- 1 will not fall out of world)'FUNCTION count_neighbours(i%,j%) LOCAL count%,l% count%=0 FOR l%=-1 TO 1 IF world! (i%+l%,j%+1) count%=count%+1 ENDIF NEXT l% IF world! (i%+1,j%) count%=count%+1 ENDIF RETURN count%ENDFUNC'' Update the world one step'PROCEDURE update_world LOCAL i%,j% ' compute neighbour counts and store FOR i%=1 TO 30 FOR j%=1 TO 30 ns%(i%,j%)[email protected]_neighbours(i%,j%) NEXT j% NEXT i% ' update the world cells FOR i%=1 TO 30 FOR j%=1 TO 30 IF world!

Thus, while it is somewhat verbose, it fully simulates Conway's Game of Life and is relatively simple to expand to feature different starting shapes.

Define life(pattern) = Prgm Local x,y,nt,count,save,xl,yl,xh,yh Define nt(y,x) = when(pxl Test(y,x), 1, 0) {}→save set Graph("Axes", "Off")→save[1] set Graph("Grid", "Off")→save[2] set Graph("Labels", "Off")→save[3] Fn Off Plot Off Clr Draw If pattern = "blinker" Then 36→yl 40→yh 78→xl 82→xh Pxl On 36,80 Pxl On 38,80 Pxl On 40,80 Else If pattern = "glider" Then 30→yl 40→yh 76→xl 88→xh Pxl On 38,76 Pxl On 36,78 Pxl On 36,80 Pxl On 38,80 Pxl On 40,80 Else If pattern = "r" Then 38-5*2→yl 38+5*2→yh 80-5*2→xl 80+5*2→xh Pxl On 38,78 Pxl On 36,82 Pxl On 36,80 Pxl On 38,80 Pxl On 40,80 End If While get Key() = 0 © Expand upper-left corner to whole cell For y,yl,yh,2 For x,xl,xh,2 If pxl Test(y,x) Then Pxl On y+1,x Pxl On y+1,x+1 Pxl On y, x+1 Else Pxl Off y+1,x Pxl Off y+1,x+1 Pxl Off y, x+1 End If End For End For © Compute next generation For y,yl,yh,2 For x,xl,xh,2 nt(y-1,x-1) + nt(y-1,x) + nt(y-1,x+2) + nt(y,x-1) + nt(y+1,x+2) + nt(y+2,x-1) + nt(y+2,x+1) + nt(y+2,x+2) → count If count = 3 Then Pxl On y,x Else If count ≠ 2 Then Pxl Off y,x End If End For End For End While © Restore changed options set Graph("Axes", save[1]) set Graph("Grid", save[2]) set Graph("Labels", save[3])End Prgm Also see Conway's Game of Life/C Considering that the simplest implementation in C++ would lack any use of the object-oriented paradigm, this code was specifically written to demonstrate the various object-oriented features of C++.

]] ;process one cell ldy #

randfill: stx $01 ;$200 for indirect ldx #$02 ;addressing stx $02randloop: lda $fe ;generate random and #$01 ;pixels on the sta ($01), Y ;screen jsr inc0103 cmp #$00 bne randloop lda $02 cmp #$06 bne randloop clearmem: lda #$df ;set $07df-$0a20 sta $01 ;to $#00 lda #$07 sta $02clearbyte: lda #$00 sta ($01), Y jsr inc0103 cmp #$20 bne clearbyte lda $02 cmp #$0a bne clearbyte starttick:copyscreen: lda #$00 ;set up source sta $01 ;pointer at sta $03 ;$01/$02 and lda #$02 ;dest pointer sta $02 ;at $03/$04 lda #$08 sta $04 ldy #$00copybyte: lda ($01), Y ;copy pixel to sta ($03), Y ;back buffer jsr inc0103 ;increment pointers cmp #$00 ;check to see bne copybyte ;if we're at $600 lda $02 ;if so, we've cmp #$06 ;copied the bne copybyte ;entire screen conway: lda #$df ;apply conway rules sta $01 ;reset the pointer sta $03 ;to $#01df/$#07df lda #$01 ;($200 - $21) sta $02 ;($800 - $21) lda #$07 sta $04onecell: lda #$00 ;process one cell ldy #$01 ;upper cell clc adc ($03), Y ldy #$41 ;lower cell clc adc ($03), Ychkleft: tax ;check to see lda $01 ;if we're at the and #$1f ;left edge tay txa cpy #$1f beq rightcellsleftcells: ldy #$00 ;upper-left cell clc adc ($03), Y ldy #$20 ;left cell clc adc ($03), Y ldy #$40 ;lower-left cell clc adc ($03), Ychkright: tax ;check to see lda $01 ;if we're at the and #$1f ;right edge tay txa cpy #$1e beq evaluaterightcells: ldy #$02 ;upper-right cell clc adc ($03), Y ldy #$22 ;right cell clc adc ($03), Y ldy #$42 ;lower-right cell clc adc ($03), Yevaluate: ldx #$01 ;evaluate total ldy #$21 ;for current cell cmp #$03 ;3 = alive beq storex ldx #$00 cmp #$02 ;2 = alive if bne storex ;c = alive lda ($03), Y and #$01 taxstorex: txa ;store to screen sta ($01), Y jsr inc0103 ;move to next cellconwayloop: cmp #$e0 ;if not last cell, bne onecell ;process next cell lda $02 cmp #$05 bne onecell jmp starttick ;run next tick inc0103: lda $01 ;increment $01 cmp #$ff ;and $03 as 16-bit bne onlyinc01 ;pointers inc $02 inc $04onlyinc01: inc $01 lda $01 sta $03 rts The solution uses one cell thick border around square Petri dish as uninhabited dire land. Sample output contains 3 generations of the blinker and 5 of the glider: See Conway's Game of Life/ALGOL 68 APL2 (Dialog) Example in one line APL \ 1130 example (very old APL dialect via simulator) APL1130From: APL \ 1130 Samples The following APL \ 1130 code will need APL385 font installed to display correctly. See Download APL TT Font ∇LIFE[⎕]∇[0] NG←LIFE CG; W[1] W←CG+(¯1⊖CG)+(1⊖CG)+(¯1⌽CG)+(1⌽CG)[2] W←W+(1⊖1⌽CG)+(¯1⊖1⌽CG)+(1⊖¯1⌽CG)+(¯1⊖¯1⌽CG)[3] NG←(3=W)+(CG∧4=W) ∇ RP←5 5⍴0 0 0 0 0 0 0 1 1 0 0 1 1 0 0 0 0 1 0 0 RP0 0 0 0 00 0 1 1 00 1 1 0 00 0 1 0 00 0 0 0 0 LIFE RP0 0 0 0 00 1 1 1 00 1 0 0 00 1 1 0 00 0 0 0 0 LIFE LIFE RP0 0 1 0 00 1 1 0 01 0 0 1 00 1 1 0 00 0 0 0 0 .................................................. One interacts with the Game of Life by creating an initial configuration and observing how it evolves. Although you should test your implementation on more complex examples such as the glider in a larger universe, show the action of the blinker (three adjoining cells in a row all alive), over three generations, in a 3 by 3 grid. (1,4)=TRUERETURN'' Count the number of neighbours of the point i,j' (Assume i/j +/- 1 will not fall out of world)'FUNCTION count_neighbours(i%,j%) LOCAL count%,l% count%=0 FOR l%=-1 TO 1 IF world! (i%+l%,j%+1) count%=count%+1 ENDIF NEXT l% IF world! (i%+1,j%) count%=count%+1 ENDIF RETURN count%ENDFUNC'' Update the world one step'PROCEDURE update_world LOCAL i%,j% ' compute neighbour counts and store FOR i%=1 TO 30 FOR j%=1 TO 30 ns%(i%,j%)[email protected]_neighbours(i%,j%) NEXT j% NEXT i% ' update the world cells FOR i%=1 TO 30 FOR j%=1 TO 30 IF world!

||

randfill: stx $01 ;$200 for indirect ldx #$02 ;addressing stx $02randloop: lda $fe ;generate random and #$01 ;pixels on the sta ($01), Y ;screen jsr inc0103 cmp #$00 bne randloop lda $02 cmp #$06 bne randloop clearmem: lda #$df ;set $07df-$0a20 sta $01 ;to $#00 lda #$07 sta $02clearbyte: lda #$00 sta ($01), Y jsr inc0103 cmp #$20 bne clearbyte lda $02 cmp #$0a bne clearbyte starttick:copyscreen: lda #$00 ;set up source sta $01 ;pointer at sta $03 ;$01/$02 and lda #$02 ;dest pointer sta $02 ;at $03/$04 lda #$08 sta $04 ldy #$00copybyte: lda ($01), Y ;copy pixel to sta ($03), Y ;back buffer jsr inc0103 ;increment pointers cmp #$00 ;check to see bne copybyte ;if we're at $600 lda $02 ;if so, we've cmp #$06 ;copied the bne copybyte ;entire screen conway: lda #$df ;apply conway rules sta $01 ;reset the pointer sta $03 ;to $#01df/$#07df lda #$01 ;($200 - $21) sta $02 ;($800 - $21) lda #$07 sta $04onecell: lda #$00 ;process one cell ldy #$01 ;upper cell clc adc ($03), Y ldy #$41 ;lower cell clc adc ($03), Ychkleft: tax ;check to see lda $01 ;if we're at the and #$1f ;left edge tay txa cpy #$1f beq rightcellsleftcells: ldy #$00 ;upper-left cell clc adc ($03), Y ldy #$20 ;left cell clc adc ($03), Y ldy #$40 ;lower-left cell clc adc ($03), Ychkright: tax ;check to see lda $01 ;if we're at the and #$1f ;right edge tay txa cpy #$1e beq evaluaterightcells: ldy #$02 ;upper-right cell clc adc ($03), Y ldy #$22 ;right cell clc adc ($03), Y ldy #$42 ;lower-right cell clc adc ($03), Yevaluate: ldx #$01 ;evaluate total ldy #$21 ;for current cell cmp #$03 ;3 = alive beq storex ldx #$00 cmp #$02 ;2 = alive if bne storex ;c = alive lda ($03), Y and #$01 taxstorex: txa ;store to screen sta ($01), Y jsr inc0103 ;move to next cellconwayloop: cmp #$e0 ;if not last cell, bne onecell ;process next cell lda $02 cmp #$05 bne onecell jmp starttick ;run next tick inc0103: lda $01 ;increment $01 cmp #$ff ;and $03 as 16-bit bne onlyinc01 ;pointers inc $02 inc $04onlyinc01: inc $01 lda $01 sta $03 rts The solution uses one cell thick border around square Petri dish as uninhabited dire land. Sample output contains 3 generations of the blinker and 5 of the glider: See Conway's Game of Life/ALGOL 68 APL2 (Dialog) Example in one line APL \ 1130 example (very old APL dialect via simulator) APL1130From: APL \ 1130 Samples The following APL \ 1130 code will need APL385 font installed to display correctly.

See Download APL TT Font ∇LIFE[⎕]∇[0] NG←LIFE CG; W[1] W←CG+(¯1⊖CG)+(1⊖CG)+(¯1⌽CG)+(1⌽CG)[2] W←W+(1⊖1⌽CG)+(¯1⊖1⌽CG)+(1⊖¯1⌽CG)+(¯1⊖¯1⌽CG)[3] NG←(3=W)+(CG∧4=W) ∇ RP←5 5⍴0 0 0 0 0 0 0 1 1 0 0 1 1 0 0 0 0 1 0 0 RP0 0 0 0 00 0 1 1 00 1 1 0 00 0 1 0 00 0 0 0 0 LIFE RP0 0 0 0 00 1 1 1 00 1 0 0 00 1 1 0 00 0 0 0 0 LIFE LIFE RP0 0 1 0 00 1 1 0 01 0 0 1 00 1 1 0 00 0 0 0 0 ..................................................

One interacts with the Game of Life by creating an initial configuration and observing how it evolves.

Although you should test your implementation on more complex examples such as the glider in a larger universe, show the action of the blinker (three adjoining cells in a row all alive), over three generations, in a 3 by 3 grid.

(1,4)=TRUERETURN'' Count the number of neighbours of the point i,j' (Assume i/j +/- 1 will not fall out of world)'FUNCTION count_neighbours(i%,j%) LOCAL count%,l% count%=0 FOR l%=-1 TO 1 IF world! (i%+l%,j%+1) count%=count%+1 ENDIF NEXT l% IF world! (i%+1,j%) count%=count%+1 ENDIF RETURN count%ENDFUNC'' Update the world one step'PROCEDURE update_world LOCAL i%,j% ' compute neighbour counts and store FOR i%=1 TO 30 FOR j%=1 TO 30 ns%(i%,j%)[email protected]_neighbours(i%,j%) NEXT j% NEXT i% ' update the world cells FOR i%=1 TO 30 FOR j%=1 TO 30 IF world!

Thus, while it is somewhat verbose, it fully simulates Conway's Game of Life and is relatively simple to expand to feature different starting shapes.

Define life(pattern) = Prgm Local x,y,nt,count,save,xl,yl,xh,yh Define nt(y,x) = when(pxl Test(y,x), 1, 0) {}→save set Graph("Axes", "Off")→save[1] set Graph("Grid", "Off")→save[2] set Graph("Labels", "Off")→save[3] Fn Off Plot Off Clr Draw If pattern = "blinker" Then 36→yl 40→yh 78→xl 82→xh Pxl On 36,80 Pxl On 38,80 Pxl On 40,80 Else If pattern = "glider" Then 30→yl 40→yh 76→xl 88→xh Pxl On 38,76 Pxl On 36,78 Pxl On 36,80 Pxl On 38,80 Pxl On 40,80 Else If pattern = "r" Then 38-5*2→yl 38+5*2→yh 80-5*2→xl 80+5*2→xh Pxl On 38,78 Pxl On 36,82 Pxl On 36,80 Pxl On 38,80 Pxl On 40,80 End If While get Key() = 0 © Expand upper-left corner to whole cell For y,yl,yh,2 For x,xl,xh,2 If pxl Test(y,x) Then Pxl On y+1,x Pxl On y+1,x+1 Pxl On y, x+1 Else Pxl Off y+1,x Pxl Off y+1,x+1 Pxl Off y, x+1 End If End For End For © Compute next generation For y,yl,yh,2 For x,xl,xh,2 nt(y-1,x-1) + nt(y-1,x) + nt(y-1,x+2) + nt(y,x-1) + nt(y+1,x+2) + nt(y+2,x-1) + nt(y+2,x+1) + nt(y+2,x+2) → count If count = 3 Then Pxl On y,x Else If count ≠ 2 Then Pxl Off y,x End If End For End For End While © Restore changed options set Graph("Axes", save[1]) set Graph("Grid", save[2]) set Graph("Labels", save[3])End Prgm Also see Conway's Game of Life/C Considering that the simplest implementation in C++ would lack any use of the object-oriented paradigm, this code was specifically written to demonstrate the various object-oriented features of C++.

;upper cell clc adc (), Y ldy # ;lower cell clc adc (), Ychkleft: tax ;check to see lda

randfill: stx $01 ;$200 for indirect ldx #$02 ;addressing stx $02randloop: lda $fe ;generate random and #$01 ;pixels on the sta ($01), Y ;screen jsr inc0103 cmp #$00 bne randloop lda $02 cmp #$06 bne randloop clearmem: lda #$df ;set $07df-$0a20 sta $01 ;to $#00 lda #$07 sta $02clearbyte: lda #$00 sta ($01), Y jsr inc0103 cmp #$20 bne clearbyte lda $02 cmp #$0a bne clearbyte starttick:copyscreen: lda #$00 ;set up source sta $01 ;pointer at sta $03 ;$01/$02 and lda #$02 ;dest pointer sta $02 ;at $03/$04 lda #$08 sta $04 ldy #$00copybyte: lda ($01), Y ;copy pixel to sta ($03), Y ;back buffer jsr inc0103 ;increment pointers cmp #$00 ;check to see bne copybyte ;if we're at $600 lda $02 ;if so, we've cmp #$06 ;copied the bne copybyte ;entire screen conway: lda #$df ;apply conway rules sta $01 ;reset the pointer sta $03 ;to $#01df/$#07df lda #$01 ;($200 - $21) sta $02 ;($800 - $21) lda #$07 sta $04onecell: lda #$00 ;process one cell ldy #$01 ;upper cell clc adc ($03), Y ldy #$41 ;lower cell clc adc ($03), Ychkleft: tax ;check to see lda $01 ;if we're at the and #$1f ;left edge tay txa cpy #$1f beq rightcellsleftcells: ldy #$00 ;upper-left cell clc adc ($03), Y ldy #$20 ;left cell clc adc ($03), Y ldy #$40 ;lower-left cell clc adc ($03), Ychkright: tax ;check to see lda $01 ;if we're at the and #$1f ;right edge tay txa cpy #$1e beq evaluaterightcells: ldy #$02 ;upper-right cell clc adc ($03), Y ldy #$22 ;right cell clc adc ($03), Y ldy #$42 ;lower-right cell clc adc ($03), Yevaluate: ldx #$01 ;evaluate total ldy #$21 ;for current cell cmp #$03 ;3 = alive beq storex ldx #$00 cmp #$02 ;2 = alive if bne storex ;c = alive lda ($03), Y and #$01 taxstorex: txa ;store to screen sta ($01), Y jsr inc0103 ;move to next cellconwayloop: cmp #$e0 ;if not last cell, bne onecell ;process next cell lda $02 cmp #$05 bne onecell jmp starttick ;run next tick inc0103: lda $01 ;increment $01 cmp #$ff ;and $03 as 16-bit bne onlyinc01 ;pointers inc $02 inc $04onlyinc01: inc $01 lda $01 sta $03 rts The solution uses one cell thick border around square Petri dish as uninhabited dire land. Sample output contains 3 generations of the blinker and 5 of the glider: See Conway's Game of Life/ALGOL 68 APL2 (Dialog) Example in one line APL \ 1130 example (very old APL dialect via simulator) APL1130From: APL \ 1130 Samples The following APL \ 1130 code will need APL385 font installed to display correctly. See Download APL TT Font ∇LIFE[⎕]∇[0] NG←LIFE CG; W[1] W←CG+(¯1⊖CG)+(1⊖CG)+(¯1⌽CG)+(1⌽CG)[2] W←W+(1⊖1⌽CG)+(¯1⊖1⌽CG)+(1⊖¯1⌽CG)+(¯1⊖¯1⌽CG)[3] NG←(3=W)+(CG∧4=W) ∇ RP←5 5⍴0 0 0 0 0 0 0 1 1 0 0 1 1 0 0 0 0 1 0 0 RP0 0 0 0 00 0 1 1 00 1 1 0 00 0 1 0 00 0 0 0 0 LIFE RP0 0 0 0 00 1 1 1 00 1 0 0 00 1 1 0 00 0 0 0 0 LIFE LIFE RP0 0 1 0 00 1 1 0 01 0 0 1 00 1 1 0 00 0 0 0 0 .................................................. One interacts with the Game of Life by creating an initial configuration and observing how it evolves. Although you should test your implementation on more complex examples such as the glider in a larger universe, show the action of the blinker (three adjoining cells in a row all alive), over three generations, in a 3 by 3 grid. (1,4)=TRUERETURN'' Count the number of neighbours of the point i,j' (Assume i/j +/- 1 will not fall out of world)'FUNCTION count_neighbours(i%,j%) LOCAL count%,l% count%=0 FOR l%=-1 TO 1 IF world! (i%+l%,j%+1) count%=count%+1 ENDIF NEXT l% IF world! (i%+1,j%) count%=count%+1 ENDIF RETURN count%ENDFUNC'' Update the world one step'PROCEDURE update_world LOCAL i%,j% ' compute neighbour counts and store FOR i%=1 TO 30 FOR j%=1 TO 30 ns%(i%,j%)[email protected]_neighbours(i%,j%) NEXT j% NEXT i% ' update the world cells FOR i%=1 TO 30 FOR j%=1 TO 30 IF world!

||

randfill: stx $01 ;$200 for indirect ldx #$02 ;addressing stx $02randloop: lda $fe ;generate random and #$01 ;pixels on the sta ($01), Y ;screen jsr inc0103 cmp #$00 bne randloop lda $02 cmp #$06 bne randloop clearmem: lda #$df ;set $07df-$0a20 sta $01 ;to $#00 lda #$07 sta $02clearbyte: lda #$00 sta ($01), Y jsr inc0103 cmp #$20 bne clearbyte lda $02 cmp #$0a bne clearbyte starttick:copyscreen: lda #$00 ;set up source sta $01 ;pointer at sta $03 ;$01/$02 and lda #$02 ;dest pointer sta $02 ;at $03/$04 lda #$08 sta $04 ldy #$00copybyte: lda ($01), Y ;copy pixel to sta ($03), Y ;back buffer jsr inc0103 ;increment pointers cmp #$00 ;check to see bne copybyte ;if we're at $600 lda $02 ;if so, we've cmp #$06 ;copied the bne copybyte ;entire screen conway: lda #$df ;apply conway rules sta $01 ;reset the pointer sta $03 ;to $#01df/$#07df lda #$01 ;($200 - $21) sta $02 ;($800 - $21) lda #$07 sta $04onecell: lda #$00 ;process one cell ldy #$01 ;upper cell clc adc ($03), Y ldy #$41 ;lower cell clc adc ($03), Ychkleft: tax ;check to see lda $01 ;if we're at the and #$1f ;left edge tay txa cpy #$1f beq rightcellsleftcells: ldy #$00 ;upper-left cell clc adc ($03), Y ldy #$20 ;left cell clc adc ($03), Y ldy #$40 ;lower-left cell clc adc ($03), Ychkright: tax ;check to see lda $01 ;if we're at the and #$1f ;right edge tay txa cpy #$1e beq evaluaterightcells: ldy #$02 ;upper-right cell clc adc ($03), Y ldy #$22 ;right cell clc adc ($03), Y ldy #$42 ;lower-right cell clc adc ($03), Yevaluate: ldx #$01 ;evaluate total ldy #$21 ;for current cell cmp #$03 ;3 = alive beq storex ldx #$00 cmp #$02 ;2 = alive if bne storex ;c = alive lda ($03), Y and #$01 taxstorex: txa ;store to screen sta ($01), Y jsr inc0103 ;move to next cellconwayloop: cmp #$e0 ;if not last cell, bne onecell ;process next cell lda $02 cmp #$05 bne onecell jmp starttick ;run next tick inc0103: lda $01 ;increment $01 cmp #$ff ;and $03 as 16-bit bne onlyinc01 ;pointers inc $02 inc $04onlyinc01: inc $01 lda $01 sta $03 rts The solution uses one cell thick border around square Petri dish as uninhabited dire land. Sample output contains 3 generations of the blinker and 5 of the glider: See Conway's Game of Life/ALGOL 68 APL2 (Dialog) Example in one line APL \ 1130 example (very old APL dialect via simulator) APL1130From: APL \ 1130 Samples The following APL \ 1130 code will need APL385 font installed to display correctly.

See Download APL TT Font ∇LIFE[⎕]∇[0] NG←LIFE CG; W[1] W←CG+(¯1⊖CG)+(1⊖CG)+(¯1⌽CG)+(1⌽CG)[2] W←W+(1⊖1⌽CG)+(¯1⊖1⌽CG)+(1⊖¯1⌽CG)+(¯1⊖¯1⌽CG)[3] NG←(3=W)+(CG∧4=W) ∇ RP←5 5⍴0 0 0 0 0 0 0 1 1 0 0 1 1 0 0 0 0 1 0 0 RP0 0 0 0 00 0 1 1 00 1 1 0 00 0 1 0 00 0 0 0 0 LIFE RP0 0 0 0 00 1 1 1 00 1 0 0 00 1 1 0 00 0 0 0 0 LIFE LIFE RP0 0 1 0 00 1 1 0 01 0 0 1 00 1 1 0 00 0 0 0 0 ..................................................

One interacts with the Game of Life by creating an initial configuration and observing how it evolves.

Although you should test your implementation on more complex examples such as the glider in a larger universe, show the action of the blinker (three adjoining cells in a row all alive), over three generations, in a 3 by 3 grid.

(1,4)=TRUERETURN'' Count the number of neighbours of the point i,j' (Assume i/j +/- 1 will not fall out of world)'FUNCTION count_neighbours(i%,j%) LOCAL count%,l% count%=0 FOR l%=-1 TO 1 IF world! (i%+l%,j%+1) count%=count%+1 ENDIF NEXT l% IF world! (i%+1,j%) count%=count%+1 ENDIF RETURN count%ENDFUNC'' Update the world one step'PROCEDURE update_world LOCAL i%,j% ' compute neighbour counts and store FOR i%=1 TO 30 FOR j%=1 TO 30 ns%(i%,j%)[email protected]_neighbours(i%,j%) NEXT j% NEXT i% ' update the world cells FOR i%=1 TO 30 FOR j%=1 TO 30 IF world!

Thus, while it is somewhat verbose, it fully simulates Conway's Game of Life and is relatively simple to expand to feature different starting shapes.

Define life(pattern) = Prgm Local x,y,nt,count,save,xl,yl,xh,yh Define nt(y,x) = when(pxl Test(y,x), 1, 0) {}→save set Graph("Axes", "Off")→save[1] set Graph("Grid", "Off")→save[2] set Graph("Labels", "Off")→save[3] Fn Off Plot Off Clr Draw If pattern = "blinker" Then 36→yl 40→yh 78→xl 82→xh Pxl On 36,80 Pxl On 38,80 Pxl On 40,80 Else If pattern = "glider" Then 30→yl 40→yh 76→xl 88→xh Pxl On 38,76 Pxl On 36,78 Pxl On 36,80 Pxl On 38,80 Pxl On 40,80 Else If pattern = "r" Then 38-5*2→yl 38+5*2→yh 80-5*2→xl 80+5*2→xh Pxl On 38,78 Pxl On 36,82 Pxl On 36,80 Pxl On 38,80 Pxl On 40,80 End If While get Key() = 0 © Expand upper-left corner to whole cell For y,yl,yh,2 For x,xl,xh,2 If pxl Test(y,x) Then Pxl On y+1,x Pxl On y+1,x+1 Pxl On y, x+1 Else Pxl Off y+1,x Pxl Off y+1,x+1 Pxl Off y, x+1 End If End For End For © Compute next generation For y,yl,yh,2 For x,xl,xh,2 nt(y-1,x-1) + nt(y-1,x) + nt(y-1,x+2) + nt(y,x-1) + nt(y+1,x+2) + nt(y+2,x-1) + nt(y+2,x+1) + nt(y+2,x+2) → count If count = 3 Then Pxl On y,x Else If count ≠ 2 Then Pxl Off y,x End If End For End For End While © Restore changed options set Graph("Axes", save[1]) set Graph("Grid", save[2]) set Graph("Labels", save[3])End Prgm Also see Conway's Game of Life/C Considering that the simplest implementation in C++ would lack any use of the object-oriented paradigm, this code was specifically written to demonstrate the various object-oriented features of C++.

;if we're at the and #

randfill: stx $01 ;$200 for indirect ldx #$02 ;addressing stx $02randloop: lda $fe ;generate random and #$01 ;pixels on the sta ($01), Y ;screen jsr inc0103 cmp #$00 bne randloop lda $02 cmp #$06 bne randloop clearmem: lda #$df ;set $07df-$0a20 sta $01 ;to $#00 lda #$07 sta $02clearbyte: lda #$00 sta ($01), Y jsr inc0103 cmp #$20 bne clearbyte lda $02 cmp #$0a bne clearbyte starttick:copyscreen: lda #$00 ;set up source sta $01 ;pointer at sta $03 ;$01/$02 and lda #$02 ;dest pointer sta $02 ;at $03/$04 lda #$08 sta $04 ldy #$00copybyte: lda ($01), Y ;copy pixel to sta ($03), Y ;back buffer jsr inc0103 ;increment pointers cmp #$00 ;check to see bne copybyte ;if we're at $600 lda $02 ;if so, we've cmp #$06 ;copied the bne copybyte ;entire screen conway: lda #$df ;apply conway rules sta $01 ;reset the pointer sta $03 ;to $#01df/$#07df lda #$01 ;($200 - $21) sta $02 ;($800 - $21) lda #$07 sta $04onecell: lda #$00 ;process one cell ldy #$01 ;upper cell clc adc ($03), Y ldy #$41 ;lower cell clc adc ($03), Ychkleft: tax ;check to see lda $01 ;if we're at the and #$1f ;left edge tay txa cpy #$1f beq rightcellsleftcells: ldy #$00 ;upper-left cell clc adc ($03), Y ldy #$20 ;left cell clc adc ($03), Y ldy #$40 ;lower-left cell clc adc ($03), Ychkright: tax ;check to see lda $01 ;if we're at the and #$1f ;right edge tay txa cpy #$1e beq evaluaterightcells: ldy #$02 ;upper-right cell clc adc ($03), Y ldy #$22 ;right cell clc adc ($03), Y ldy #$42 ;lower-right cell clc adc ($03), Yevaluate: ldx #$01 ;evaluate total ldy #$21 ;for current cell cmp #$03 ;3 = alive beq storex ldx #$00 cmp #$02 ;2 = alive if bne storex ;c = alive lda ($03), Y and #$01 taxstorex: txa ;store to screen sta ($01), Y jsr inc0103 ;move to next cellconwayloop: cmp #$e0 ;if not last cell, bne onecell ;process next cell lda $02 cmp #$05 bne onecell jmp starttick ;run next tick inc0103: lda $01 ;increment $01 cmp #$ff ;and $03 as 16-bit bne onlyinc01 ;pointers inc $02 inc $04onlyinc01: inc $01 lda $01 sta $03 rts The solution uses one cell thick border around square Petri dish as uninhabited dire land. Sample output contains 3 generations of the blinker and 5 of the glider: See Conway's Game of Life/ALGOL 68 APL2 (Dialog) Example in one line APL \ 1130 example (very old APL dialect via simulator) APL1130From: APL \ 1130 Samples The following APL \ 1130 code will need APL385 font installed to display correctly. See Download APL TT Font ∇LIFE[⎕]∇[0] NG←LIFE CG; W[1] W←CG+(¯1⊖CG)+(1⊖CG)+(¯1⌽CG)+(1⌽CG)[2] W←W+(1⊖1⌽CG)+(¯1⊖1⌽CG)+(1⊖¯1⌽CG)+(¯1⊖¯1⌽CG)[3] NG←(3=W)+(CG∧4=W) ∇ RP←5 5⍴0 0 0 0 0 0 0 1 1 0 0 1 1 0 0 0 0 1 0 0 RP0 0 0 0 00 0 1 1 00 1 1 0 00 0 1 0 00 0 0 0 0 LIFE RP0 0 0 0 00 1 1 1 00 1 0 0 00 1 1 0 00 0 0 0 0 LIFE LIFE RP0 0 1 0 00 1 1 0 01 0 0 1 00 1 1 0 00 0 0 0 0 .................................................. One interacts with the Game of Life by creating an initial configuration and observing how it evolves. Although you should test your implementation on more complex examples such as the glider in a larger universe, show the action of the blinker (three adjoining cells in a row all alive), over three generations, in a 3 by 3 grid. (1,4)=TRUERETURN'' Count the number of neighbours of the point i,j' (Assume i/j +/- 1 will not fall out of world)'FUNCTION count_neighbours(i%,j%) LOCAL count%,l% count%=0 FOR l%=-1 TO 1 IF world! (i%+l%,j%+1) count%=count%+1 ENDIF NEXT l% IF world! (i%+1,j%) count%=count%+1 ENDIF RETURN count%ENDFUNC'' Update the world one step'PROCEDURE update_world LOCAL i%,j% ' compute neighbour counts and store FOR i%=1 TO 30 FOR j%=1 TO 30 ns%(i%,j%)[email protected]_neighbours(i%,j%) NEXT j% NEXT i% ' update the world cells FOR i%=1 TO 30 FOR j%=1 TO 30 IF world!

||

randfill: stx $01 ;$200 for indirect ldx #$02 ;addressing stx $02randloop: lda $fe ;generate random and #$01 ;pixels on the sta ($01), Y ;screen jsr inc0103 cmp #$00 bne randloop lda $02 cmp #$06 bne randloop clearmem: lda #$df ;set $07df-$0a20 sta $01 ;to $#00 lda #$07 sta $02clearbyte: lda #$00 sta ($01), Y jsr inc0103 cmp #$20 bne clearbyte lda $02 cmp #$0a bne clearbyte starttick:copyscreen: lda #$00 ;set up source sta $01 ;pointer at sta $03 ;$01/$02 and lda #$02 ;dest pointer sta $02 ;at $03/$04 lda #$08 sta $04 ldy #$00copybyte: lda ($01), Y ;copy pixel to sta ($03), Y ;back buffer jsr inc0103 ;increment pointers cmp #$00 ;check to see bne copybyte ;if we're at $600 lda $02 ;if so, we've cmp #$06 ;copied the bne copybyte ;entire screen conway: lda #$df ;apply conway rules sta $01 ;reset the pointer sta $03 ;to $#01df/$#07df lda #$01 ;($200 - $21) sta $02 ;($800 - $21) lda #$07 sta $04onecell: lda #$00 ;process one cell ldy #$01 ;upper cell clc adc ($03), Y ldy #$41 ;lower cell clc adc ($03), Ychkleft: tax ;check to see lda $01 ;if we're at the and #$1f ;left edge tay txa cpy #$1f beq rightcellsleftcells: ldy #$00 ;upper-left cell clc adc ($03), Y ldy #$20 ;left cell clc adc ($03), Y ldy #$40 ;lower-left cell clc adc ($03), Ychkright: tax ;check to see lda $01 ;if we're at the and #$1f ;right edge tay txa cpy #$1e beq evaluaterightcells: ldy #$02 ;upper-right cell clc adc ($03), Y ldy #$22 ;right cell clc adc ($03), Y ldy #$42 ;lower-right cell clc adc ($03), Yevaluate: ldx #$01 ;evaluate total ldy #$21 ;for current cell cmp #$03 ;3 = alive beq storex ldx #$00 cmp #$02 ;2 = alive if bne storex ;c = alive lda ($03), Y and #$01 taxstorex: txa ;store to screen sta ($01), Y jsr inc0103 ;move to next cellconwayloop: cmp #$e0 ;if not last cell, bne onecell ;process next cell lda $02 cmp #$05 bne onecell jmp starttick ;run next tick inc0103: lda $01 ;increment $01 cmp #$ff ;and $03 as 16-bit bne onlyinc01 ;pointers inc $02 inc $04onlyinc01: inc $01 lda $01 sta $03 rts The solution uses one cell thick border around square Petri dish as uninhabited dire land. Sample output contains 3 generations of the blinker and 5 of the glider: See Conway's Game of Life/ALGOL 68 APL2 (Dialog) Example in one line APL \ 1130 example (very old APL dialect via simulator) APL1130From: APL \ 1130 Samples The following APL \ 1130 code will need APL385 font installed to display correctly.

See Download APL TT Font ∇LIFE[⎕]∇[0] NG←LIFE CG; W[1] W←CG+(¯1⊖CG)+(1⊖CG)+(¯1⌽CG)+(1⌽CG)[2] W←W+(1⊖1⌽CG)+(¯1⊖1⌽CG)+(1⊖¯1⌽CG)+(¯1⊖¯1⌽CG)[3] NG←(3=W)+(CG∧4=W) ∇ RP←5 5⍴0 0 0 0 0 0 0 1 1 0 0 1 1 0 0 0 0 1 0 0 RP0 0 0 0 00 0 1 1 00 1 1 0 00 0 1 0 00 0 0 0 0 LIFE RP0 0 0 0 00 1 1 1 00 1 0 0 00 1 1 0 00 0 0 0 0 LIFE LIFE RP0 0 1 0 00 1 1 0 01 0 0 1 00 1 1 0 00 0 0 0 0 ..................................................

One interacts with the Game of Life by creating an initial configuration and observing how it evolves.

Although you should test your implementation on more complex examples such as the glider in a larger universe, show the action of the blinker (three adjoining cells in a row all alive), over three generations, in a 3 by 3 grid.

(1,4)=TRUERETURN'' Count the number of neighbours of the point i,j' (Assume i/j +/- 1 will not fall out of world)'FUNCTION count_neighbours(i%,j%) LOCAL count%,l% count%=0 FOR l%=-1 TO 1 IF world! (i%+l%,j%+1) count%=count%+1 ENDIF NEXT l% IF world! (i%+1,j%) count%=count%+1 ENDIF RETURN count%ENDFUNC'' Update the world one step'PROCEDURE update_world LOCAL i%,j% ' compute neighbour counts and store FOR i%=1 TO 30 FOR j%=1 TO 30 ns%(i%,j%)[email protected]_neighbours(i%,j%) NEXT j% NEXT i% ' update the world cells FOR i%=1 TO 30 FOR j%=1 TO 30 IF world!

Thus, while it is somewhat verbose, it fully simulates Conway's Game of Life and is relatively simple to expand to feature different starting shapes.

Define life(pattern) = Prgm Local x,y,nt,count,save,xl,yl,xh,yh Define nt(y,x) = when(pxl Test(y,x), 1, 0) {}→save set Graph("Axes", "Off")→save[1] set Graph("Grid", "Off")→save[2] set Graph("Labels", "Off")→save[3] Fn Off Plot Off Clr Draw If pattern = "blinker" Then 36→yl 40→yh 78→xl 82→xh Pxl On 36,80 Pxl On 38,80 Pxl On 40,80 Else If pattern = "glider" Then 30→yl 40→yh 76→xl 88→xh Pxl On 38,76 Pxl On 36,78 Pxl On 36,80 Pxl On 38,80 Pxl On 40,80 Else If pattern = "r" Then 38-5*2→yl 38+5*2→yh 80-5*2→xl 80+5*2→xh Pxl On 38,78 Pxl On 36,82 Pxl On 36,80 Pxl On 38,80 Pxl On 40,80 End If While get Key() = 0 © Expand upper-left corner to whole cell For y,yl,yh,2 For x,xl,xh,2 If pxl Test(y,x) Then Pxl On y+1,x Pxl On y+1,x+1 Pxl On y, x+1 Else Pxl Off y+1,x Pxl Off y+1,x+1 Pxl Off y, x+1 End If End For End For © Compute next generation For y,yl,yh,2 For x,xl,xh,2 nt(y-1,x-1) + nt(y-1,x) + nt(y-1,x+2) + nt(y,x-1) + nt(y+1,x+2) + nt(y+2,x-1) + nt(y+2,x+1) + nt(y+2,x+2) → count If count = 3 Then Pxl On y,x Else If count ≠ 2 Then Pxl Off y,x End If End For End For End While © Restore changed options set Graph("Axes", save[1]) set Graph("Grid", save[2]) set Graph("Labels", save[3])End Prgm Also see Conway's Game of Life/C Considering that the simplest implementation in C++ would lack any use of the object-oriented paradigm, this code was specifically written to demonstrate the various object-oriented features of C++.

f ;left edge tay txa cpy #

randfill: stx $01 ;$200 for indirect ldx #$02 ;addressing stx $02randloop: lda $fe ;generate random and #$01 ;pixels on the sta ($01), Y ;screen jsr inc0103 cmp #$00 bne randloop lda $02 cmp #$06 bne randloop clearmem: lda #$df ;set $07df-$0a20 sta $01 ;to $#00 lda #$07 sta $02clearbyte: lda #$00 sta ($01), Y jsr inc0103 cmp #$20 bne clearbyte lda $02 cmp #$0a bne clearbyte starttick:copyscreen: lda #$00 ;set up source sta $01 ;pointer at sta $03 ;$01/$02 and lda #$02 ;dest pointer sta $02 ;at $03/$04 lda #$08 sta $04 ldy #$00copybyte: lda ($01), Y ;copy pixel to sta ($03), Y ;back buffer jsr inc0103 ;increment pointers cmp #$00 ;check to see bne copybyte ;if we're at $600 lda $02 ;if so, we've cmp #$06 ;copied the bne copybyte ;entire screen conway: lda #$df ;apply conway rules sta $01 ;reset the pointer sta $03 ;to $#01df/$#07df lda #$01 ;($200 - $21) sta $02 ;($800 - $21) lda #$07 sta $04onecell: lda #$00 ;process one cell ldy #$01 ;upper cell clc adc ($03), Y ldy #$41 ;lower cell clc adc ($03), Ychkleft: tax ;check to see lda $01 ;if we're at the and #$1f ;left edge tay txa cpy #$1f beq rightcellsleftcells: ldy #$00 ;upper-left cell clc adc ($03), Y ldy #$20 ;left cell clc adc ($03), Y ldy #$40 ;lower-left cell clc adc ($03), Ychkright: tax ;check to see lda $01 ;if we're at the and #$1f ;right edge tay txa cpy #$1e beq evaluaterightcells: ldy #$02 ;upper-right cell clc adc ($03), Y ldy #$22 ;right cell clc adc ($03), Y ldy #$42 ;lower-right cell clc adc ($03), Yevaluate: ldx #$01 ;evaluate total ldy #$21 ;for current cell cmp #$03 ;3 = alive beq storex ldx #$00 cmp #$02 ;2 = alive if bne storex ;c = alive lda ($03), Y and #$01 taxstorex: txa ;store to screen sta ($01), Y jsr inc0103 ;move to next cellconwayloop: cmp #$e0 ;if not last cell, bne onecell ;process next cell lda $02 cmp #$05 bne onecell jmp starttick ;run next tick inc0103: lda $01 ;increment $01 cmp #$ff ;and $03 as 16-bit bne onlyinc01 ;pointers inc $02 inc $04onlyinc01: inc $01 lda $01 sta $03 rts The solution uses one cell thick border around square Petri dish as uninhabited dire land. Sample output contains 3 generations of the blinker and 5 of the glider: See Conway's Game of Life/ALGOL 68 APL2 (Dialog) Example in one line APL \ 1130 example (very old APL dialect via simulator) APL1130From: APL \ 1130 Samples The following APL \ 1130 code will need APL385 font installed to display correctly. See Download APL TT Font ∇LIFE[⎕]∇[0] NG←LIFE CG; W[1] W←CG+(¯1⊖CG)+(1⊖CG)+(¯1⌽CG)+(1⌽CG)[2] W←W+(1⊖1⌽CG)+(¯1⊖1⌽CG)+(1⊖¯1⌽CG)+(¯1⊖¯1⌽CG)[3] NG←(3=W)+(CG∧4=W) ∇ RP←5 5⍴0 0 0 0 0 0 0 1 1 0 0 1 1 0 0 0 0 1 0 0 RP0 0 0 0 00 0 1 1 00 1 1 0 00 0 1 0 00 0 0 0 0 LIFE RP0 0 0 0 00 1 1 1 00 1 0 0 00 1 1 0 00 0 0 0 0 LIFE LIFE RP0 0 1 0 00 1 1 0 01 0 0 1 00 1 1 0 00 0 0 0 0 .................................................. One interacts with the Game of Life by creating an initial configuration and observing how it evolves. Although you should test your implementation on more complex examples such as the glider in a larger universe, show the action of the blinker (three adjoining cells in a row all alive), over three generations, in a 3 by 3 grid. (1,4)=TRUERETURN'' Count the number of neighbours of the point i,j' (Assume i/j +/- 1 will not fall out of world)'FUNCTION count_neighbours(i%,j%) LOCAL count%,l% count%=0 FOR l%=-1 TO 1 IF world! (i%+l%,j%+1) count%=count%+1 ENDIF NEXT l% IF world! (i%+1,j%) count%=count%+1 ENDIF RETURN count%ENDFUNC'' Update the world one step'PROCEDURE update_world LOCAL i%,j% ' compute neighbour counts and store FOR i%=1 TO 30 FOR j%=1 TO 30 ns%(i%,j%)[email protected]_neighbours(i%,j%) NEXT j% NEXT i% ' update the world cells FOR i%=1 TO 30 FOR j%=1 TO 30 IF world!

||

randfill: stx $01 ;$200 for indirect ldx #$02 ;addressing stx $02randloop: lda $fe ;generate random and #$01 ;pixels on the sta ($01), Y ;screen jsr inc0103 cmp #$00 bne randloop lda $02 cmp #$06 bne randloop clearmem: lda #$df ;set $07df-$0a20 sta $01 ;to $#00 lda #$07 sta $02clearbyte: lda #$00 sta ($01), Y jsr inc0103 cmp #$20 bne clearbyte lda $02 cmp #$0a bne clearbyte starttick:copyscreen: lda #$00 ;set up source sta $01 ;pointer at sta $03 ;$01/$02 and lda #$02 ;dest pointer sta $02 ;at $03/$04 lda #$08 sta $04 ldy #$00copybyte: lda ($01), Y ;copy pixel to sta ($03), Y ;back buffer jsr inc0103 ;increment pointers cmp #$00 ;check to see bne copybyte ;if we're at $600 lda $02 ;if so, we've cmp #$06 ;copied the bne copybyte ;entire screen conway: lda #$df ;apply conway rules sta $01 ;reset the pointer sta $03 ;to $#01df/$#07df lda #$01 ;($200 - $21) sta $02 ;($800 - $21) lda #$07 sta $04onecell: lda #$00 ;process one cell ldy #$01 ;upper cell clc adc ($03), Y ldy #$41 ;lower cell clc adc ($03), Ychkleft: tax ;check to see lda $01 ;if we're at the and #$1f ;left edge tay txa cpy #$1f beq rightcellsleftcells: ldy #$00 ;upper-left cell clc adc ($03), Y ldy #$20 ;left cell clc adc ($03), Y ldy #$40 ;lower-left cell clc adc ($03), Ychkright: tax ;check to see lda $01 ;if we're at the and #$1f ;right edge tay txa cpy #$1e beq evaluaterightcells: ldy #$02 ;upper-right cell clc adc ($03), Y ldy #$22 ;right cell clc adc ($03), Y ldy #$42 ;lower-right cell clc adc ($03), Yevaluate: ldx #$01 ;evaluate total ldy #$21 ;for current cell cmp #$03 ;3 = alive beq storex ldx #$00 cmp #$02 ;2 = alive if bne storex ;c = alive lda ($03), Y and #$01 taxstorex: txa ;store to screen sta ($01), Y jsr inc0103 ;move to next cellconwayloop: cmp #$e0 ;if not last cell, bne onecell ;process next cell lda $02 cmp #$05 bne onecell jmp starttick ;run next tick inc0103: lda $01 ;increment $01 cmp #$ff ;and $03 as 16-bit bne onlyinc01 ;pointers inc $02 inc $04onlyinc01: inc $01 lda $01 sta $03 rts The solution uses one cell thick border around square Petri dish as uninhabited dire land. Sample output contains 3 generations of the blinker and 5 of the glider: See Conway's Game of Life/ALGOL 68 APL2 (Dialog) Example in one line APL \ 1130 example (very old APL dialect via simulator) APL1130From: APL \ 1130 Samples The following APL \ 1130 code will need APL385 font installed to display correctly.

See Download APL TT Font ∇LIFE[⎕]∇[0] NG←LIFE CG; W[1] W←CG+(¯1⊖CG)+(1⊖CG)+(¯1⌽CG)+(1⌽CG)[2] W←W+(1⊖1⌽CG)+(¯1⊖1⌽CG)+(1⊖¯1⌽CG)+(¯1⊖¯1⌽CG)[3] NG←(3=W)+(CG∧4=W) ∇ RP←5 5⍴0 0 0 0 0 0 0 1 1 0 0 1 1 0 0 0 0 1 0 0 RP0 0 0 0 00 0 1 1 00 1 1 0 00 0 1 0 00 0 0 0 0 LIFE RP0 0 0 0 00 1 1 1 00 1 0 0 00 1 1 0 00 0 0 0 0 LIFE LIFE RP0 0 1 0 00 1 1 0 01 0 0 1 00 1 1 0 00 0 0 0 0 ..................................................

One interacts with the Game of Life by creating an initial configuration and observing how it evolves.

Although you should test your implementation on more complex examples such as the glider in a larger universe, show the action of the blinker (three adjoining cells in a row all alive), over three generations, in a 3 by 3 grid.

(1,4)=TRUERETURN'' Count the number of neighbours of the point i,j' (Assume i/j +/- 1 will not fall out of world)'FUNCTION count_neighbours(i%,j%) LOCAL count%,l% count%=0 FOR l%=-1 TO 1 IF world! (i%+l%,j%+1) count%=count%+1 ENDIF NEXT l% IF world! (i%+1,j%) count%=count%+1 ENDIF RETURN count%ENDFUNC'' Update the world one step'PROCEDURE update_world LOCAL i%,j% ' compute neighbour counts and store FOR i%=1 TO 30 FOR j%=1 TO 30 ns%(i%,j%)[email protected]_neighbours(i%,j%) NEXT j% NEXT i% ' update the world cells FOR i%=1 TO 30 FOR j%=1 TO 30 IF world!

Thus, while it is somewhat verbose, it fully simulates Conway's Game of Life and is relatively simple to expand to feature different starting shapes.

Define life(pattern) = Prgm Local x,y,nt,count,save,xl,yl,xh,yh Define nt(y,x) = when(pxl Test(y,x), 1, 0) {}→save set Graph("Axes", "Off")→save[1] set Graph("Grid", "Off")→save[2] set Graph("Labels", "Off")→save[3] Fn Off Plot Off Clr Draw If pattern = "blinker" Then 36→yl 40→yh 78→xl 82→xh Pxl On 36,80 Pxl On 38,80 Pxl On 40,80 Else If pattern = "glider" Then 30→yl 40→yh 76→xl 88→xh Pxl On 38,76 Pxl On 36,78 Pxl On 36,80 Pxl On 38,80 Pxl On 40,80 Else If pattern = "r" Then 38-5*2→yl 38+5*2→yh 80-5*2→xl 80+5*2→xh Pxl On 38,78 Pxl On 36,82 Pxl On 36,80 Pxl On 38,80 Pxl On 40,80 End If While get Key() = 0 © Expand upper-left corner to whole cell For y,yl,yh,2 For x,xl,xh,2 If pxl Test(y,x) Then Pxl On y+1,x Pxl On y+1,x+1 Pxl On y, x+1 Else Pxl Off y+1,x Pxl Off y+1,x+1 Pxl Off y, x+1 End If End For End For © Compute next generation For y,yl,yh,2 For x,xl,xh,2 nt(y-1,x-1) + nt(y-1,x) + nt(y-1,x+2) + nt(y,x-1) + nt(y+1,x+2) + nt(y+2,x-1) + nt(y+2,x+1) + nt(y+2,x+2) → count If count = 3 Then Pxl On y,x Else If count ≠ 2 Then Pxl Off y,x End If End For End For End While © Restore changed options set Graph("Axes", save[1]) set Graph("Grid", save[2]) set Graph("Labels", save[3])End Prgm Also see Conway's Game of Life/C Considering that the simplest implementation in C++ would lack any use of the object-oriented paradigm, this code was specifically written to demonstrate the various object-oriented features of C++.

f beq rightcellsleftcells: ldy #[[

randfill: stx $01 ;$200 for indirect ldx #$02 ;addressing stx $02randloop: lda $fe ;generate random and #$01 ;pixels on the sta ($01), Y ;screen jsr inc0103 cmp #$00 bne randloop lda $02 cmp #$06 bne randloop clearmem: lda #$df ;set $07df-$0a20 sta $01 ;to $#00 lda #$07 sta $02clearbyte: lda #$00 sta ($01), Y jsr inc0103 cmp #$20 bne clearbyte lda $02 cmp #$0a bne clearbyte starttick:copyscreen: lda #$00 ;set up source sta $01 ;pointer at sta $03 ;$01/$02 and lda #$02 ;dest pointer sta $02 ;at $03/$04 lda #$08 sta $04 ldy #$00copybyte: lda ($01), Y ;copy pixel to sta ($03), Y ;back buffer jsr inc0103 ;increment pointers cmp #$00 ;check to see bne copybyte ;if we're at $600 lda $02 ;if so, we've cmp #$06 ;copied the bne copybyte ;entire screen conway: lda #$df ;apply conway rules sta $01 ;reset the pointer sta $03 ;to $#01df/$#07df lda #$01 ;($200 - $21) sta $02 ;($800 - $21) lda #$07 sta $04onecell: lda #$00 ;process one cell ldy #$01 ;upper cell clc adc ($03), Y ldy #$41 ;lower cell clc adc ($03), Ychkleft: tax ;check to see lda $01 ;if we're at the and #$1f ;left edge tay txa cpy #$1f beq rightcellsleftcells: ldy #$00 ;upper-left cell clc adc ($03), Y ldy #$20 ;left cell clc adc ($03), Y ldy #$40 ;lower-left cell clc adc ($03), Ychkright: tax ;check to see lda $01 ;if we're at the and #$1f ;right edge tay txa cpy #$1e beq evaluaterightcells: ldy #$02 ;upper-right cell clc adc ($03), Y ldy #$22 ;right cell clc adc ($03), Y ldy #$42 ;lower-right cell clc adc ($03), Yevaluate: ldx #$01 ;evaluate total ldy #$21 ;for current cell cmp #$03 ;3 = alive beq storex ldx #$00 cmp #$02 ;2 = alive if bne storex ;c = alive lda ($03), Y and #$01 taxstorex: txa ;store to screen sta ($01), Y jsr inc0103 ;move to next cellconwayloop: cmp #$e0 ;if not last cell, bne onecell ;process next cell lda $02 cmp #$05 bne onecell jmp starttick ;run next tick inc0103: lda $01 ;increment $01 cmp #$ff ;and $03 as 16-bit bne onlyinc01 ;pointers inc $02 inc $04onlyinc01: inc $01 lda $01 sta $03 rts The solution uses one cell thick border around square Petri dish as uninhabited dire land. Sample output contains 3 generations of the blinker and 5 of the glider: See Conway's Game of Life/ALGOL 68 APL2 (Dialog) Example in one line APL \ 1130 example (very old APL dialect via simulator) APL1130From: APL \ 1130 Samples The following APL \ 1130 code will need APL385 font installed to display correctly. See Download APL TT Font ∇LIFE[⎕]∇[0] NG←LIFE CG; W[1] W←CG+(¯1⊖CG)+(1⊖CG)+(¯1⌽CG)+(1⌽CG)[2] W←W+(1⊖1⌽CG)+(¯1⊖1⌽CG)+(1⊖¯1⌽CG)+(¯1⊖¯1⌽CG)[3] NG←(3=W)+(CG∧4=W) ∇ RP←5 5⍴0 0 0 0 0 0 0 1 1 0 0 1 1 0 0 0 0 1 0 0 RP0 0 0 0 00 0 1 1 00 1 1 0 00 0 1 0 00 0 0 0 0 LIFE RP0 0 0 0 00 1 1 1 00 1 0 0 00 1 1 0 00 0 0 0 0 LIFE LIFE RP0 0 1 0 00 1 1 0 01 0 0 1 00 1 1 0 00 0 0 0 0 .................................................. One interacts with the Game of Life by creating an initial configuration and observing how it evolves. Although you should test your implementation on more complex examples such as the glider in a larger universe, show the action of the blinker (three adjoining cells in a row all alive), over three generations, in a 3 by 3 grid. (1,4)=TRUERETURN'' Count the number of neighbours of the point i,j' (Assume i/j +/- 1 will not fall out of world)'FUNCTION count_neighbours(i%,j%) LOCAL count%,l% count%=0 FOR l%=-1 TO 1 IF world! (i%+l%,j%+1) count%=count%+1 ENDIF NEXT l% IF world! (i%+1,j%) count%=count%+1 ENDIF RETURN count%ENDFUNC'' Update the world one step'PROCEDURE update_world LOCAL i%,j% ' compute neighbour counts and store FOR i%=1 TO 30 FOR j%=1 TO 30 ns%(i%,j%)[email protected]_neighbours(i%,j%) NEXT j% NEXT i% ' update the world cells FOR i%=1 TO 30 FOR j%=1 TO 30 IF world!

||

randfill: stx $01 ;$200 for indirect ldx #$02 ;addressing stx $02randloop: lda $fe ;generate random and #$01 ;pixels on the sta ($01), Y ;screen jsr inc0103 cmp #$00 bne randloop lda $02 cmp #$06 bne randloop clearmem: lda #$df ;set $07df-$0a20 sta $01 ;to $#00 lda #$07 sta $02clearbyte: lda #$00 sta ($01), Y jsr inc0103 cmp #$20 bne clearbyte lda $02 cmp #$0a bne clearbyte starttick:copyscreen: lda #$00 ;set up source sta $01 ;pointer at sta $03 ;$01/$02 and lda #$02 ;dest pointer sta $02 ;at $03/$04 lda #$08 sta $04 ldy #$00copybyte: lda ($01), Y ;copy pixel to sta ($03), Y ;back buffer jsr inc0103 ;increment pointers cmp #$00 ;check to see bne copybyte ;if we're at $600 lda $02 ;if so, we've cmp #$06 ;copied the bne copybyte ;entire screen conway: lda #$df ;apply conway rules sta $01 ;reset the pointer sta $03 ;to $#01df/$#07df lda #$01 ;($200 - $21) sta $02 ;($800 - $21) lda #$07 sta $04onecell: lda #$00 ;process one cell ldy #$01 ;upper cell clc adc ($03), Y ldy #$41 ;lower cell clc adc ($03), Ychkleft: tax ;check to see lda $01 ;if we're at the and #$1f ;left edge tay txa cpy #$1f beq rightcellsleftcells: ldy #$00 ;upper-left cell clc adc ($03), Y ldy #$20 ;left cell clc adc ($03), Y ldy #$40 ;lower-left cell clc adc ($03), Ychkright: tax ;check to see lda $01 ;if we're at the and #$1f ;right edge tay txa cpy #$1e beq evaluaterightcells: ldy #$02 ;upper-right cell clc adc ($03), Y ldy #$22 ;right cell clc adc ($03), Y ldy #$42 ;lower-right cell clc adc ($03), Yevaluate: ldx #$01 ;evaluate total ldy #$21 ;for current cell cmp #$03 ;3 = alive beq storex ldx #$00 cmp #$02 ;2 = alive if bne storex ;c = alive lda ($03), Y and #$01 taxstorex: txa ;store to screen sta ($01), Y jsr inc0103 ;move to next cellconwayloop: cmp #$e0 ;if not last cell, bne onecell ;process next cell lda $02 cmp #$05 bne onecell jmp starttick ;run next tick inc0103: lda $01 ;increment $01 cmp #$ff ;and $03 as 16-bit bne onlyinc01 ;pointers inc $02 inc $04onlyinc01: inc $01 lda $01 sta $03 rts The solution uses one cell thick border around square Petri dish as uninhabited dire land. Sample output contains 3 generations of the blinker and 5 of the glider: See Conway's Game of Life/ALGOL 68 APL2 (Dialog) Example in one line APL \ 1130 example (very old APL dialect via simulator) APL1130From: APL \ 1130 Samples The following APL \ 1130 code will need APL385 font installed to display correctly.

See Download APL TT Font ∇LIFE[⎕]∇[0] NG←LIFE CG; W[1] W←CG+(¯1⊖CG)+(1⊖CG)+(¯1⌽CG)+(1⌽CG)[2] W←W+(1⊖1⌽CG)+(¯1⊖1⌽CG)+(1⊖¯1⌽CG)+(¯1⊖¯1⌽CG)[3] NG←(3=W)+(CG∧4=W) ∇ RP←5 5⍴0 0 0 0 0 0 0 1 1 0 0 1 1 0 0 0 0 1 0 0 RP0 0 0 0 00 0 1 1 00 1 1 0 00 0 1 0 00 0 0 0 0 LIFE RP0 0 0 0 00 1 1 1 00 1 0 0 00 1 1 0 00 0 0 0 0 LIFE LIFE RP0 0 1 0 00 1 1 0 01 0 0 1 00 1 1 0 00 0 0 0 0 ..................................................

One interacts with the Game of Life by creating an initial configuration and observing how it evolves.

Although you should test your implementation on more complex examples such as the glider in a larger universe, show the action of the blinker (three adjoining cells in a row all alive), over three generations, in a 3 by 3 grid.

(1,4)=TRUERETURN'' Count the number of neighbours of the point i,j' (Assume i/j +/- 1 will not fall out of world)'FUNCTION count_neighbours(i%,j%) LOCAL count%,l% count%=0 FOR l%=-1 TO 1 IF world! (i%+l%,j%+1) count%=count%+1 ENDIF NEXT l% IF world! (i%+1,j%) count%=count%+1 ENDIF RETURN count%ENDFUNC'' Update the world one step'PROCEDURE update_world LOCAL i%,j% ' compute neighbour counts and store FOR i%=1 TO 30 FOR j%=1 TO 30 ns%(i%,j%)[email protected]_neighbours(i%,j%) NEXT j% NEXT i% ' update the world cells FOR i%=1 TO 30 FOR j%=1 TO 30 IF world!

Thus, while it is somewhat verbose, it fully simulates Conway's Game of Life and is relatively simple to expand to feature different starting shapes.

Define life(pattern) = Prgm Local x,y,nt,count,save,xl,yl,xh,yh Define nt(y,x) = when(pxl Test(y,x), 1, 0) {}→save set Graph("Axes", "Off")→save[1] set Graph("Grid", "Off")→save[2] set Graph("Labels", "Off")→save[3] Fn Off Plot Off Clr Draw If pattern = "blinker" Then 36→yl 40→yh 78→xl 82→xh Pxl On 36,80 Pxl On 38,80 Pxl On 40,80 Else If pattern = "glider" Then 30→yl 40→yh 76→xl 88→xh Pxl On 38,76 Pxl On 36,78 Pxl On 36,80 Pxl On 38,80 Pxl On 40,80 Else If pattern = "r" Then 38-5*2→yl 38+5*2→yh 80-5*2→xl 80+5*2→xh Pxl On 38,78 Pxl On 36,82 Pxl On 36,80 Pxl On 38,80 Pxl On 40,80 End If While get Key() = 0 © Expand upper-left corner to whole cell For y,yl,yh,2 For x,xl,xh,2 If pxl Test(y,x) Then Pxl On y+1,x Pxl On y+1,x+1 Pxl On y, x+1 Else Pxl Off y+1,x Pxl Off y+1,x+1 Pxl Off y, x+1 End If End For End For © Compute next generation For y,yl,yh,2 For x,xl,xh,2 nt(y-1,x-1) + nt(y-1,x) + nt(y-1,x+2) + nt(y,x-1) + nt(y+1,x+2) + nt(y+2,x-1) + nt(y+2,x+1) + nt(y+2,x+2) → count If count = 3 Then Pxl On y,x Else If count ≠ 2 Then Pxl Off y,x End If End For End For End While © Restore changed options set Graph("Axes", save[1]) set Graph("Grid", save[2]) set Graph("Labels", save[3])End Prgm Also see Conway's Game of Life/C Considering that the simplest implementation in C++ would lack any use of the object-oriented paradigm, this code was specifically written to demonstrate the various object-oriented features of C++.

]] ;upper-left cell clc adc (), Y ldy # ;left cell clc adc (), Y ldy # ;lower-left cell clc adc (), Ychkright: tax ;check to see lda

randfill: stx $01 ;$200 for indirect ldx #$02 ;addressing stx $02randloop: lda $fe ;generate random and #$01 ;pixels on the sta ($01), Y ;screen jsr inc0103 cmp #$00 bne randloop lda $02 cmp #$06 bne randloop clearmem: lda #$df ;set $07df-$0a20 sta $01 ;to $#00 lda #$07 sta $02clearbyte: lda #$00 sta ($01), Y jsr inc0103 cmp #$20 bne clearbyte lda $02 cmp #$0a bne clearbyte starttick:copyscreen: lda #$00 ;set up source sta $01 ;pointer at sta $03 ;$01/$02 and lda #$02 ;dest pointer sta $02 ;at $03/$04 lda #$08 sta $04 ldy #$00copybyte: lda ($01), Y ;copy pixel to sta ($03), Y ;back buffer jsr inc0103 ;increment pointers cmp #$00 ;check to see bne copybyte ;if we're at $600 lda $02 ;if so, we've cmp #$06 ;copied the bne copybyte ;entire screen conway: lda #$df ;apply conway rules sta $01 ;reset the pointer sta $03 ;to $#01df/$#07df lda #$01 ;($200 - $21) sta $02 ;($800 - $21) lda #$07 sta $04onecell: lda #$00 ;process one cell ldy #$01 ;upper cell clc adc ($03), Y ldy #$41 ;lower cell clc adc ($03), Ychkleft: tax ;check to see lda $01 ;if we're at the and #$1f ;left edge tay txa cpy #$1f beq rightcellsleftcells: ldy #$00 ;upper-left cell clc adc ($03), Y ldy #$20 ;left cell clc adc ($03), Y ldy #$40 ;lower-left cell clc adc ($03), Ychkright: tax ;check to see lda $01 ;if we're at the and #$1f ;right edge tay txa cpy #$1e beq evaluaterightcells: ldy #$02 ;upper-right cell clc adc ($03), Y ldy #$22 ;right cell clc adc ($03), Y ldy #$42 ;lower-right cell clc adc ($03), Yevaluate: ldx #$01 ;evaluate total ldy #$21 ;for current cell cmp #$03 ;3 = alive beq storex ldx #$00 cmp #$02 ;2 = alive if bne storex ;c = alive lda ($03), Y and #$01 taxstorex: txa ;store to screen sta ($01), Y jsr inc0103 ;move to next cellconwayloop: cmp #$e0 ;if not last cell, bne onecell ;process next cell lda $02 cmp #$05 bne onecell jmp starttick ;run next tick inc0103: lda $01 ;increment $01 cmp #$ff ;and $03 as 16-bit bne onlyinc01 ;pointers inc $02 inc $04onlyinc01: inc $01 lda $01 sta $03 rts The solution uses one cell thick border around square Petri dish as uninhabited dire land. Sample output contains 3 generations of the blinker and 5 of the glider: See Conway's Game of Life/ALGOL 68 APL2 (Dialog) Example in one line APL \ 1130 example (very old APL dialect via simulator) APL1130From: APL \ 1130 Samples The following APL \ 1130 code will need APL385 font installed to display correctly. See Download APL TT Font ∇LIFE[⎕]∇[0] NG←LIFE CG; W[1] W←CG+(¯1⊖CG)+(1⊖CG)+(¯1⌽CG)+(1⌽CG)[2] W←W+(1⊖1⌽CG)+(¯1⊖1⌽CG)+(1⊖¯1⌽CG)+(¯1⊖¯1⌽CG)[3] NG←(3=W)+(CG∧4=W) ∇ RP←5 5⍴0 0 0 0 0 0 0 1 1 0 0 1 1 0 0 0 0 1 0 0 RP0 0 0 0 00 0 1 1 00 1 1 0 00 0 1 0 00 0 0 0 0 LIFE RP0 0 0 0 00 1 1 1 00 1 0 0 00 1 1 0 00 0 0 0 0 LIFE LIFE RP0 0 1 0 00 1 1 0 01 0 0 1 00 1 1 0 00 0 0 0 0 .................................................. One interacts with the Game of Life by creating an initial configuration and observing how it evolves. Although you should test your implementation on more complex examples such as the glider in a larger universe, show the action of the blinker (three adjoining cells in a row all alive), over three generations, in a 3 by 3 grid. (1,4)=TRUERETURN'' Count the number of neighbours of the point i,j' (Assume i/j +/- 1 will not fall out of world)'FUNCTION count_neighbours(i%,j%) LOCAL count%,l% count%=0 FOR l%=-1 TO 1 IF world! (i%+l%,j%+1) count%=count%+1 ENDIF NEXT l% IF world! (i%+1,j%) count%=count%+1 ENDIF RETURN count%ENDFUNC'' Update the world one step'PROCEDURE update_world LOCAL i%,j% ' compute neighbour counts and store FOR i%=1 TO 30 FOR j%=1 TO 30 ns%(i%,j%)[email protected]_neighbours(i%,j%) NEXT j% NEXT i% ' update the world cells FOR i%=1 TO 30 FOR j%=1 TO 30 IF world!

||

randfill: stx $01 ;$200 for indirect ldx #$02 ;addressing stx $02randloop: lda $fe ;generate random and #$01 ;pixels on the sta ($01), Y ;screen jsr inc0103 cmp #$00 bne randloop lda $02 cmp #$06 bne randloop clearmem: lda #$df ;set $07df-$0a20 sta $01 ;to $#00 lda #$07 sta $02clearbyte: lda #$00 sta ($01), Y jsr inc0103 cmp #$20 bne clearbyte lda $02 cmp #$0a bne clearbyte starttick:copyscreen: lda #$00 ;set up source sta $01 ;pointer at sta $03 ;$01/$02 and lda #$02 ;dest pointer sta $02 ;at $03/$04 lda #$08 sta $04 ldy #$00copybyte: lda ($01), Y ;copy pixel to sta ($03), Y ;back buffer jsr inc0103 ;increment pointers cmp #$00 ;check to see bne copybyte ;if we're at $600 lda $02 ;if so, we've cmp #$06 ;copied the bne copybyte ;entire screen conway: lda #$df ;apply conway rules sta $01 ;reset the pointer sta $03 ;to $#01df/$#07df lda #$01 ;($200 - $21) sta $02 ;($800 - $21) lda #$07 sta $04onecell: lda #$00 ;process one cell ldy #$01 ;upper cell clc adc ($03), Y ldy #$41 ;lower cell clc adc ($03), Ychkleft: tax ;check to see lda $01 ;if we're at the and #$1f ;left edge tay txa cpy #$1f beq rightcellsleftcells: ldy #$00 ;upper-left cell clc adc ($03), Y ldy #$20 ;left cell clc adc ($03), Y ldy #$40 ;lower-left cell clc adc ($03), Ychkright: tax ;check to see lda $01 ;if we're at the and #$1f ;right edge tay txa cpy #$1e beq evaluaterightcells: ldy #$02 ;upper-right cell clc adc ($03), Y ldy #$22 ;right cell clc adc ($03), Y ldy #$42 ;lower-right cell clc adc ($03), Yevaluate: ldx #$01 ;evaluate total ldy #$21 ;for current cell cmp #$03 ;3 = alive beq storex ldx #$00 cmp #$02 ;2 = alive if bne storex ;c = alive lda ($03), Y and #$01 taxstorex: txa ;store to screen sta ($01), Y jsr inc0103 ;move to next cellconwayloop: cmp #$e0 ;if not last cell, bne onecell ;process next cell lda $02 cmp #$05 bne onecell jmp starttick ;run next tick inc0103: lda $01 ;increment $01 cmp #$ff ;and $03 as 16-bit bne onlyinc01 ;pointers inc $02 inc $04onlyinc01: inc $01 lda $01 sta $03 rts The solution uses one cell thick border around square Petri dish as uninhabited dire land. Sample output contains 3 generations of the blinker and 5 of the glider: See Conway's Game of Life/ALGOL 68 APL2 (Dialog) Example in one line APL \ 1130 example (very old APL dialect via simulator) APL1130From: APL \ 1130 Samples The following APL \ 1130 code will need APL385 font installed to display correctly.

See Download APL TT Font ∇LIFE[⎕]∇[0] NG←LIFE CG; W[1] W←CG+(¯1⊖CG)+(1⊖CG)+(¯1⌽CG)+(1⌽CG)[2] W←W+(1⊖1⌽CG)+(¯1⊖1⌽CG)+(1⊖¯1⌽CG)+(¯1⊖¯1⌽CG)[3] NG←(3=W)+(CG∧4=W) ∇ RP←5 5⍴0 0 0 0 0 0 0 1 1 0 0 1 1 0 0 0 0 1 0 0 RP0 0 0 0 00 0 1 1 00 1 1 0 00 0 1 0 00 0 0 0 0 LIFE RP0 0 0 0 00 1 1 1 00 1 0 0 00 1 1 0 00 0 0 0 0 LIFE LIFE RP0 0 1 0 00 1 1 0 01 0 0 1 00 1 1 0 00 0 0 0 0 ..................................................

One interacts with the Game of Life by creating an initial configuration and observing how it evolves.

Although you should test your implementation on more complex examples such as the glider in a larger universe, show the action of the blinker (three adjoining cells in a row all alive), over three generations, in a 3 by 3 grid.

(1,4)=TRUERETURN'' Count the number of neighbours of the point i,j' (Assume i/j +/- 1 will not fall out of world)'FUNCTION count_neighbours(i%,j%) LOCAL count%,l% count%=0 FOR l%=-1 TO 1 IF world! (i%+l%,j%+1) count%=count%+1 ENDIF NEXT l% IF world! (i%+1,j%) count%=count%+1 ENDIF RETURN count%ENDFUNC'' Update the world one step'PROCEDURE update_world LOCAL i%,j% ' compute neighbour counts and store FOR i%=1 TO 30 FOR j%=1 TO 30 ns%(i%,j%)[email protected]_neighbours(i%,j%) NEXT j% NEXT i% ' update the world cells FOR i%=1 TO 30 FOR j%=1 TO 30 IF world!

Thus, while it is somewhat verbose, it fully simulates Conway's Game of Life and is relatively simple to expand to feature different starting shapes.

Define life(pattern) = Prgm Local x,y,nt,count,save,xl,yl,xh,yh Define nt(y,x) = when(pxl Test(y,x), 1, 0) {}→save set Graph("Axes", "Off")→save[1] set Graph("Grid", "Off")→save[2] set Graph("Labels", "Off")→save[3] Fn Off Plot Off Clr Draw If pattern = "blinker" Then 36→yl 40→yh 78→xl 82→xh Pxl On 36,80 Pxl On 38,80 Pxl On 40,80 Else If pattern = "glider" Then 30→yl 40→yh 76→xl 88→xh Pxl On 38,76 Pxl On 36,78 Pxl On 36,80 Pxl On 38,80 Pxl On 40,80 Else If pattern = "r" Then 38-5*2→yl 38+5*2→yh 80-5*2→xl 80+5*2→xh Pxl On 38,78 Pxl On 36,82 Pxl On 36,80 Pxl On 38,80 Pxl On 40,80 End If While get Key() = 0 © Expand upper-left corner to whole cell For y,yl,yh,2 For x,xl,xh,2 If pxl Test(y,x) Then Pxl On y+1,x Pxl On y+1,x+1 Pxl On y, x+1 Else Pxl Off y+1,x Pxl Off y+1,x+1 Pxl Off y, x+1 End If End For End For © Compute next generation For y,yl,yh,2 For x,xl,xh,2 nt(y-1,x-1) + nt(y-1,x) + nt(y-1,x+2) + nt(y,x-1) + nt(y+1,x+2) + nt(y+2,x-1) + nt(y+2,x+1) + nt(y+2,x+2) → count If count = 3 Then Pxl On y,x Else If count ≠ 2 Then Pxl Off y,x End If End For End For End While © Restore changed options set Graph("Axes", save[1]) set Graph("Grid", save[2]) set Graph("Labels", save[3])End Prgm Also see Conway's Game of Life/C Considering that the simplest implementation in C++ would lack any use of the object-oriented paradigm, this code was specifically written to demonstrate the various object-oriented features of C++.

;if we're at the and #

randfill: stx $01 ;$200 for indirect ldx #$02 ;addressing stx $02randloop: lda $fe ;generate random and #$01 ;pixels on the sta ($01), Y ;screen jsr inc0103 cmp #$00 bne randloop lda $02 cmp #$06 bne randloop clearmem: lda #$df ;set $07df-$0a20 sta $01 ;to $#00 lda #$07 sta $02clearbyte: lda #$00 sta ($01), Y jsr inc0103 cmp #$20 bne clearbyte lda $02 cmp #$0a bne clearbyte starttick:copyscreen: lda #$00 ;set up source sta $01 ;pointer at sta $03 ;$01/$02 and lda #$02 ;dest pointer sta $02 ;at $03/$04 lda #$08 sta $04 ldy #$00copybyte: lda ($01), Y ;copy pixel to sta ($03), Y ;back buffer jsr inc0103 ;increment pointers cmp #$00 ;check to see bne copybyte ;if we're at $600 lda $02 ;if so, we've cmp #$06 ;copied the bne copybyte ;entire screen conway: lda #$df ;apply conway rules sta $01 ;reset the pointer sta $03 ;to $#01df/$#07df lda #$01 ;($200 - $21) sta $02 ;($800 - $21) lda #$07 sta $04onecell: lda #$00 ;process one cell ldy #$01 ;upper cell clc adc ($03), Y ldy #$41 ;lower cell clc adc ($03), Ychkleft: tax ;check to see lda $01 ;if we're at the and #$1f ;left edge tay txa cpy #$1f beq rightcellsleftcells: ldy #$00 ;upper-left cell clc adc ($03), Y ldy #$20 ;left cell clc adc ($03), Y ldy #$40 ;lower-left cell clc adc ($03), Ychkright: tax ;check to see lda $01 ;if we're at the and #$1f ;right edge tay txa cpy #$1e beq evaluaterightcells: ldy #$02 ;upper-right cell clc adc ($03), Y ldy #$22 ;right cell clc adc ($03), Y ldy #$42 ;lower-right cell clc adc ($03), Yevaluate: ldx #$01 ;evaluate total ldy #$21 ;for current cell cmp #$03 ;3 = alive beq storex ldx #$00 cmp #$02 ;2 = alive if bne storex ;c = alive lda ($03), Y and #$01 taxstorex: txa ;store to screen sta ($01), Y jsr inc0103 ;move to next cellconwayloop: cmp #$e0 ;if not last cell, bne onecell ;process next cell lda $02 cmp #$05 bne onecell jmp starttick ;run next tick inc0103: lda $01 ;increment $01 cmp #$ff ;and $03 as 16-bit bne onlyinc01 ;pointers inc $02 inc $04onlyinc01: inc $01 lda $01 sta $03 rts The solution uses one cell thick border around square Petri dish as uninhabited dire land. Sample output contains 3 generations of the blinker and 5 of the glider: See Conway's Game of Life/ALGOL 68 APL2 (Dialog) Example in one line APL \ 1130 example (very old APL dialect via simulator) APL1130From: APL \ 1130 Samples The following APL \ 1130 code will need APL385 font installed to display correctly. See Download APL TT Font ∇LIFE[⎕]∇[0] NG←LIFE CG; W[1] W←CG+(¯1⊖CG)+(1⊖CG)+(¯1⌽CG)+(1⌽CG)[2] W←W+(1⊖1⌽CG)+(¯1⊖1⌽CG)+(1⊖¯1⌽CG)+(¯1⊖¯1⌽CG)[3] NG←(3=W)+(CG∧4=W) ∇ RP←5 5⍴0 0 0 0 0 0 0 1 1 0 0 1 1 0 0 0 0 1 0 0 RP0 0 0 0 00 0 1 1 00 1 1 0 00 0 1 0 00 0 0 0 0 LIFE RP0 0 0 0 00 1 1 1 00 1 0 0 00 1 1 0 00 0 0 0 0 LIFE LIFE RP0 0 1 0 00 1 1 0 01 0 0 1 00 1 1 0 00 0 0 0 0 .................................................. One interacts with the Game of Life by creating an initial configuration and observing how it evolves. Although you should test your implementation on more complex examples such as the glider in a larger universe, show the action of the blinker (three adjoining cells in a row all alive), over three generations, in a 3 by 3 grid. (1,4)=TRUERETURN'' Count the number of neighbours of the point i,j' (Assume i/j +/- 1 will not fall out of world)'FUNCTION count_neighbours(i%,j%) LOCAL count%,l% count%=0 FOR l%=-1 TO 1 IF world! (i%+l%,j%+1) count%=count%+1 ENDIF NEXT l% IF world! (i%+1,j%) count%=count%+1 ENDIF RETURN count%ENDFUNC'' Update the world one step'PROCEDURE update_world LOCAL i%,j% ' compute neighbour counts and store FOR i%=1 TO 30 FOR j%=1 TO 30 ns%(i%,j%)[email protected]_neighbours(i%,j%) NEXT j% NEXT i% ' update the world cells FOR i%=1 TO 30 FOR j%=1 TO 30 IF world!

||

randfill: stx $01 ;$200 for indirect ldx #$02 ;addressing stx $02randloop: lda $fe ;generate random and #$01 ;pixels on the sta ($01), Y ;screen jsr inc0103 cmp #$00 bne randloop lda $02 cmp #$06 bne randloop clearmem: lda #$df ;set $07df-$0a20 sta $01 ;to $#00 lda #$07 sta $02clearbyte: lda #$00 sta ($01), Y jsr inc0103 cmp #$20 bne clearbyte lda $02 cmp #$0a bne clearbyte starttick:copyscreen: lda #$00 ;set up source sta $01 ;pointer at sta $03 ;$01/$02 and lda #$02 ;dest pointer sta $02 ;at $03/$04 lda #$08 sta $04 ldy #$00copybyte: lda ($01), Y ;copy pixel to sta ($03), Y ;back buffer jsr inc0103 ;increment pointers cmp #$00 ;check to see bne copybyte ;if we're at $600 lda $02 ;if so, we've cmp #$06 ;copied the bne copybyte ;entire screen conway: lda #$df ;apply conway rules sta $01 ;reset the pointer sta $03 ;to $#01df/$#07df lda #$01 ;($200 - $21) sta $02 ;($800 - $21) lda #$07 sta $04onecell: lda #$00 ;process one cell ldy #$01 ;upper cell clc adc ($03), Y ldy #$41 ;lower cell clc adc ($03), Ychkleft: tax ;check to see lda $01 ;if we're at the and #$1f ;left edge tay txa cpy #$1f beq rightcellsleftcells: ldy #$00 ;upper-left cell clc adc