using System.Collections.Generic;
public static List<Point> path = new List<Point>();
public static void Main(){
Random rand = new Random();
Point pointA = new Point(0,1);
Point pointB = new Point(0,5);
Circle[,] obstacles = new Circle[rows, cols];
for (int i = 0; i < rows; i++)
for (int j = 0; j < cols; j++)
obstacles[2, 3] = new Circle(1,2);
obstacles[5, 8] = new Circle(1,2);
int turns = FindPath(pointA, pointB, obstacles);
Console.WriteLine("Turns taken: " + turns);
Console.WriteLine("Path: ");
foreach (Point p in path)
Console.WriteLine("(" + p.X + ", " + p.Y + ")");
static int FindPath(Point pointA, Point pointB, Circle[,] obstacles)
Point currentPos = pointA;
Queue<Point> pointsToVisit = new Queue<Point>();
for (int x = 0; x < 10; x++)
for (int y = 0; y < 10; y++)
pointsToVisit.Enqueue(new Point(x, y));
HashSet<Point> visitedPoints = new HashSet<Point>();
while (pointsToVisit.Count > 0)
Point nextPoint = pointsToVisit.Dequeue();
if (obstacles[nextPoint.X, nextPoint.Y] != null)
visitedPoints.Add(nextPoint);
int distance = Math.Abs(nextPoint.X - currentPos.X) + Math.Abs(nextPoint.Y - currentPos.Y);
if (nextPoint.X > currentPos.X)
else if (nextPoint.Y > currentPos.Y)
else if (nextPoint.X < currentPos.X)
else if (nextPoint.Y < currentPos.Y)
if (obstacles[currentPos.X + 1, currentPos.Y] == null)
pointsToVisit.Enqueue(new Point(currentPos.X + 1, currentPos.Y));
if (obstacles[currentPos.X, currentPos.Y - 1] == null)
pointsToVisit.Enqueue(new Point(currentPos.X, currentPos.Y - 1));
if (obstacles[currentPos.X - 1, currentPos.Y] == null)
pointsToVisit.Enqueue(new Point(currentPos.X - 1, currentPos.Y));
if (obstacles[currentPos.X, currentPos.Y + 1] == null)
pointsToVisit.Enqueue(new Point(currentPos.X, currentPos.Y + 1));
public int X { get; set; }
public int Y { get; set; }
public Point(int x, int y)
public override bool Equals(object obj)
Point other = obj as Point;
return X == other.X && Y == other.Y;
public override int GetHashCode()
return X.GetHashCode() ^ Y.GetHashCode();
public int X { get; set; }
public int Y { get; set; }
public Circle(int x, int y)
public override bool Equals(object obj)
Circle other = obj as Circle;
return X == other.X && Y == other.Y;
public override int GetHashCode()
return X.GetHashCode() ^ Y.GetHashCode();