Conway’s game of life


Author Message
thwill

Guru

Joined: 16/09/2019
Location: United Kingdom
Posts: 4048
Posted: 07:16pm 25 Apr 2020      

Hey Bill,

Very pretty.

I don't have a Micromite, but I ported your code to the Colour Maximite (replace "Else If" with "ElseIf") and gave it a bit of a prod. Note that results with the CMM may differ from the uM as I don't know if Geoff optimised variable resolution (a significant bottleneck) in the BASIC interpreter between v4.5 and 5.

The best optimisation I could find was this:

Sub NextGen ' Breed the next generation into a new matrix
 Print Chr$(27) "[H"
 For y = 1 To MatY
   b = 0
   c = CurM(1, y - 1) + CurM(1, y) + CurM(1, y + 1)
   s$ = Space$(MatX)
   For x = 1 To MatX
     d = CurM(x + 1, y - 1) + CurM(x + 1, y) + CurM(x + 1, y + 1)
     adj = b + c + d
     If CurM(x, y) Then
       Poke Var s$, x, &h4f
       MewM(x, y) = (adj = 3) Or (adj = 4)
     Else
       MewM(x, y) = (adj = 3)
     EndIf
     b = c
     c = d
   Next x
   Print s$
 Next y
End Sub


And similarly for NextGen2.

This was ~30% faster than the original code on my CMM.

Basically this:
1. reduces the number of variable lookups.
2. prints the matrix a line at a time instead of a cell at a time.

Shorter variable names also help, but I expect that is one of the things that "crunch  on load" might be doing for you; I have no experience with MMEdit since I am using a Raspberry Pi as my serial terminal not Windoze.

I believe there is a further optimisation at the expense of clarity & flexibility by using a hardcoded matrix width and using a 1D instead of 2D array but I would guess it would only get you another 10% at most.

Best wishes,

Tom