Game Development Reference
In-Depth Information
square's private blanks, however, because those squares are where we will make
our moves if we find any.
We loop through the original square's blanks, checking them against the helper's
blanks. We count the common blanks and store the private blanks. When we are
done, we look at the numbers. Without common blanks, the helper cannot feed
the original square any new information. Without private blanks, the original
square has no moves to make. If there are common blanks but no private blanks,
the original square might be a good candidate to help the helper square, but we do
not pursue that. The user told the AI to look for moves for the original square.
We are finally ready to compute the numbers. We compute the minimum com-
mon mines and clear (safe) squares among the common blank squares as seen by
the helper. We start with the number of mines they see and decrement that count
by any flags they see since they may know where some of their mines are. We then
decrement by the number of private blanks that could hide mines to determine
their view of the minimum number of mines in the shared blank squares. Then we
make similar computations for the minimum number of clear squares, starting
with the blanks they see and decrementing that by the number of mines they do not
know about, which is the number they see less any flags they have placed. Then we
decrement again by their private blanks that could be safe, and we are left with their
view of the minimumnumber of safe squares among the common blank squares. It
takes a ton of code to get to this point. Adding some Debug.Writeline statements
might be a good idea here. The output will show in the Immediate window when
you run the game in the debugger. Some error checks might be good here as well.
The minimum commonmines should not be greater than the number of mines the
original square needs to place. The minimum common clear squares should not be
greater than the number of safe squares that have to be around the original square.
If you don't think your code is working correctly, add those error checks. If you are
unsure about your code, use Debug.Writeline to display all the computed numbers
so that you can compare them to the board.
All that remains is to evaluate the quality of the numbers. The numbers could
indicate that the private squares are mines or that the private squares are safe. The
code sets the two variables passed in by reference to the correct move and to a
collection holding the proper squares.
VB does automatic garbage collection, so we do not worry about what happens to an object when
no variables point to it.
Search Nedrilad ::

Custom Search