Пример #1
0
 public void Init(int id, Vector2Int pos, Vector2Int concretePos, Vector2Int size, ConcreteMap concreteMap)
 {
     m_id                    = id;
     m_pos                   = pos;
     m_concreteMap           = concreteMap;
     m_area                  = new RectInt(concretePos, size);
     transform.localPosition = new Vector3(m_area.center.x, m_area.center.y, -0.1f);
     transform.localScale    = new Vector3(size.x, size.y, 1);
 }
Пример #2
0
        public SmoothWizard(ConcreteMap concreteMap, List<PathNode> path)
        {
            InitPath = path;
            this.concreteMap = concreteMap;

            pathMap = new Dictionary<int, int>();
            for (var i = 0; i < InitPath.Count; i++)
                this.pathMap[InitPath[i].Id] = i + 1;
        }
Пример #3
0
        // Done!
        public static void XmlRawSave(string path, ConcreteMap map, int version = 2)
        {
            switch (version)
            {
            case 1: XmlRawSaveV1(path, map); return;

            case 2: XmlRawSaveV2(path, map); return;
            }
            throw new FileLoadException("Invalid Version: " + version);
        }
Пример #4
0
        public SmoothWizard(ConcreteMap concreteMap, List <IPathNode> path)
        {
            InitialPath  = path;
            _concreteMap = concreteMap;

            _pathMap = new Dictionary <int, int>();
            for (var i = 0; i < InitialPath.Count; i++)
            {
                _pathMap[InitialPath[i].IdValue] = i + 1;
            }
        }
Пример #5
0
        // Done!
        public ConcreteMap ToConcreteMap()
        {
            ConcreteMap cm = new ConcreteMap(false);

            for (int i = 0; i < this.Count; ++i)
            {
                var node = this[i].ConcreteNode;
                cm.Add(node);
            }
            return(cm);
        }
Пример #6
0
        // Done!
        #region General

        // Done!
        public static void Save(string path, ConcreteMap map)
        {
            var fi = new FileInfo(path);

            if (fi.Extension == Constants.RawXmlMapExtension)
            {
                BinaryRawSave(path, map);
            }
            else if (fi.Extension == Constants.RawBinaryMapExtension)
            {
                XmlRawSave(path, map);
            }
        }
Пример #7
0
 // 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);
     }
 }
Пример #8
0
        public override IConcreteFunction CreateConcrete(FunnyType[] concreteTypesMap)
        {
            var res = new ConcreteMap
            {
                Name     = Name,
                ArgTypes = new[]
                {
                    FunnyType.ArrayOf(concreteTypesMap[0]),
                    FunnyType.Fun(concreteTypesMap[1], concreteTypesMap[0])
                },
                ReturnType = FunnyType.ArrayOf(concreteTypesMap[1])
            };

            return(res);
        }
Пример #9
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);
        }
Пример #10
0
        public void CreateHierarchicalMapNP(ConcreteMap concreteMap, int clusterSize, int maxLevel, EntranceStyle style)
        {
            ClusterSize     = clusterSize;
            EntranceStyle   = style;
            MaxLevel        = maxLevel;
            ConcreteMap     = concreteMap;
            HierarchicalMap = new HierarchicalMap(concreteMap, clusterSize, maxLevel);

            List <Entrance> entrances;
            List <Cluster>  clusters;

            CreateEntrancesAndClusters(out entrances, out clusters);
            HierarchicalMap.Clusters = clusters;

            CreateAbstractNodes(entrances);
            CreateEdgesNP(entrances, clusters);
        }
    public HierarchicalMap CreateHierarchicalMap(ConcreteMap concreteMap, int clusterSize, int maxLevel)
    {
        m_concreteMap     = concreteMap;
        m_clusterSize     = clusterSize;
        m_maxLevel        = maxLevel;
        m_hierarchicalMap = new HierarchicalMap(concreteMap, clusterSize, maxLevel);

        List <Cluster>  clusters  = new List <Cluster>();
        List <Entrance> entrances = new List <Entrance>();

        CreateClustersAndEntrances(clusters, entrances);
        m_hierarchicalMap.InitClusters(clusters);

        CreateAbstractNodes(entrances);
        CreateEdges(clusters, entrances);

        return(m_hierarchicalMap);
    }
