Example #1
0
    /// <summary>
    /// What the apeal is to the agent for executing an attack on the target.
    /// The higher the rating the higher the appeal value, and the more likely
    /// the agent is to attack.
    /// </summary>
    /// <returns>The appeal of attacking the target</returns>
    /// <param name="percept">Percept, environment we're evaluating</param>
    float appealOfAttacking(Percept percept)
    {
        // If the enemy is not dashing and we are at med-high health, we want to attack
        if (target.getCurrentChickenState() != ChickenState.Dashing)
        {
            // If enemy is within attack range (roughly 3.4 units)
            if (Vector3.Distance(target.transform.position, control.transform.position) <= 3.5)
            {
                // If we have moderate HP
                if (percept.curHealth / control.getMaxHealth() >= .45F)
                {
                    return(1);
                }

                // If we have subpar HP
                if (percept.curHealth / control.getMaxHealth() < .45F)
                {
                    // If we have teammates nearby
                    if (percept.numOfTeamates > 1)
                    {
                        return(1);
                    }
                    return(0.5F); // Attack if we must
                }
            }
        }

        // If enemy is dashing
        if (target.getCurrentChickenState() == ChickenState.Dashing)
        {
            if (percept.curHealth / control.getMaxHealth() >= .45F)
            {
                return(0.5F); // If we have moderate HP, might as well attack
            }
            return(0.3F);     // Only attack if we really need to
        }
        return(0);
    }