예제 #1
0
파일: MapFile.cs 프로젝트: r3db/Vlcr
 // Done!
 private static void RemakeConnectors(ConcreteMap map, IList <XmlNodeReference> con)
 {
     for (int i = 0; i < con.Count; ++i)
     {
         var xnr        = con[i];
         var parentNode = map.FindByName(xnr.Parent);
         var exit       = new MapNode(NodeType.Exit)
         {
             Location = xnr.Location, Parent = parentNode
         };
         exit.Exits.Add(map.FindByName(xnr.Pointer));
         parentNode.Exits.Add(exit);
     }
 }
예제 #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);
        }