public static float Calculate(CollectorAgent collectorAgent, int maxSteps) { return((DeathReward(collectorAgent) + StepReward(collectorAgent) + HpReward(collectorAgent) ) / maxSteps); }
private void HpDecay(CollectorAgent collectorAgent, int maxSteps) { if (collectorAgent.Collector.IsDead) { return; } collectorAgent.Collector.hp -= collectorInitialHp * 2 / maxSteps; }
public static void ProcessMe(CollectorAgent agent) { var reward = CollectorRewardFunction.Calculate(agent, 3000); if (Math.Abs(reward) > 0.0001f) { agent.AddReward(reward); } }
void Start() { agent = gameObject.GetComponentInChildren <CollectorAgent>(); targets = gameObject.GetComponentsInChildren <BaseTarget>().ToList(); goal = gameObject.GetComponentInChildren <BaseGoal>(); SetResourceRequirements(); SetAgentTarget(); }
private static float StepReward(CollectorAgent collectorAgent) { if (collectorAgent.Collector.IsDead) { return(0f); } return(-1F); }
private static float DeathReward(CollectorAgent collectorAgent) { if (!collectorAgent.Collector.IsDead) { return(0f); } return(-5F); }
private static float HpReward(CollectorAgent collectorAgent) { if (collectorAgent.Collector.IsDead) { return(0f); } var hp = collectorAgent.Collector.hp; return(hp / 10); }
// Update is called once per frame void Update() { cool -= Time.deltaTime; if (cool <= 0) { cool += timeToSpawn; NavMeshHit hit; if (NavMesh.SamplePosition(new Vector3( Mathf.Lerp(bounds.xMin, bounds.xMax, Random.value), 0, Mathf.Lerp(bounds.yMin, bounds.yMax, Random.value) ), out hit, 1000, NavMesh.AllAreas)) { GameObject food = Instantiate(foodPrefab); food.transform.position = hit.position; float minDist = Mathf.Infinity; CollectorAgent closest = null; foreach (CollectorAgent agent in agents) { NavMeshPath path = new NavMeshPath(); NavMesh.CalculatePath(agent.transform.position, food.transform.position, NavMesh.AllAreas, path); float thisDist = pathLength(path); if (agent.target == null && thisDist < minDist) { minDist = thisDist; closest = agent; } } if (closest != null) { closest.target = food; } else { Destroy(food); } } } }