Example #1
0
    private Path GetNewPathDestination()
    {
        if (knowsObjLocation)
        {
            return(Utilities.AStar(Utilities.GetNodeFromNodeIndex(NodeTable.instance.GetNodesList(), NodeTable.instance.GetCurrentNodeIndex()), Utilities.GetNodeFromNodeIndex(NodeTable.instance.GetNodesList(), objectiveLocation)));
        }

        List <PathDestinationCandidate> canditates = new List <PathDestinationCandidate>();

        // Debug.Log("-----------------------------");

        for (int i = 0; i < aiBehaviour.nodeTable.nonVisitedNodes.Count; i++)
        {
            //The non discovered connections must lead to, at least, one non known node

            int promisingValue = aiBehaviour.nodeTable.nonVisitedNodes[i].GetPromissingValue();

            if (promisingValue > 0)
            {
                PathDestinationCandidate newCandidate = new PathDestinationCandidate(aiBehaviour.nodeTable.nonVisitedNodes[i], promisingValue);
                //Debug.Log("Adicionou candidato line " + aiBehaviour.nodeTable.nonVisitedNodes[i].GetNodeIndex().line + "  column " + aiBehaviour.nodeTable.nonVisitedNodes[i].GetNodeIndex().column);
                canditates.Add(newCandidate);
            }
            //If thet node is not a promissing one, remove from the list to avoid future validations
            else
            {
                aiBehaviour.nodeTable.nonVisitedNodes.RemoveAt(i);
            }
        }

        int chosen      = 0;
        int chosenSize  = 100;
        int chosenValue = -100;

        List <Path> paths = new List <Path>();

        for (int i = 0; i < canditates.Count; i++)
        {
            Path path = Utilities.AStar(Utilities.GetNodeFromNodeIndex(NodeTable.instance.GetNodesList(), NodeTable.instance.GetCurrentNodeIndex()), canditates[i].GetNode());
            path.SetPromissingValue(canditates[i].GetPromissingValue());
            paths.Add(path);
        }

        List <Path> minimunPath = new List <Path>();

        for (int i = 0; i < paths.Count; i++)
        {
            int pathSize = paths[i].GetNodesList().Count;
            if (pathSize < chosenSize)
            {
                chosenSize = pathSize;

                minimunPath.Clear();
                minimunPath.Add(paths[i]);
            }
            else if (pathSize == chosenSize)
            {
                minimunPath.Add(paths[i]);
            }

            // Path path = Utilities.AStar(Utilities.GetNodeFromNodeIndex(NodeTable.instance.GetNodesList(), NodeTable.instance.GetCurrentNodeIndex()), canditates[i].GetNode());
        }

        for (int i = 0; i < minimunPath.Count; i++)
        {
            int pathValue = minimunPath[i].GetPromissingValue();
            if (pathValue > chosenValue)
            {
                chosenValue = pathValue;
                chosen      = i;
            }

            // Path path = Utilities.AStar(Utilities.GetNodeFromNodeIndex(NodeTable.instance.GetNodesList(), NodeTable.instance.GetCurrentNodeIndex()), canditates[i].GetNode());
        }

        return(minimunPath[chosen]);
    }