public override void ApplyEffects(PloobsEngine.IA.WorldState WorldState)
        {
            ////remove the resources
            foreach (var item in resourcesNeeded)
            {
                WorldSymbol WorldSymbol2 = WorldState.GetSymbol(item.Key);
                WorldSymbol2.SetSymbol <int>(WorldSymbol2.GetSymbol <int>() - item.Value);
                WorldState.SetSymbol(WorldSymbol2);
            }


            ///add one house
            WorldSymbol WorldSymbol = WorldState.GetSymbol(houseName);

            if (WorldSymbol == null)
            {
                WorldSymbol = new WorldSymbol(houseName, 1);
                WorldState.SetSymbol(WorldSymbol);
            }
            else
            {
                int val = WorldSymbol.GetSymbol <int>();
                WorldSymbol.SetSymbol(val + 1);
                WorldState.SetSymbol(WorldSymbol);
            }

            base.ApplyEffects(WorldState);
        }
 public override void ApplyEffects(PloobsEngine.IA.WorldState WorldState)
 {
     ////add the resource
     {
         WorldSymbol WorldSymbol2 = WorldState.GetSymbol(resourceName);
         WorldSymbol2.SetSymbol <int>(WorldSymbol2.GetSymbol <int>() + Quantity);
         WorldState.SetSymbol(WorldSymbol2);
     }
 }
Exemple #3
0
        public void teste()
        {
            BlackBoard BlackBoard = new PloobsEngine.IA.BlackBoard();
            WorldState WorldState = new PloobsEngine.IA.WorldState();

            WorldState.SetSymbolValue <int>("gold", 5);
            WorldState.SetSymbolValue <int>("wood", 5);
            WorldState.SetSymbolValue <int>("castle", 0);
            WorldState.SetSymbolValue <int>("warrior", 0);
            WorldState.SetSymbolValue <bool>("attack", false);
            BlackBoard.SetEntry <WorldState>("WorldState", WorldState);

            Dictionary <string, int> resneeded = new Dictionary <string, int>();

            resneeded.Add("gold", 10);

            Dictionary <string, int> resneeded2 = new Dictionary <string, int>();

            resneeded2.Add("wood", 2);
            resneeded2.Add("gold", 2);

            Dictionary <string, int> unitneeded = new Dictionary <string, int>();

            unitneeded.Add("warrior", 3);

            List <PloobsEngine.IA.Action> actions = new List <PloobsEngine.IA.Action>();

            actions.Add(new GatherResource("gold", 5));
            actions.Add(new GatherResource("wood", 5));
            actions.Add(new Build(resneeded, "castle", 1));
            actions.Add(new MakeUnit("warrior", "castle", resneeded2));
            actions.Add(new Patrol());
            actions.Add(new Attack(unitneeded));

            GoalPlanning GoalPlanning = new GoalPlanning(BlackBoard);
            PlanSet      PlanSet      = GoalPlanning.GetPlan(new GoalAttack(), actions);

            System.Diagnostics.Debug.Assert(PlanSet != null);

            foreach (var item in PlanSet.Actions)
            {
                Console.WriteLine(item.Name);
            }
        }
Exemple #4
0
        public override PlanSet CreatePlan(WorldState actual, Goal destiny)
        {
            int     iter    = 0;
            PlanSet PlanSet = new PlanSet();
            PriorityQueueB <pathrecnode> processing = new PriorityQueueB <pathrecnode>(new comparer());
            List <WorldState>            close      = new List <WorldState>();

            processing.Push(
                new pathrecnode()
            {
                act        = new List <Action>(),
                WorldState = actual,
                f          = 0,
                g          = 0,
                h          = 0,
            }
                );

            pathrecnode current = null;

            while (processing.Count != 0)
            {
                current = processing.Pop();

                if (destiny.Evaluate(current.WorldState) == true)
                {
                    break;
                }

                if (close.Contains(current.WorldState))
                {
                    continue;
                }
                else
                {
                    close.Add(current.WorldState);
                }

                List <Action> acts = new List <Action>();
                foreach (var item in Actions)
                {
                    if (item.GetPreConditions(current.WorldState).isCompatibleSource(current.WorldState))
                    {
                        if (item.ProceduralPreConditions(current.WorldState))
                        {
                            acts.Add(item);
                        }
                    }
                }

                foreach (var item in acts)
                {
                    WorldState ws = current.WorldState.Clone();
                    foreach (var item2 in item.GetEffects(current.WorldState).GetSymbols())
                    {
                        ws.SetSymbol(item2.Clone());
                    }
                    item.ApplyEffects(ws);

                    pathrecnode pathrec = new pathrecnode();
                    pathrec.WorldState = ws;
                    pathrec.act        = new List <Action>(current.act.ToArray());
                    pathrec.act.Add(item);
                    pathrec.g += 1 + item.Cost;
                    pathrec.h  = destiny.GetHeuristic(pathrec.WorldState);
                    //pathrec.WorldState.GetHeuristic(destiny.WorldState);
                    pathrec.f = pathrec.g + pathrec.h;
                    processing.Push(pathrec);
                }


                iter++;
                if (iter > MaxIteration)
                {
                    return(null);
                }

                Debug(processing, iter);
            }

            if (current != null)
            {
                foreach (var item in current.act)
                {
                    PlanSet.Actions.Add(item);
                    System.Diagnostics.Debug.WriteLine(item.Name);
                }
            }


            return(PlanSet);
        }
Exemple #5
0
 public abstract PlanSet CreatePlan(WorldState actual, Goal destiny);
        public void teste()
        {
            BlackBoard BlackBoard = new PloobsEngine.IA.BlackBoard();
            WorldState WorldState = new PloobsEngine.IA.WorldState();
            WorldState.SetSymbolValue<int>("gold", 5);
            WorldState.SetSymbolValue<int>("wood", 5);
            WorldState.SetSymbolValue<int>("castle", 0);
            WorldState.SetSymbolValue<int>("warrior", 0);
            WorldState.SetSymbolValue<bool>("attack", false);
            BlackBoard.SetEntry<WorldState>("WorldState", WorldState);
            
            Dictionary<string, int> resneeded = new Dictionary<string, int>();
            resneeded.Add("gold",10);

            Dictionary<string, int> resneeded2 = new Dictionary<string, int>();
            resneeded2.Add("wood", 2);
            resneeded2.Add("gold", 2);

            Dictionary<string, int> unitneeded = new Dictionary<string, int>();
            unitneeded.Add("warrior", 3);

            List<PloobsEngine.IA.Action> actions = new List<PloobsEngine.IA.Action>();
            actions.Add(new GatherResource("gold",5));
            actions.Add(new GatherResource("wood", 5));
            actions.Add(new Build(resneeded, "castle", 1));
            actions.Add(new MakeUnit("warrior", "castle", resneeded2));
            actions.Add(new Patrol());
            actions.Add(new Attack(unitneeded));
            
            GoalPlanning GoalPlanning = new GoalPlanning(BlackBoard);
            PlanSet PlanSet = GoalPlanning.GetPlan(new GoalAttack(), actions);

            System.Diagnostics.Debug.Assert(PlanSet != null);

            foreach (var item in PlanSet.Actions)
            {
                Console.WriteLine(item.Name);
            }
        }
Exemple #7
0
 public abstract int GetHeuristic(WorldState WorldState);
Exemple #8
0
 public abstract bool Evaluate(WorldState state);