Conway's Game Of Life


Closed Thread
Results 1 to 40 of 46

Hybrid View

  1. #1
    Join Date
    Jul 2003
    Location
    Colorado Springs
    Posts
    4,959


    Did you find this post helpful? Yes | No

    Default

    That was fast.

    Did it make a significant difference?
    With it wrapping at the edges, I would imagine things stay "alive" much longer.
    <br>
    DT

  2. #2
    Join Date
    Feb 2007
    Posts
    55


    Did you find this post helpful? Yes | No

    Default

    maybe too fast, ive noticed a mistake!

    i didnt try it without the wrap around effect, as i do believe it would die a lot quicker.

    but i did for example stop checking cell 40 as a neighbour to cell 31 as it over a column away from each other.

    so for cell 31, i only check 30,22,23,38,39 and 24,32 (not cell+9 = 40)

    and here is the mistake: I should check cell 16 (cell - 15)

    '0 8 16 24 32 40 48 56
    '1 9 17 25 33 41 49 57
    '2 10 18 26 34 42 50 58
    '3 11 19 27 35 43 51 59
    '4 12 20 28 36 44 52 60
    '5 13 21 29 37 45 53 61
    '6 14 22 30 38 46 54 62
    '7 15 23 31 39 47 55 63

    but checking cell 40 wouldnt be such a bad thing as it would be a slightly diagonal wrapping around effect.


  3. #3


    Did you find this post helpful? Yes | No

    Default Re: Conway's Game Of Life NeoPixel

    Thread resurrection. Code help please.

    I'm working on this using a sequential 256 led neopixel string which is laid out in a prebuilt 16x16 matrix panel.

    The neopixel string works fine but is like a snakes and ladder board in that starting from bottom left corner you go along the bottom up at the end of the row then back along then up a row and along etc etc. (Back and forth)

    This arrangement is of course different to the actual LIFE array in PIC memory which is arranged as per the diagram.

    So I want to transfer data from the Life byte array into the NeoPixel byte array adjusting the NeoPixel(address) when necessary.

    The diagram might make it easier to see what i mean..

    Code:
    'Life Array 16x16 in memory.     'Life Array 16x16 Neopixel Matrix String.  
    
    '         Top                                  Top
    '240 -------------- 255             '255 -------------- 240
    '224 -------------- 239             '224 -------------- 239
    '208 -------------- 223             '223 -------------- 208
    '192 -------------- 207             '192 -------------- 207
    '176 -------------- 191             '191 -------------- 176
    '160 --x----------- 175             '160 --x----------- 175
    '144 ---x---------- 159             '159 ----------x--- 144
    '128 -xxx---------- 143             '128 -xxx---------- 143
    '112 -------------- 127             '127 -------------- 112
    '96  -------------- 111              '96  -------------- 111
    '80  -------------- 95               '95  -------------- 80
    '64  -------------- 79               '64  -------------- 79
    '48  -------------- 63               '63  -------------- 48
    '32  -------------- 47               '32  -------------- 47
    '16  -------------- 31               '31  -------------- 16
    '0   -------------- 15                '0   -------------- 15   
    '        Bottom                              Bottom
    Hopefully you see the problem, I can't see an efficient way to transfer the data from the LIFE to the NEOPIXEL array whilst correcting the address on the alternate lines..

    A simple Pixel(A) = Life(A) works for 0-15, 32-47 etc etc but not for 16-31, or 48-63 etc etc as the data ends up on the wrong part of the screen..

    Any brilliant ideas.

    You can see the problem on 144-159 with test data, it ends up on the wrong part of the screen.
    Last edited by retepsnikrep; - 15th May 2020 at 10:41.

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


    Did you find this post helpful? Yes | No

    Default Re: Conway's Game Of Life

    Here's an idea, untested, don't know if it compiles.
    Code:
    InPtr VAR BYTE
    OutPtr VAR BYTE
    
    Row VAR BYTE
    Col VAR BYTE
    
    Even VAR BIT
    
    
    Translate:
      InPtr = 0
    
      FOR Row = 0 to 15			' Cycle thru 16 rows
         FOR Col = 0 to 15			' of 16 pixels each
           IF Row.0 = 0 THEN		' If the row number is even     
             OutPtr = (Row*16) + Col        ' Output pixels in true order       
           ELSE
             OutPtr = (Row*16) + (15-Col)   ' Output pixels in reversed order        
           ENDIF
           NeoArray[OutPtr] = LifeArray[InPtr]
         NEXT
      NEXT
      InPtr = InPtr + 1
    RETURN

  5. #5


    Did you find this post helpful? Yes | No

    Default Re: Conway's Game Of Life

    Thanks Henrik that was just the kick start I needed.

    Now to get the rest sorted..

    Last edited by retepsnikrep; - 15th May 2020 at 13:06.

  6. #6


    Did you find this post helpful? Yes | No

    Default Re: Conway's Game Of Life

    Still working on this.

    Thanks to help with example code on this and other NeoPixel threads I now have a 1024 led.

    Driving 1024 leds with (PIC 18F26K80) at just over 3hz

    Need to work on optimizing the code, adding colour and generally enhancing the experience.

    The four 8x32 leds strip are connected in series and fixed on the backboard of this nice neat white deep photo frame using double sided adhesive sheet.

    The LEDS are a perfect fit in this $10 ebay frame so highly recommended for similar projects.

    White Shadow Box Photo Frame with Deep Mount 32 X 32cm


  7. #7


    Did you find this post helpful? Yes | No

    Default 1024 led Code optimisation: Conway's Game Of Life

    This is progressing very nicely and I now have 1024 leds in colour.

    In order to conserve RAM I got rid of two of the colour arrays for the NeoPixels and just kept a single array with RGB info in bits 5,6,7 and brightness info in bit 0-4.


    So optimising code is my next priority.

    The actual WS2812B led driving code is limited by strict timing protocols and is already in assembler so we will ignore that for now.

    Evaluation of the 1024 grid life matrix must take some time so perhaps you can have a look at the code and if any glaring time sucking stuff leaps out make suggestions?

    This part evaluates the primary 32 x 32 matrix and poulates a secondary 32 x 32 matrix with the updated information based on 'life' standard rules.

    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
    	
    	IF counter = 0 OR counter = 32 OR counter = 64 OR counter = 96 OR counter = 128 OR counter = 160 OR counter = 192 OR counter = 224_ 
        or counter = 256 OR counter = 288 OR counter = 320 OR counter = 352 OR counter = 384 OR counter = 416 OR counter = 448 OR counter = 480_
        or counter = 512 OR counter = 544 OR counter = 576 OR counter = 608 OR counter = 640 OR counter = 672 OR counter = 704 OR counter = 736_
        or counter = 768 OR counter = 800 OR counter = 832 OR counter = 864 OR counter = 896 OR counter = 928 OR counter = 960 OR counter = 992_
        THEN     
        lefedge = 1
    	ENDIF 	
    	
      	IF counter = 31 OR counter = 63 OR counter = 95 OR counter = 127 OR counter = 159 OR counter = 191 OR counter = 223_ 
        or counter = 255 OR counter = 287 OR counter = 319 OR counter = 351 OR counter = 383 OR counter = 415 OR counter = 447 OR counter = 479_
        or counter = 511 OR counter = 543 OR counter = 575 OR counter = 607 OR counter = 639 OR counter = 671 OR counter = 703 OR counter = 735_
        or counter = 767 OR counter = 799 OR counter = 831 OR counter = 863 OR counter = 895 OR counter = 927 OR counter = 959 OR counter = 991_
        THEN    
        rigedge = 1
    	ENDIF    
    	
    'Grid Evaluation	
    	        	
    	
    	IF led [counter-1] > 0 AND counter > 0 THEN
    	    Colour[population] = led[counter-1]
    		population = population + 1
    	ENDIF
    	
    	IF led [counter+1] > 0 AND counter < 1023 THEN
    	    Colour[population] = led[counter+1]
    		population = population + 1  		
    	ENDIF
    	
    	IF botedge = 0 THEN
    		IF led [counter-31] > 0 THEN
    		    Colour[population] = led[counter-31]
    			population = population + 1			
    		ENDIF
    		IF led [counter-32] > 0 THEN
    		    Colour[population] = led[counter-32]  
    			population = population + 1
    		ENDIF
    		IF  rigedge = 0 and led [counter-33] > 0 THEN
    		    Colour[population] = led[counter-33]
    			population = population + 1
    		ENDIF
    	ENDIF
    	
    	IF topedge = 0 THEN
    		IF led [counter+31] > 0 THEN
    		    Colour[population] = led[counter+31]
    			population = population + 1
    		ENDIF
    		IF led [counter+32] > 0 THEN
    		    Colour[population] = led[counter+32]
    			population = population + 1
    		ENDIF
    		IF  rigedge = 0 and led [counter+33] > 0 THEN 
    		    Colour[population] = led[counter+33]
    			population = population + 1
    		ENDIF
    	ENDIF
    	
    	lednew[counter] = led[counter]
    	
    	IF led[counter] > 0 THEN
    		IF population > 3 OR population < 2 THEN
    			lednew[counter] = 0
    		ENDIF
    	ENDIF
    	
    	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]
                
                else   
                
                lednew[counter] = led[counter]     'White LED
    		    
    		    endif   	
    			
    		ENDIF
    	ENDIF
    NEXT counter

    The second section moves data from the led matrix into the NeoPixel led array for display.
    I previously posted about this due to the led matrix and NeoPixel matrix having a different layout.

    It all works well at about 3hz but i'm looking for speed increases if possible.

    Code:
       	alive = 0	            'Clears alive accumulator
    	dead = 0                'Clears dead checksum accumulator
    
      FOR Row = 0 to 31			' Cycle thru 32 rows
        
         FOR Col = 0 to 31			' of 32 pixels each          
           InPtr = (Row * 32) + Col   '  
           led[InPtr] = lednew[InPtr]         
           IF Row.0 = 0 THEN	' If the row number is even   
             OutPtr =  InPtr        ' Output pixels in true order       
           ELSE
             OutPtr = (Row * 32) + (31-Col)   ' Output pixels in reversed order        
           ENDIF
           
           IF led[InPtr] > 0 THEN
           NeoLed(OutPtr) = Led[InPtr]	
           alive = alive + 1
           dead = dead + InPtr
    	   else 
           NeoLed(OutPtr) = 0	
    	   ENDIF
          
         NEXT
      NEXT

    The current colour code can be seen running in this short video.


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