Game Development Reference
In-Depth Information
Return (Fox)
End Function
For the hounds, we will return a copy of the game state's array holding the
locations of all of the hounds. Add the following code to the Public Methods region:
'Where are the hounds?
Public Function HoundsAt() As Integer()
'Create a new array.
Dim Locations(3) As Integer
Dim i As Integer
'Fill that array from our private copy.
Fori=0To3
Locations(i) = Hounds(i)
Next
'Return that array to protect our private copy.
Return Locations
End Function
To be a valid move, the target square has to be open. If it has a checker on it, it is
blocked. We could use the FoxAt() and HoundsAt () functions, but the code is
easier to read if we can just ask the game state if a checker is on a given square.
Add the following code to the Public Methods region:
'Is some square occupied?
Public Function HasChecker(ByVal ss As Integer) As Boolean
'Is the fox there?
If ss = Fox Then Return True
Dim i As Integer
'Is one of the hounds there?
Fori=0To3
If ss = Hounds(i) Then Return True
Next
Return False
End Function
While we are in the Public Methods , we will add some code that the AI will need.
Other code might want to know these things, but the AI has to be able to get to
them. Add the following code to the Public Methods region:
'Fox wants 0, Hounds want TRAPPED (127).
Public Function GameRank() As Integer
Return Rank
End Function
Search Nedrilad ::




Custom Search