473,395 Members | 1,574 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

AlphaBeta Search

I know this probably seems trivial, but I can't seem to find the bug in
my alphabeta search implementation.

I'm testing it with the game of tic-tac-toe. If the first player plays
in a corner, the correct move is to play in the center, but for some
reason my code thinks the center and remaining corner positions are all
equally good moves.

I adopted my code almost exactly from the pseudo-code posted in the
wikipedia article (http://en.wikipedia.org/wiki/Alpha-beta_pruning).
Can anyone point out if I'm doing anything clearly wrong, or if the
pseudo-code isn't correct? Any help is appreciated.

infinity = 1e99999999
def alphaBeta(root, maxDepth=10):
"""Search game to determine best action; use alpha-beta pruning."""

player = root.turn

def is_terminal(node, depth):
'''The default test cuts off at depth d or at a terminal
state.'''
return depth maxDepth or node.isGameOver()

def heuristic_value(node):
'''Returns heuristic value of game relative to the turn in the
root game.'''
player1Score,player2Score = node.getScore()
if node.turn == player:
score = player1Score-player2Score
else:
score = player2Score-player1Score
return score

def search(node, alpha, beta, depth):
if is_terminal(node, depth):
return heuristic_value(node)
for nextNode in node.getNextNodes():
v = alpha = max(alpha, -search(nextNode, -beta, -alpha,
depth+1))
if alpha >= beta:
break
return v

# Evaluate all choices.
choices = map(lambda node: (search(node, -infinity, infinity, 0),
node.actionHistory[-1]),
root.getNextNodes())

# Chose best action.
score,action = max(choices)

return action

Jan 13 '07 #1
2 3847
Chris wrote:
I know this probably seems trivial, but I can't seem to find the bug in
my alphabeta search implementation.
This is another alphabeta implementation (all the nicest algorithms are
inside this AIMA codebase):
http://aima.cs.berkeley.edu/python/games.html

Later when you program works you can find this helpful to improve your
algorithm:
http://citeseer.ist.psu.edu/11954.html

Bye,
bearophile

Jan 13 '07 #2
bearophileH...@lycos.com wrote:
Chris wrote:
I know this probably seems trivial, but I can't seem to find the bug in
my alphabeta search implementation.

This is another alphabeta implementation (all the nicest algorithms are
inside this AIMA codebase):
http://aima.cs.berkeley.edu/python/games.html

Later when you program works you can find this helpful to improve your
algorithm:
http://citeseer.ist.psu.edu/11954.html
Thanks. I actually already knew about the AIMA implementation, and used
that and an alternative version on wikipedia to fix my code. It turns
out my heuristic_value function was incorrect. I've also managed to get
it working with a transposition table, which has really sped things up.

Jan 13 '07 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: R. Rajesh Jeba Anbiah | last post by:
Q: Is PHP search engine friendly? Q: Will search engine spiders crawl my PHP pages? A: Spiders should crawl anything provided they're accessible. Since, nowadays most of the websites are been...
10
by: Anand Pillai | last post by:
To search a word in a group of words, say a paragraph or a web page, would a string search or a regexp search be faster? The string search would of course be, if str.find(substr) != -1:...
1
by: Les Juby | last post by:
A year or two back I needed a search script to scan thru HTML files on a client site. Usual sorta thing. A quick search turned up a neat script that provided great search results. It was fast,...
5
by: George | last post by:
Hi, Anyone has the background for explaining? I have made a search on my name and I have got a link to another search engine. The link's title was the search phrase for the other search engine...
39
by: Noticedtrends | last post by:
Can inference search-engines narrow-down the number of often irrelevant results, by using specific keywords; for the purpose of discerning emerging social & business trends? For example, if...
28
by: joshc | last post by:
If I have an array of data that I know to be sorted in increasing order, and the array is less than 50 elements, and I want to find the first element greater than a certain value, is a simple...
4
by: BenCoo | last post by:
Hello, In a Binary Search Tree I get the error : Object must be of type String if I run the form only with the "Dim bstLidnummer As New BinarySearchTree" it works fine. Thanks for any...
1
Merlin1857
by: Merlin1857 | last post by:
How to search multiple fields using ASP A major issue for me when I first started writing in VB Script was constructing the ability to search a table using multiple field input from a form and...
0
by: passion | last post by:
"Specialized Search Engines" along with Google Search Capability (2 in 1): http://specialized-search-engines.blogspot.com/ Billions of websites are available on the web and plenty of extremely...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.