CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 4 of 4

Thread: Tic Tac Toe AI

  1. #1
    Join Date
    Mar 2009
    Posts
    1

    Tic Tac Toe AI

    Hi all, I am an A level student and really new to programming and we are meant to make a tic tac toe game where human player can play against computer, however so far I have only implemented the code for 2 human players and it detects if any1 wins...what I now need is AI for the computer's turn...

    Can I please get any help to get started on the AI....

    Ive attached full code in a word document and a screen shot of the program.

    I use visual studio 2008...

    EDIT: I did some research and lot of other developers made their game by using labels in array...but problem here is that they made it in VB6 where creating control array is as simple as copy and pasting and in vb.net its not......so I read the Microsoft's article on how to create (duplicate) controls array but I don't know how to merge that into my game even if i start all over again from scratch which I don't mind if it solves the problem.

    Thank you.
    Attached Files Attached Files
    Last edited by vohom001; March 17th, 2009 at 09:15 PM.

  2. #2
    Join Date
    Jan 2006
    Location
    Fox Lake, IL
    Posts
    15,007

    Re: Tic Tac Toe AI

    Just create a program that will play ITSELF, and you'll also have an automatic opponent, that can't be beat.
    David

    CodeGuru Article: Bound Controls are Evil-VB6
    2013 Samples: MS CODE Samples

    CodeGuru Reviewer
    2006 Dell CSP
    2006, 2007 & 2008 MVP Visual Basic
    If your question has been answered satisfactorily, and it has been helpful, then, please, Rate this Post!

  3. #3
    Join Date
    Jun 2004
    Location
    NH
    Posts
    678

    Re: Tic Tac Toe AI

    Ha,
    Number of players,... zero. (War games)

    If it is to be intelligent artificially, then you'll nead to teach it futility.
    Tic tac toe cannot be won, if played correctly by both players.
    What player is to be the first to realize that there is no point in playing anymore.
    The real winner.
    It's also important to teach AI routines the concept of no.

    I'd like to help, but why is the code in .doc form?

  4. #4
    Join Date
    Jul 2008
    Location
    WV
    Posts
    5,362

    Re: Tic Tac Toe AI

    There are probably several ways that you could do this, should be fairly simple. Basically you just need to have the code look at where the Xs and Os currently are and have the computer place it's X or O in the desired position. If it is done well then it will never be possible to beat the computer but just to make it interesting you could add in a random chance that the computer will make a mistake once in a while.

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

Featured