Martin Pilch
Martin Pilch

Reputation: 3295

Representation and heuristic of Connect6 game in Prolog

I want to represent game connect6 wiki (maybe predicate stone(P, X, Y), where P is player, X,Y are coords would by good). Also I want to use any good heuristic to solve the problem (to make opponent). Can you give me a hint to any article about game AI in Prolog? Thanks

Upvotes: 4

Views: 1320

Answers (2)

Fred Foo
Fred Foo

Reputation: 363517

If you're implementing Connect6 on a finite board, then a possible representation for this game would be a list of lists of variables, initially unbound. You'd "place a stone" by unifying a variable with one of the atoms black or white. You can then test whether a position P is still empty with var(P). This representation should be a lot faster to manipulate than a list of stone/3 terms. It works because in Connect6, you can't ever remove a stone.

I assume that by heuristic you mean an evaluation function suitable for minimax, negamax or alpha-beta search. Considering the game rules, I'd suggest that for each player, you count the number of rows of length five and score those 5, score those of length four 4, etc. This gives you two scores S1 and S2. Subtracting S2 from S1 yields the relative advantage for player 1. Then find some way to normalize these into the range [-1,1] or score a situation where the game is over infinity of minus infinity. (How to represent all that in Prolog is left as an exercise.)

Upvotes: 2

Mark Bolusmjak
Mark Bolusmjak

Reputation: 24399

You probably want to look up http://en.wikipedia.org/wiki/Minimax game trees. To optimize the search, you probably don't want to consider all possible moves. Maybe just moves that are in-line with an existing piece and 6 or less spaces from it.

Then you need an http://en.wikipedia.org/wiki/Evaluation_function. Probably something like assigning a score to "how close am I to completing a line" overall the lines in progress.

Building and optimizing a game tree is more of a mechanical process. Creating an evaluation function is the fun part that will give your AI opponent it's unique flavor.

Searching google for "minimax game tree prolog" turned up a nice powerpoint: http://staff.science.uva.nl/~arnoud/education/ZSB/2009/

Upvotes: 2

Related Questions