Game Development Reference
In-Depth Information
A Rule for Single-Square Evaluation
Let us create our first rule. The first rule will ask the question, ''Can I tell what
goes in the blanks surrounding a revealed square using the revealed count and the
number of flags and blanks surrounding the revealed square?'' This boils down to
two statements: If the number of flags around the revealed number equals the
revealed numbers, then any surrounding blanks must be safe. And if the number
revealed minus the number of flags is equal to the number of blanks, then any
surrounding blanks are all mines. More simply, ''These are safe because I know
all of the mines already,'' or ''Mines are all that are left.''
This rule will require that our AI find out a number of basic statistics. How many
flags surround the revealed square? How many blanks? The revealed square itself
gives the number of nearby mines. In addition to statistics, the rule will want to
know what squares around the revealed square are blanks because the action of
the rule, if it executes, will be to click them all or flag them all. It turns out that
three of our rules will need this data. It will be a lot easier to get this data if we can
get the Square objects to tell us their row and column data so that we can get their
neighbors and their key value. Add the following to the Square class:
'Let the outside world ask but not set our row
Public ReadOnly Property R() As Integer
Get
Return Row
End Get
End Property
'Let the world ask our column, too
Public ReadOnly Property C() As Integer
Get
Return Col
End Get
End Property
Since many rules will need the basic data, we should place the code for it in a
separate file where all rules can get to it. Add a module to the project (similar to
adding a class) and name it AI.vb. Then add the following code:
'Note the three ByRef parameters - we write to them
Public Function BasicStatsAndBlanks(ByVal RevealedSquare As Square, _
ByVal Neighbors As Collection, _
ByRef sees As Integer, ByRef flags As Integer, _
 
Search Nedrilad ::




Custom Search