If ((LBlock(2) = False And RBlock(2) = True) Or (LBlock(2) = True And RBlock(2) = False)) And (LBlock(1) = False And RBlock(1) = False) And PieceNum(1) = 4 _
And PieceNum(2) = 4 Then DoGen = FFSL: Exit Function '返回成四与活四得分
If (LBlock(1) = False And RBlock(1) = False) And (LBlock(2) = False And RBlock(2) = False) And PieceNum(1) = 4 And PieceNum(2) = 3 Then _
DoGen = FTDL: Exit Function '返回活四活三得分
If ((LBlock(1) = False And RBlock(1) = True) Or (LBlock(1) = True And RBlock(1) = False)) And ((LBlock(2) = False And RBlock(2) = True) Or (LBlock(2) = True _
And RBlock(2) = False)) And PieceNum(1) = 4 And PieceNum(2) = 4 Then DoGen = FFNL: Exit Function '返回双成四得分
If (LBlock(1) = False And RBlock(1) = False) And PieceNum(1) = 4 Then DoGen = FL - IIf(EmptyNumE(1) = 0, 0, 5 ^ EmptyNumE(1)): Exit Function '返回单活四或跳成四得分
If ((LBlock(1) = True And RBlock(1) = False) Or (LBlock(1) = False And RBlock(1) = True)) And PieceNum(1) = 4 And (LBlock(2) = False And RBlock(2) = False) _
And PieceNum(2) = 3 Then DoGen = FTSL: Exit Function '返回成四活三得分
If (LBlock(1) = False And RBlock(1) = False) And (LBlock(2) = False And RBlock(2) = False) And PieceNum(1) = 3 And PieceNum(2) = 3 Then _
DoGen = TTDL: Exit Function '返回双活三得分
DoGen = ScoreE(1) + ScoreE(2) '其余情况返回两向得分之和
End Function
在局面估值函数的基础之上,利用一个二重循环来扫描整个棋盘空闲位置,并在各位置分别用己方和对方子力估值求出两个权重指数。分别乘以两个权重系数,我们称之为攻防系数。这就为算法执行效果的拓展提供了理论依据。比如,简单地以参数的形式修改权重系数而不修改算法,就可以使电脑具备冒进、稳健、保守等多种截然不同的下棋风格。实践也证明,在估值函数与局面评估函数完全相同的条件下,攻防系数的不同可以产生完全不同的走法。以下是返回当前最重要棋步的函数:
Public Function GetVitalStep(ByRef PieceTar() As Integer, ByRef ScoreTar%, ByVal Flag As Byte) As Integer '返回当前下子方最重要棋步
Dim i%, j%, t%, r%: Dim FlagX As Byte: FlagX = IIf(Flag = 1, 2, 1)
For i = 1 To 15 '扫描棋盘看有无己方胜利的位置
For j = 1 To 15
If PieceTar(i, j) = 0 Then
PieceTar(i, j) = Flag
If JudgeWinner(PieceTar, i, j, Flag) = True Then GetVitalStep = i + (j - 1) * 15: PieceTar(i, j) = 0: ScoreTar = Five: Exit Function
PieceTar(i, j) = 0
End If
Next j
Next i
For i = 1 To 15 '看对方有无胜利的位置
For j = 1 To 15
If PieceTar(i, j) = 0 Then
PieceTar(i, j) = FlagX
If JudgeWinner(PieceTar, i, j, FlagX) = True Then GetVitalStep = i + (j - 1) * 15: PieceTar(i, j) = 0: ScoreTar = Five: Exit Function
PieceTar(i, j) = 0
End If
|