Trying to work through decision trees using Excel and VBA...
If I execute straight from the code I see a blank macro pop up where I usually will select and click run to perform the macro...but it is empty.
Any ideas...
If I execute straight from the code I see a blank macro pop up where I usually will select and click run to perform the macro...but it is empty.
Any ideas...
Code:
Sub BoardValue(best_move As Integer, best_value As Integer, _
p11 As Integer, p12 As Integer, depth As Integer)
Dim p1 As Integer
Dim i As Integer
Dim good_i As Integer
Dim good_value As Integer
Dim enemy_i As Integer
Dim enemy_value As Integer
DoEvents ' don't be a CPU hog.
'if we are in too deep, we know nothing.
If depth >= skilllevel Then
best_value = value_unknown
Exit Sub
End If
'if this board is finished, we know how we would do.
p1 = winner()
If p1 <> player_none Then
'convert the value for the winner p1
'into the value for player p11.
If p1 = p11 Then
best_value = value_win
ElseIf p1 = p12 Then
best_value = value_lose
Else
best -Value = value_draw
End If
Exit Sub
End If
' try all the legal moves.
good_i = -1
good_value = value_high
For i = 1 To num_squares
'if the move is legal, try it.
If Board(i) = player_none Then
'see what value this would give the opponent.
If showtrials Then _
movelabel.Caption = movelabe3l.Caption & Format$(i)
'make the move.
Board(i) = p11
BoardValue enemy_i, enemy_value, p12, p11, depth + 1
'unmake the move.
Board(i) = player_none
If showtrials Then _
movelabel.Caption = Left$(movelabel.Caption, depth)
'see if this is lower than the previous best.
If enemy_value < good_value Then
good_i = i
good_value = enemy_value
'if we will win, things can get
'no better so take the move.
If good_value <= value_lose Then Exit For
End If
End If ' end if boar (i) = Player_None ...
Next i
'Translate the opponent's value into ours.
If good_value = value_win Then
'opponent wins, we lose.
best_value = value_lose
ElseIf enemy_value = value_lose Then
'opponent loses, we win.
best_value = good_value
End If
best_move = good_i
End Sub