Esempio n. 1
0
    public IEnumerator NewBestishPath(int ignoredRnd)
    {
        //Return to a proper state
        movement = movementMax;
        //Clear old bestish path stuff
        nodeWithValues.Clear();
        if (previosUnWalkableNode != null)
        {
            previosUnWalkableNode.occupied = false;
        }
        //Find all accessable nodes
        //yield return StartCoroutine(GatherReachableNodes(transform.position, movement));

        nodeForEval.Clear();
        visitedRowCol = new bool[Mathf.RoundToInt(m_grid.gridWorldSize.x), Mathf.RoundToInt(m_grid.gridWorldSize.y)];
        reachableNodes2(transform.position, 0);
        Debug.Log("# of eval nodes " + nodeForEval.Count);

        // remove nodes for eval, remove gather reachable, create a reachable with single gather and return function

        //float stay = Sigmoid(m_grid.NodeFromWorldPoint(transform.position).threatLvl * stayWeight);  //Eval original node for possible leaving dangers  TODO balence
        float stay   = m_grid.NodeFromWorldPoint(transform.position).threatLvl *stayWeight;
        float master = 99999f;

        //Eval each node for danger if left and value if moved
        for (int i = 0; i < nodeForEval.Count; i++)
        {
            if (nodeForEval[i].walkable && !nodeForEval[i].occupied)
            {
                justREturnedPath = false; //UnsureWhat this fixes
                yield return(null);

                updateOccupiedNode();

                //Debug.Log("walkable And !occupied");
                //yield return StartCoroutine(locationEval(nodeForEval[i])); //unsure what this does

                vMove[] tmp = m_Action.EvalFunctForAi(nodeForEval[i], target.position);  //Eval the action
                for (int k = 0; k < tmp.Length; k++)
                {
                    //float Action = Sigmoid(tmp[k].value + actWeight);
                    float Action = tmp[k].value * actWeight;
                    master = Action + stay;
                    //master = Sigmoid(Action + -stay);
                    tmp[k].value = master;
                    Debug.Log(gameObject.name + " Charge: " + Action + " Stay: " + stay + "Master Weight: " + master + " " + tmp[k].endNode.worldPosition);
                    nodeWithValues.Add(tmp[k]);
                }

                /* float Action = Sigmoid(tmp[0].value + actWeight);
                 * master = Sigmoid(Action + -stay);
                 * tmp[0].value = master;
                 * Debug.Log(gameObject.name + " Charge: " + Action + " Stay: " + stay + "Master Weight: " + master);
                 * nodeWithValues.Add(tmp[0]);*/
            }
        }
        nodeWithValues.Sort();
        Debug.Log(gameObject.name + " BEST move " + nodeWithValues[0].value + " loc:" + nodeWithValues[0].endNode.worldPosition);

        yield return(null);
    }