Game Development Reference
In-Depth Information
Private Sub FaHButton_DragDrop(ByVal sender As Object, _
ByVal e As System.Windows.Forms.DragEventArgs) Handles Me.DragDrop
Debug.WriteLine("DragDrop event.")
'We will need the board's game state.
Dim MainForm As Board = CType(Me.Parent, Board)
Dim GS As GameState = MainForm.CurrentGame
Dim Source As FaHButton = CType(e.Data.GetData(GetType(FaHButton)),
If Source.HoundNumber < 0 Then
'Fox moved.
MainForm.CurrentGame = GS.ProposeFoxTo(MySubscript)
'Hound moved.
MainForm.CurrentGame = GS.ProposeHoundTo(Source.HoundNumber,
End If
End Sub
Run the code and make moves for the fox and the hounds. Use the Undo button
to go backward. Make a number of moves and notice that the board colors
correctly and numbers the squares when the line is broken. Our game so far has
the same game play as a folding checkerboard and five checkers, but the inter-
activity is notably better. The coloring and numbering tells the state of the game
at a glance. This is more engaging for a human player, and it makes the game far
easier on the AI and on the AI programmer.
Adding the AI
The AI in these pages uses look-ahead. It was developed from code that used only
the heuristics. On the CD, the AI code will have both versions. The heuristics-
only AI has the hounds keeping the wall intact if they can. Without look-ahead,
they fail to know how to put it back together when broken. Likewise, the fox AI
breaks the wall by getting lucky, but once it is broken, it heads for the hole and
freedom. There were many benefits to writing the AI this way. First, it proved that
the heuristics worked as expected. Second, it provided experience at writing
code that took moves in the game framework. The heuristics-only AI is in the
No Lookahead region of the file AI.vb on the CD. If you have trouble with the
look-ahead AI, switch to the heuristics-only AI. You can do this by copying the No
Lookahead region to your AI.vb code and then changing the calls to Fox2() and
Search Nedrilad ::

Custom Search