# Tic Tac Toe Problem

• 10-17-2009, 04:30 AM
shtinky
Tic Tac Toe Problem
I have created a Java Program to run tic tac toe between the computer and a user. The problem i have is the program overwrites a space when it is taken already and I can not figure out what to do to tell the program to skip that space if already taken.
• 10-17-2009, 04:33 AM
Fubarable
• 10-17-2009, 04:38 AM
Fubarable
Forget Java for a minute. Logically, what must be done to make sure that the computer doesn't select a spot already selected?
• 10-17-2009, 04:43 AM
shtinky
It has to keep check of what spots are being used?
• 10-17-2009, 04:46 AM
Fubarable
Quote:

Originally Posted by shtinky
It has to keep check of what spots are being used?

Exactly. And where is this information stored in your program?
• 10-17-2009, 04:53 AM
shtinky
Code:

```            /**     * Fill a given two-dimensional character array with a given     * character     *     * @param a  the array to fill     * @param c  the character to use     */     public static void fill2D(char[][] a, char c) {         for (int i = 0; i < a.length; i++) {             for (int j = 0; j < a[i].length; j++) {                 a[i][j] = c;             }         }     }```
• 10-17-2009, 04:55 AM
Fubarable
Well which class variable holds this information? What gets filled via the fill2D method?
• 10-17-2009, 04:58 AM
shtinky
the board gets filled via fill2d... correct? the spaces in the board of 2d arrays
• 10-17-2009, 05:05 AM
Fubarable
right. so you must check that the spot you want to fill isn't already occupied. You'll likely want to create a while loop to keep checking that spot until an empty one is found.
• 10-17-2009, 05:07 AM
shtinky
where would i go inserting the while loop?
• 10-17-2009, 05:13 AM
Fubarable
Quote:

Originally Posted by shtinky
where would i go inserting the while loop?

Rather than just give you the answer for this, it is far better for you to think logically about your program and try to figure out where would be the best spot. If you apply yourself, you'll figure it out. Best of luck!