Thread: Complex and baffling AI. How the friggin jiggin do I do it? Friggin Jiggin help me!

  1. #1
    Unregistered Leeman_s's Avatar
    Join Date
    Oct 2001
    Posts
    753

    Complex and baffling AI. How the friggin jiggin do I do it? Friggin Jiggin help me!

    Ok, after my tic tac toe game I decided I wanted to make a connect 4 game. The only thing thats got me is the AI and checking for a win. In tic tac toe, there were lots less squares so this was MUCH easier. There has got to be some kind of short cut. My AI and win-checking in tic tac toe was a little long, and for connect four it would just be horrible! How would you guys do AI and checking for a win in connect 4?

  2. #2
    LoL, Friggin Jiggin! Funny words.

    Well...Let me think a little. If you wanted to do that, all you'll have to do is extend the boxes a little. Instead of a 3x3 winning area, it'll just be a little more win checking. Just use the basic TicTacToe AI with some extensions. Don't just copy and paste though.

    I think if you were to use booleans for each square, and made it so that if it's a good move, it is true, and if it's a bad move, it's false, it would work. After this, figure out the best play, and if you feel like wasting more time, then you can make it figure out the BEST play.
    What will people say if they hear that I'm a Jesus freak?
    What will people do if they find that it's true?
    I don't really care if they label me a Jesus freak, there is no disguising the truth!

    Jesus Freak, D.C. Talk

    -gnu-ehacks

  3. #3
    Unregistered
    Guest
    Well, I'm no AI expert by any stretch, but there are a few things you can do to reduce the code (unless you've already thought of them).

    For starters, don't bother checking for a win until the player has taken 3 turns.

    You could represent the graph as a double subscripted array of 0,1, and 2 (0 for open, 1 for filled by you, 2 for filled by them). So your array would look like Board[x][y], then you would just have to check for three "2"'s in a row for x, y, or diagonal [x+1][y+1].

    Also, make sure that if a player has open spaces on both ends and only need one more to win, your program doesn't hang (as both choices would result in a loss).

    I realize my description sucks, so here's a diagram of what I mean (x = filled space, o = open):

    oxxxo


    I don't know if any of this helps at all, but I hope it does.

  4. #4
    Registered User
    Join Date
    Sep 2001
    Posts
    412
    Well:

    1) Check for victory by checking the last move made -- any winning combo must contain the last piece played. There are only 16 combinations that result in victory that pass through any given space, and you'll have less if the piece was played near an edge.

    2) AI is a tricky subject. You could try to use move prediction, but this can become complicated to solve algorithmically. You could try some advanced game playing, like a genetic algorithm, but formulation of such a problem could be complicated.

    I don't know if there is a relly good algorithm for connect-4... you may need to play around with it.

  5. #5
    Registered User
    Join Date
    Sep 2001
    Posts
    412
    Try this algorithm for size:

    http://www.pomakis.com/~pomakis/c4/

Popular pages Recent additions subscribe to a feed