Visual Basic Connect 4 AI Minimax

时间:2017-04-30 18:25:27

标签: vb.net artificial-intelligence minimax

我正在尝试使用Visual Basic 2008创建Connect 4,但我的启发式功能基本上导致了问题;即使深度只有3,它也需要很长时间。我试图想出一些更好的算法,但我不能。是否有更有能力和快速的启发式函数算法?

这是我的极小极大和启发式;

Function Minimax(ByVal VirtualArray As Array, ByVal node As Integer, ByVal depth As Integer, ByVal MaxPlayer As Boolean)

    Dim best As Integer = Integer.MinValue

    If depth = 0 Or Terminal(node, VirtualArray) = True Then Return Heuristic(MaxPlayer, VirtualArray)

    If MaxPlayer = True Then
        For i = 1 To 7
            best = Math.Max(Minimax(VirtualPlay(i, VirtualArray, MaxPlayer), i, depth - 1, False), best)
        Next
    Else
        For i = 1 To 7
            best = Math.Max(Minimax(VirtualPlay(i, VirtualArray, MaxPlayer), i, depth - 1, True), best)
        Next
    End If

    Return best

End Function
Function Heuristic(ByVal MaxPlayer As Boolean, ByVal VirtualArray As Array)

    Dim score As Integer = 0
    Dim Opponent As Integer

    If Player = 1 Then Opponent = 2 Else Opponent = 1

    If CheckWinner(VirtualArray, Player) = True Then Return 1000000

    Dim threes As Integer = CheckThree(VirtualArray, Player) * 50
    Dim twos As Integer = CheckTwo(VirtualArray, Player) * 10
    Dim oppThrees As Integer = CheckThree(VirtualArray, Opponent) * 50
    Dim oppTwos As Integer = CheckTwo(VirtualArray, Opponent) * 10

    score = threes + twos - oppThrees - oppTwos

    If CheckWinner(VirtualArray, Opponent) = True Then
        Return -1000000
    Else
        Return score
    End If

End Function

0 个答案:

没有答案