views:

1017

answers:

3

Hey, I am trying to write a simple AI for a "Get four" game. The basic game principles are done, so I can throw in coins of different color, and they stack on each other and fill a 2D Array and so on and so forth. until now this is what the method looks like:

public int insert(int x, int color)  //0 = empty, 1=player1 2=player2"

X is the horizontal coordinate, as the y coordinate is determined by how many stones are in the array already, I think the idea is obvious.

Now the problem is I have to rate specific game situations, so find how many new pairs, triplets and possible 4 in a row I can get in a specific situation to then give each situation a specific value. With these values I can setup a "Game tree" to then decide which move would be best next (later on implementing Alpha-Beta-Pruning). My current problem is that I can't think of an efficient way to implement a rating of the current game situation in a java method. Any ideas would be greatly appreciated! greetings from Germany Mr. Pink

+4  A: 

I'm guessing that this is a homework assignment, and that you mean you want to write the evaluation function and don't know what tricks to use?

The game is called "Connect 4" in English, so you can google for "connect 4 evaluation function".

You can find enough people discussion heuristics.

Please don't copy an actual source code, it's an important exercise :)

Uri
-1 I don't understand how this is getting upvoted. Telling someone to use Google is not an answer. I can live with links to Wikipedia but this is not acceptable to me.
Outlaw Programmer
A googleable phrase is useful at times and If you look at the history then you'll see that the question originally didn't contain the phrase "Connect 4".
Joachim Sauer
I'm the one that edited it into the correct name of the game, that seemed to be the main problem he had. Hence, I told him what the correct name was and where to look it up.
Uri
+1  A: 

The search space for Connect 4 isn't impossibly large. For a simple implementation, albeit one that'll take a while to run (perhaps tens of minutes) do a minimax search until someone wins, or the game ends. Assign +1 or -1 for a win for one player or the other, and 0 for a draw.

Bill Michell
With a highly optimized program like Fhourstones(http://homepages.cwi.nl/~tromp/c4/fhour.html) it would still take you around 10 minutes to solve the game from start to finish.. Performance for 8+ moves is better, but still not all that fast, especially when using a sub-optimal algorithm.
Tim
A: 

bollocks. search space is huge. you need to use a predefined table if you want to do that.