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

    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.

  2. #2


    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.

  3. #3
    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

  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

    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

  5. #5


    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.

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


    Did you find this post helpful? Yes | No

    Default Re: Conway's Game Of Life

    From 3 to 15 frames per second in a couple of hours, I call that improvement.
    At one place (at least) you first do IF LED[Counter] = 0 and then a couple of lines further down you do IF LED[Counter] > 0 which seems a bit of a wate since you already know if it IS 0 and if it's not it's got to be > 0 (since it can't be negative in case you're not using LONGs). There's also Population = Population + 1 in 8 places, can you move that outside each of the IF/THEN statements and only have ONE of them? That likely won't increase performance but will save space (if that matter at all).

    We're probably talking microseconds here but since it all executes 1024 times per frame it does add up.

    Anyhow, nice job and keep those updates and videos coming!

  7. #7


    Did you find this post helpful? Yes | No

    Default Re: Conway's Game Of Life

    Quote Originally Posted by HenrikOlsson View Post
    From 3 to 15 frames per second in a couple of hours, I call that improvement!
    Thanks to all who have contributed so far.

    I will post the complete code and circuit schematic etc when I have it finished and we can't eek out any more speed.

    I tweaked if LED[Counter] = 0 and that gives another HZ I think.

    Code space is not an issue. RAM Might be later.
    Last edited by retepsnikrep; - 23rd May 2020 at 15:16.

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


    Did you find this post helpful? Yes | No

    Default Re: Conway's Game Of Life

    last time i played with "life" i never found a way to detect a stable repetitive cycling pattern.
    are you determining if boring stuck patterns ensue ?
    Warning I'm not a teacher

  9. #9


    Did you find this post helpful? Yes | No

    Default Re: Conway's Game Of Life

    For the big evaluation routine we currently have this giving about 15hz

    Code:
    '----------------------- Also creating a newled data array to be displayed on next generation -------------
    
    FOR counter = 0 TO 1023
    
    	population = 0 :topedge	= 0 :botedge = 0 :lefedge = 0 :rigedge = 0
    
    'Grid Edge Detection
    	
    	IF counter < 32 THEN botedge = 1
    
    	IF counter > 991 THEN topedge = 1
    	
    '*******************************************************************************	  	
    	
        TempCount = Counter & 31
        If TempCount = 0 THEN
        lefedge = 1
        ENDIF
    
    
        IF TempCount = 31 THEN
        rigedge = 1
        ENDIF	
    	
    '*******************************************************************************		
    
    'Grid Evaluation	 
    
    
    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 [CntMinus31] > 0 THEN
    		    Colour[population] = led[CntMinus31]
    			population = population + 1			
    		ENDIF
    		IF led [CntMinus32] > 0 THEN
    		    Colour[population] = led[CntMinus32]  
    			population = population + 1
    		ENDIF
    		IF  rigedge = 0 then
                if led [CntMinus33] > 0 THEN
    		    Colour[population] = led[CntMinus33]
    			population = population + 1
    			endif
    		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 then 
                if led [CntPlus33] > 0 THEN 
    		    Colour[population] = led[CntPlus33]
    			population = population + 1
    			endif
    		ENDIF
    	ENDIF       
    
        lednew[counter] = led[counter]
    	
    	IF led[counter] = 0 THEN
    		IF population = 3 THEN
    		
    		    if Colour[0] = Colour[1] then
    		    lednew[counter] = Colour[0]
    		    
    		    elseif Colour[0] = Colour[2] then
                lednew[counter] = Colour[0]
                
                elseif Colour[1] = Colour[2] then
                lednew[counter] = Colour[1]
                
        	    endif   	
    			
    		ENDIF
    	else   	
    		IF population > 3 OR population < 2 THEN
    			lednew[counter] = 0
    		ENDIF
    			
    	ENDIF
    
    NEXT counter
    Last edited by retepsnikrep; - 23rd May 2020 at 15:20.

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