Thread: My 'Connect four'. Two-player version available. Pls help me with the AI part...

  1. #1
    Registered User Nutshell's Avatar
    Join Date
    Jan 2002
    Posts
    1,020

    My 'Connect four'. Two-player version available. Pls help me with the AI part...

    Hi,

    This is my connect 4 game. TOOK ME A WHOLE DAY! It's currently two-player only, and i want to make a computer player. However, as i mentioned in another thread, i do not know how to check for winning moves and blocking moves WITHOUT check all possible ones each by each, if thats in fact possible, which i think is. If there is, please teach me. Any help, i'll really appreciate it.

    Thnx in advance.!.

    I'll post the source soon, or if people really ask for it, thank you.

  2. #2
    Rambling Man
    Join Date
    Jan 2002
    Posts
    1,050
    There is a significant difference between listing all of the possible moves and listing all of the possible moves to a certain situation. Listing all of the possible moves would be around 9! (362,880) moves for a tic-tac-toe game. Listing all of the possible moves for a certain situation can be as low as 9 moves and can be as high as 362,880 for the algorithm to work properly with TTT. Of course no AI algorithm is going to consist of 362,880 moves (listing all of the possible moves) , so most programmers just have an AI algorithm that lists moves to certain situations. The AI algorithm I used for my TTT game had 4 different situations with all of the moves the AI should make under that situation. Unless you are going to use a special algorithm (I believe there are some out there) you are going to have to use the commonly used algorithm of listing all of the possible moves to a situation, where the more situations you list the more adaptive (better) your AI will be. It appears that you want somebody to show you a way on how to do some type of a special algorithm. Hopefully now you can see the difference between listing all of the possible moves and listing all of the possible to a certain situation, because there is a distinct difference.

    BtW, I haven't got to try your game out yet...I'm still at school.

    EDIT: I played your game just now, and I have to say I'm impressed. I like the layout of the game, and the change of colors with the pieces. However, I still have a few suggestions. Try to create an intro (doesn't have to be much), and a better ending than 'Player X wins'. Also, clear the screen after the player is asked if they want to play again. And a scoring table would be nice too.
    Last edited by TechWins; 04-24-2002 at 04:04 PM.

  3. #3
    Unregistered
    Guest
    AI is just a list of records, the situation and moves.

  4. #4
    Registered User Nutshell's Avatar
    Join Date
    Jan 2002
    Posts
    1,020
    Thnx for comments.

    Techwins, if i do the AI the common way, it will be pretty long. I would have to do something like:
    Code:
    if ( board[ col ][ row ] == currentPlayer &&
         board[ col ][ row + 1 ] == currentPlayer &&
         board[ col ][ row + 2 ] == currentPlayer &&
         board[ col ][ row + 3 ] != 'X' &&
         board[ col ][ row + 3 ] != 'O' )
       /* move to there */
    MMMM that looks ok. Ok i'll try that. But i'm interersted the 'special algorithms' you were talking about. Do you have any examples?

    You are right. An intro would be cool. BUt i am trying to keep the board at the top left hand corner to do all the gotoxy's, make it easier. Scoring board is good, i'll do it after doing my AI.

    THnx

  5. #5
    Rambling Man
    Join Date
    Jan 2002
    Posts
    1,050
    Yeah, that's pretty much how I'd do the AI. Create an AI hiearchy, where the most important task the AI should do goes first and the least important (completely random) should go last. However, try to create a little unpredictabitly by the AI.

    You are right. An intro would be cool. BUt i am trying to keep the board at the top left hand corner to do all the gotoxy's, make it easier. Scoring board is good, i'll do it after doing my AI.
    Just do an intro such as how I did an intro in my maze game.

    {
    intro();

    clrscr();

    game();

    clrscr();

    end();
    }


    That's about as basic as gets in creating an intro and an ending for the game.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Problem building Quake source
    By Silvercord in forum Game Programming
    Replies: 16
    Last Post: 07-11-2010, 09:13 AM
  2. Binary Search Trees Part III
    By Prelude in forum A Brief History of Cprogramming.com
    Replies: 16
    Last Post: 10-02-2004, 03:00 PM
  3. Connect four AI demo
    By Sang-drax in forum Game Programming
    Replies: 6
    Last Post: 06-15-2004, 09:21 AM
  4. Linked list part 2 (Syntax error free version)
    By davidvoyage200 in forum C++ Programming
    Replies: 1
    Last Post: 03-16-2003, 10:07 AM
  5. structure vs class
    By sana in forum C++ Programming
    Replies: 13
    Last Post: 12-02-2002, 07:18 AM