class find_path
{
public static int bfs(int[] start, int[] end,List<List<int>> board)
{
List<List<int>> Visited = new List<List<int>>();
Queue<List<int> > queue = new Queue<List<int>>();
Visited.Add(start.ToList());
queue.Enqueue(start.ToList());
while (queue.Count > 0)
{
var x = queue.Dequeue();
List<int[]> possiblePositions = new List<int[]>();
possiblePositions.Add(new int[] {x[0]-1, x[1], x[2]+1});
possiblePositions.Add(new int[] {x[0]-1, x[1]-1, x[2]+1});
possiblePositions.Add(new int[] {x[0]-1, x[1]+1, x[2]+1});
possiblePositions.Add(new int[] {x[0]+1, x[1]-1, x[2]+1});
possiblePositions.Add(new int[] {x[0]+1, x[1], x[2]+1});
possiblePositions.Add(new int[] {x[0]+1, x[1]+1, x[2]+1});
possiblePositions.Add(new int[] {x[0], x[1]+1, x[2]+1});
possiblePositions.Add(new int[] {x[0], x[1]-1, x[2]+1});
foreach (int[] position in possiblePositions)
{
if (position[0] > -1 && position[0] < 8 && position[1] > -1 && position[1] < 8)
{
if (board[position[0]][position[1]] == 2)
{
return position[2];
}
if (board[position[0]][position[1]] != 1)
{
if (!Visited.Contains(position.Take(2).ToList()))
{
queue.Enqueue(position.ToList());
Visited.Add(position.Take(2).ToList());
}
}
}
}
}
return -1;
}
}
class find_path
{
public static int bfs(int[] start, int[] end,List<List<int>> board)
{
List<List<int>> Visited = new List<List<int>>();
Queue<List<int> > queue = new Queue<List<int>>();
Visited.Add(start.ToList());
queue.Enqueue(start.ToList());
while (queue.Count > 0)
{
var x = queue.Dequeue();
List<int[]> possiblePositions = new List<int[]>();
possiblePositions.Add(new int[] {x[0]-1, x[1], x[2]+1});
possiblePositions.Add(new int[] {x[0]-1, x[1]-1, x[2]+1});
possiblePositions.Add(new int[] {x[0]-1, x[1]+1, x[2]+1});
possiblePositions.Add(new int[] {x[0]+1, x[1]-1, x[2]+1});
possiblePositions.Add(new int[] {x[0]+1, x[1], x[2]+1});
possiblePositions.Add(new int[] {x[0]+1, x[1]+1, x[2]+1});
possiblePositions.Add(new int[] {x[0], x[1]+1, x[2]+1});
possiblePositions.Add(new int[] {x[0], x[1]-1, x[2]+1});
foreach (int[] position in possiblePositions)
{
if (position[0] > -1 && position[0] < 8 && position[1] > -1 && position[1] < 8)
{
if (board[position[0]][position[1]] == 2)
{
return position[2];
}
if (board[position[0]][position[1]] != 1)
{
if (!Visited.Contains(position.Take(2).ToList()))
{
queue.Enqueue(position.ToList());
Visited.Add(position.Take(2).ToList());
}
}
}
}
}
return -1;
}
}