Esempio n. 1
0
    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));
    }
Esempio n. 2
0
    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));
    }
Esempio n. 3
0
    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));
    }
Esempio n. 4
0
    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));
    }
 // Called when checking if the action can be applied to the current world state
 public override bool CheckPreconditions(StateList world, StateList goal)
 {
     // goal is provided as a parameter to be used in derived functions
     // If all precons pass, then we're good
     return(world.Matches(preconditions));
 }