コード例 #1
0
        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);
        }
コード例 #2
0
 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);
     }
 }
コード例 #3
0
        private bool depthSearch(WorldState WorldState)
        {
            if (destiny.Evaluate(WorldState) == true)
            {
                return(true);
            }

            List <Action> acts = new List <Action>();

            foreach (var item in Actions)
            {
                if (item.GetPreConditions(WorldState).isCompatibleSource(WorldState))
                {
                    if (item.ProceduralPreConditions(WorldState))
                    {
                        acts.Add(item);
                    }
                }
            }

            if (acts.Count == 0)
            {
                return(false);
            }

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

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

                if (depthSearch(ws) == true)
                {
                    act.AddFirst(item);
                    return(true);
                }
            }

            return(false);
        }
コード例 #4
0
        public override PlanSet CreatePlan(WorldState actual, Goal destiny)
        {
            PlanSet PlanSet = new PlanSet();

            WorldState current = actual.Clone();
            int        iter    = 0;

            while (!destiny.Evaluate(current))
            {
                Action act = null;
                foreach (var item in Actions)
                {
                    if (item.GetPreConditions(current).isCompatibleSource(current))
                    {
                        if (item.ProceduralPreConditions(current))
                        {
                            act = item;
                            break;
                        }
                    }
                }

                if (act != null)
                {
                    foreach (var item in act.GetEffects(current).GetSymbols())
                    {
                        current.SetSymbol(item.Clone());
                    }
                    act.ApplyEffects(current);
                }
                else
                {
                    return(null);
                }
                iter++;
                if (iter > MaxIteration)
                {
                    return(null);
                }

                System.Diagnostics.Debug.WriteLine(act.Name);
            }
            System.Diagnostics.Debug.WriteLine(destiny.Name);
            return(PlanSet);
        }
コード例 #5
0
        public override PlanSet CreatePlan(WorldState actual, Goal destiny)
        {
            PlanSet PlanSet = new PlanSet();
            LinkedList <pathrec> processing = new LinkedList <pathrec>();

            processing.AddLast(
                new pathrec()
            {
                act        = new List <Action>(),
                WorldState = actual
            }
                );

            int     iter    = 0;
            pathrec current = null;

            while (processing.Count != 0)
            {
                current = processing.First.Value;
                processing.RemoveFirst();

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

                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);

                    System.Diagnostics.Debug.WriteLine(item.Name);

                    pathrec pathrec = new pathrec();
                    pathrec.WorldState = ws;
                    pathrec.act        = new List <Action>(current.act.ToArray());
                    pathrec.act.Add(item);
                    processing.AddLast(pathrec);
                }

                System.Diagnostics.Debug.WriteLine("---START");
                foreach (var item in processing)
                {
                    System.Diagnostics.Debug.WriteLine("-<>-");
                    foreach (var item2 in item.act)
                    {
                        System.Diagnostics.Debug.WriteLine(item2.Name);
                    }
                }
                System.Diagnostics.Debug.WriteLine("---END");

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

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


            return(PlanSet);
        }
コード例 #6
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);
        }