Beispiel #1
0
    /* calculateCost calculates a new fTotalCost value for this node using the dynamic weighting
     * Parameters: (float) gNewFromStartingNode is the new gNewFromStartingNode cost to be used in calculating the new f value
     * (Vector3) goalPosition is the goal position to be used in calculating new f value
     * Return: none
     */
    public void calculateCost(float gNewFromStartingNode, Vector3 goalPosition)
    {
        float W;         // is the weight to be added to the huristic

        if (nodesExpandedForThis <= N)
        {
            W = 1 - (nodesExpandedForThis / N);
        }
        else
        {
            W = 0f;
        }
        gFromStartingNode = gNewFromStartingNode;
        hCostToGoal       = (goalPosition - polygonBeingHeld.getCenterVector()).magnitude;
        fTotalCost        = gFromStartingNode + (1 + (epsion * W)) * hCostToGoal;
    }
 /* The method calculateCost calcluates the new cost from the passed parameters
  * Paremeter: float gNewFromStartingNode - g cost from start node
  * Vector3 goalPosition - position of the goal
  */
 public void calculateCost(float gNewFromStartingNode, Vector3 goalPosition)
 {
     gFromStartingNode = gNewFromStartingNode;
     hCostToGoal       = (goalPosition - polygonBeingHeld.getCenterVector()).magnitude;
     fTotalCost        = gFromStartingNode + hCostToGoal;
 }