Пример #1
0
    void Init(int[,] mapData)
    {
        //if (mapManager != null)
        //{
        //    maximum_xPosition = mapManager.MapWidth;
        //    maximum_yPosition = mapManager.MapHeight;
        //} else
        //{
        //    Debug.LogWarning("MapManager not found. Initializing nodearray with default values:" +
        //        " maximum_xPosition " + maximum_xPosition + " maximum_yPosition " + maximum_yPosition);
        //}

        m_width  = mapData.GetLength(0);
        m_height = mapData.GetLength(1);

        nodes = new Node[m_width, m_height];

        for (int x = 0; x < m_width; x++)
        {
            for (int y = 0; y < m_height; y++)
            {
                Node.NodeType newNodeType = (Node.NodeType)mapData[x, y];
                nodes[x, y] = new Node(x, y, newNodeType);
            }
        }

        for (int x = 0; x < m_width; x++)
        {
            for (int y = 0; y < m_height; y++)
            {
                nodes[x, y].adjacentNodes = GetAdjacentNodesAtPosition(x, y);
            }
        }
    }
Пример #2
0
    void Add(GameObject go, Node.NodeType type)
    {
        go.AddComponent <Node>();
        Node node = go.GetComponent <Node>();

        node.nodeType = type;
        print("done");
    }
Пример #3
0
    void targetClosest(Node.NodeType targetType)
    {
        //check whether all of the food has been picked up
        if (targetType == Node.NodeType.food)
        {
            bool foodAvailable = false;
            for (int i = 0; i < foodNodes.Count; i++)
            {
                if (foodNodes[i].gameObject.GetComponent <Food>().PickUpState == Food.PickUpStates.Static)
                {
                    foodAvailable = true;
                }
            }

            if (!foodAvailable)
            {
                setState(MoveState.toSpawn);
                return;
            }
        }

        List <Node> consideredList = targetType == Node.NodeType.food ? foodNodes : spawnNodes;

        Node closestNode = null;

        for (int i = 0; i < consideredList.Count; i++)
        {
            if (consideredList[i].GetComponent <Food>())
            {
                if (consideredList[i].GetComponent <Food>().PickUpState != Food.PickUpStates.Static)
                {
                    continue;
                }
            }

            if (closestNode == null)
            {
                closestNode = consideredList[i];
            }
            else if (closestNode != consideredList[i])
            {
                float currentClosest    = Vector3.Distance(gameObject.transform.position, closestNode.gameObject.transform.position);
                float currentConsidered = Vector3.Distance(gameObject.transform.position, consideredList[i].gameObject.transform.position);

                if (currentConsidered < currentClosest)
                {
                    closestNode = consideredList[i];
                }
            }
        }

        if (closestNode != null)
        {
            currentTarget = closestNode;
        }
    }
Пример #4
0
    public Tile GetColorFromNodeType(Node.NodeType nodeType)
    {
        if (nodeColorLookupTable.ContainsValue(nodeType))
        {
            Tile color = nodeColorLookupTable.FirstOrDefault(x => x.Value == nodeType).Key;
            return(color);
        }

        return(colorDefault);
    }
Пример #5
0
 private IEnumerable <Node> GetDestinationNodes(IEnumerable <Edge> list, Node.NodeType type)
 {
     foreach (var e in list)
     {
         if (e.to.Type == type)
         {
             yield return(e.to);
         }
     }
 }
 /// <summary>
 /// Set the value of the node at the given x & y coordinates
 /// </summary>
 /// <param name="x">X coordinate</param>
 /// <param name="y">Y coordinate</param>
 /// <param name="pType">What we are setting it to.</param>
 public void SetNode(int x, int y, Node.NodeType pType)
 {
     foreach (var n in Nodes)
     {
         if (n.X == x && n.Y == y)
         {
             n.Type = pType;
         }
     }
 }
Пример #7
0
 public void SetPillNodeType(int pX, int pY, Node.NodeType pType)
 {
     foreach (var item in Map.Nodes)
     {
         if (item.X == pX && item.Y == pY)
         {
             item.Type = pType;
         }
     }
 }
Пример #8
0
 public FormSim()
 {
     this.WindowState = FormWindowState.Maximized;
     InitializeComponent();
     populateGrid();
     updateGrid();
     this.nodeType             = Node.NodeType.free;
     threads                   = new List <Thread>();
     this.buttonStop.BackColor = System.Drawing.Color.IndianRed;
 }
