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

• 04-24-2002
Nutshell
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.

I'll post the source soon, or if people really ask for it, thank you.
• 04-24-2002
TechWins
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.:cool: 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.:)
• 04-24-2002
Unregistered
AI is just a list of records, the situation and moves.
• 04-24-2002
Nutshell

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
• 04-25-2002
TechWins
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.

Quote:

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.