Game Development Reference
In-Depth Information
the name of the button to BookButton and the text to AI Book . Set the enabled
property to false. (Figure 7.6 shows the button in place.) Then switch back to the
Code view and add the following code:
Private Sub BookButton_Click(ByVal sender As System.Object, _
ByVal e As System.EventArgs) Handles BookButton.Click
'Make sure the topic button gets enabled and disabled.
FirstThought("Executing from the topic of moves (could be risky!)")
Call ExecuteBook()
End Sub
All that remains is a few details. Add the following line of code to the EndGame()
BookButton.Enabled = False
Add the following line of code to NewGame():
BookButton.Enabled = True
Now we are ready to test. Run the code and start an expert-level game. Click the
AI Book button until the AI hits a mine or until it successfully executes a second
move. Let the regular AI take over if it can. If the regular AI gets stumped, go back
to the AI Book button.
With a new game, see if you can click the AI Book button enough times that the
AI runs out of book moves to attempt before it hits a mine. This may require you
to run a large number of failed games before it happens. This illustrates why we
did not add all the possible combinations to the collections; it will be rare to
exhaust them all without gaining some traction for the regular AI. This can be
seen in Figure 7.6. Note the every-other pattern you get on the top row. The topic
of moves won't attempt adjacent squares, so it skips a square. If the topic finally
gets in a second move, this every-other pattern gives the regular AI a fighting
chance to make additional moves via RuleTwoFar in the regular AI.
Our hybrid AI has a reasonable opening book and a very solid rule-base for
general play, but it lacks an endgame AI. Endgame in Minesweeper often boils
down to, ''You have to make N fifty-fifty guesses to complete this board.'' Our
code demonstrates how a book of moves can provide a powerful adjunct to a
good AI, but there is no book of moves, and there are no general rules that will
help when it comes down to just guessing.
Search Nedrilad ::

Custom Search