Never Registered? If you are new to theConnection, please complete the form below.
![Inc Inc](https://geekland.eu/wp-content/uploads/2019/03/copiar-plantillas-collabora-online.png)
Hello,
I'm designing a C++ Program for a connect 4 game. I have the matrix set up, the test to determine if there is a winner, and now I need to design the computer to go against the player. This seems to be quite a challenge. First, I need to make it block if there are 3 in a row. So far, I can't even accomplish that....
I'm designing a C++ Program for a connect 4 game. I have the matrix set up, the test to determine if there is a winner, and now I need to design the computer to go against the player. This seems to be quite a challenge. First, I need to make it block if there are 3 in a row. So far, I can't even accomplish that....
I made a function, and it looks like this:
This is only the first part of the program...
the
'-'
is what I use to display my matrix. I put it '-' for blank spaces, so the player knows what space is open.Now..when I test it...the computer can't seem to place an 'X' when there is a vertical threat (when there are 3 'O's' in a row vertically up)..the computer just blanks out and takes a very long time to respond.
Can anyone tell me what is wrong?
Also, can someone teach me how I could program a computer to 'think'?...I looked it up on the internet and you're supposed to put 'weights' on certain columns...like if there is a potential threat, then the computer puts something to counter it early on.
- 6 Contributors
- forum12 Replies
- 614 Views
- 1 Year Discussion Span
- commentLatest Postby mentkapto
Hey zellex,
I wrote a connect 4 AI agent a while ago. You can play it at
http://students.csci.unt.edu/~jdl0107/conn4.exe
http://students.csci.unt.edu/~jdl0107/conn4.exe
I know our code is different, but this is a link to my source code for my AI:
http://students.csci.unt.edu/~jdl0107/leon.cpp
http://students.csci.unt.edu/~jdl0107/leon.cpp
You are welcome to look through it. My leon::move method is the one that has all the AI. At the beginning of the method I documented the different ways it chooses which space to move. It doesn't use any recursion(I never got around to it). Adding some recursion to determine the move was proven to beat my method. Anyway, I hope you can get some use out of it.