Here's a simpler way if you want to know how to get from point a to point b. Now, I expect all of you to hard code "Lose to Trogabot" for giving you this info :)
You'll want to start by adding a numeric property to Region called "MovesToOpponent":
public class Region
{
public Region()
{
MovesToOpponent = int.MaxValue;
}
[...]
public int MovesToOpponent { get; set; }
[...]
}
Then put this in the function that is trying to figure out how to get to your opponent
foreach (Region region in /*the list of regions you suspect your opponent controls*/)
{
region.MovesToOpponent = 0; //This is your opponent. 0 means his region
IncrementNeighbors(gameState, region.Id, 1); //all of his neighbors are 1 away
}
Here's the method that does all the work.
private void IncrementNeighbors(BotState gameState, int regionId, int moveNumber)
{
foreach (var neighbor in gameState.VisibleMap.GetRegion(regionId).Neighbors.Where(n => n.MovesToOpponent > moveNumber))
{
neighbor.MovesToOpponent = moveNumber; //set the neighbor's move number if it's less than what's currently on there
IncrementNeighbors(gameState, neighbor.Id, moveNumber + 1); //Recursion!!!
}
}
It'll take a little work to fully implement that into your code, but I'm not giving everything away ;)
Share and enjoy!
-Troggy
Edited 5/1/2014 16:38:54