Game Development Reference
Hounds2() in the Public Interface region to Fox1() and Hounds1() . The look-
ahead AI code here has numerous debug statements, not all of which are com-
mented out. All of them are there to aid in debugging the code, so feel free to
uncomment them if things go wrong.
This look-ahead implementation uses recursion. Recursion is when a routine
directly or indirectly calls itself. ''My best move depends on their countermove,
which depends on the best move I can take after that,'' involves recursion. Notice
that ''best move'' is mentioned twice. Our AI will call itself when looking ahead.
The limit on search depth or the use of a heuristic will stop the chain from going
Our AI has two parts each for the fox and for the hounds. The first part is asked to
pick a move from its available moves. It does this by examining the expected
outcomes of each of the moves. In the code, you will see this in terms of the best
current move being based on the best future result. The basic request of ''give me
your best move'' has the code looking ahead with each of the possible moves to
decide what is best. That is to say that for every candidate move, there is a future
result that can be used to rank the candidates. We can use game state for both the
candidates and the results.
Since the same code is used to generate both moves and results, we will need to
make sure that the program returns the appropriate one. When the outside world
calls, it wants the move, not the result. When the fox is looking ahead to consider
a candidate move, it will want a countermove from the hounds, not results.
When the fox looks ahead for how well things turn out after the hounds take their
countermove, the fox wants results.
Connecting the UI to the AI
The first task will be to add code for the Fox and Hounds buttons on the board.
Switch to the Board.vb tab in the editor and add the following code to the class. It
will generate errors that we will fix shortly.
'Move the fox.
Private Sub FoxButton_Click(ByVal sender As System.Object, _
ByVal e As System.EventArgs) Handles FoxButton.Click
'Give the user an hourglass.
Me.Cursor = Cursors.WaitCursor
'Do some performance measurements.
Dim startTime As Date = Now
'Take an actual move.