Help with understanding my current coding of boolean array

  • (2 Pages)
  • +
  • 1
  • 2

27 Replies - 889 Views - Last Post: 13 September 2012 - 10:51 PM Rate Topic: -----

#16 Cuzzie  Icon User is offline

  • D.I.C Regular
  • member icon

Reputation: 72
  • View blog
  • Posts: 341
  • Joined: 16-July 10

Re: Help with understanding my current coding of boolean array

Posted 13 September 2012 - 04:54 AM

View Postprogrammingdoesmyheadin, on 13 September 2012 - 11:23 AM, said:

That's basically what I had done so far but the problem I'm really having with the code is the method ! :/ I don't know how to go about writing it.. I dont even know how to start :(


Which methods are you having problems with? nextGeneration? countNeighbours? Or something else?
Was This Post Helpful? 0
  • +
  • -

#17 programmingdoesmyheadin  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 11
  • Joined: 12-September 12

Re: Help with understanding my current coding of boolean array

Posted 13 September 2012 - 05:21 AM

 
    {
        boolean [][] newBoard = new boolean[board1.length]
        [board1[0].length];
        
        int count = countNeighbours(newBoard, 1, 1);
        if (count < 2)
        {
            newBoard[row][column] = board[row][column]
            newBoard[row][column] =".";

        }
        else if (count == 2)
        {
            newBoard[row][column] = board[row][column];
            newBoard[row][column] ="*";
        }
        return newBoard;
    }



would this be right? :/ better yet, does it answer the question? lol
Sorry, I'm just trying to figure this out considering I can't seem to get my head around this language at all :(
Was This Post Helpful? 0
  • +
  • -

#18 programmingdoesmyheadin  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 11
  • Joined: 12-September 12

Re: Help with understanding my current coding of boolean array

Posted 13 September 2012 - 05:27 AM

View PostCuzzie, on 13 September 2012 - 04:54 AM, said:

View Postprogrammingdoesmyheadin, on 13 September 2012 - 11:23 AM, said:

That's basically what I had done so far but the problem I'm really having with the code is the method ! :/ I don't know how to go about writing it.. I dont even know how to start :(


Which methods are you having problems with? nextGeneration? countNeighbours? Or something else?


I was having trouble with nextGeneration but I think I figured it out.. do you mind checking my code (my last post) and telling me if it's right?
Was This Post Helpful? 0
  • +
  • -

#19 Judison  Icon User is offline

  • New D.I.C Head

Reputation: 1
  • View blog
  • Posts: 32
  • Joined: 08-August 12

Re: Help with understanding my current coding of boolean array

Posted 13 September 2012 - 06:58 AM

View Postprogrammingdoesmyheadin, on 13 September 2012 - 05:27 AM, said:

View PostCuzzie, on 13 September 2012 - 04:54 AM, said:

View Postprogrammingdoesmyheadin, on 13 September 2012 - 11:23 AM, said:

That's basically what I had done so far but the problem I'm really having with the code is the method ! :/ I don't know how to go about writing it.. I dont even know how to start :(


Which methods are you having problems with? nextGeneration? countNeighbours? Or something else?


I was having trouble with nextGeneration but I think I figured it out.. do you mind checking my code (my last post) and telling me if it's right?



Helllooo I finished my code, but your code is wrong, I'll give you a hint don't use 1,1 , does you "." "*" any of the strings, use true or false instead

If your unsw like me, read the last 3 weeks slides, you'll get it
Was This Post Helpful? 0
  • +
  • -

#20 pbl  Icon User is offline

  • There is nothing you can't do with a JTable
  • member icon

Reputation: 8066
  • View blog
  • Posts: 31,310
  • Joined: 06-March 08

Re: Help with understanding my current coding of boolean array

Posted 13 September 2012 - 02:14 PM

Quote

A live neighbour is defined as true, I'm really uncertain how to implement this because I would need to count the neighbours right? But I'm not supposed to count it in this method, as I have done it for another separate method.

I have already told you, you can't do it with just boolean
You need a class for every cell that contains actualState, nextGenerationState
when you are all dione you copy the nextGenerationState into the actualState
The same class can hold the number of neighbors this simplifies the coding
and at construction time you can even build a list of the neineighbors... thats simplify a lot the coding
Was This Post Helpful? 1
  • +
  • -

#21 programmingdoesmyheadin  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 11
  • Joined: 12-September 12

Re: Help with understanding my current coding of boolean array

Posted 13 September 2012 - 05:30 PM

[/quote]

Helllooo I finished my code, but your code is wrong, I'll give you a hint don't use 1,1 , does you "." "*" any of the strings, use true or false instead

[/quote]


Heyy :) Sorry, but I don't understand what you are trying to say here :/ So the bit where i put 1,1 is wrong.. but is that the only thing i need to change? is everything else right? :/

