コード例 #1
0
    public void ExpandNode(NavNode n)
    {
        foreach (NavIncAStar pf in g_Pathfinders)
        {
            pf.RemoveFromFringe(n);
            if (pf.DynamicWeight)
            {
                pf.HeuristicWeight += pf.DynamicWeightStep;
            }
        }

        RemoveFromFringe(n);

        // loop adjacent
        Dictionary <NavNode, GRID_DIRECTION> neighbors = g_Grid.GetNeighborNodes(n);

        foreach (NavNode neighbor in neighbors.Keys)
        {
            if (neighbor.IsWalkable())
            {
                if (!g_gVal.ContainsKey(neighbor))
                {
                    g_gVal.Add(neighbor, float.MaxValue);
                }
                float val = g_gVal[n] + ComputeNodeCost(n, neighbor, neighbors[neighbor]);
                if (g_gVal[neighbor] > val)
                {
                    g_gVal[neighbor] = val;
                    g_Parents.Remove(neighbor);
                    g_Parents.Add(neighbor, n);
                    if (!g_ClosedListA.Contains(neighbor))
                    {
                        if (g_OpenList.Contains(neighbor))
                        {
                            RemoveFromFringe(neighbor);
                        }
                        g_OpenList.Add(neighbor);
                        g_Fringe.Add(val, neighbor);
                        if (!g_ClosedListH.Contains(neighbor))
                        {
                            foreach (NavIncAStar pf in g_Pathfinders)
                            {
                                float totVal = val + pf.ComputeNodeHeuristic(neighbor);
                                if (totVal <= (pf.g_SecondaryHeuristicsWeight * val))
                                {
                                    pf.RemoveFromFringe(neighbor);
                                    pf.g_OpenList.Add(neighbor);
                                    pf.g_Fringe.Add(totVal, neighbor);
                                }
                            }
                        }
                    }
                }
            }
        }
    }
コード例 #2
0
    public void ExpandNode(NavNode n)
    {
        RemoveFromFringe(n);

        if (DynamicWeight)
        {
            HeuristicWeight += DynamicWeightStep;
        }

        // loop adjacent
        Dictionary <NavNode, GRID_DIRECTION> neighbors = g_Grid.GetNeighborNodes(n);

        foreach (NavNode neighbor in neighbors.Keys)
        {
            if (neighbor.IsWalkable())
            {
                if (!g_gVal.ContainsKey(neighbor))
                {
                    g_gVal.Add(neighbor, float.MaxValue);
                }
                float val = g_gVal[n] + ComputeNodeCost(n, neighbor, neighbors[neighbor]);
                if (g_gVal[neighbor] > val)
                {
                    g_gVal[neighbor] = val;
                    g_Parents.Remove(neighbor);
                    g_Parents.Add(neighbor, n);
                    if (!g_ClosedList.Contains(neighbor))
                    {
                        if (g_OpenList.Contains(neighbor))
                        {
                            RemoveFromFringe(neighbor);
                        }
                        g_OpenList.Add(neighbor);
                        if (UseBeaconHeuristic)
                        {
                            if (UseBeaconHeuristic && g_Fringe.Count > BeaconFringeLimit)
                            {
                                NavNode last = g_Fringe.Values[g_Fringe.Count - 1];
                                g_gVal.Remove(last);
                                g_Parents.Remove(last);
                                g_OpenList.RemoveWhere(i => i.Equals(last));
                                g_Fringe.RemoveAt(g_Fringe.Count - 1);
                            }
                        }
                        g_Fringe.Add(val + ComputeNodeHeuristic(neighbor), neighbor);
                    }
                }
            }
        }
    }