Results 1 to 4 of 4

Thread: I need help to get started with making a TicTacToe game..

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Oct 2002
    Posts
    210

    I need help to get started with making a TicTacToe game..

    I only have codes that make each cmdbuttons to change its text to X when a user clicks at them.

    I can't figure out how to make the computer decide which box it would want to pick.

    Even if i wanted the comp to randomize and pick any buttons that are not yet chosen, how would i do that? I don't know if I can randomize buttons.. If you know what I mean.. Like..

    VB Code:
    1. Dim RndPick As Integer
    2. Randomize
    3. RndPick = Rnd() * 9 + 1
    4. If RndPick = 1 Then Button1.Text = "O"

    That's how I've thought of the comp choosing a button, but when it comes to the part where the comp has to block a 3 straight Xs...

    Can someone get me started with this?

    Thanks in advance.

  2. #2

    Thread Starter
    Addicted Member
    Join Date
    Oct 2002
    Posts
    210

    Hmm...

    All I can think of as of now is to try every possibilities... Like, make a function that determines which box the CPU is going to choose, and see if ONLY button1 is checked, then choose a couple of possible winning picks.

    But that would make the code to be really long. There has to be a shorter way... I think..

    Any help?

  3. #3
    Hyperactive Member
    Join Date
    Dec 2001
    Location
    Dublin, Ireland
    Posts
    262
    This might give you some ideas:-

    http://visualbasic.about.com/library.../aa093002a.htm

    It uses 2-dimensional arrays to track the positions of tic/tacs. There are other ways you could do it. Looking at the the above link you will see the 8 possible lines that create a win. You could track how close to complete a line gets after each move.

  4. #4

    Thread Starter
    Addicted Member
    Join Date
    Oct 2002
    Posts
    210
    Hey, thanks!
    It'll help me a lot!

    However...
    I was thinking about playing against the comp...

    Here is a link of a source code of a tic tac toe game with AI: http://freevbcode.com/code/TTT_AI.zip.

    I can't figure it out... Especially the part about patterns in AI module...

    Here's another example, which, of course, I couldn't understand : http://freevbcode.com/code/nghtcros.zip.
    Last edited by nahya^^; Nov 7th, 2002 at 08:50 PM.

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