public override void OnInspectorGUI() { m_Target = (UtilityAI)target; DrawDefaultInspector(); DrawStatesInspector(); }
public void UpdateUtilityActions() { CAA caa; UtilityAction selected; for (int i = 0; i < this.caas.Count; ++i) { // caa links a controller to its currently running actions // -> its 'ctr' field is the controller (i.e. a bunny) // -> its 'main' field contains a running action which cannot be parallelizable // -> its 'parallelizables' field contains all possible running parallelizables actions caa = this.caas[i]; // select best action by score selected = UtilityAI.Select(caa.ctr, this.actions); // if there is already an action running (i.e. it is a coroutine) if (caa.main != null && caa.main.isRunning) { // if best action is not one of the current actions if (!caa.IsCurrentlyRunning(selected)) { // if selected is parallelizable && current allows it if (selected.isParallelizable && !caa.main.isForceAlone) { // start selected action caa.StartAction(selected); } // if current is stoppable else if (caa.main.isStoppable) { // stop current action caa.StopMainAction(); // start selected action caa.StartAction(selected); } } // here either : // - current is unstoppable or // - current does not allow parallelization or // - selected is already running or // - selected has been launch. } // if current is not running (i.e. there is no 'current' or it is not a coroutine) else { // start selected action caa.StartAction(selected); } } }
// Use this for initialization void Start() { utilityAI = GetComponent <UtilityAI> (); //aiAgent = GameObject.FindGameObjectWithTag ("Agent"); currentHealth = maxHealth; currentAmmo = ammoCapacity; inRange = false; }
// Use this for initialization private void Start() { hunger = Random.Range(0, 10); boredom = Random.Range(0, 10); energy = Random.Range(0, 10); hygiene = Random.Range(0, 10); utility = GameObject.Find("_Utility"); utilityScript = utility.GetComponent <UtilityAI>(); rigidBody = GetComponent <Rigidbody>(); utilityComp = new float[4]; targets = new string[4]; targets[0] = "Food"; targets[1] = "Sleep"; targets[2] = "Couch"; targets[3] = "Shower"; }
public override void onAddedToEntity() { enabled = false; var reasoner = new FirstScoreReasoner <UtilityMiner>(); // sleep is most important // AllOrNothingQualifier with required threshold of 1 so all scorers must score // - we have to be home to sleep // - we have to have some fatigue var fatigueConsideration = new AllOrNothingConsideration <UtilityMiner>(1) .addAppraisal(new ActionAppraisal <UtilityMiner>(c => c.minerState.currentLocation == MinerState.Location.Home ? 1 : 0)) .addAppraisal(new ActionAppraisal <UtilityMiner>(c => c.minerState.fatigue > 0 ? 1 : 0)); fatigueConsideration.action = new ActionExecutor <UtilityMiner>(c => c.sleep()); reasoner.addConsideration(fatigueConsideration); // thirst is next // AllOrNothingQualifier with required threshold of 1 so all scorers must score // - we have to be at the saloon to drink // - we have to be thirsty var thirstConsideration = new AllOrNothingConsideration <UtilityMiner>(1) .addAppraisal(new ActionAppraisal <UtilityMiner>(c => c.minerState.currentLocation == MinerState.Location.Saloon ? 1 : 0)) .addAppraisal(new ActionAppraisal <UtilityMiner>(c => c.minerState.thirst > 0 ? 1 : 0)); thirstConsideration.action = new ActionExecutor <UtilityMiner>(c => c.drink()); reasoner.addConsideration(thirstConsideration); // depositing gold is next // AllOrNothingQualifier with required threshold of 1 so all scorers must score // - we have to be at the bank to deposit gold // - we have to have gold to deposit var goldConsideration = new AllOrNothingConsideration <UtilityMiner>(1) .addAppraisal(new ActionAppraisal <UtilityMiner>(c => c.minerState.currentLocation == MinerState.Location.Bank ? 1 : 0)) .addAppraisal(new ActionAppraisal <UtilityMiner>(c => c.minerState.gold > 0 ? 1 : 0)); goldConsideration.action = new ActionExecutor <UtilityMiner>(c => c.depositGold()); reasoner.addConsideration(goldConsideration); // decide where to go. this will override mining and send us elsewhere if a scorer scores // AllOrNothingQualifier with required threshold of 0 so we get a sum of all scorers // - if we are max fatigued score // - if we are max thirsty score // - if we are at max gold score // - if we are not at the mine score // Action has a scorer to score all the locations. It then moves to the location that scored highest. var moveConsideration = new AllOrNothingConsideration <UtilityMiner>(0) .addAppraisal(new ActionAppraisal <UtilityMiner>(c => c.minerState.fatigue >= MinerState.MAX_FATIGUE ? 1 : 0)) .addAppraisal(new ActionAppraisal <UtilityMiner>(c => c.minerState.thirst >= MinerState.MAX_THIRST ? 1 : 0)) .addAppraisal(new ActionAppraisal <UtilityMiner>(c => c.minerState.gold >= MinerState.MAX_GOLD ? 1 : 0)) .addAppraisal(new ActionAppraisal <UtilityMiner>(c => c.minerState.currentLocation != MinerState.Location.Mine ? 1 : 0)); var moveAction = new MoveToBestLocation(); moveAction.addScorer(new ChooseBestLocation()); moveConsideration.action = moveAction; reasoner.addConsideration(moveConsideration); // mining is last // AllOrNothingQualifier with required threshold of 1 so all scorers must score // - we have to be at the mine to dig for gold // - we have to not be at our max gold var mineConsideration = new AllOrNothingConsideration <UtilityMiner>(1) .addAppraisal(new ActionAppraisal <UtilityMiner>(c => c.minerState.currentLocation == MinerState.Location.Mine ? 1 : 0)) .addAppraisal(new ActionAppraisal <UtilityMiner>(c => c.minerState.gold >= MinerState.MAX_GOLD ? 0 : 1)); mineConsideration.action = new ActionExecutor <UtilityMiner>(c => c.digForGold()); reasoner.addConsideration(mineConsideration); // default, fall-through action is to head to the mine reasoner.defaultConsideration.action = new ActionExecutor <UtilityMiner>(c => c.goToLocation(MinerState.Location.Mine)); _ai = new UtilityAI <UtilityMiner>(this, reasoner); }
private static UniformGrid UnitTestCrossover(int rows) { int columns = StaticRandom.Next(2, 13); #region build parents SolidColorBrush[][] parents = UtilityWPF.GetRandomColors(rows, 96, 224). Select(o => { SolidColorBrush brush = new SolidColorBrush(o); return(Enumerable.Range(0, columns). Select(p => brush). ToArray()); }). ToArray(); #endregion int numSlices = 1 + StaticRandom.Next(columns - 1); // Crossover SolidColorBrush[][] children = UtilityAI.Crossover(parents, numSlices); #region build return UniformGrid grid = new UniformGrid() { Columns = columns, Rows = rows, }; for (int row = 0; row < rows; row++) { for (int col = 0; col < columns; col++) { Border rect = new Border() { Background = children[row][col], BorderBrush = Brushes.Black, CornerRadius = new CornerRadius(6), BorderThickness = new Thickness(1), Margin = new Thickness(3), }; if (col == 0) { Color color = UtilityWPF.ExtractColor(children[row][col]); TextBlock text = new TextBlock() { Text = string.Format("{0} {1} {2}", color.R, color.G, color.B), Foreground = new SolidColorBrush(UtilityWPF.OppositeColor(color)), HorizontalAlignment = HorizontalAlignment.Center, VerticalAlignment = VerticalAlignment.Center, }; //rect.Child = text; } grid.Children.Add(rect); } } #endregion return(grid); }
protected virtual void Awake() { this.utilityAI = new UtilityAI(this.actions, this); this.controllers = new List <CAA>(); }