In the isColValid method I have to return true if a column falls on the Grid and false otherwise. IN the firstEmpty method I have to return the row of the first empty cell or -1 if there is no empty row in this column. When checking for a win im not sure how to do the diagonals and on the rows and columns im not sure how to logically express the indices cannot == '*' for a win.

In the isColValid method I have to return true if a column falls on the Grid and false otherwise. IN the firstEmpty method I have to return the row of the first empty cell or -1 if there is no empty row in this column. When checking for a win im not sure how to do the diagonals and on the rows and columns im not sure how to logically express the indices cannot == '*' for a win.

Here's a way to get started with the program code that is already in place:

See? For starters just make sure that you can show the board and make a simple move and show the board again. Don't worry about actually playing a game. Just make sure you can make a move and see its effect on the state of the board.

If you don't see this, then trace through the code and see where it is going wrong. Look carefully at the code, and if you aren't sure what it is doing, make the program tell you. (Put print statements that tell the values of arguments at the beginning of functions that are called and put print statements that show what the function is going to return. Stuff like that.)

Quote:

Originally Posted by wayfaring_stranger

In the isColValid method I have to return true if a column falls on the Grid and false otherwise.

So, you have a 2D array whose size is ROWS x COLS, right? How do you tell whether a column number (the value entered by the user) is valid? Well if it is less than zero or greater than or equal to COLS, it's invalid, right? So make the function return "true" or "false" depending on whether the value of the argument is in the proper range. If the user tries a column that is not valid, the program will (eventually) have to ask the user for another value. (Don't worry about that part yet, just make sure it can make a valid move and then change the hard-coded move with a column value that is less than zero or greater than the maximum allowable column number and see that it rejects that.)

Go on to the next function that you need: firstEmpty. Looking at the way that you are printing the array, I perceive that the top row is number zero, and the bottom is row number ROWS-1, right?

Furthermore...

You have initialized the array so that all values are '*' and if a previous move has resulted in a character that is not '*' in a particular row and column, you can't put anything else there, right?

So...

For a given column, you start looking at the bottom row and work your way back up, checking board[row][column] for the given column to see if it is equal to '*' If you find a row for which the board's value is not '*', then that is the first valid place on in that column, so you return that row value. If you get all of the way to the top row (row == 0) without finding a '*' you know that a move for that column is invalid, so you return -1.

And so it goes...

Bottom line: Start with a single play hard-coded into the main() program. Try a couple of different columns.
Then hard-code six or seven moves to the same column and see what happens. By hard-coding a few plays in main() you can run it over and over and over again without having to enter user plays from the terminal. This is important for preliminary debugging. I mean I can't speak for you, but in my experience, I might have to run it a lot of times (a whole lot) before getting the first parts in place, and having to enter six or seven moves manually each run is just too, too tedious.

Once you get past that point chip away at the other issues...

If you get stuck at a particular point, post the code that you have implemented so far and ask specific questions.

would this check each row(starting at the bottom) for the user given column?

No.

Think about it. I mean, really think about it. Then look at your code again. Then don't look at the code again, but think of a process that will do the deed:

Maybe something like this.

The column number is fixed (it is a parameter of the function), so you only need need one loop (for the row number).

The bottom row is numbered ROWS-1, so that's the first thing you check. (In other words, initialize the loop counter to ROWS-1). You will decrement the loop counter (the row number) each time through the loop, and will exit the loop "normally" if the loop counter ever gets to a value that is not >= 0.

Now...

Inside the loop, look at the current [row][column] value and see if it is '*'. If it is '*', then the value of the row counter is what you want to return. You can return that value without having to go through the loop any more.

However...

If the current element is not '*', then you haven't found an unoccupied cell yet, so the row counter is decremented, and it goes through the loop again.

If it gets all of the way to the top row without finding a '*', (leaves the loop "normally") that means that all of the rows of that column are occupied, so return -1.

Ok I got some help from my schools lab tutor about the check for empty. Now I am getting an Array out of bounds error in my checkForWin method I have been through it a hundred times and can't figure it out.

Post the exact error message. There will (probably) be enough information there to help you track it down. Look at what the error message is trying to tell you. (Really: look at it!) If you don't understand it, maybe someone can walk you through the steps to debug it.

Then print out the values of i, j, j+1, j+2, j+3 just before that statement is executed and see if any of the printed values is greater than the value of the corresponding dimension of the array. (According to your original post, the array was declared to have dimension [ROWS][COLUMNS] so in this statement, the value of i should be less than ROWS and j and j+1 and j+2 and j+3 should all be less than COLUMNS, right?)

ok I think I have a pretty good grasp of 2D arrays now.. I am pretty confident I have all the methods right now except my isColValid method. When I run the program and play 6 black... nothing shows up in column 6 when I play it. I am a student and just starting working with 2d arrays so I apologize that I don't know everything about debugging and knowing exactly what I should look for because this is my second class working with java and my teacher has her own way of teaching it so somethings I might need to know she might be teaching later on so there is nothing i can do about that.

My entire code has changed a bit so ill post it all and highlight the isColValid method.