Game Development Reference
In-Depth Information
Me.CurrentGame = AI.MoveFox(ThisGame)
'Show how long it took.
Debug.WriteLine("Fox move took " & HowLong(startTime) & " ms.")
'Get rid of the hourglass.
Me.Cursor = Cursors.Default
End Sub
'Move a hound.
Private Sub HoundsButton_Click(ByVal sender As System.Object, _
ByVal e As System.EventArgs) Handles HoundsButton.Click
'Give the user an hourglass.
Me.Cursor = Cursors.WaitCursor
'Get the current time for performance.
Dim startTime As Date = Now
'Make a move.
Me.CurrentGame = AI.MoveHounds(ThisGame)
'Show how long it all took.
Debug.WriteLine("Hounds move took " & HowLong(startTime) & " ms.")
'Get rid of the hourglass.
Me.Cursor = Cursors.Default
End Sub
'Do the time math and output the result.
Private Function HowLong(ByVal startTime As Date) As String
'Fix the stop time since we compute with it twice.
Dim stopTime As Date = Now
'We have to do the seconds and ms seperately . . .
Dim secs As Integer = stopTime.Subtract(startTime).Seconds
'...since the ms roll over to zero each full second.
Dim ms As Integer = stopTime.Subtract(startTime).Milliseconds
'Combine them and output the string.
Return (secs * 1000 + ms).ToString
End Function
We exploit the fact that the AI code will be passing around and returning game
state here. If the AI goes off the rails and returns a future result instead of a
current move, the board will show that future result. We do this to minimize the
amount of code; it's not generally a good idea.
The Public Interface to the AI
We are ready for a deep dive into the AI. Add a module to the project and name it
AI.vb. The first thing we will add is the public interface to the AI. It protects the
 
Search Nedrilad ::




Custom Search