HP Forums
John Conway's Game of Life - Printable Version

+- HP Forums (https://www.hpmuseum.org/forum)
+-- Forum: HP Software Libraries (/forum-10.html)
+--- Forum: HP Prime Software Library (/forum-15.html)
+--- Thread: John Conway's Game of Life (/thread-15796.html)



John Conway's Game of Life - btabone - 10-26-2020 03:02 PM

One more implementation of John Conway's Game of Life on HP Prime. I like this particular problem as a tool for learning new platforms. This was a chance to get comfortable with matrix operations and references as well as play around with rendering on the screen and learn HP Prime programming in general. The source is in github here:

https://github.com/hybridmachine/hpprime/tree/main/GameOfLife

I have attached the most recent version on this thread as well.

Right now (as of 10/26/2020) there are three pre-canned starting patterns and the app only renders the first 50 generations but it is a start. When launched:

1) First the user is prompted for a grid size (m x m). 50 is a reasonable place to start.

2) The user is prompted to pick a starting pattern

Once done, the rendering progresses until generation 50.

I do plan to add:
1) initial pattern loading from a user defined matrix
2) generation count display. -> Added 11/6/2020
3) auto vs stepped rendering (where the user can choose to pause and single step).

[attachment=8823]

[attachment=8824]


RE: John Conway's Game of Life - Arno K - 10-27-2020 03:41 PM

I tried your program in the emulator, there it runs without any problem. My HW1 and my HW2 error out with insufficient memory in the line you DIMGROB(...).
Arno


RE: John Conway's Game of Life - StephenG1CMZ - 10-27-2020 04:24 PM

On the Android, I get a syntax error at SLIST on line 82 (with the default Function app).
(Or earlier, with Geometry app as my default).


RE: John Conway's Game of Life - btabone - 10-27-2020 10:11 PM

(10-27-2020 03:41 PM)Arno K Wrote:  I tried your program in the emulator, there it runs without any problem. My HW1 and my HW2 error out with insufficient memory in the line you DIMGROB(...).
Arno

What size grid are you specifying? I'll try it out on my end. I test in the PC simulator and on my gen 2 HP prime. I usually run a 50x50 grid.


RE: John Conway's Game of Life - btabone - 10-27-2020 10:21 PM

(10-27-2020 04:24 PM)StephenG1CMZ Wrote:  On the Android, I get a syntax error at SLIST on line 82 (with the default Function app).
(Or earlier, with Geometry app as my default).

I had a copy paste issue, ΣLIST pasted in as SLIST from vi for some reason. I fixed it in github, should work now.


RE: John Conway's Game of Life - pinkman - 10-27-2020 10:31 PM

I guess SLIST() stands for ΣLIST()
On the iOS app I get no result: blank screen and nothing moves, then the app crashes (not the program, the iOS app).


RE: John Conway's Game of Life - btabone - 10-28-2020 02:11 AM

(10-27-2020 10:31 PM)pinkman Wrote:  I guess SLIST() stands for ΣLIST()
On the iOS app I get no result: blank screen and nothing moves, then the app crashes (not the program, the iOS app).

What size grid to you specify (I start with 50, that works on my gen 2 HP Prime). I think I need to switch from matrices to arrays of bits for the internal data structure. Optimization time Smile


RE: John Conway's Game of Life - Arno K - 10-28-2020 06:50 AM

(10-27-2020 10:11 PM)btabone Wrote:  
(10-27-2020 03:41 PM)Arno K Wrote:  I tried your program in the emulator, there it runs without any problem. My HW1 and my HW2 error out with insufficient memory in the line you DIMGROB(...).
Arno

What size grid are you specifying? I'll try it out on my end. I test in the PC simulator and on my gen 2 HP prime. I usually run a 50x50 grid.

Well, when I start it from the program-catalogue I am prompted to input a number, the same as entering in the input line, I tried diverse (2,3,50,100) on my HW2 always that error.
Arno


RE: John Conway's Game of Life - btabone - 10-28-2020 07:08 PM

(10-28-2020 06:50 AM)Arno K Wrote:  
(10-27-2020 10:11 PM)btabone Wrote:  What size grid are you specifying? I'll try it out on my end. I test in the PC simulator and on my gen 2 HP prime. I usually run a 50x50 grid.

Well, when I start it from the program-catalogue I am prompted to input a number, the same as entering in the input line, I tried diverse (2,3,50,100) on my HW2 always that error.
Arno

Are you running the code from https://github.com/hybridmachine/hpprime/blob/main/GameOfLife/GameOfLife.hp ? I have a commented out SUBGROB line but no DIMGROB . It should prompt you for two things. The first is the size of the play board (50 works well for me) the second is the starting pattern. In any event, I am working on some memory optimizations, I think passing around the board matrix like that is eating up stack memory for the functions, I'm going to experiment with making it a program global then longer term I'll look at using bit masks instead of complete integers for the on/off state info held in that matrix.


RE: John Conway's Game of Life - Arno K - 10-29-2020 02:41 PM

I took the version to be downloaded here, it only prompts for one input, as I didn't know what to enter I tried 0, 1, 2 and later 50, 1 and 2 worked fine in the emulator. Perhaps you should write a self-explaining input part for your program.
Arno


RE: John Conway's Game of Life - btabone - 10-30-2020 02:28 AM

(10-29-2020 02:41 PM)Arno K Wrote:  I took the version to be downloaded here, it only prompts for one input, as I didn't know what to enter I tried 0, 1, 2 and later 50, 1 and 2 worked fine in the emulator. Perhaps you should write a self-explaining input part for your program.
Arno

I found a bug where I wasn't properly setting up G1 (where I do the render then copy to G0). I fixed that (had to actually DIMGROB(G1...) and also moved the CurrentGen and NextGen matrices to app global variables to reduce memory load from passing by value. There are more optimizations to do but I think this should get over the first set of issues. I also default to a size 50 square grid (works for me on my PC simulator and my G2 Prime).

Code is updated both here and on github


RE: John Conway's Game of Life - Arno K - 10-30-2020 04:31 PM

Ok, now it works on my HW2 and the emulator, the line asking for the grid-size is not properly displayed and the programs name should end with".hpprgm", otherwise it can't be opened by the Connectivity Kit, although it is shown in the Content-Window. I had to open it with notepad+ and copy the contents into a newly made program in the ConnKit.
Arno


RE: John Conway's Game of Life - btabone - 11-02-2020 10:58 PM

(10-30-2020 04:31 PM)Arno K Wrote:  Ok, now it works on my HW2 and the emulator, the line asking for the grid-size is not properly displayed and the programs name should end with".hpprgm", otherwise it can't be opened by the Connectivity Kit, although it is shown in the Content-Window. I had to open it with notepad+ and copy the contents into a newly made program in the ConnKit.
Arno

Arno,

Good info on the .hpprgm, I'll rename it in github and here. Thanks for all of the feedback. My next adventure is to convert to using a list of integers for bit masking instead of a full matrix, since that will be much more space efficient than the current full matrix approach. I'll fix the label for the starting grid size as well.