Results 1 to 11 of 11
  1. #1
    shtinky is offline Member
    Join Date
    Oct 2009
    Posts
    5
    Rep Power
    0

    Default 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.
    Last edited by shtinky; 10-17-2009 at 05:18 AM. Reason: Code tags added to aid readability

  2. #2
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    26

  3. #3
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    26

    Default

    Forget Java for a minute. Logically, what must be done to make sure that the computer doesn't select a spot already selected?

  4. #4
    shtinky is offline Member
    Join Date
    Oct 2009
    Posts
    5
    Rep Power
    0

    Default

    It has to keep check of what spots are being used?

  5. #5
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    26

    Default

    Quote Originally Posted by shtinky View Post
    It has to keep check of what spots are being used?
    Exactly. And where is this information stored in your program?

  6. #6
    shtinky is offline Member
    Join Date
    Oct 2009
    Posts
    5
    Rep Power
    0

    Default

    Java 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;
                }
            }
        }

  7. #7
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    26

    Default

    Well which class variable holds this information? What gets filled via the fill2D method?

  8. #8
    shtinky is offline Member
    Join Date
    Oct 2009
    Posts
    5
    Rep Power
    0

    Default

    the board gets filled via fill2d... correct? the spaces in the board of 2d arrays
    Last edited by shtinky; 10-17-2009 at 05:04 AM.

  9. #9
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    26

    Default

    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. #10
    shtinky is offline Member
    Join Date
    Oct 2009
    Posts
    5
    Rep Power
    0

    Default

    where would i go inserting the while loop?

  11. #11
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    26

    Default

    Quote Originally Posted by shtinky View Post
    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!

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
  •