Пример #1
0
        // Done!
        private void FindPath(VisualMapNode vStart, VisualMapNode vClose)
        {
            if (vStart == null)
            {
                MessageBox.Show("Invalid Start MapNode");
                return;
            }

            if (vClose == null)
            {
                MessageBox.Show("Invalid Goal MapNode");
                return;
            }

            this.ClearPathSelection();

            var start = vStart.ConcreteNode;
            var close = vClose.ConcreteNode;

            var startStub = MapNode.ToVirtual(start, Vector.Average(start.Geometry));               // Change to Exact Location
            var closeStub = ConcreteMap.AdaptNodeToGoal(close, Vector.Average(close.Geometry));     // Change to Exact Location

            if (this.cognitive.Checked == true)
            {
                ICognitiveStateSearchable <MapNode> iss = new CognitiveAStar <MapNode>(startStub, closeStub, this.agentCharacter);
                iss.FindPath();

                var path = iss.Path;
                path.Add(closeStub.Clone());
                //FillGeometryPath(map, path);
                this.ForceParentUpdate(path);
            }
            else
            {
                IStateSearchable <MapNode> iss = new AStar <MapNode>(startStub, closeStub);
                iss.FindPath();

                var path = iss.Path;
                path.Add(closeStub.Clone());
                //FillGeometryPath(map, path);
                this.ForceParentUpdate(path);
            }



            ConcreteMap.RestoreNodeFromGoal(close);
        }
Пример #2
0
        // Done!
        private static void TestPathHelper(ConcreteMap map, bool cognitive, string startNode, string closeNode, bool solution, int count)
        {
            MapNode start = map.FindByName(startNode);
            MapNode close = map.FindByName(closeNode);

            var startStub = MapNode.ToVirtual(start, Vector.Average(start.Geometry));
            var closeStub = ConcreteMap.AdaptNodeToGoal(close, Vector.Average(close.Geometry));

            Assert.AreNotEqual(start, null);
            Assert.AreNotEqual(close, null);

            Assert.AreNotEqual(startStub, null);
            Assert.AreNotEqual(closeStub, null);

            IList <MapNode> path;

            if (cognitive == true)
            {
                ICognitiveStateSearchable <MapNode> iss = new CognitiveAStar <MapNode>(startStub, closeStub, AgentCharacter.Default);
                iss.FindPath();
                Assert.AreEqual(solution, iss.HasSolution);
                Assert.AreEqual(count, iss.Path.Count);
                path = iss.Path;
            }
            else
            {
                IStateSearchable <MapNode> iss = new AStar <MapNode>(startStub, closeStub);
                iss.FindPath();
                Assert.AreEqual(solution, iss.HasSolution);
                Assert.AreEqual(count, iss.Path.Count);
                path = iss.Path;
            }

            path.Add(closeStub);
            foreach (var item in path)
            {
                Console.WriteLine(item.ToString());
            }
            Console.WriteLine(new string('-', 70));

            ConcreteMap.RestoreNodeFromGoal(close);
        }