Game Development Reference
In-Depth Information
first move again. We don't want to take the first move if somehow somebody has
already clicked the second move or marked the second move as being a mine. The
code checks for the second square's text, instead of checking to see if it is revealed.
If it is revealed with no text, that means it is a zero square, and we should let the
regular AI take the first move since it is free. If the second move has text, that text
is either a number or a flag marker, both of which we want to avoid. For the same
reason, we want all the surrounding squares not to have been clicked. We are
hoping the first move reveals a 1, and for the sake of the second move we want the
maximum number of squares to be available to hold that one mine, minimizing
the chances that the second move is the one holding it. If the square meets all our
needs, we click it (and hope).
The first move is a risky move that usually does not tell us a whole lot. The second
move is likewise risky, but hopefully it tells us something useful. Add the fol-
lowing code to the same region:
Public Function BookSecondMove(ByVal FirstSq As Square, _
ByVal SecondSq As Square, ByVal theField As PlayingField) As Integer
'Take the second move if the first move looks good.
'First move has to have revealed a minimally risky number.
If FirstSq.Text <> "1" Then Return 0
'First square needs eight unclicked neighbors.
Dim Sq As Square
For Each Sq In theField.NearNeighbors(FirstSq.R, FirstSq.C)
If Sq.IsRevealed() Then Return 0
Next
'First move was perfect, attempt the second move.
theField.MoreThoughts("Book Second Move attempting R" & _
SecondSq.R.ToString & " C" & SecondSq.C.ToString)
Call SecondSq.LeftClick()
'We took one move.
Return 1
End Function
The second move code has the same idea: Make numerous checks and, if they
pass, take the second move. The first move has to have shown a 1. The sur-
rounding squares have not been revealed, so the one mine has the lowest
probability of being on the second move's square. If that is the case, the second
move is worth taking. Now we need to code to execute these first and second
moves.
Search Nedrilad ::




Custom Search