Game Development Reference
In-Depth Information
#Region "With Lookahead"
Private Function Fox2(ByVal GS As GameState, ByVal depth As Integer, _
ByVal WantMove As Boolean) As GameState
'Move to lowest steps square if I have one.
'I'm not moving if I already won or lost.
If GS.GameRank = 0 Or GS.GameRank = TRAPPED Then
Debug.WriteLine("Fox2: Game already over, not moving.")
Return GS
End If
'Get my potential moves.
Dim ss As Integer
Dim SortedMoves As New Collection
'The fox can move to any neighbor . . .
For Each ss In Moves.Neighbors(GS.FoxAt)
'...that is not blocked.
If Not GS.HasChecker(ss) Then
'We have a potential move, represented by its game state.
'Store it in the sorted list.
AddGameStateKeepSorted(GS.ProposeFoxTo(ss), SortedMoves)
End If
Next
'If I can't move, return the existing game.
'This should never happen since it means I'm trapped
'but it protects the rest of the code that follows.
If SortedMoves.Count = 0 Then
Debug.WriteLine("#########################"&_
"Fox2: not trapped, but no candidates.")
Return GS
End If
'Look at the lowest steps move as our first candidate.
Dim Candidate As GameState
Candidate = CType(SortedMoves(1), GameState)
'Is freedom reachable?
If GS.GameRank < UNREACHABLE Then
'I need to win - for now, follow shortest path.
'This means fox never looks ahead when hounds
'have to look ahead.
Search Nedrilad ::




Custom Search