public override StateList Simulate(StateList world, StateList goal) { StateList simulated = (StateList)world.Clone(); simulated.SetState("IsPatrolling", 1.0f); return(simulated); }
public void StateMatchingPartial() { // Test a match of a goal that doesn't care about some parts of our world // Populate our world StateList world = new StateList(); world.SetState("health", 10.0f); world.SetState("ammo", 40.0f); world.SetState("locationX", 15.0f); world.SetState("locationY", -35.0f); // our goal only cares about location StateList goal = new StateList(); goal.SetState("locationX", 15.0f); goal.SetState("locationY", -35.0f); // This is no longer bidirectional Assert.True(world.Matches(goal)); }
public void StateMatchingMissingInfo() { // Test a match failure of a world that doesn't have info our goal needs // Populate our world - no ammo StateList world = new StateList(); world.SetState("health", 10.0f); world.SetState("locationX", 15.0f); world.SetState("locationY", -35.0f); // our goal only cares about location and ammo StateList goal = new StateList(); goal.SetState("ammo", 40.0f); goal.SetState("locationX", 15.0f); goal.SetState("locationY", -35.0f); goal.SaveCache(); // We can't match info we don't have Assert.False(world.Matches(goal)); }
public void StateMatchingPerfect() { // Tests a perfect match // Populate our world StateList world = new StateList(); world.SetState("health", 10.0f); world.SetState("ammo", 40.0f); world.SetState("locationX", 15.0f); world.SetState("locationY", -35.0f); // Set our goal StateList goal = new StateList(); goal.SetState("health", 10.0f); goal.SetState("ammo", 40.0f); goal.SetState("locationX", 15.0f); goal.SetState("locationY", -35.0f); // They should be perfectly equal Assert.True(world.Matches(goal)); Assert.True(goal.Matches(world)); }
// Called when planning, to simulate the effects of the action to the world public override StateList Simulate(StateList world) { StateList applied = world.Copy(); postconditions.SaveCache(); // check each property in the state, and change it from precondition to postcondition foreach (State postcondition in postconditions.states) { applied.SetState(postcondition.Name, postcondition.Value); } return(applied); }
public void StateMatchingOutOfOrder() { // Test a match with elements added out of order // Populate our world StateList world = new StateList(); world.SetState("health", 10.0f); world.SetState("ammo", 40.0f); world.SetState("locationX", 15.0f); world.SetState("locationY", -35.0f); // Set our goal StateList goal = new StateList(); goal.SetState("locationY", -35.0f); goal.SetState("ammo", 40.0f); goal.SetState("locationX", 15.0f); goal.SetState("health", 10.0f); // They should still match Assert.True(world.Matches(goal)); Assert.True(goal.Matches(world)); }
// Use this for initialization void Start() { broadcast = true; Button = GetComponent <ButtonLogic>(); // == PRECONDITIONS == // preconditions = new StateList(); // All of the blocking doors must be opened foreach (DoorLogic d in BlockingDoors) { string state = d.gameObject.name + " is open"; preconditions.SetState(state, 1.0f); } // The button has to not be already pressed preconditions.SetState(Button.gameObject.name + " is pressed", 0.0f); // == POSTCONDITIONS == // postconditions = new StateList(); // Our postconditions is the button is pressed postconditions.SetState(Button.gameObject.name + " is pressed", 1.0f); // And the door the button was hooked up to is opened if (Button.door) { postconditions.SetState(Button.door.gameObject.name + " is open", 1.0f); } }