public void AddDuplicateConsiderationTest() { var b = new Behaviour(); var consideration = new BehaviourConsideration(); b.AddConsideration(consideration); b.AddConsideration(consideration); }
public void DoesNotAddDuplicateOptionTest() { var b = new Behaviour(); var o = new Option(); Assert.That(b.AddConsideration(o), Is.True); Assert.That(b.AddConsideration(o), Is.False); }
public void Inititalize() { _toon = new Toon(); _ac = new ActionCollection(); _cc = new ConsiderationCollection(); _oc = new OptionCollection(_ac, _cc); _bc = new BehaviourCollection(_oc); _aic = new AiCollection(_bc); // The main AI _ai = new UtilityAi("ai", _aic); var coreBehaviour = new Behaviour("coreBehaviour", _bc); coreBehaviour.Selector = new MaxUtilitySelector(); _ai.AddBehaviour(coreBehaviour.NameId); // Eat Option _eatOption = new Option(); _eatOption.Measure = new WeightedMetrics(1.4f); var eatAction = new EatAction(); var hungerConsideration = new HungerConsideration(); (_eatOption as Option).SetAction(eatAction); _eatOption.AddConsideration(hungerConsideration); _eatOption.AddConsideration(new InverseBladderConsideration()); coreBehaviour.AddConsideration(_eatOption); // Drink Option _drinkOption = new Option(); _drinkOption.Measure = new WeightedMetrics(3.0f); var drinkAction = new DrinkAction(); var thirstConsideration = new ThirstConsideration(); (_drinkOption as Option).SetAction(drinkAction); _drinkOption.AddConsideration(thirstConsideration); _drinkOption.AddConsideration(new InverseBladderConsideration()); // Toilet Option _toiletOption = new Option(); _toiletOption.Measure = new WeightedMetrics(); var toiletAction = new ToiletAction(); var bladderConsideration = new BladderConsideration(); (_toiletOption as Option).SetAction(toiletAction); _toiletOption.AddConsideration(bladderConsideration); coreBehaviour.AddConsideration(_eatOption); coreBehaviour.AddConsideration(_drinkOption); coreBehaviour.AddConsideration(_toiletOption); Console.WriteLine(coreBehaviour); _scheduler = new Scheduler(); }
public void ConsiderTest([Values(-1f, 0f, 0.5f, 1f, 2f)] float value) { var b = new Behaviour(); var context = new BehaviourContext(); var consideration = new BehaviourConsideration(); b.AddConsideration(consideration); context.Bval = value; var cVal = value.Clamp01(); b.Consider(context); Assert.That(b.Utility.Value, Is.EqualTo(cVal).Within(Tolerance)); Assert.That(b.Utility.Weight, Is.EqualTo(One).Within(Tolerance)); }
protected override void DefineBehaviours() { B = new Behaviour(BehaviourDefs.LiveLong, Behaviours); B.AddOption(OptionDefs.Drink); B.AddOption(OptionDefs.Eat); B.AddOption(OptionDefs.Toilet); B.AddOption(OptionDefs.Sleep); B.AddOption(OptionDefs.Shower); B.AddOption(OptionDefs.Exercise); B.AddOption(OptionDefs.Idle); B.AddConsideration(ConsiderationDefs.LiveLong); B = new Behaviour(BehaviourDefs.Prosper, Behaviours); B.AddOption(OptionDefs.Work); B.AddOption(OptionDefs.Read); B.AddConsideration(ConsiderationDefs.Prosper); }
public void BehaviourSelectionTest() { var ai = new UtilityAi(); var context = new UaiContext(); var b1 = new Behaviour(); b1.NameId = "b1"; var b2 = new Behaviour(); b2.NameId = "b2"; var consideration1 = new BehaviourConsideration1(); var consideration2 = new BehaviourConsideration2(); b1.AddConsideration(consideration1); b2.AddConsideration(consideration2); var a1 = new MockAction(); a1.NameId = "a1"; var fo1 = new ConstantUtilityOption(); fo1.SetAction(a1); b1.AddOption(fo1); var a2 = new MockAction(); a2.NameId = "a2"; var fo2 = new ConstantUtilityOption(); fo2.SetAction(a2); b2.AddOption(fo2); ai.AddBehaviour(b1); ai.AddBehaviour(b2); context.Val1 = 1.0f; context.Val2 = 0.0f; var sel1 = ai.Select(context); Assert.That(sel1 == a1); context.Val1 = 0.0f; context.Val2 = 1.0f; var sel2 = ai.Select(context); Assert.That(sel2 == a2); }