Win a copy of The Way of the Web Tester: A Beginner's Guide to Automating Tests this week in the Testing forum!

Help in connect four

Kabir Shah
Ranch Hand
Posts: 125
I have already posted few messages in this forum, should mention that members here are quiet helpful in nature(though my problem was not solved, at least it was discussed at a length).

I have written a connect four program but it plays random unless it gets to see 4 in row for the depth it is searching. To make it better I wanted to apply alpha-beta pruning but I was not successful in doing so.Hence I tried to write a method which will determine connect in 3 for itself as well as for the opponent.

As I wrote this code and compiled it, It only looks for connect in 3 rather than blocking or going for win. It doesnot give priority to connect 4 as to connect 3 even though I have given higher value for connect four.

This is my code for checking the connect 3:.

And here is the minmax code:

-Thank you.

Fred Hamilton
Ranch Hand
Posts: 684
Hi Gurudas, sorry I did not get back to you. I looked at your code a few times, and the descriptions, but was unable to unlock the secrets. It's hard enough for me to figure out my own recursions.

I am interested in game programming, at some point I will probably take a stab at writing a connect 4, and I'll share the results with you.

In the meantime, you may benefit from this website, which has an entire page devoted to programming a recursive connect4 algorithm.

Let us know if it helps.

http://erwnerve.tripod.com/prog/recursion/

p.s. the connect 4 chapter is followe by a chapter on alphabeta pruning

Kabir Shah
Ranch Hand
Posts: 125
@Fred
I got the minmax algorithm from there only.. that was my first step( later on I found nega max).
But alpha beta pruning was of no help.

Fred Hamilton
Ranch Hand
Posts: 684
ok well good luck. maybe give the sun forums a try, they have a special forum on algorithms. If you don't get a solution here that is.

also there is Google groups, they have all sorts of forums on programming. I've had success with recursion topics in this forum, not sure if they will debug java code though.