Пример #9
0
    // Start is called before the first frame update
    void Start()
    {
        m_startingNode = m_grid.GetNode(Node.NodeType.PLAYER_SPAWN);
        Node.NodeType [] invalidNodeTypes = new Node.NodeType [] { Node.NodeType.WALL, Node.NodeType.VILLAIN_WALL };
        m_playerEntity     = new EntityMover(m_startingNode, EntityMover.Directions.RIGHT, invalidNodeTypes);
        transform.position = m_startingNode.WorldPosition;

        m_updatePositionCooler = 3.0f;

        // Reset transform scale
        transform.localScale = Vector3.one;
    }
Пример #10
0
        public Flow(ref FileBase file)
        {
            mNodes = new List <Node>();

            file.Skip(0xC);
            ushort flowCount  = file.ReadUInt16();
            ushort labelCount = file.ReadUInt16();

            file.Skip(0x4);

            for (int i = 0; i < flowCount; i++)
            {
                Node.NodeType type = (Node.NodeType)file.ReadUInt16();

                switch (type)
                {
                case Node.NodeType.NodeType_Message:
                    mNodes.Add(new MessageNode(ref file));
                    break;

                case Node.NodeType.NodeType_Entry:
                    mNodes.Add(new EntryNode(ref file));
                    break;

                case Node.NodeType.NodeType_Event:
                    mNodes.Add(new EventNode(ref file));
                    break;

                case Node.NodeType.NodeType_Branch:
                    mNodes.Add(new BranchNode(ref file));
                    break;

                default:
                    Console.WriteLine($"Unsupported type: {(int)type}");
                    break;
                }
            }

            mLabels = new List <ushort>();

            for (int i = 0; i < labelCount; i++)
            {
                mLabels.Add(file.ReadUInt16());
            }

            while (file.Position() % 0x10 != 0)
            {
                file.Skip(0x1);
            }
        }
Пример #11
0
    public Node.NodeType GetNodeTypeAtPosition(int xPosition, int yPosition)
    {
        TileBase tile = tilemapTerrain.GetTile(new Vector3Int(xPosition, yPosition, 0));

        if (terrainDifficultyDict.ContainsKey(tile))
        {
            Node.NodeType nodeTypeTile = terrainDifficultyDict[tile];
            //Debug.Log("The tile "+ tile.ToString() + " at position " + xPosition + "," + yPosition + " is classified as type " + nodeTypeTile.ToString());

            return(nodeTypeTile);
        }

        return(Node.NodeType.blockedTerrain);
    }
Пример #12
0
    /// <summary>
    /// Sets a node's type if the chosen recipient's type is "Open".
    /// </summary>
    private Node SetNode(Node.NodeType type, Vector3 position)
    {
        var  x         = (int)position.x;
        var  z         = (int)position.z;
        Node recipient = nodes [z, x].GetComponent <Node> ();

        if (recipient.Type == Node.NodeType.Open)
        {
            recipient.Type = type;
        }
        else
        {
            // Call the method recursively until an open node is found.
            SetNode(type, position);
        }
        return(recipient);
    }
Пример #13
0
            Node getNode(Node.NodeType type)
            {
                int index = ( int )type;

                if (Keys.Length > index)
                {
                    return(Keys[index]);
                }
                return(null);

#if false
                Node node = null;
                if (Parent != null)
                {
                    node = Parent.Nodes[getKey(type)] as Node;
                }
                return(node);
#endif
            }
Пример #14
0
        //start simulation
        private void button2_Click(object sender, EventArgs e)
        {
            if ((Check_In.Count == Check_Out.Count) && Check_In.Count != 0 && Check_Out.Count != 0 && (Check_In.Count == airport.flights.Count && Check_Out.Count == airport.flights.Count))
            {
                btnStart.Enabled       = false;
                btnEnd.Enabled         = false;
                button2.Enabled        = false;
                btnReset.Enabled       = true;
                btnDelete.Enabled      = false;
                buttonObstacle.Enabled = false;

                this.nodeType = Node.NodeType.free;

                this.OptimumPath();
            }
            else
            {
                MessageBox.Show("Please add equal amount of check-in and check-out \n and make sure to have the same number of checks the same as flights");
                btnReset.Enabled = true;
            }
        }
