Author: Edward Seid
Date: 08:49:20 09/29/03
Writing in VB.NET. Nearly everyone codes in C, but I hope someone can verify
the correctness of my algorithm.
I've read various websites and papers about alpha-beta pruning and it seems that
every pseudocode I've seen, though 95% similar, differs in some detail, whether
it be the order of statements, naming conventions, or initialization of some
variables.
So I'll post my VB.NET procedure, in hopes that someone can tell me if it is
correct or not. Thanks in advance.
---------------------
Const NEGATIVEINFINITY as Integer = -2147483647
Const POSITIVEINFINITY as Integer = 2147483647
' the board array is a 10x12 mailbox representation
Public board as Integer() = New Integer(119) {}
Public epSquare, sideToMove as Integer
' The first call to the AlphaBeta subroutine is like this:
' bestScore = AlphaBeta(depth, NEGATIVEINFINITY, POSITIVEINFINITY)
Function AlphaBeta(ByVal deep As Integer, ByVal alpha As Integer, ByVal beta As
Integer) As Integer
Dim possibleMoves As Integer(,)
Dim index, width As Integer
Dim score As Integer
If deep = 0 Then
Return Evaluate()
End If
possibleMoves = GenerateMoves()
' get the width, which is hidden in an unused 4th column in possibleMoves
array
' the first 3 columns (0-2) of possibleMoves are from, to, enpassanttarget
width = possibleMoves(0, 3)
possibleMoves(0, 3) = 0
If width = 0 Then
Return Evaluate()
End If
For index = 0 To width - 1
MakeMove(possibleMoves(index, 0), possibleMoves(index, 1),
possibleMoves(index, 2))
nodeCount += 1
score = -AlphaBeta(deep - 1, -beta, -alpha)
UnmakeMove(moveStack(ply, 0), moveStack(ply, 1), moveStack(ply - 1, 2))
' The following lines are what I need feedback on... are they correct?
If alpha >= beta Then
Return alpha
End If
If score > alpha Then
alpha = score
End If
Next
Return alpha
End Function ' AlphaBeta
This page took 0.01 seconds to execute
Last modified: Thu, 15 Apr 21 08:11:13 -0700
Current Computer Chess Club Forums at Talkchess. This site by Sean Mintz.