/// <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)); }
// 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>(); }
/// <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)); }
/// <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)); }
/// <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); }
/// <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); }
/// <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); }
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); } }
public void SetBB(BeliefBase bb) { this.bb = bb; }