Do i just get rid of the 1,1 without replacing it? and are you saying to replace ".""*" with true and false?

Sorry i just need clarification :)
Was This Post Helpful? 0
  • +
  • -

#22 programmingdoesmyheadin  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 11
  • Joined: 12-September 12

Re: Help with understanding my current coding of boolean array

Posted 13 September 2012 - 06:07 PM

Okay, I think i've figured it out...
Except, i just don't know what to put instead of 1,1 considering we dont know how many rows and cols there are? :/ any suggestions?


   public static boolean[][] nextGeneration(boolean[][] board1)
    {
        int row=0;
        int col=0;
        boolean [][] newBoard = new boolean[board1.length]
        [board1[row].length];
        
        int count = countNeighbours(newBoard, 1, 1);
        if (count < 2 || count > 3)
        {
            newBoard[row][col] = board1[row][col];
            newBoard[row][col] = false;

        }
        else if (count == 2 || count == 3)
        {
            newBoard[row][col] = board1[row][col];
            newBoard[row][col] = true;
        }
        return newBoard;
    }




DOES THAT ANSWER THE QUESTION THOUGH? :( It compiles but I'm not sure if it answers the question
Was This Post Helpful? 0
  • +
  • -

#23 programmingdoesmyheadin  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 11
  • Joined: 12-September 12

Re: Help with understanding my current coding of boolean array

Posted 13 September 2012 - 06:18 PM

Sorry, last post i promise! haha :)

is this bit necessary within both if statements or not?


 newBoard[row][col] = board1[row][col];



Was This Post Helpful? 0
  • +
  • -

#24 Cuzzie  Icon User is offline

  • D.I.C Regular
  • member icon

Reputation: 72
  • View blog
  • Posts: 341
  • Joined: 16-July 10

Re: Help with understanding my current coding of boolean array

Posted 13 September 2012 - 06:38 PM

View Postprogrammingdoesmyheadin, on 14 September 2012 - 01:07 AM, said:

Okay, I think i've figured it out...
Except, i just don't know what to put instead of 1,1 considering we dont know how many rows and cols there are? :/ any suggestions?


   public static boolean[][] nextGeneration(boolean[][] board1)
    {
        int row=0;
        int col=0;
        boolean [][] newBoard = new boolean[board1.length]
        [board1[row].length];
        
        int count = countNeighbours(newBoard, 1, 1);
        if (count < 2 || count > 3)
        {
            newBoard[row][col] = board1[row][col];
            newBoard[row][col] = false;

        }
        else if (count == 2 || count == 3)
        {
            newBoard[row][col] = board1[row][col];
            newBoard[row][col] = true;
        }
        return newBoard;
    }