Пример #15
0
 private void resetSim()
 {
     btnReset.Enabled       = false;
     btnStart.Enabled       = true;
     button2.Enabled        = true;
     buttonObstacle.Enabled = true;
     btnEnd.Enabled         = true;
     btnDelete.Enabled      = true;
     pictureBox1.Invalidate();
     label2.Text = "";
     //stopSim();
     this.WindowState = FormWindowState.Maximized;
     populateGrid();
     updateGrid();
     this.nodeType = Node.NodeType.free;
     this.movers   = new List <List <Mover> >();
     Optimum_Paths = new List <List <Node> >();
     Check_In      = new List <Node>();
     Check_Out     = new List <Node>();
     timerFlow.Stop();
     timer.Stop();
 }
Пример #16
0
        internal IEnumerable <Node> GetNeighborsOf(Node n, Node.NodeType type)
        {
            var edges = GetEdgesFrom(n, this.Edges);

            return(GetDestinationNodes(edges, type));
        }
Пример #17
0
        public static List <Edge> GetChildrenRelations(string sql,
                                                       Node.NodeType nodeType, string nodeId, DateTime?datumOd, DateTime?datumDo,
                                                       IDataParameter[] parameters, int level, bool goDeep,
                                                       Edge parent, ExcludeDataCol excludeICO, decimal minPodil, Relation.AktualnostType aktualnost)
        {
            if (excludeICO == null)
            {
                excludeICO = new ExcludeDataCol();
            }

            string cnnStr = Devmasters.Config.GetWebConfigValue("CnnString");

            List <Edge> relations = new List <Edge>();

            if (level == 0 && parent == null)
            {
                //add root node / edge
                relations.Add(
                    new Edge()
                {
                    From = null,
                    Root = true,
                    To   = new Node()
                    {
                        Id = nodeId, Type = nodeType
                    },
                    RelFrom  = datumOd,
                    RelTo    = datumDo,
                    Distance = 0
                }
                    );
            }
            //get zakladni informace o subj.

            //find politician in the DB
            var db      = new Devmasters.PersistLib();
            var sqlCall = HlidacStatu.Lib.DirectDB.GetRawSql(System.Data.CommandType.Text, sql, parameters);
            //string sqlFirma = "select top 1 stav_subjektu from firma where ico = @ico";

            var ds = db.ExecuteDataset(cnnStr, System.Data.CommandType.Text, sqlCall, null);

            if (ds.Tables[0].Rows.Count > 0)
            {
                List <AngazovanostData> rows = new List <AngazovanostData>();
                foreach (DataRow dr in ds.Tables[0].Rows)
                {
                    AngazovanostData angaz = null;
                    var ico = (string)dr["VazbakIco"];
                    if (string.IsNullOrEmpty(ico))
                    {
                        if (dr.Table.Columns.Contains("vazbakOsobaId"))
                        {
                            var vazbakOsobaId = (int?)PersistLib.IsNull(dr["vazbakOsobaId"], null);
                            if (vazbakOsobaId != null)
                            {
                                Osoba o = Osoby.GetById.Get(vazbakOsobaId.Value);
                                angaz = new AngazovanostData()
                                {
                                    subjId   = vazbakOsobaId.Value.ToString(),
                                    NodeType = Node.NodeType.Person,
                                    fromDate = (DateTime?)PersistLib.IsNull(dr["datumOd"], null),
                                    toDate   = (DateTime?)PersistLib.IsNull(dr["datumDo"], null),
                                    kod_ang  = Convert.ToInt32(dr["typVazby"]),
                                    descr    = (string)PersistLib.IsNull(dr["PojmenovaniVazby"], ""),
                                    podil    = (decimal?)PersistLib.IsNull(dr["podil"], null)
                                };
                            }
                        }
                    }
                    else
                    {
                        angaz = new AngazovanostData()
                        {
                            subjId   = ico,
                            subjname = "",
                            NodeType = Node.NodeType.Company,
                            fromDate = (DateTime?)PersistLib.IsNull(dr["datumOd"], null),
                            toDate   = (DateTime?)PersistLib.IsNull(dr["datumDo"], null),
                            kod_ang  = Convert.ToInt32(dr["typVazby"]),
                            descr    = (string)PersistLib.IsNull(dr["PojmenovaniVazby"], ""),
                            podil    = (decimal?)PersistLib.IsNull(dr["podil"], null)
                        };
                    }
                    rows.Add(angaz);
                }

                List <AngazovanostData> filteredRels = new List <AngazovanostData>();
                //delete vazby ve stejnem obdobi
                if (rows.Count > 0)
                {
                    //per ico
                    foreach (var gIco in rows.Select(m => m.subjId).Distinct())
                    {
                        var relsForIco = rows.Where(m => m.subjId == gIco);
                        //find longest, or separate relation
                        foreach (var r in relsForIco)
                        {
                            if (relsForIco
                                .Any(rr =>
                                     rr != r &&
                                     rr.fromDate < r.fromDate &&
                                     (rr.toDate > r.toDate || rr.toDate.HasValue == false)
                                     )
                                )
                            {
                                //skip
                            }
                            else
                            {
                                filteredRels.Add(r);
                            }
                        }
                    }
                }

                foreach (AngazovanostData ang in filteredRels.OrderBy(m => m.kod_ang))
                {
                    if (ang.kod_ang == 100) //souhrny (casove) vztah, zkontroluj, zda uz tam neni jiny vztah se stejnym rozsahem doby
                    {
                        if (
                            relations.Any(
                                r => r.To.Id == ang.subjId &&
                                r.To.Type == ang.NodeType &&
                                r.RelFrom == ang.fromDate &&
                                r.RelTo == ang.toDate
                                )
                            )
                        {
                            continue;
                        }
                    }
                    var rel = AngazovanostDataToEdge(ang,
                                                     new Node()
                    {
                        Type = nodeType, Id = nodeId
                    },
                                                     new Node()
                    {
                        Type = ang.NodeType, Id = ang.subjId
                    },
                                                     level + 1
                                                     );


                    if (excludeICO.Contains(rel))
                    {
                        continue;//skip to the next
                    }
                    if (rel.Aktualnost >= aktualnost)
                    {
                        relations.Add(rel);
                    }
                }
            }

            if (goDeep && relations.Count > 0)
            {
                level++;
                List <Edge> deeperRels  = new List <Edge>();
                List <Edge> excludeMore = new List <Edge>();
                if (parent != null)
                {
                    excludeMore = relations.ToList();
                }

                ////navazej na ten, ktery je nejdelsi
                //var parentRels = relations.GroupBy(x => new { x.To.Id }, (key, rels) =>
                //{
                //    DateTime? fromDate = rels.Any(m => m.FromDate == null) ? (DateTime?)null : rels.Min(m => m.FromDate);
                //    DateTime? toDate = rels.Any(m => m.ToDate == null) ? (DateTime?)null : rels.Max(m => m.ToDate);
                //    Relation bestRelation = Relation.GetLongestRelation(rels);

                //    return new
                //    {
                //        SubjIco = key.To.Id,
                //        FromDate = fromDate,
                //        ToDate = toDate,
                //        BestRelation = bestRelation,
                //    };

                //});



                foreach (var rel in relations.Where(m => m.Root == false))
                {
                    //old
                    deeperRels.AddRange(

                        vsechnyDcerineVazbyInternal(rel.To.Id, level, goDeep, rel,
                                                    excludeICO.AddItem(new ExcludeData(rel)),
                                                    rel.RelFrom, rel.RelTo, minPodil, aktualnost)
                        );
                }
                relations.AddRange(deeperRels);
            }

            if (level == 0)
            {
                //remove inactive companies from last branches
                //TODO
            }
            return(relations);
        }
