my AI logic is to :
1 - play winning games
2 - defend winning games
3 - play games to make 3 blocks
4 - defend 3 blocks
5 - play games to make 2 blocks
6 - worst case .. play randomly that doesn't make a winning game for the opponent
I know .... the logic isn't good at all ...
so i need some help to improve the logic + to tell me your opinion
My advice is to start again. Try to keep functions as simple and small as possible and do not use goto anywhere.
Upon starting again, firstly, make sure that you have made a board that you can play on (just have the computer doing random moves) without any bugs or errors.
Then write the checks for win/loss/draw and make sure they work correctly.
Finally, start on making the AI. I found the best way to make an AI play this game was to analyze the situation for each square horizontally, vertically and diagonally, adding integers to a two dimensional array, which reflect the benefits of playing in a square. e.g.
If playing on a square wins instantly for computer - 100000
If playing on a square blocks player immediate win - 5000
etc...
The computer then plays on the highest value square.
thanks #Mats for your reply :)
I think you're right i need to start from the beginning but
making a board and winning algorithm is easy and it isn't a problem
the problem is the AI ... I don't know how to "analyze the situation for each square horizontally, vertically and diagonally, adding integers to a two dimensional array, which reflect the benefits of playing in a square. "
so if you have any ideas please tell me
making a board and winning algorithm is easy and it isn't a problem
If it's easy and it's not a problem, then good. That must be implemented first before you make your AI. Otherwise, you have no board to analyze.
the problem is the AI ... I don't know how to "analyze the situation for each square horizontally, vertically and diagonally, adding integers to a two dimensional array, which reflect the benefits of playing in a square. "
How exactly is your winning algorithm going to work? hmm...
thanks for replying :)
I've already made a board and winning algorithm you can check the code
and I've made an AI too but it isn't good enough ..
I want to make an AI that cannot be defeated as connect 4 is a solved game so I want to know how should AI work ? how should it analyze the situation to get the best play
Making a perfect play AI is very difficult. It's seriously inadvisable to have that as an early AI goal. You can however, with fairly simple methods, make an AI that can beat adults.
Is this for college/university or just a personal project?
you're right but I will do my best
I'm making a new AI algorithm and when I finish I'll post it
.........
I'm just having fun :D
I'm 16 years old so I'm not in a college :D