首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 网络技术 > 网络基础 >

哪位高手能帮小弟我的程序写PVS(主要变例搜索)

2012-02-17 
谁能帮我的程序写PVS(主要变例搜索)各位帮帮忙了!~REM 将116、士115、士114、象113、象112、车111、车110、马109、

谁能帮我的程序写PVS(主要变例搜索)
各位帮帮忙了!~

 REM 将116、士115、士114、象113、象112、车111、车110、马109、马108、包107、包106、卒105、卒104、卒103、卒102、卒101(黑)
  REM 帅216、仕215、仕214、相213、相212、车211、车210、马209、马208、炮207、炮206、兵205、兵204、兵203、兵202、兵201(红)

  Public Function SearchFull(ByVal Cer As Byte, ByVal Steps As Integer, ByVal UpMax As Long, ByVal Alpha As Integer, ByVal Beta As Integer) As Integer

  ''Cer=1计算黑方的棋子 Cer=2计算红方的棋子 棋盘ChessBoard(90)
  ''返回分数
  Dim i As Integer, j As Integer
  Dim T As Byte, T1 As Integer, T3 As Integer, T4 As Integer ''临时变量
  Dim ChessValue As Long ''记录棋子当前落子点的分数
  Dim MaxValue As Long


  Dim Sc(scMAXDOWNPOINT) As CHESSER ''用来存储我方搜索到的每种走法

  Dim k As Integer

  n = n + 1

  MaxValue = -10000

  Steps = Steps - 1

  If Steps < 1 Then

  Return qSearch(Cer, 10, Alpha, Beta, False) ''返回估值

  Exit Function

  End If


  k = MakeMove(Sc, Cer)  

'排序程序,略过


  ''搜索找到的所有落子点(Sc数组)
  For i = 0 To k - 1

  ''落子点不能有自己的棋
  If Int(ChessBoard(Sc(i).ObjXy) / 100) <> Cer Then
  ''GetLocateValue判断落子点的分数

  T1 = CchessValue(Cer, ChessBoard(Sc(i).ObjXy), Sc(i).ObjXy)

  T3 = ChessBoard(Sc(i).InitXy) ''保存(起点的棋子)
  T4 = ChessBoard(Sc(i).ObjXy) ''(终点的棋子)

  ''如果吃到王就不再运算
  If T4 Mod 100 = 16 Then Return -9999


  ChessBoard(Sc(i).InitXy) = 0 ''移动棋子
  ChessBoard(Sc(i).ObjXy) = T3 ''试下棋


  ''如果有吃子,Eval减分
  If T4 <> 0 Then

  Eval = Eval + CchessValue(0, T4, Sc(i).ObjXy)

  End If


  Eval = -Eval : Ply = Ply + 1

  ChessValue = SearchFull(NextCer(Cer), Steps - 1, MaxValue, -Beta, -Alpha)  

  Eval = -Eval : Ply = Ply - 1


  ChessBoard(Sc(i).InitXy) = T3 ''恢复棋盘
  ChessBoard(Sc(i).ObjXy) = T4

  If T4 <> 0 Then

  Eval = Eval - CchessValue(0, T4, Sc(i).ObjXy) ''恢复Eval

  End If

  If MaxValue < ChessValue Then MaxValue = ChessValue

  End If


  '新增
  If MaxValue > Alpha Then Alpha = MaxValue


  If (MaxValue > Beta) Then Return -MaxValue

  Next i

  Return -MaxValue

  End Function

[解决办法]
Public Function SearchFull(ByVal Cer As Byte, ByVal Steps As Integer, ByVal UpMax As Long, ByVal Alpha As Integer, ByVal Beta As Integer) As Integer 

''Cer=1计算黑方的棋子 Cer=2计算红方的棋子 棋盘ChessBoard(90) 
''返回分数 
Dim i As Integer, j As Integer 
Dim T As Byte, T1 As Integer, T3 As Integer, T4 As Integer ''临时变量 
Dim ChessValue As Long ''记录棋子当前落子点的分数 
Dim MaxValue As Long 


Dim Sc(scMAXDOWNPOINT) As CHESSER ''用来存储我方搜索到的每种走法 

Dim k As Integer 
dim fFoundPv as Boolean = FALSE

n = n + 1 

MaxValue = -10000 



Steps = Steps - 1 

If Steps < 1 Then 

Return qSearch(Cer, 10, Alpha, Beta, False) ''返回估值 

Exit Function 

End If 


k = MakeMove(Sc, Cer)

'排序程序,略过 


''搜索找到的所有落子点(Sc数组) 
For i = 0 To k - 1 

''落子点不能有自己的棋 
If Int(ChessBoard(Sc(i).ObjXy) / 100) <> Cer Then 
''GetLocateValue判断落子点的分数 

T1 = CchessValue(Cer, ChessBoard(Sc(i).ObjXy), Sc(i).ObjXy) 

T3 = ChessBoard(Sc(i).InitXy) ''保存(起点的棋子) 
T4 = ChessBoard(Sc(i).ObjXy) ''(终点的棋子) 

''如果吃到王就不再运算 
If T4 Mod 100 = 16 Then Return -9999 


ChessBoard(Sc(i).InitXy) = 0 ''移动棋子 
ChessBoard(Sc(i).ObjXy) = T3 ''试下棋 


''如果有吃子,Eval减分 
If T4 <> 0 Then 

Eval = Eval + CchessValue(0, T4, Sc(i).ObjXy) 

End If 


Eval = -Eval : Ply = Ply + 1 

if fFoundPv then
SearchFull(NextCer(Cer), Steps - 1, MaxValue, -Alpha-1, -Alpha)

   if ((val > alpha) and (val < beta)) then ''检查失败 

maxvalue=-SearchFull(NextCer(Cer), Steps - 1, MaxValue, -Beta, -Alpha)

   endif
else
ChessValue = -SearchFull(NextCer(Cer), Steps - 1, MaxValue, -Beta, -Alpha)
end if

Eval = -Eval : Ply = Ply - 1 


ChessBoard(Sc(i).InitXy) = T3 ''恢复棋盘 
ChessBoard(Sc(i).ObjXy) = T4 

If T4 <> 0 Then 

Eval = Eval - CchessValue(0, T4, Sc(i).ObjXy) ''恢复Eval 

End If 

If MaxValue < ChessValue Then MaxValue = ChessValue 

End If 


'新增 
If MaxValue > Alpha Then Alpha = MaxValue 


If (MaxValue > Beta) Then Return -MaxValue 

Next i 

Return -MaxValue 

End Function
[解决办法]
If MaxValue > Alpha Then Alpha = MaxValue : fFoundPv = TRUE

热点排行