Game Development Reference
In-Depth Information
If bestRule IsNot Nothing Then
theField.MoreThoughts("
Executing " & bestRule.GetType.Name)
bestRule.Execute()
Else
theField.MoreThoughts("
No good ideas found.")
End If
End Sub
Adding the Framework to the Game
The right place to create and hold a FrameWork object is in PlayingField .We
only need one copy of it, and we only need to initialize it once. We will need to
make it available to the squares so they can ask to run the AI when they get user
input. Switch to the Code view of PlayingField and add the following code to the
class just below the declarations for Field and the three Num variables. (We are
keeping this kind of data together to make it easier to find.)
'This is the AI.
Public Brains As New FrameWork
Have VB create the skeleton of the Load event handler for PlayingField . Add
code to it so that it resembles the following:
Private Sub PlayingField_Load(ByVal sender As Object, ByVal e As
System.EventArgs) Handles Me.Load
'All we have to do is load the rules IN ORDER
Brains.AddRule(New RuleOne)
End Sub
The framework is available and loaded; next, we need to call it. Return to the
MouseUp event handler in Square.vb, locate the placeholder AI code, and replace
the placeholder code, including the begin and end comments, with the following:
'Run the real AI
theField.FirstThought("Thinking about Square at Row=" & _
Row.ToString & ", Col=" & Col.ToString)
theField.Brains.RunAI(Me)
Now run the game and right-click on the revealed squares. The game plays as
expected; we are ready for another rule.
Rules for Two-Square Evaluation
The next two rules are very similar: They use the information from two revealed
squares to look for moves. These rules could be combined into a single rule, but
 
Search Nedrilad ::




Custom Search