DOES THAT ANSWER THE QUESTION THOUGH? :( It compiles but I'm not sure if it answers the question


You are assigning 0 to both row and col in the method, so that means every time you call the method, you will only be modifying newBoard[0][0].

View Postprogrammingdoesmyheadin, on 14 September 2012 - 01:18 AM, said:

is this bit necessary within both if statements or not?


 newBoard[row][col] = board1[row][col];




newBoard[row][col] = board1[row][col];
newBoard[row][col] = false;



The value of board1[row][col] that you assign to newBoard[row][col] will be replaced by "false" straight away.
Was This Post Helpful? 0
  • +
  • -

#25 programmingdoesmyheadin  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 11
  • Joined: 12-September 12

Re: Help with understanding my current coding of boolean array

Posted 13 September 2012 - 06:55 PM

Quote

You are assigning 0 to both row and col in the method, so that means every time you call the method, you will only be modifying newBoard[0][0].

okay, if that's the case then how am i supposed to initialise row and col correctly?

Quote

The value of board1[row][col] that you assign to newBoard[row][col] will be replaced by "false" straight away.


So are you saying that I don't need 'newBoard[row][col] = board1[row][col];'? or that my if statement is wrong altogether?
Was This Post Helpful? 0
  • +
  • -

#26 Judison  Icon User is offline

  • New D.I.C Head

Reputation: 1
  • View blog
  • Posts: 32
  • Joined: 08-August 12

Re: Help with understanding my current coding of boolean array

Posted 13 September 2012 - 08:08 PM

View Postprogrammingdoesmyheadin, on 13 September 2012 - 06:07 PM, said:

Okay, I think i've figured it out...
Except, i just don't know what to put instead of 1,1 considering we dont know how many rows and cols there are? :/ any suggestions?


   public static boolean[][] nextGeneration(boolean[][] board1)
    {
        int row=0;
        int col=0;
        boolean [][] newBoard = new boolean[board1.length]
        [board1[row].length];
        
        int count = countNeighbours(newBoard, 1, 1);
        if (count < 2 || count > 3)
        {
            newBoard[row][col] = board1[row][col];
            newBoard[row][col] = false;

        }
        else if (count == 2 || count == 3)
        {
            newBoard[row][col] = board1[row][col];
            newBoard[row][col] = true;
        }
        return newBoard;
    }




DOES THAT ANSWER THE QUESTION THOUGH? :( It compiles but I'm not sure if it answers the question


change 1,1 to row and col not sure sure about the rest of the code..... don't really understand it sorry
Was This Post Helpful? 0
  • +
  • -

#27 programmingdoesmyheadin  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 11
  • Joined: 12-September 12

Re: Help with understanding my current coding of boolean array

Posted 13 September 2012 - 09:15 PM

View PostJudison, on 13 September 2012 - 08:08 PM, said:

View Postprogrammingdoesmyheadin, on 13 September 2012 - 06:07 PM, said:

Okay, I think i've figured it out...
Except, i just don't know what to put instead of 1,1 considering we dont know how many rows and cols there are? :/ any suggestions?


   public static boolean[][] nextGeneration(boolean[][] board1)
    {
        int row=0;
        int col=0;
        boolean [][] newBoard = new boolean[board1.length]
        [board1[row].length];
        
        int count = countNeighbours(newBoard, 1, 1);
        if (count < 2 || count > 3)
        {
            newBoard[row][col] = board1[row][col];
            newBoard[row][col] = false;

        }
        else if (count == 2 || count == 3)
        {
            newBoard[row][col] = board1[row][col];
            newBoard[row][col] = true;
        }
        return newBoard;
    }




DOES THAT ANSWER THE QUESTION THOUGH? :( It compiles but I'm not sure if it answers the question


change 1,1 to row and col not sure sure about the rest of the code..... don't really understand it sorry



Thanks for your help :) Did you end up finding a way to implement the rules? because i cant figure out a way to code whether a cell is alive or dead in the nextGeneration method :(
Was This Post Helpful? 0
  • +
  • -

#28 Judison  Icon User is offline

  • New D.I.C Head

Reputation: 1
  • View blog
  • Posts: 32
  • Joined: 08-August 12

Re: Help with understanding my current coding of boolean array

Posted 13 September 2012 - 10:51 PM

View Postprogrammingdoesmyheadin, on 13 September 2012 - 09:15 PM, said:

View PostJudison, on 13 September 2012 - 08:08 PM, said:

View Postprogrammingdoesmyheadin, on 13 September 2012 - 06:07 PM, said:

Okay, I think i've figured it out...
Except, i just don't know what to put instead of 1,1 considering we dont know how many rows and cols there are? :/ any suggestions?


   public static boolean[][] nextGeneration(boolean[][] board1)
    {
        int row=0;
        int col=0;
        boolean [][] newBoard = new boolean[board1.length]
        [board1[row].length];
        
        int count = countNeighbours(newBoard, 1, 1);
        if (count < 2 || count > 3)
        {
            newBoard[row][col] = board1[row][col];
            newBoard[row][col] = false;

        }
        else if (count == 2 || count == 3)
        {
            newBoard[row][col] = board1[row][col];
            newBoard[row][col] = true;
        }
        return newBoard;
    }




DOES THAT ANSWER THE QUESTION THOUGH? :( It compiles but I'm not sure if it answers the question


change 1,1 to row and col not sure sure about the rest of the code..... don't really understand it sorry



Thanks for your help :) Did you end up finding a way to implement the rules? because i cant figure out a way to code whether a cell is alive or dead in the nextGeneration method :(


true and false is the way of determining if the cell is alive or dead for our assignment, you don't use any of the strings, you might want to add if board is true in the if function
Was This Post Helpful? 0
  • +
  • -

  • (2 Pages)
  • +
  • 1
  • 2