Пример #18
0
 internal List <Node> GetNodesOfType(Node.NodeType searchtype)
 {
     return(this.Nodes.FindAll(n => n.Type == searchtype));
 }
Пример #19
0
    private void BuildBoardVisualMesh()
    {
        Node[] nodeDatas   = CurrentBoard.Nodes;
        Node[] visualNodes = new Node[XCount * YCount * ZCount];
        Board  visualBoard = new Board(transform.position, WorldSize, NodeRadius);

        visualBoard.Nodes = visualNodes;

        GameObject floorObject = new GameObject("Floor");

        //Get Data from original nodes
        for (int z = 0; z < ZCount; ++z)
        {
            for (int y = 0; y < YCount; ++y)
            {
                for (int x = 0; x < XCount; ++x)
                {
                    Node          currentData = nodeDatas[Index3D(x, y, z)];
                    Node.NodeType type        = (y == 0) ? Node.NodeType.Normal : Node.NodeType.Empty;
                    visualNodes[Index3D(x, y, z)] = new Node(x, y, z, currentData.WorldPosition, type, floorObject, visualBoard);
                }
            }
        }

        for (int z = 0; z < ZCount; z += 2)
        {
            for (int x = 0; x < XCount; x += 2)
            {
                Vector3    position = new Vector3(x, 1, z);
                GameObject floor    = Instantiate(_floorPrefab, position, Quaternion.identity);
                _boardVisualObjects.Add(floor);
            }
        }

        for (int z = 0; z < ZCount; ++z)
        {
            for (int x = 0; x < XCount; ++x)
            {
                if (z % 2 == 0)
                {
                    Vector3 position      = new Vector3(x, 1, z);
                    float   rotationAngle = 0.0f;
                    bool    build         = false;
                    if (x == 0)
                    {
                        rotationAngle = -90.0f;
                        build         = true;
                    }

                    if (x == XCount - 2)
                    {
                        rotationAngle = 90.0f;
                        position.x   += 2;
                        position.z   += 2;
                        build         = true;
                    }
                    if (build)
                    {
                        GameObject wall = Instantiate(_wallPrefab, position, Quaternion.Euler(0, rotationAngle, 0));
                        _boardVisualObjects.Add(wall);
                    }
                }

                if (x % 2 == 0)
                {
                    Vector3 position      = new Vector3(x, 1, z);
                    float   rotationAngle = 0.0f;
                    bool    build         = false;
                    if (z == 0)
                    {
                        position.x   += 2;
                        rotationAngle = -180.0f;
                        build         = true;
                    }

                    if (z == ZCount - 2)
                    {
                        position.z += 2;
                        build       = true;
                    }
                    if (build)
                    {
                        GameObject wall = Instantiate(_wallPrefab, position, Quaternion.Euler(0, rotationAngle, 0));
                        _boardVisualObjects.Add(wall);
                    }
                }
            }
        }


        _boardVisualObjects.Add(floorObject);

        //Build upper floor
        List <Node> upperNodeList = new List <Node>();

        for (int z = 0; z < ZCount; ++z)
        {
            for (int x = 0; x < XCount; ++x)
            {
                for (int y = 1; y < YCount; ++y)
                {
                    if (nodeDatas[Index3D(x, y, z)].IsSolid)
                    {
                        upperNodeList.Add(nodeDatas[Index3D(x, y, z)]);
                    }
                }
                if (upperNodeList.Count == 1)
                {
                    GameObject go = Level.LevelCreator.Instance.CreateObjectAtNode(
                        CurrentBoard.GetNodeInfoAt(x, 0, z, Side.Top), _stoneShortPrefab, Vector3.zero, Quaternion.identity);
                    _boardVisualObjects.Add(go);
                }
                else if (upperNodeList.Count == 2)
                {
                    GameObject go = Level.LevelCreator.Instance.CreateObjectAtNode(CurrentBoard.GetNodeInfoAt(x, 0, z, Side.Top),
                                                                                   _stoneTallPrefab, Vector3.zero, Quaternion.identity);
                    _boardVisualObjects.Add(go);
                }
                upperNodeList.Clear();
            }
        }
    }
