public void TestFindEdges()
		{
			var edgeDetection = new EdgeDetectionAlgorithm();
			var points = edgeDetection.GetEdgePoints(_map);

			var edges = edgeDetection.GroupToEdges(points);

			Assert.IsTrue(edges.Count() == 3);
		}
Exemplo n.º 2
0
		private void CalculateNextTarget()
		{
		    Point startFrom = LastValidPoint ?? _robot.StartPosition;

            DebugHelper.StoreAsBitmap(string.Format("C:\\debugMinimap-{0}.png", DateTime.Now.Ticks), _mapExplored.Map);

			_waypointQueue.Clear();
			List<Point> route = null;
			var DijkstraHelper = new DijkstraHelper(_mapExplored);

			var goal = GetGoalPoint();
			if (goal != null)
			{
                route = DijkstraHelper.GetPath(startFrom, goal, _pathLog);
			}

			if (route == null || !route.Any())
			{
				EdgeDetectionAlgorithm edgeDetection = new EdgeDetectionAlgorithm();

				var edges = edgeDetection
                                .GroupToEdges(edgeDetection.GetEdgePoints(_mapExplored.Map))
                                .OrderByDescending(edge => edge.Width)
                                .ToList();

               foreach (var edge in edges)
			   {

                   var path = DijkstraHelper.GetPath(startFrom, edge.CenterPoint, _pathLog);
					if (path != null && path.Any())
					{
						route = path;
						break;
					}
				}
			}

			if (route != null && route.Any())
			{
				route.ForEach(wp => _waypointQueue.Enqueue(wp));
			}
			else
			{
                SimulationEngine.EndSimulation("Robot stuck!");
				//throw new ApplicationException("No further valid edges or target found!");
			}
		}
		public void TestFindEdgePoints()
		{
			var edgeDetection = new EdgeDetectionAlgorithm();
			var points = edgeDetection.GetEdgePoints(_map);

			Assert.IsTrue(points.Contains(new Point { X = 0, Y = 2 }));
			Assert.IsTrue(points.Contains(new Point { X = 1, Y = 3 }));

			Assert.IsTrue(points.Contains(new Point { X = 3, Y = 3 }));
			Assert.IsTrue(points.Contains(new Point { X = 4, Y = 3 }));

			Assert.IsTrue(points.Contains(new Point { X = 0, Y = 7 }));
			Assert.IsTrue(points.Contains(new Point { X = 1, Y = 6 }));
			Assert.IsTrue(points.Contains(new Point { X = 2, Y = 5 }));
			Assert.IsTrue(points.Contains(new Point { X = 3, Y = 5 }));
			Assert.IsTrue(points.Contains(new Point { X = 4, Y = 5 }));
		}