Game Development Reference
In-Depth Information
'Compare us to existing moves.
Dim i As Integer
Dim GS As GameState
For i = 1 To SortedMoves.Count
GS = CType(SortedMoves(i), GameState)
'Smallest first.
If NewGS.GameRank < GS.GameRank Then
'Add it here and we are done.
SortedMoves.Add(NewGS, Nothing, i)
Return
End If
Next
'Add it at the end.
SortedMoves.Add(NewGS)
End Sub
#End Region
Recall the discussion of the evaluation function and how sometimes we want to
use rank and sometimes we want to use how fast something happens. Evaluating
the moves by rank alone gives the results we saw in Figures 6.7-6.9. As mentioned
in the sidebar, that code is on the CD as AI.V5.vb. The final version of a better
move is simpler than the intermediate versions. Let us add code for the fox to the
Internal Stuff region:
Private Function BetterFoxMove(ByVal Result As GameState, _
ByVal BetterThan As GameState) As Boolean
'Anything is better than nothing.
If BetterThan Is Nothing Then Return True
'Smaller rank is better for fox.
'For good moves, take the earlier one.
If Result.GameRank < UNREACHABLE _
And BetterThan.GameRank < UNREACHABLE Then
'Settle good moves by time.
If Result.MoveCount < BetterThan.MoveCount Then
Debug.WriteLine("Fox: Result of " & Result.GameRank.ToString & _
" is better than " & BetterThan.GameRank.ToString)
Return True
Else
'If need be, add a debug statement here.
End If
Search Nedrilad ::




Custom Search