Пример #20
0
 public Node GetNode(Node.NodeType nodeType)
 {
     return(Nodes.First(n => n.Type == nodeType));
 }
Пример #21
0
    public Node GetRandomNode(Node.NodeType nodeType)
    {
        List <Node> filteredNodes = Nodes.FindAll(n => n.Type == nodeType);

        return(filteredNodes [UnityEngine.Random.Range(0, filteredNodes.Count)]);
    }
Пример #22
0
 private void buttonObstacle_Click_1(object sender, EventArgs e)
 {
     this.nodeType = Node.NodeType.obs;
 }
Пример #23
0
 /// <summary>
 /// Set the visualisation for this node.
 /// </summary>
 public void Visualise(Node.NodeType type)
 {
     targetRotation = rotationMap [type];
     StartCoroutine(RotateToTarget());
 }
Пример #24
0
 //
 /// <summary>
 /// Button Delete, is used for assigning the field nodeType to Node.NodeType.free
 /// </summary>
 /// <param name="sender"></param>
 /// <param name="e"></param>
 private void btnDelete_Click(object sender, EventArgs e)
 {
     this.nodeType = Node.NodeType.free;
 }
Пример #25
0
 /// <summary>
 /// Button End, is used for assigning the field nodeType to Node.NodeType.path
 /// </summary>
 /// <param name="sender"></param>
 /// <param name="e"></param>
 private void btnEnd_Click(object sender, EventArgs e)
 {
     nodeType = Node.NodeType.end;
 }
Пример #26
0
 /// <summary>
 /// Button Start, is used for assigning the field nodeType to Node.NodeType.path
 /// </summary>
 /// <param name="sender"></param>
 /// <param name="e"></param>
 private void button4_Click(object sender, EventArgs e)
 {
     nodeType = Node.NodeType.start;
 }
