Xt = Xtmp: Yt = Ytmp
For i = 1 To 4 - Count '计算前面的相反方向
ExitFor = True
Xt = Xtmp + i * XInt: Yt = Ytmp + i * YInt
If Xt < 1 Or Xt > 15 Or Yt < 1 Or Yt > 15 Then RB = True: Exit For
If PieceTar(Xt, Yt) = Flag Then PieceNum = PieceNum + 1
If PieceTar(Xt, Yt) = IIf(Flag = 1, 2, 1) Then RB = True: Exit For
If PieceTar(Xt, Yt) = 0 Then
Xt = Xt + XInt: Yt = Yt + YInt
If Xt < 1 Or Xt > 15 Or Yt < 1 Or Yt > 15 Then RB = False: Exit For
If PieceTar(Xt, Yt) = 0 Then RB = False: Exit For
If PieceTar(Xt, Yt) = Flag Then EmptyNum = EmptyNum + 1
If PieceTar(Xt, Yt) = IIf(Flag = 1, 2, 1) Then RB = False: Exit For
End If
ExitFor = False
Next i
If ExitFor = False Then
Xt = Xt + XInt: Yt = Yt + YInt
If Xt < 1 Or Xt > 15 Or Yt < 1 Or Yt > 15 Then
RB = True
ElseIf PieceTar(Xt, Yt) = 0 Then RB = False
ElseIf PieceTar(Xt, Yt) = IIf(Flag = 2, 1, 2) Then RB = True
End If
End If
LBlock(ArrNum) = LB: RBlock(ArrNum) = RB: Value = IIf(EmptyNum = 0, 5 ^ PieceNum, 5 ^ PieceNum - 5 ^ EmptyNum)
EmptyNumE(ArrNum) = EmptyNum
'左右状态赋值给其相应的记录数组;并将分值赋给相应记分数组
ScoreE(ArrNum) = IIf(RB, IIf(LB, 1, Value / 2), IIf(LB, Value / 2, Value))
JudgeLineNum = PieceNum '返回最大共线子数
End Function
在单线棋形判断函数的基础上,可评估某点综合棋局情况时多重方向上的棋形叠加。如前所述,用冒泡排序法选出两种最优单线棋形得分;这样做在不改变程序核心的权重估值算法的前提下很大程度上提高了程序执行效率。以下为多线棋形评估函数:
Public Function DoGen(ByRef PieceTar() As Integer, ByVal Xt%, ByVal Yt%, ByVal Flag As Byte) '棋局综合情况评估函数
PieceNum(1) = JudgeLineNum(Piece, Xt, Yt, 1, 0, 1, Flag)
'在调用函数进行数组赋值时可以同时进行返回值处理
PieceNum(2) = JudgeLineNum(Piece, Xt, Yt, 1, 1, 2, Flag)
PieceNum(3) = JudgeLineNum(Piece, Xt, Yt, 0, 1, 3, Flag)
PieceNum(4) = JudgeLineNum(Piece, Xt, Yt, -1, 1, 4, Flag)
Call ArraySort(ScoreE, PieceNum, EmptyNumE, LBlock, RBlock)
'调用数组排序函数对得分数组进行排序
If (LBlock(1) = False And RBlock(1) = False) And (LBlock(2) = False And LBlock(2) = False) And PieceNum(1) = 4 And PieceNum(2) = 4 Then _
DoGen = FFDL: Exit Function '如果双活四则返回双活四得分
|