コード例 #1
0
        /// <summary>
        /// We update the beliefbase
        /// </summary>
        /// <param name="percepts">The percepts we retrieved for this agent from the environment</param>
        protected override void UpdateBeliefs(Dictionary <string, object> percepts)
        {
            var beliefSetTowns = BeliefBase.GetBeliefSet("towns").Values;
            var beliefSetMines = BeliefBase.GetBeliefSet("mines").Values;

            foreach (var town in (percepts["towns"] as List <Town>))
            {
                if (!beliefSetTowns.Contains(town))
                {
                    beliefSetTowns.Add(town);
                }
            }

            foreach (var goldMine in beliefSetMines.Select(x => (GoldMine)x).ToList())
            {
                if (!(percepts["mines"] as List <GoldMine>).Contains(goldMine) &&
                    Math.Pow(CurrentX - goldMine.X, 2) + Math.Pow(CurrentY - goldMine.Y, 2) < 4)
                {
                    beliefSetMines.Remove(goldMine);
                }
            }

            foreach (var goldMine in (percepts["mines"] as List <GoldMine>))
            {
                if (!beliefSetMines.Contains(goldMine))
                {
                    beliefSetMines.Add(goldMine);
                }
            }

            BeliefBase.UpdateBelief(new Belief("inx", CurrentX));
            BeliefBase.UpdateBelief(new Belief("iny", CurrentY));
            BeliefBase.UpdateBelief(new Belief("hasgold", HasGold));
        }
コード例 #2
0
ファイル: GameController.cs プロジェクト: nasa03/Jasonity
 // Start is called before the first frame update
 public override void Start()
 {
     bob  = Agent.Create(new AgentArchitecture(), "", new Runtime.Settings()); //aqui de alguna manera creo un agente que diga hola
     bb   = new BeliefBase();
     pl   = new PlanLibrary();
     lamp = lightbulb.GetComponent <Lamp>();
     lightOnAgentScript  = lightOnAgent.GetComponent <LightOnAgent>();
     lightOffAgentScript = lightOffAgent.GetComponent <LightOffAgent>();
 }
コード例 #3
0
 /// <summary>
 /// We initialize the agent with a current set of intentions
 /// </summary>
 /// <param name="desires">The current set of desires</param>
 /// <param name="intention">The current intention</param>
 /// <returns>An asynchronous task of the agent fulfilling the intentions</returns>
 public override Task Init(List <Desire <GoldMineAction, GoldMineAgent, GoldMineEnvironment> > desires,
                           List <Intention <GoldMineAction, GoldMineAgent, GoldMineEnvironment> > intentions)
 {
     BeliefBase.AddBeliefSet(new BeliefSet("mines"));
     BeliefBase.AddBeliefSet(new BeliefSet("towns"));
     Actions.Add(new GoToAction());
     Actions.Add(new MineGoldAction());
     Actions.Add(new SellGoldAction());
     return(base.Init(desires, intentions));
 }
コード例 #4
0
        /// <summary>
        /// We initialize the agent with a current set of intentions
        /// </summary>
        /// <param name="desires">The current set of desires</param>
        /// <param name="intentions">The current intentions</param>
        /// <returns>An asynchronous task of the agent fulfilling the intentions</returns>
        public override Task Init(List <Desire <BlocksworldAction, BlocksworldAgent, BlocksworldEnvironment> > desires,
                                  List <Intention <BlocksworldAction, BlocksworldAgent, BlocksworldEnvironment> > intentions)
        {
            var table = new Table();

            BeliefBase.AddBeliefSet(new BeliefSet("blocks"));
            BeliefBase.UpdateBelief(new Belief("inarm", null));
            BeliefBase.UpdateBelief(new Belief("table", table));
            Actions.Add(new PickupAction(table));
            Actions.Add(new PutDownAction(table));
            Actions.Add(new StackAction());
            Actions.Add(new UnstackAction());
            return(base.Init(desires, intentions));
        }
コード例 #5
0
        /// <summary>
        /// The beliefbase of the agent is updated through the received percepts
        /// </summary>
        /// <param name="percepts">The percepts as a list of keyvalue pairs</param>
        protected override void UpdateBeliefs(Dictionary <string, object> percepts)
        {
            var perceptedTable = (Table)percepts["table"];

            BeliefBase.UpdateBelief(new Belief("table", perceptedTable));
            BeliefBase.UpdateBelief(new Belief("inarm", InArm));
            var beliefsetBlocks    = BeliefBase.GetBeliefSet("blocks");
            var newBeliefSetBlocks = new BeliefSet("blocks");

            foreach (var block in perceptedTable.Blocks)
            {
                UpdateFactForOneBlock(beliefsetBlocks, newBeliefSetBlocks, block);
            }

            BeliefBase.UpdateBeliefSet(newBeliefSetBlocks);
        }
コード例 #6
0
        /// <summary>
        /// Extracts facts for STRIPS from the current beliefbase
        /// </summary>
        /// <returns>A list of STRIP facts</returns>
        protected override List <Fact> ExtractFactsFromBeliefBase()
        {
            var facts = new List <Fact> {
                new Fact("ArmHolds", new ValueParameter(BeliefBase.GetBelief("inarm").Value))
            };
            var blocks = BeliefBase.GetBeliefSet("blocks").Values;

            foreach (Block block in blocks)
            {
                if (block.Lower != null)
                {
                    facts.Add(new Fact("On", new ValueParameter(block), new ValueParameter(block.Lower)));
                }

                if (block.Upper == null)
                {
                    facts.Add(new Fact("Clear", new ValueParameter(block)));
                }
            }
            return(facts);
        }
コード例 #7
0
        /// <summary>
        /// Extracts facts from a beliefbase
        /// </summary>
        /// <returns>A list of facts</returns>
        protected override List <Fact> ExtractFactsFromBeliefBase()
        {
            var lstFact = new List <Fact>();

            lstFact.Add(new Fact(Definitions.HasGold, new ValueParameter(BeliefBase.GetBelief("hasgold").GetValue <bool>())));

            lstFact.Add(new Fact(Definitions.In, new ValueParameter(BeliefBase.GetBelief("inx").Value),
                                 new ValueParameter(BeliefBase.GetBelief("iny").Value)));

            foreach (Town town in BeliefBase.GetBeliefSet("towns").Values)
            {
                lstFact.Add(new Fact(Definitions.Town, new ValueParameter(town.X), new ValueParameter(town.Y)));
            }

            foreach (GoldMine mine in BeliefBase.GetBeliefSet("mines").Values)
            {
                lstFact.Add(new Fact(Definitions.Mine, new ValueParameter(mine.X), new ValueParameter(mine.Y)));
            }

            return(lstFact);
        }
コード例 #8
0
        public static Agent Create(AgentArchitecture agArch, string asSrc, Settings stts)
        {
            try
            {
                Agent      ag = new Agent();
                Reasoner   r  = new Reasoner(ag, null, agArch, stts);
                BeliefBase bb = null;
                bb = new BeliefBase();


                ag.SetBB(bb);
                ag.InitAg();

                //bb.Init(ag);

                ag.Load(asSrc);
                return(ag);
            }
            catch (Exception e)
            {
                throw new JasonityException(e.Message);
            }
        }
コード例 #9
0
 public void SetBB(BeliefBase bb)
 {
     this.bb = bb;
 }