Conway's Game Of Life


Closed Thread
Results 1 to 40 of 46

Hybrid View

  1. #1
    Join Date
    Oct 2005
    Location
    Sweden
    Posts
    3,612


    Did you find this post helpful? Yes | No

    Default Re: Conway's Game Of Life

    What size are all the different arrays?

  2. #2
    Join Date
    Oct 2005
    Location
    Sweden
    Posts
    3,612


    Did you find this post helpful? Yes | No

    Default Re: Conway's Game Of Life

    In the Grid Evalutaion section, precalculating the Array index values and replacing the AND-logic with nested IF/THEN saves Another bunch of cycles
    Code:
    'Grid Evaluation	
    
    CntPlus33 VAR WORD
    CntPlus32 VAR WORD
    CntPlus31 VAR WORD
    CntPlus1  VAR WORD
    
    CntMinus33 VAR WORD
    CntMinus32 VAR WORD
    CntMinus31 VAR WORD
    CntMinus1  VAR WORD
    
    CntPlus33 = Counter + 33
    CntPlus32 = Counter + 32
    CntPlus31 = Counter + 31
    CntPlus1 = Counter +1
    
    CntMinus33 = Counter - 33
    CntMinus32 = Counter - 32
    CntMinus31 = Counter - 31
    CntMinus1 = Counter - 1	        	
    	
    	IF led[CntMinus1] > 0 THEN
          IF counter > 0 THEN
    	    Colour[population] = led[CntMinus1]
    		population = population + 1
    	  ENDIF
    	ENDIF
    	
    	IF led[CntPlus1] > 0 THEN
          IF counter < 1023 THEN
    	    Colour[population] = led[CntPlus1]
    		population = population + 1  		
           ENDIF
        ENDIF
    	
    	IF botedge = 0 THEN
    		IF led [CntMinus33] > 0 THEN
    		    Colour[population] = led[CntMinus33]
    			population = population + 1			
    		ENDIF
    		IF led [CntMinus32] > 0 THEN
    		    Colour[population] = led[CntMinus32]  
    			population = population + 1
    		ENDIF
    		IF  rigedge = 0 and led [CntMinus33] > 0 THEN
    		    Colour[population] = led[CntMinus33]
    			population = population + 1
    		ENDIF
    	ENDIF
    	
    	IF topedge = 0 THEN
    		IF led [CntPlus31] > 0 THEN
    		    Colour[population] = led[CntPlus31]
    			population = population + 1
    		ENDIF
    		IF led [CntPlus32] > 0 THEN
    		    Colour[population] = led[CntPlus32]
    			population = population + 1
    		ENDIF
    		IF  rigedge = 0 and led [CntPlus33] > 0 THEN 
    		    Colour[population] = led[CntPlus33]
    			population = population + 1
    		ENDIF
    	ENDIF
    It's not nearly as elegant but it does increase the performance a bit. All in all that 1024 iteration FOR/NEXT loop took 265ms to execute on my test board, now it's 67. Obviously I don't know if it still WORKS so it might all be for nothing :-)

    /Henrik.

  3. #3


    Did you find this post helpful? Yes | No

    Default Re: Conway's Game Of Life

    I'm very grateful for all these interesting replies. Thank you.

    There are three basic 1024 element byte arrays.


    Led var byte[1024] used to hold the current generation of cells


    LedNew var byte [1024] used to to hold the next generation of cells (This is copied into the Led array after evaluation is completed)


    NeoLed var byte [1024] used to hold the NeoPixel led data.

    This third array is required because the layout of the NeoPixels grid is one continuous string of 1024 leds arranged like a snakes and ladders board.

    This is different to the other two arrays which are a conventional X/Y grid layout, so the Led data has to be parsed and re-organised to display correctly on the neopixel grid.


    How are people timing the loops etc.
    I would be interested in that code so I can see what difference changes make.

  4. #4
    Join Date
    Oct 2005
    Location
    Sweden
    Posts
    3,612


    Did you find this post helpful? Yes | No

    Default Re: Conway's Game Of Life

    There's also an array called colour, how large is that?

    For this I just toggle an output and measure it with the scope but for more precise measurements I use one of the onboard timers. Reset it, start it, execute code, stop it, output its value.
    Doing that it's important to have SOME idea about what you're measuring in order to set up the timer with proper prescaling value to make sure you don't overflow, giving you false readings.

  5. #5


    Did you find this post helpful? Yes | No

    Default Re: Conway's Game Of Life

    I incorporated all those ideas and it is now running at over 13hz v 3hz before. Well done Team!

    The Colour Array is only 8 elements and holds the colour of any adjacent cells to the one being tested.



    Which of these two is technically quickest? Both seem to work well but I haven't got timing set up yet.

    Code:
      Temp = Counter // 32
    
      If Temp = 0 THEN
        lefedge = 1
      ENDIF
    
      IF Temp = 31 THEN
        rigedge = 1
      ENDIF
    or

    Code:
    Temp = Counter & 65504
    If Temp = 0 THEN
    lefedge = 1
    ENDIF
    
    
    IF Temp = 31 THEN
    rigedge = 1
    ENDIF

    Here we have it at 13hz..

    Last edited by retepsnikrep; - 23rd May 2020 at 13:48.

  6. #6
    Join Date
    May 2013
    Location
    australia
    Posts
    2,645


    Did you find this post helpful? Yes | No

    Default Re: Conway's Game Of Life

    hmm i think i got that the wrong way round
    try Temp = Counter & 31

    the bitwise and is faster than a // which uses a divide

    i wonder about led/LedNew arrays as byte . a cell is either dead or not dead a bit can store that info
    Warning I'm not a teacher

  7. #7
    Join Date
    Oct 2005
    Location
    Sweden
    Posts
    3,612


    Did you find this post helpful? Yes | No

    Default Re: Conway's Game Of Life

    Great that it all still works!
    I timed it and Richards is a quite a bit quicker. On my test setup it went from 67 to 48ms which is not surprising since, generally speaking, anything involving division is a killer.
    I also found that I had missed one AND statement, replaced that with nested IFs and I'm now measuring 44.7ms

  8. #8


    Did you find this post helpful? Yes | No

    Default Re: Conway's Game Of Life

    That all works and I changed the AND statements.
    Maybe 15hz now but I need to do some proper timing.

    I wonder about led/LedNew arrays as byte . a cell is either dead or not dead a bit can store that info
    The arrays also store LED RGB colour and brightness information so one bit is not sufficient.
    The colour of a new cell is dependent on the adjacent three populated cells that spawn it.

Similar Threads

  1. programming jumping game
    By bokken in forum mel PIC BASIC Pro
    Replies: 3
    Last Post: - 17th February 2012, 06:40
  2. Simon Game
    By flotulopex in forum Code Examples
    Replies: 1
    Last Post: - 4th November 2010, 06:25
  3. EEPROM life expectancy?
    By muddy0409 in forum General
    Replies: 3
    Last Post: - 1st May 2007, 12:44
  4. home brew game console W interface
    By PICMAN in forum General
    Replies: 1
    Last Post: - 15th March 2005, 22:25
  5. Game port to USB adaptor
    By Squibcakes in forum mel PIC BASIC Pro
    Replies: 0
    Last Post: - 24th September 2004, 03:16

Members who have read this thread : 2

You do not have permission to view the list of names.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts