Game Development Reference
statement. The declaration comes right after a comment. After you comment out
the declarations, the two lines will look like the following.
'Look at the lowest steps move as our first candidate.
'Dim Candidate As GameState
Now you can run the game and test the new code using the Fox button. See how
much faster the topic move is than the look-ahead? Note that the fox stops trying
to go up when it gets to square number 8 or after eight moves have elapsed.
The opening moves for Minesweeper that we have discussed can be reduced to,
''Click a square in a particular untouched area. If you get a 1, click a particular
neighbor of that square, hoping to get a 1 or a 0.'' So our topic expects to have to
try a first move and then a second move. Our topic also expects to operate only in
places where no squares have been clicked. This is different from the rule-based
AI from Chapter 4 that operates only on revealed squares. This gives us two
reasons not to use the existing rule-based framework for our new code. The first
reason is that the existing framework doesn't work with blank squares. The
second reason is that we do not want the general AI to make risky moves unless
the player directly tells it to. Since the topic of moves is small and reasonably
simple, we will just use some hard-coded AI. Just because a book of moves often
fits very well into a rule-based approach does not mean that it always has to be
implemented that way.
Open your Minesweeper project from Chapter 4. The code on the CD has an AI
Auto button, and we will see it in Figure 7.6. The AI Auto button is very handy.
After every book move, you should click the AI Auto button to make sure that
you take any risk-free moves before going back to the topic. The bulk of our code
is in three routines. We need a first move routine, a second move routine, and
something to execute them. We will put the move routines in the file AI.vb. Open
that file and add the following code just above the End Module statement:
#Region "Book of Moves Code"
Public Function BookFirstMove(ByVal FirstSq As Square, _
ByVal SecondSq As Square, ByVal theField As PlayingField) As Integer
'Did somebody already click first move?
If FirstSq.IsRevealed Then Return 0