public override void AddReward(BaseAgent agent, float[] vectorActions) { if (agent.GetComponent <ObservableFields>().FieldsHash.ContainsKey(Label)) { agent.AddReward(Reward / (float)agent.agentParameters.maxStep); } }
/* * Start: inicializa todos los atributos. */ public void Start() { miniCameraController = FindObjectOfType <MiniCameraCotroller>(); plantComponent = gameObject.GetComponent <Plant>(); if (gameObject.CompareTag("Plantas")) { StartCoroutine(GrowPlant(plantComponent.plantGrowTime)); timeOfLife = 0.0f; return; } baseAgent = GetComponent <BaseAgent>(); if (!gameObject.CompareTag("HuevosRana") && !gameObject.CompareTag("HuevosPez")) { dna = baseAgent.dna; perfectDna = baseAgent.perfectDna; worstDna = baseAgent.worstDna; return; } if (agent != null) { dna = gameObject.GetComponent <Roe>().dna; perfectDna = gameObject.GetComponent <Roe>().perfectDna; worstDna = gameObject.GetComponent <Roe>().worstDna; } timeOfLife = 0.0f; timeInPhase = 0.0f; }
public virtual List <float> CollectObservations(BaseAgent agent) { List <float> obs = new List <float>(); IntObs(agent).MatchSome(io => obs.Add(io)); FloatObs(agent).MatchSome(io => obs.Add(io)); Vec2Obs(agent).MatchSome(io => { obs.Add(io.x); obs.Add(io.y); }); Vec3Obs(agent).MatchSome(io => { obs.Add(io.x); obs.Add(io.y); obs.Add(io.z); }); FloatArrObs(agent).MatchSome(io => obs.AddRange(io)); FloatListObs(agent).MatchSome(io => obs.AddRange(io)); QuatObs(agent).MatchSome(io => { obs.Add(io.x); obs.Add(io.y); obs.Add(io.z); obs.Add(io.w); }); return(obs); }
/* * NewPhase: se encarga de cambiar la fase del agente. */ public void NewPhase() { if (agent != null) { GameObject obj = Instantiate(agent, new Vector2(this.transform.position.x, this.transform.position.y), this.transform.rotation); BaseAgent objAgent = obj.GetComponent <BaseAgent>(); if (baseAgent != null) { objAgent.Init(dna, perfectDna, worstDna, baseAgent.hunger); if (isTarget) { obj.GetComponent <Clickeable>().Evolve(); } baseAgent.DeadAction(); } else { objAgent.Init(dna, perfectDna, worstDna, 1); if (isTarget) { obj.GetComponent <Clickeable>().Evolve(); } Destroy(gameObject); } obj.GetComponent <LifeCycle>().InitCycle(dna, timeOfLife, worstDna, perfectDna); } }
protected override void ClearTriggers() { base.ClearTriggers(); triggerSourceComponent = null; triggerComponents = null; triggeringComponents = null; }
public virtual void AgentAction(BaseAgent agent, float[] vectorAction) { if (agent.gameObject.tag == Tag) { base.AgentAction(agent, vectorAction); } }
public virtual void Reset(BaseAgent agent) { if (agent.gameObject.tag == Tag) { base.Reset(agent); } }
protected override void Awake() { base.Awake(); agentComponent = null; fadeStarted = false; fadeConcluded = false; }
public override Option <List <float> > FloatListObs(BaseAgent agent) { List <float> observations = new List <float>(); foreach (GameObject targetObj in area.FindGameObjectsWithTagInChildren(Tag)) { ObservableFields target = targetObj.GetComponent <ObservableFields>(); if (target.gameObject == agent.gameObject) { continue; } for (int i = 0; i < NumFields; i++) { float f = 0; target.FieldsHash.TryGetValue(String.Concat(FieldName, i), out f); if (ShowFields) { var level = new List <string>() { ".", ".", ".", "." }; level[(int)(f * 4)] = "|"; //TAG: MakeEvent area.Logger.Log(Logger.CreateMessage(LogMessageType.Agent, String.Join("", level)), agent); } observations.Add(f); } } return(observations.SomeNotNull()); }
public override void AddReward(BaseAgent agent, float[] vectorActions) { if (resetNextFrame) { agent.Done(); myArea.ResetArea(); resetNextFrame = false; } else { List <GameObject> objs = myArea.FindGameObjectsWithTagInChildren(Tag); foreach (GameObject obj in objs) { if ((obj.transform.position - agent.gameObject.transform.position).sqrMagnitude < Distance * Distance) { if (ResetTime < 0) { ResetTime = Time.time; } ResetAreaAfter = AcademyParameters.Update(academy, ResetAreaAfterKeyVal, ResetAreaAfter); if (Time.time - ResetTime >= ResetAreaAfter) { agent.AddReward(Reward); resetNextFrame = true; } } else { ResetTime = -1; } } } }
public override void AddReward(BaseAgent agent, float[] vectorAction) { bool isOut = false; foreach (GameObject TargetObject in TargetObjects) { if (TargetObject == agent.gameObject) { continue; } if ((new Vector2(TargetObject.transform.position.x, TargetObject.transform.position.z)).sqrMagnitude > Radius * Radius) { agent.AddReward(Amount); isOut = true; } if (Mathf.Abs(TargetObject.transform.localPosition.y - PositionY) > LimitY) { agent.AddReward(Amount); isOut = true; } } if (isOut && Reset) { agent.Done(); agent.Reset(); } }
public virtual void Initialize(BaseAgent agent) { if (agent.area.academy == null) { agent.area.academy = Object.FindObjectOfType <Academy>(); } }
public override void Initialize(BaseAgent agent) { academy = agent.area.academy; Reward = AcademyParameters.FetchOrParse(academy, RewardKeyVal); myArea = agent.gameObject.GetComponentInParent <PersonalityQuarksArea>(); }
protected virtual void OnCollisionEnter2D(Collision2D collision) { GameObject adversaryObject = null; BaseAgent adversaryComponent = null; if ((collision != null) && (adversaryObjects != null) && (adversaryComponents != null)) { if (collision.gameObject != null) { /*halmeida - this is the invader's object.*/ for (int i = 0; i < adversaryObjects.Length; i++) { adversaryObject = adversaryObjects[i]; if (adversaryObject == collision.gameObject) { adversaryComponent = adversaryComponents[i]; if (adversaryComponent != null) { adversaryComponent.SufferHPDamage((int)finalAttack, gameObject, this); adversaryComponent.SufferPush((Vector2)transform.position, finalAttack); } break; } } } } }
public override Option <Vector3> Vec3Obs(BaseAgent agent) { return(agent.gameObject.GetComponent <Rigidbody>() .SomeNotNull() .Map(rb => agent.gameObject.transform.InverseTransformDirection(rb.velocity)) .Map(vel => new Vector3(vel.x, vel.y, vel.z))); }
private void TestPacker() { List <Image> imageList = new List <Image>(); canvas.GetComponentsInChildren <Image>(imageList); spriteList = new List <Sprite>(imageList.Count); List <Texture2D> texture2DList = new List <Texture2D>(imageList.Count); foreach (Image image in imageList) { spriteList.Add(image.sprite); texture2DList.Add(image.sprite.texture); } baseAgent = new BaseAgent(); baseAgent.SetFilterMode(FilterMode.Point); if (baseAgent.GenerateAtlas(texture2DList, null)) { rt = baseAgent.RenderToRT(); } baseAgent.ReplaceImage(imageList); baseAgent.Release(true); }
protected virtual void ApplyContinuousEffect(BaseAgent triggeringComponent, float timeStep) { int applicableEffect = 0; if (triggeringComponent != null) { switch (effectCode) { case EFFECT_CODE_HP_DAMAGE: accumulatedEffect += timeStep * effectIntensity; applicableEffect = (int)accumulatedEffect; if (applicableEffect > 0) { accumulatedEffect -= applicableEffect; triggeringComponent.SufferHPDamage(applicableEffect, gameObject, triggerSourceComponent); } break; case EFFECT_CODE_HP_RECOVERY: accumulatedEffect += timeStep * effectIntensity; applicableEffect = (int)accumulatedEffect; if (applicableEffect > 0) { accumulatedEffect -= applicableEffect; triggeringComponent.AddToCurrentHP(applicableEffect, false); } break; } } }
// Spawn an animal of the given name at the given location public void spawnAnimalAtLocation(string name, Vector2 location) { if (animalHolder == null) { animalHolder = new GameObject("Animals").transform; } BaseAgent toSpawn = null; if (name == "sheep") { toSpawn = SHEEP[Random.Range(0, SHEEP.Length)]; BaseAgent spawned = Instantiate(toSpawn, location, Quaternion.identity); spawned.transform.SetParent(animalHolder); this.spawnedSheep.Add(spawned); } else if (name == "wolf") { toSpawn = WOLVES[Random.Range(0, WOLVES.Length)]; BaseAgent spawned = Instantiate(toSpawn, location, Quaternion.identity); spawned.transform.SetParent(animalHolder); } else { Debug.Log("Attempted to spawn unrecognized animal"); } }
public override void Initialize(BaseAgent agent) { if (agent.gameObject.CompareTag(Tag)) { agent.GetComponent <ObservableFields>().FieldsHash.Add(Label, Time.time); } }
public override void Initialize(BaseAgent agent) { base.Initialize(agent); PositionY = agent.gameObject.transform.position.y; academy = agent.area.academy; PlayAreaDistance = AcademyParameters.FetchOrParse(academy, PlayAreaDistanceKeyVal); }
protected override void Awake() { base.Awake(); agentComponent = null; waypointComponent = null; waypointPosition = Vector2.zero; agentPositioned = false; }
public override void ExtractInterests(ChallengeStage stage) { base.ExtractInterests(stage); if (stage != null) { agentComponent = stage.GetAgent(agentID); } }
public override Option <List <float> > FloatListObs(BaseAgent agent) { return(agent.gameObject.transform .SomeNotNull() .Map(t => new List <float>() { t.position.x, t.position.y, t.position.z })); }
public override void ExtractInterests(ChallengeStage stage) { base.ExtractInterests(stage); if (stage != null) { cameraController = stage.GetCameraController(); targetAgent = (targetAgentID == BaseAgent.INVALID_AGENT_ID) ? null : stage.GetAgent(targetAgentID, targetNodeID); } }
public void OnConsumption(BaseAgent consumingAgent) { Debug.Log("Agent Consuming"); agent = consumingAgent; agent.Consume(this); CanConsume = false; ConsumeTimer = Time.fixedTime + 8; RechargeTimer = Time.fixedTime + 16; }
public override List <float> CollectObservations(BaseAgent agent) { if (agent.gameObject.tag == Tag) { return(base.CollectObservations(agent)); } return(new List <float>()); }
public override Option <float> FloatObs(BaseAgent agent) { return(((BaseAgent)agent).TriggerCollider .Filter(tc => tc != null) .Map(tc => tc.gameObject) .Filter(tc => tc.gameObject.tag == Tag) .Map(tc => 1f) .Else(0f.Some())); }
/// <summary> /// 单一agent前进 /// </summary> /// <param name="preData"></param> /// <param name="agent"></param> /// <returns></returns> internal async Task MoveSingleAgents(IExecuteData preData, BaseAgent agent) { if (agent == null) { await MoveUnusualAgent(preData); return; } await agent.MoveIn(preData); }
// Remove all the info from the Hud public void ClearInfo() { this.agent = null; this.insistanceTexts.Clear(); foreach (Transform child in HudInsistanceGroup.transform) { GameObject.Destroy(child.gameObject); } }
public Solver(InputInterface p_inputInterface, StateEncoder p_encoder, BaseAgent p_agent, IExploration p_exp, Logger p_logger) { _inputInterface = p_inputInterface; _encoder = p_encoder; _agent = p_agent; _exploration = p_exp; _logger = p_logger; _gameState = new StateVar(); _histogram = new Dictionary <int, int>(); }