Page 2 of 2 FirstFirst 12
Results 21 to 27 of 27
Like Tree4Likes

Thread: Game of Life , Adam & Eve

  1. #21
    rapito is offline Member
    Join Date
    Sep 2011
    Posts
    13
    Rep Power
    0

    Default Re: Game of Life , Adam & Eve

    Back a few post I "binary" explained how it should be if it is 3 in a row...
    Using the paint method first it just paints the one at the top and int he bottom of the one in the center meaning this:
    000
    111
    000

    does this

    020
    000
    020

    2 = Next Cell to live
    It should paint the Dead ones though....

  2. #22
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    SW Missouri
    Posts
    17,308
    Rep Power
    25

    Default Re: Game of Life , Adam & Eve

    I have checked it yet but my first idea is that a cell needs 4 states. When counting the neighbors only the alive or dying(currently alive but will be dead) are counted, not the dead or coming alive (currently dead but will be alive).

  3. #23
    rapito is offline Member
    Join Date
    Sep 2011
    Posts
    13
    Rep Power
    0

    Default Re: Game of Life , Adam & Eve

    Why should i count the next one to be alive?
    I managed to fix the array issue and with the painting debugging my result is how it should be (Just if i click each cell to change its color depending on its next state):

    000 -> 020
    111 -> 323
    000 -> 020

    3 = Next Gen Dead Cell
    2 = Next Gen Alive Cell

    Which four states would these be and what would I use them for?
    Last edited by rapito; 09-24-2011 at 01:46 AM.

  4. #24
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    SW Missouri
    Posts
    17,308
    Rep Power
    25

    Default Re: Game of Life , Adam & Eve

    I didn't see that you did that by using two arrays. I only used one to keep the cells' state in.

    You have too many statics variables. Here are some changes you could make:
    Java Code:
    	public  CellEntity cells[][] = new CellEntity[X_CELLARRAY][Y_CELLARRAY];
    
    		for (int px=0; px<cells.length ; px++)
    			for(int py=0; py<cells[px].length; py++)
    
    
    
    		CellEntity[][] newGen = cells.clone();     // Save current map
    
    		for (int px=0; px < cells.length ; px++)
    		  for(int py=0; py < cells[px].length; py++)			
    		    cells[px][py].survive(cells, newGen);      // Mark cells in newGen using cells as source
    
    	public void survive(CellEntity[][] cells, CellEntity[][] newGen) 	{
    
    		int vivas = fam(cells);
    
    
    
    	public int fam(CellEntity[][] cells) {
    		
    		int fam=0;
    		if(x > 0 && x < cells.length-1 
             && y > 0 && y < cells[0].length-1  ){
    Last edited by Norm; 09-24-2011 at 03:27 AM.

  5. #25
    rapito is offline Member
    Join Date
    Sep 2011
    Posts
    13
    Rep Power
    0

    Default Re: Game of Life , Adam & Eve

    I got it working...
    This is the zip file containing it:
    TDO.zip
    I Will edit my first post and post the solution.

    For some reason my CellEntity class was behaving as static.
    I fixed my issue by creating a 2 dimensional int array with values calculated with the next gen values instead of having the method kill the cloned array of the Cell Entities, then just make the cels suicide or come ti live dependin on the array values!

    Thanks for your help Norm! :D
    I Really Appreciate it!
    I hope i get an A :P ^_^

  6. #26
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    SW Missouri
    Posts
    17,308
    Rep Power
    25

    Default Re: Game of Life , Adam & Eve

    my CellEntity class was behaving as static.
    See the end of my last post

  7. #27
    rapito is offline Member
    Join Date
    Sep 2011
    Posts
    13
    Rep Power
    0

    Default Re: Game of Life , Adam & Eve

    I tried that too several times, and exatly that same way, got the same results XD

Page 2 of 2 FirstFirst 12

Similar Threads

  1. game of life, using 2d array
    By aramiky818 in forum New To Java
    Replies: 1
    Last Post: 09-09-2011, 05:47 AM
  2. Game of Life GUI Error
    By Lavace in forum New To Java
    Replies: 3
    Last Post: 01-03-2011, 01:57 PM
  3. Game of life methods help
    By bigskers76 in forum New To Java
    Replies: 26
    Last Post: 12-12-2009, 03:11 PM
  4. game of life
    By bigskers76 in forum New To Java
    Replies: 10
    Last Post: 12-09-2009, 05:21 AM
  5. A more efficient Game of Life
    By unreal4evr in forum New To Java
    Replies: 3
    Last Post: 03-27-2009, 03:08 AM

Tags for this Thread

Posting Permissions

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