CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Page 3 of 3 FirstFirst 123
Results 31 to 37 of 37
  1. #31
    Join Date
    May 2006
    Location
    UK
    Posts
    4,473

    Re: help help, ... :) "game of life",

    I need this assignment please because I have to solve it.
    Yes you're quite right you have to solve it.

    But instead of False True I need it 0 1
    Ok but that's easy for you to change.

    exactly same this assignment which disccussed here.
    Lucky you, that'll make things a lot easier for you.

    please help cause I have tough courses
    Oh poor you
    Posting code? Use code tags like this: [code]...Your code here...[/code]
    Click here for examples of Java Code

  2. #32
    Join Date
    Mar 2010
    Posts
    4

    Re: help help, ... :) "game of life",

    oh please I wanna help

    because really I don't understand JAVA

    and there are many seperated codes here I don't know what I have to pick

    please help

    don't worry about zeros one .

    just make it done for me.

  3. #33
    Join Date
    Mar 2010
    Posts
    4

    Re: help help, ... :) "game of life",

    I put this cod:
    Code:
    		
    public class Life {
    	public static void main(String[] args) {
    
    		boolean[][] cell = new boolean[5][5];
    
    		for (int i=0;i<cell.length;i++)
    			for (int j=0;j<cell[0].length;j++)
    				cell[i][j] = false;
    
    		cell[1][2] = true;
    		cell[1][1] = true;
    		cell[1][0] = true;
    
    		for (int i=cell.length-1;i>=0;i--)
    		{
    			for (int j=0;j<cell[0].length;j++)
    			{
    				System.out.print(cell[i][j]+" ");
    			}
    			System.out.println();
    		}
    
    		System.out.println(numberOfNeighbors(cell,1,1)+" "+ checkCell(cell,1,1));
    
    		cell = nextGeneration(cell);
    
    		for (int i=cell.length-1;i>=0;i--)
    		{
    			for (int j=0;j<cell[0].length;j++)
    			{
    				System.out.print(cell[i][j]+" ");
    			}
    			System.out.println();
    		}
    
    	}
    	public static boolean isInside(boolean[][] cells, int x, int y) {
    
    		if ((cells.length <= x) || (x < 0) || (cells[0].length <= y) || (y < 0))
    			return false;
    
    		return true;
    
    	}
    	public static boolean checkCell(boolean[][] cells, int x, int y) {
    
    		return isInside(cells, x, y) && cells[x][y];
    
    	}
    	public static int numberOfNeighbors(boolean[][] cells,int x,int y) {
    
    		int count=0,j=0,i=1,marker=0;
    
    		while (marker < 3)
    		{
    			if ((checkCell(cells,x+j,y)) && (cells[x+j][y] != cells[x][y]))
    				count++;
    			if (checkCell(cells,x+j,y+i))
    				count++;
    			if (checkCell(cells,x+j,y-i))
    				count++;
    
    			j=1;
    
    			marker++;
    
    			if (marker == 2)
    				j=-1;
    
    		}
    
    		return count;
    	}
    	public static boolean[][] nextGeneration(boolean[][] cells) {
    
    
    		boolean[][] cell = new boolean[cells.length][cells[0].length];
    
    		for (int i=0;i<cells.length;i++)
    			for (int j=0;j<cells[0].length;j++)
    				cell[i][j] = false;
    
    		for (int i=0;i<cells.length;i++)
    			for (int j=0;j<cells[0].length;j++)
    			{
    				if ((checkCell(cells,i,j)) && (numberOfNeighbors(cells,i,j) > 2)) 
    				{
    					cell[i][j] = true;
    				}
    
    				if (numberOfNeighbors(cells,i,j) == 3)
    				{
    					cell[i][j] = true;
    				}
    
    				else
    				{
    					cell[i][j] = false;
    				}
    			}
    
    
    		return cell;
    	}
    }
    It gives me :

    false false false false false
    false false false false false
    false false false false false
    true true true false false
    false false false false false
    2 true
    false false false false false
    false false false false false
    false true false false false
    false false false false false
    false true false false false

    <<< but the correct way is
    input:
    false false false false false
    false false false false false
    false false false false false
    true true true false false
    false false false false false

    output:

    false false false false false
    false false false false false
    false true false false false
    false true false false false
    false true false false false

  4. #34
    Join Date
    May 2006
    Location
    UK
    Posts
    4,473

    Re: help help, ... :) "game of life",

    There's only one cell that is wrong and that is the case where a cell stays alive if it has 2 or 3 neighbours. So you need to look at the code that handles this case - of course it would be eaiser for you to do this if you had documented which bit of code handled which case.
    Posting code? Use code tags like this: [code]...Your code here...[/code]
    Click here for examples of Java Code

  5. #35
    Join Date
    Mar 2010
    Posts
    4

    Re: help help, ... :) "game of life",

    Quote Originally Posted by sanfor View Post
    i did it ;P

    Code:
    		int numberOfNeighbors;
    		
    		if (checkCell(cells,x,y))
    			numberOfNeighbors=-1;
    		else
    			numberOfNeighbors=0;
    before:

    Code:
    false false false false false 
    false false false false false 
    false false false false false 
    true true true false false 
    false false false false false
    after:

    Code:
    false false false false false 
    false false false false false 
    false true false false false 
    false true false false false 
    false true false false false
    I don't know where I have to add this code to fix the problem.

    again, please I need help.

  6. #36
    dlorde is offline Elite Member Power Poster
    Join Date
    Aug 1999
    Location
    UK
    Posts
    10,163

    Re: help help, ... :) "game of life",

    Quote Originally Posted by NOT-BAD View Post
    I don't know where I have to add this code to fix the problem.
    You claim you already wrote the code that does other checks of the neighbours, so you ought to know where it goes. If not, find code that looks similar, and insert it there (hint: the nextGeneration(..) method). Some things you need to figure out for yourself.

    Why do we never have time to do it right, but always have time to do it over?
    Anon.
    Please use &#91;CODE]...your code here...&#91;/CODE] tags when posting code. If you get an error, please post the full error message and stack trace, if present.

  7. #37
    Join Date
    Jun 2007
    Location
    Aurora CO USA
    Posts
    137

    Re: help help, ... :) "game of life",

    Quote Originally Posted by NOT-BAD View Post
    oh please I wanna help

    because really I don't understand JAVA

    and there are many seperated codes here I don't know what I have to pick

    please help

    In case you're wondering why you're getting the responses you see here, this is an assistance forum, not a homework cheating forum.

    You say you don't really understand Java, but isn't that the point of the class you are taking? If you don't understand, how is having someone else do your work going to help you understand better? I suggest you do some more reading and/or work with your instructor, because you do need more help if this is the case.

    don't worry about zeros one .

    just make it done for me.


    Not going to happen. Most of us here are helping out in our spare time in addition to what ever full time jobs we have. We don't have the time or inclination to write your homework for you. We've already put in the time to learn and know the subject. This is where you do the same. If you read this entire thread, you'll see the difference between the amount of effort Sanfor put in and what you're giving. That level of effort is directly reflected in the answers you're getting.

Page 3 of 3 FirstFirst 123

Posting Permissions

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





Click Here to Expand Forum to Full Width

Featured