Пример #12
0
        public HierarchicalMap CreateHierarchicalMap(ConcreteMap concreteMap, int clusterSize, int maxLevel, EntranceStyle style)
        {
            _clusterSize     = clusterSize;
            _entranceStyle   = style;
            _maxLevel        = maxLevel;
            _concreteMap     = concreteMap;
            _hierarchicalMap = new HierarchicalMap(concreteMap, clusterSize, maxLevel);

            List <Entrance> entrances;
            List <Cluster>  clusters;

            CreateEntrancesAndClusters(out entrances, out clusters);
            _hierarchicalMap.Clusters = clusters;

            CreateAbstractNodes(entrances);
            CreateEdges(entrances, clusters);

            return(_hierarchicalMap);
        }
Пример #13
0
        // Done!
        public static ConcreteMap XmlRawOpen1(string path)
        {
            ConcreteMap map = new ConcreteMap();
            IList <XmlNodeReference> con = new List <XmlNodeReference>();

            Random         r   = new Random();
            XPathDocument  doc = new XPathDocument(path);
            XPathNavigator nav = doc.CreateNavigator();

            var xmlNodes = nav.Select("Nodes/Node");

            while (xmlNodes.MoveNext())
            {
                var cNode = xmlNodes.Current;

                // Add Node!
                var node = new MapNode(cNode.GetAttribute("Name", string.Empty), NodeType.Geometry)
                {
                    Constraints = ParseConstraints(cNode, true, r)
                };
                map.Add(node);

                // Add Geometry
                var xmlGeometry = cNode.Select("Vector");
                while (xmlGeometry.MoveNext())
                {
                    node.Geometry.Add(ParseXmlVector(xmlGeometry.Current));
                }

                // Add Exits
                var xmlExits = cNode.Select("Exit");
                while (xmlExits.MoveNext())
                {
                    con.Add(ParseXmlExit(xmlExits.Current, node));
                }
            }

            // Remake Connectors
            RemakeConnectors(map, con);

            return(map);
        }
Пример #14
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);
        }
Пример #15
0
        // Done!
        #region Static Methods

        // Done!
        public static ConcreteVisualMap LoadFrom(ConcreteMap cm)
        {
            if (cm == null || cm.Count == 0)
            {
                return(new ConcreteVisualMap());
            }

            var cvm = new ConcreteVisualMap();

            for (int i = 0; i < cm.Count; ++i)
            {
                float hx = float.MaxValue;
                float hy = float.MaxValue;
                float lx = float.MinValue;
                float ly = float.MinValue;

                if (cm[i].Geometry.Count > 0)
                {
                    hx = cm[i].Geometry.Min(x => x.X);
                    hy = cm[i].Geometry.Min(x => x.Y);
                    lx = cm[i].Geometry.Max(x => x.X);
                    ly = cm[i].Geometry.Max(x => x.Y);
                }

                cvm.Add(new VisualMapNode
                {
                    ConcreteNode  = cm[i],
                    FillShape     = false,
                    FillShapePath = false,
                    IsLocked      = false,
                    IsVisible     = true,
                    Visuals       = new MapVisuals {
                        Geometry = Pens.Blue
                    },
                    Min = new Vector(hx, hy),
                    Max = new Vector(lx, ly),
                });
            }
            return(cvm);
        }
Пример #16
0
        // Done!
        #region Binary Raw

        // Done!
        public static void BinaryRawSave(string path, ConcreteMap map)
        {
            File.WriteAllBytes(path, Helpers.ToByteArray(map));
        }
Пример #17
0
 private ConcreteNode GetNode(int top, int left)
 {
     return(ConcreteMap.Graph.GetNode(ConcreteMap.GetNodeIdFromPos(top, left)));
 }
Пример #18
0
        public static ConcreteMap CreateTiling(int width, int height, IPassability passability, TileType tilingType = TileType.Octile)
        {
            var tiling = new ConcreteMap(tilingType, width, height, passability);

            return(tiling);
        }