Пример #27
0
 int getKey(Node.NodeType type)
 {
     return(Key[( int )type]);
 }
    // Description: Updates all the node related fields in the inspector
    // PRE:         N/A
    // POST:        The node related fields in the inspector accurately reflect the data
    private void UpdateNodeInspector()
    {
        if (selectedNodes.Count <= 0)
        {
            nodePropertyDropdown.GetComponent <Dropdown>().interactable = false;
            nodePropertyDropdown.GetComponent <Image>().color           = _originalDropdownColor;
            sinkCheckbox.GetComponent <Toggle>().interactable           = false;
            sinkCheckbox.GetComponentInChildren <Text>().color          = _originalCheckboxLabelColor;
            sourceCheckbox.GetComponent <Toggle>().interactable         = false;
            sourceCheckbox.GetComponentInChildren <Text>().color        = _originalCheckboxLabelColor;
        }
        else if (selectedNodes.Count == 1)
        {
            nodePropertyDropdown.GetComponent <Dropdown>().interactable = true;
            nodePropertyDropdown.GetComponent <Dropdown>().value        = (int)selectedNodes[0].NodeProperty;
            nodePropertyDropdown.GetComponent <Image>().color           = _originalDropdownColor;
            sinkCheckbox.GetComponent <Toggle>().interactable           = true;
            sinkCheckbox.GetComponent <Toggle>().isOn            = selectedNodes[0].IsSink;
            sinkCheckbox.GetComponentInChildren <Text>().color   = _originalCheckboxLabelColor;
            sourceCheckbox.GetComponent <Toggle>().interactable  = true;
            sourceCheckbox.GetComponent <Toggle>().isOn          = selectedNodes[0].IsSource;
            sourceCheckbox.GetComponentInChildren <Text>().color = _originalCheckboxLabelColor;
        }
        else //implied (selectedNodes.Count > 1)
        {
            bool          firstSinkValue      = selectedNodes[0].IsSink;
            bool          uniformSinkValues   = true;
            bool          firstSourceValue    = selectedNodes[0].IsSource;
            bool          uniformSourceValues = true;
            Node.NodeType firstNodeType       = selectedNodes[0].NodeProperty;
            bool          uniformNodeTypes    = true;

            for (int i = 1; i < selectedNodes.Count && (uniformSinkValues || uniformSourceValues || uniformNodeTypes); i++)
            {
                if (uniformSinkValues && firstSinkValue != selectedNodes[i].IsSink)
                {
                    uniformSinkValues = false;
                }

                if (uniformSourceValues && firstSourceValue != selectedNodes[i].IsSource)
                {
                    uniformSourceValues = false;
                }

                if (uniformNodeTypes && firstNodeType != selectedNodes[i].NodeProperty)
                {
                    uniformNodeTypes = false;
                }
            }

            if (!uniformSinkValues)
            {
                sinkCheckbox.GetComponentInChildren <Text>().color = valuesNotUniformColor;
            }
            if (!uniformSourceValues)
            {
                sourceCheckbox.GetComponentInChildren <Text>().color = valuesNotUniformColor;
            }
            if (!uniformNodeTypes)
            {
                nodePropertyDropdown.GetComponent <Image>().color = valuesNotUniformColor;
            }
        }
    }
Пример #29
0
        /// <summary>
        /// Creates a node, adds to the graph and returns its reference.
        /// </summary>
        /// <param name="x">X coordinate.</param>
        /// <param name="y">Y coordinate.</param>
        /// <param name="z">Z coordinate.</param>
        /// <returns>The reference of the new node / null if the node is already in the graph.</returns>
        public Node AddNode(int id, Node.NodeType type)
        {
            Node NewNode = new Node(id, type);

            return(AddNode(NewNode) ? NewNode : null);
        }
Пример #30
0
        public static Node.PathInfo NearestPill(Node currentNode, GameState gs, Direction initialDir, Node.NodeType type)
        {
            Node bestNode = null;

            Node.PathInfo bestPath = null;
            foreach (Node node in gs.Map.Nodes)
            {
                if (node.Walkable)
                {
                    if (node.Type == type)
                    {
                        if (bestPath == null)
                        {
                            bestNode = node;
                            bestPath = gs.Pacman.Node.ShortestPath[node.X, node.Y, (int)initialDir];
                            continue;
                        }
                        Node.PathInfo curPath = currentNode.ShortestPath[node.X, node.Y, (int)initialDir];
                        if (curPath != null && curPath.Distance < bestPath.Distance)
                        {
                            bestNode = node;
                            bestPath = curPath;
                        }
                    }
                }
            }
            return(bestPath);
        }