Game Development Reference
theField.MoreThoughts(Me.GetType.Name & " sees " & _
SquaresList.Count.ToString & " safe squares to click.")
'Tell the framework how many moves
This code will depend on a routine in AI.vb that we have not written yet. The
important point here is that the rule asks the squares directly adjacent to the
revealed square for help. For most squares, that will be eight surrounding
squares, and the NearNeighbor function finds them. We store them in the
CloseNeighbors collection. Everything else in this routine is generic. Now we turn
to AI.vb to implement the matcher. Add the following code to AI.vb:
'This function does the work for two rules
'This code tries to use a helper to help find moves
'Two byRef parameters
Public Sub TwoSquareMatcher(ByVal RevealedSquare As Square, _
ByVal Helpers As Collection, _
ByRef SimonSays As BasicRule.PossibleActions, _
ByRef SquaresList As Collection)
'Clear the list of proposed moves in case we do not find any
'We should be part of a playing field
Dim theField As PlayingField = RevealedSquare.Parent
'Get the basic data of the revealed square
'Who is around me?
Dim Neighbors As Collection = theField.NearNeighbors(RevealedSquare.R, _
'We keep a bunch of numbers:
'How many mines do we see?
Dim sees As Integer = 0
'And how many flags are around us?
Dim flags As Integer = 0
'And how many blanks are around us?