C#C
C#2y ago
Cam

✅ Dictionary not returning Value

HashCode keys are the same however its for some reason not returning the value from the dictionary

Pathfinding Class
c#
        public List<PathNode>? findPath(int startPointX, int startPointY, int endPointX, int endPointY)
        {
            PathNode startNode = getNode(startPointX, startPointY);
            PathNode endNode = getNode(endPointX, endPointY);
            Debug.WriteLine("[Birds Eye] New Pathfinding Begun");
            {
                openList.Add(startNode);

                for (int x = 0; x < panelWidth; x++)
                {
                    for (int y = 0; y < panelHeight; y++)
                    {
                        PathNode pathNode = getNode(x, y);
                        pathNode.gCost = int.MaxValue;
                        pathNode.calculateFCost();
                        pathNode.cameFromNode = null;
                    }
                }
                startNode.gCost = 0;
                Debug.WriteLine("[Birds Eye] G Cost Initialized");
                startNode.hCost = calculatDistanceCost(startNode, endNode);
                Debug.WriteLine("[Birds Eye] H Cost Initialized");
                startNode.calculateFCost();
                Debug.WriteLine("[Birds Eye] F Cost Initialized");

                while (openList.Count > 0)
                {
                    PathNode currentNode = getLowestFCostNode(openList);
                    Debug.WriteLine("[Birds Eye] Current Node Initialized");
                    if (currentNode == endNode)
                    {
                        return finalPath(endNode);
                    }
                    openList.Remove(currentNode);
                    closedList.Add(currentNode);
                    Debug.WriteLine("[Birds Eye] Searching Neighbours");
                    foreach (PathNode neighbourNode in getNeighbour(currentNode))
                    {

                        Debug.WriteLine("[Birds Eye] New Panel Node Reached");
                        if (closedList.Contains(neighbourNode)) continue;
                        int tentativeGCost = currentNode.gCost + calculatDistanceCost(currentNode, neighbourNode);
                        if (tentativeGCost < currentNode.gCost)
                        {
                            
                            neighbourNode.cameFromNode = currentNode;
                            neighbourNode.gCost = tentativeGCost;
                            neighbourNode.hCost = calculatDistanceCost(neighbourNode, endNode);
                            neighbourNode.calculateFCost();

                            if (!openList.Contains(neighbourNode))
                            {
                                openList.Add(neighbourNode);
                                Debug.WriteLine("[Birds Eye] Added Neighbour to Open List");

                            }
                        }
                    }
                }
                Debug.WriteLine("[Birds Eye] No Path Found");
                return null;
            }
        }
Was this page helpful?