示例#1
0
        public void BasicTest()
        {
            var planningActions = new List <PlanningAction <string> >()
            {
                new PlanningAction <string>(
                    name: "init",
                    conditions: x => true,
                    effects: x =>
                {
                    x = "init";
                }
                    ),
                new PlanningAction <string>(
                    name: "execute",
                    conditions: x => x == "init",
                    effects: x =>
                {
                    x = "finish";
                })
            };

            //var actions = plan.Prepare()
            //        .AddState().Finish()
            //        .Solve("init", "finish")
            //        .PrintToConsole();

            var plan    = new GraphPlan <string>(Enums.PlanningMethod.DepthFirst, planningActions, new StringComparerer());
            var actions = plan.MakePlan("init", "finish");

            actions.PrintToConsole();
            //.Do("init")
        }
示例#2
0
        public void NoDice()
        {
            var planningActions = new List <PlanningAction <string> >()
            {
                new PlanningAction <string>(
                    name: "init",
                    conditions: x => true,
                    effects: x =>
                {
                    x = "init";
                }
                    ),
                new PlanningAction <string>(
                    name: "execute",
                    conditions: x => x == "init",
                    effects: x =>
                {
                    x = "finish";
                })
            };

            var plan    = new GraphPlan <string>(Enums.PlanningMethod.DepthFirst, planningActions, new StringComparerer());
            var actions = plan.MakePlan("init", "init");

            actions.PrintToConsole();
        }
示例#3
0
        public void TestSimpleGame()
        {
            var initState = new SimpleGame.SimpleGameState();

            var endState = new SimpleGame.SimpleGameState();

            endState.Player.hasAxe = false;
            endState.Player.Wood   = 20;
            endState.axeAvailable  = false;

            var planningActions = new List <PlanningAction <SimpleGame.SimpleGameState> >()
            {
                new PlanningAction <SimpleGame.SimpleGameState>(
                    name: "chopWood",
                    conditions: x =>
                {
                    return(x.Player.hasAxe);
                },
                    effects: x =>
                {
                    x.Player.Wood++;
                    if (x.Player.axeLife > 0)
                    {
                        x.Player.axeLife--;
                    }
                }
                    ),
                new PlanningAction <SimpleGame.SimpleGameState>(
                    name: "getAxe",
                    conditions: x =>
                {
                    return(!x.Player.hasAxe && x.axeAvailable);
                },
                    effects: x =>
                {
                    x.Player.hasAxe = true;
                    x.axeAvailable  = false;
                }
                    ),
                new PlanningAction <SimpleGame.SimpleGameState>(
                    name: "createAxe",
                    conditions: x =>
                {
                    return(x.Player.Wood >= 5);
                },
                    effects: x =>
                {
                    x.Player.hasAxe = true;
                    x.Player.Wood  -= 2;
                }
                    )
            };

            var plan    = new GraphPlan <SimpleGame.SimpleGameState>(Enums.PlanningMethod.DepthFirst, planningActions, new GameStateComparer());
            var actions = plan.MakePlan(initState, endState);

            actions.Do(initState);
        }
示例#4
0
        public void NicoArrivesAtWork()
        {
            var beginState = new Models.HQState()
            {
                Employees = new List <Models.Employee>()
                {
                    new Models.Employee()
                    {
                        IsAtWork = true,
                        Name     = "nico"
                    }
                }
                ,
                Servers = new List <Models.Server>()
                {
                    new Models.Server()
                    {
                        Behaviour   = Models.ServerBehaviour.WhenAtWork,
                        ServerState = Models.ServerState.NotFound,
                        snapshot_id = "snapshot_x",
                        provider    = "digitalocean",
                        ServerName  = "server-AtWork"
                    },
                    new Models.Server()
                    {
                        Behaviour   = Models.ServerBehaviour.AlwaysOn,
                        ServerState = Models.ServerState.On,
                        snapshot_id = "snapshot_x",
                        provider    = "digitalocean",
                        ServerName  = "server-AlwaysOn"
                    },
                }
            };


            var desiredEndState = AtWork(beginState);

            var actions = planner.MakePlan(beginState, desiredEndState);

            string t = "";
        }