Welcome to the MacNN Forums.

If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

You are here: MacNN Forums > Software - Troubleshooting and Discussion > Developer Center > Connect 4 Board Evaluation Function

Connect 4 Board Evaluation Function
Thread Tools
Mac Elite
Join Date: Jun 2000
Location: NY
Status: Offline
Reply With Quote
Dec 2, 2004, 03:27 PM
 
Im programing an artificial player for connect 4, and need a good board evaluation function to start off with. For those that dont know what this is, its a function which takes in the current board, and the position of the next move and then returns and integer for that move. The higher the integer the better the position is. Thanks!
     
Senior User
Join Date: Feb 2001
Location: Deer Crossing, CT
Status: Offline
Reply With Quote
Dec 3, 2004, 07:36 AM
 
So, are you looking for someone to code this function for you or are you looking for ideas?
20" iMac G5! :D AND MacBook 1.83GHz!
Canon Digital Rebel Kit + 75 - 300mm lens. Yum Yum! :D
Check out my OS X Musical Scales program
     
Addicted to MacNN
Join Date: Mar 2000
Location: London, UK
Status: Offline
Reply With Quote
Dec 3, 2004, 09:20 AM
 
Do your own homework.
     
Junior Member
Join Date: Nov 2001
Location: Seattle
Status: Offline
Reply With Quote
Dec 5, 2004, 03:08 AM
 
One possible function would be to go through every possible way of getting four in a row in the game, and giving a score based on how close each player is to completing that particular 4-in-a-row. For example, if the current player is 'x' and the opponent is 'o', you could do something like:

4 x's = 1000 points
3 x's, 1 blank = 100 points
2 x's, 2 blank = 10 points
1 x, 3 blanks = 1 point
all blank, or if there is at least one x and one o = 0 points
1 o, 3 blanks = -1 point
2 o's, 2 blanks = -10 points
3 o's, 1 blank = -100 points
4 o's = -1000 points

Then add up the score for each of the possible ways of getting 4-in-a-row to get the total score for the board.

This is somewhat primitive, but it should work. Of course you'll have to play around with the point values to get this to work well; I just picked numbers off the top of my head. I haven't played connect-4 for a long time, so I don't know any strategy. If you have any general heuristic strategies when you play, it might be worth incorporating them into the board evaluation function. Perhaps it's easier to get 4-in-a-row horizontally or diagonally than it is vertically, or better to play in the center rather than the sides. Rules like this can be implemented in the above scoring function by weighing the scores of various 4-in-a-row sets appropriately.
     
Jsnuff1  (op)
Mac Elite
Join Date: Jun 2000
Location: NY
Status: Offline
Reply With Quote
Dec 6, 2004, 06:50 PM
 
thanks much juggle, as to the other two posters no i was not looking for someone to hand me the code but a very helpful post like juggles, something you two are obviously not cabable of. If anyone else has other ideas it would be greatly appreciated.
     
Forum Regular
Join Date: Jan 2001
Status: Offline
Reply With Quote
Dec 7, 2004, 12:51 PM
 
I did a assignment just like that for ~ 2 month ago, we used the eval function described by Juggle5. You can always let to AI player play eachother with diffrent weights in the eval function and see if one of them is winning more then tho otherone.
     
Senior User
Join Date: Feb 2001
Location: Deer Crossing, CT
Status: Offline
Reply With Quote
Dec 8, 2004, 10:52 AM
 
Originally posted by Jsnuff1:
thanks much juggle, as to the other two posters no i was not looking for someone to hand me the code but a very helpful post like juggles, something you two are obviously not cabable of. If anyone else has other ideas it would be greatly appreciated.

Jsnuff1,

I asked what you are looking for, code or ideas. It was a simple question. I am capable of many things, but a mind reader I am not. Calling me incapable certainly doesn't encourage me to help you out though, that's for sure.
20" iMac G5! :D AND MacBook 1.83GHz!
Canon Digital Rebel Kit + 75 - 300mm lens. Yum Yum! :D
Check out my OS X Musical Scales program
     
   
Thread Tools
Forum Links
Forum Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On
Top
Privacy Policy
All times are GMT -5. The time now is 09:23 PM.
All contents of these forums © 1995-2011 MacNN. All rights reserved.
Branding + Design: www.gesamtbild.com
vBulletin v.3.8.7 © 2000-2011, Jelsoft Enterprises Ltd., Content Relevant URLs by vBSEO 3.3.2