public override Queue <Location> ExtractPlan(Subject s, Intention i, Beliefs b, List <Location> path) { Queue <Location> plan = new Queue <Location>(); Location dest = new Location(); HashSet <Location> fov = FOV.GetFov(b.Agents[i.ID].Direction, b.Agents[i.ID].Location); if (fov.Except(FOV.GetSharedFov(s, b.Agents[i.ID])).Count() > 0) { dest = Util.RandomElement(fov.Except(FOV.GetSharedFov(s, b.Agents[i.ID])).ToList(), s.Location); } else { dest = Util.RandomElement(fov.ToList(), s.Location); } FlankNode fNode = new FlankNode(null, dest, b.Agents[i.ID].Location) { CurLocation = new Location(s.Location), Obstacles = new HashSet <Location>(b.Obstacles.Keys) }; fNode.Obstacles.UnionWith(Util.GetDynamicObstacles(s.ID, s.Location, b)); plan = Planner.Search(fNode); return(plan); }
// The recursive higher-order observation method as described in the thesis. // It has a height limiter to specify the desired max order of observation. public void UpdateToM(Subject s, Beliefs b, HashSet <Location> fov, int height) { if (height == 0 || b.Sees.Agents.Count == 0) { return; } foreach (KeyValuePair <char, Subject> kvp in b.Sees.Agents) { HashSet <Location> intersectFov = FOV.GetSharedFov(kvp.Value, s); VisionPercept vp = Sight.Perceive(kvp.Key, intersectFov); AudioPercept ap = Hearing.Perceive(kvp.Key, kvp.Value.Location); if (!b.ToM.ContainsKey(kvp.Key)) { b.ToM.Add(kvp.Key, new Beliefs()); } b.ToM[kvp.Key].Update(vp); b.ToM[kvp.Key].Update(ap); UpdateToM(kvp.Value, b.ToM[kvp.Key], intersectFov, height - 1); } }
public Agent(Environnement env) { captor = new Captor(env); effector = new Effector(env); _beliefs = new Beliefs(); this._beliefs.environment = env; }
protected override bool Succeeded(Intention i, Beliefs b) { // If eating and counter is done, remove food object from level. if (i.Name == "eat") { if (counter < 0.1f) { b.Foods.Remove(Location); Manager.Instance.RemoveObject(Location); return(true); } } if (i.Name == "wait") { if (counter < 0.1f) { return(true); } } // Searching succeedes if room has been explored. if (i.Name == "search" && !b.Rooms.ContainsKey(i.ID)) { return(true); } return(false); }
public override Queue <Location> ExtractPlan(Subject s, Intention i, Beliefs b, List <Location> path) { Queue <Location> plan = new Queue <Location>(); Subject subj = new Subject(); if (b.Sees.Agents.Count > 0 || b.Hears.Agents.Count > 0) { subj = Util.NearestAgent(Util.Merge(b.Hears.Agents, b.Sees.Agents).Values.ToList(), s.Location); i.ID = subj.ID; } else { subj.Location = s.Location; } FleeNode fNode = new FleeNode(null, s.Location, subj.Location, 10) { CurLocation = new Location(s.Location), Obstacles = new HashSet <Location>(b.Obstacles.Keys) }; plan = Planner.Search(fNode); return(plan); }
public static HashSet <Location> GetDynamicObstacles(char id, Location loc, Beliefs b) { HashSet <Location> obstacles = new HashSet <Location>(); foreach (KeyValuePair <char, Subject> kvp in b.Sees.Agents) { if (kvp.Key == '0' || kvp.Value.Location == loc) { continue; } if (IsCat(id) || (IsChild(id) && !IsRegrouping(kvp.Key) && (!b.ToM[kvp.Key].Sees.Agents.ContainsKey(id) || IsHigherRank(kvp.Key, id) || IsRecovering(kvp.Key) || IsUrgent(kvp.Key)))) { obstacles.Add(kvp.Value.Location); } } return(obstacles); }
public bool HasReasonFor(Subject s, Beliefs b, Intention i) { if (!new Capture().HasReasonFor(s, b, i)) { if (b.Sees.Agents.ContainsKey('0')) { if (b.ToM['0'].Sees.Agents.ContainsKey(s.ID)) { if (Util.GetAgentSpeed('0') != (int)Speed.VeryFast) { return(true); } } else { if (Util.L1Distance(s.Location, b.Agents['0'].Location) <= 2) { return(true); } } } } return(false); }
public override bool PrePerform() { GameObject victim = Inventory.GetItem(VictimKey); if (victim) { if (victim.activeSelf) { if ((Time.time - mLastAttack) > TimeBetweenAttacks) { Health health = victim.GetComponent <Health>(); health.ReduceHealth(Damage); if (health.CurrentAmount <= 0) { Loot loot = victim.GetComponent <Loot>(); if (loot && mCargo) { mCargo.Add(loot.Value); } victim.gameObject.SetActive(false); } mLastAttack = Time.time; } } if (!victim.activeSelf) { Inventory.RemoveItem(VictimKey); Beliefs.RemoveState(FoundVictimKey); } } return(false); }
public bool HasReasonFor(Subject s, Beliefs b, Intention i) { if (!new Recover().HasReasonFor(s, b, i)) { if (b.Sees.Agents.ContainsKey('0')) { if (b.ToM['0'].Hears.Agents.ContainsKey(s.ID) || Util.GetAgentSpeed('0') == (int)Speed.VeryFast) { return(true); } // If lower rank, Misdirect the cat if another agent is seen // and sees this agent and they both see the cat. if (b.Sees.Agents.Count > 1) { foreach (Subject subj in b.Sees.Agents.Values) { if (Util.IsChild(subj.ID) && b.ToM[subj.ID].Sees.Agents.ContainsKey(s.ID) && ((b.ToM[subj.ID].Sees.Agents.ContainsKey('0') && Util.IsHigherRank(subj.ID, s.ID)) || !b.ToM[subj.ID].Sees.Agents.ContainsKey('0'))) { return(true); } } } } } return(false); }
void GetTired() { Beliefs.ModifyState("IsExhausted", 0); Invoke ("GetTired", Random.Range(TiredProbMin, TiredProbMax)); }
private void SetPriors(AllergenData data, int numVulnerabilities, Beliefs beliefs) { int nY = AllergenData.NumYears; int nN = data.DataCountChild.Length; int nA = data.NumAllergens; bool useUniformClassPrior = true; if (beliefs == null) { this.probSensClassPrior.ObservedValue = useUniformClassPrior ? Dirichlet.PointMass(Vector.Constant(numVulnerabilities, 1.0 / numVulnerabilities)) : Dirichlet.Symmetric(numVulnerabilities, 0.1); this.probSens1Prior.ObservedValue = Util.ArrayInit(nA, numVulnerabilities, (a, v) => new Beta(1, 1)); this.probGainPrior.ObservedValue = Util.ArrayInit(nY, y => Util.ArrayInit(nA, numVulnerabilities, (a, v) => new Beta(1, 1))); this.probRetainPrior.ObservedValue = Util.ArrayInit(nY, y => Util.ArrayInit(nA, numVulnerabilities, (a, v) => new Beta(1, 1))); this.probSkinIfSensPrior.ObservedValue = new Beta(2.0, 1); this.probSkinIfNotSensPrior.ObservedValue = new Beta(1, 2.0); this.probIgeIfSensPrior.ObservedValue = new Beta(2.0, 1); this.probIgeIfNotSensPrior.ObservedValue = new Beta(1, 2.0); } else { this.probSensClassPrior.ObservedValue = beliefs.ProbVulnerabilityClass; probSens1Prior.ObservedValue = Util.ArrayInit(nA, numVulnerabilities, (a, v) => beliefs.ProbSensitizationAgeOne[a, v]); probGainPrior.ObservedValue = Util.ArrayInit(nY, y => Util.ArrayInit(nA, numVulnerabilities, (a, v) => beliefs.ProbGainSensitization[y][a, v])); probRetainPrior.ObservedValue = Util.ArrayInit(nY, y => Util.ArrayInit(nA, numVulnerabilities, (a, v) => beliefs.ProbRetainSensitization[y][a, v])); probSkinIfSensPrior.ObservedValue = beliefs.ProbSkinIfSensitized; probSkinIfNotSensPrior.ObservedValue = beliefs.ProbSkinIfNotSensitized; probIgeIfSensPrior.ObservedValue = beliefs.ProbIgEIfSensitized; probIgeIfNotSensPrior.ObservedValue = beliefs.ProbIgEIfNotSensitized; } }
protected override bool Sound(Queue <Location> plan, Intention i, Beliefs b) { // If exploring and the entire path is within FOV, this area of the room // is already searched so re-plan. if (i.Name == "explore") { List <Location> intersect = plan.Intersect(b.Sees.Locations).ToList(); if (intersect.Count == plan.Count) { return(false); } } // Re-plan if an obstacle is discovered which is located on the current // planned path. foreach (Location loc in plan) { if (b.Obstacles.ContainsKey(loc)) { return(false); } } return(true); }
public Beliefs Run(AllergenData data, int numVulnerabilities, Beliefs beliefs = null, bool initializeMessages = true, bool showFactorGraph = false) { this.Engine.ShowFactorGraph = showFactorGraph; if (initializeMessages && BreakSymmetry) { this.InitializeMessages(data, numVulnerabilities); } this.SetObservations(data, numVulnerabilities); this.SetPriors(data, numVulnerabilities, beliefs); var result = new Beliefs(); Engine.NumberOfIterations = this.Iterations; result.Sensitization = Engine.Infer <Bernoulli[][, ]>(this.sensitized); result.ProbSkinIfSensitized = Engine.Infer <Beta>(this.probSkinIfSens); result.ProbSkinIfNotSensitized = Engine.Infer <Beta>(this.probSkinIfNotSens); result.ProbIgEIfSensitized = Engine.Infer <Beta>(this.probIgeIfSens); result.ProbIgEIfNotSensitized = Engine.Infer <Beta>(this.probIgeIfNotSens); result.ProbSensitizationAgeOne = Engine.Infer <Beta[, ]>(this.probSens1); result.ProbGainSensitization = Engine.Infer <Beta[][, ]>(this.probGain); result.ProbRetainSensitization = Engine.Infer <Beta[][, ]>(this.probRetain); result.VulnerabilityClass = Engine.Infer <Discrete[]>(this.sensClass); return(result); }
public Population(Civilization civlization, Upkeep upkeep, Beliefs beliefs, PopulationType startingType) { Civilization = civlization; Upkeep = upkeep; Beliefs = beliefs; PopulationType = startingType; }
private IEnumerable <Attitude <IntentionType, T> > LookForTours(List <Attitude <DesireType, T> > desires) { var visitDesire = desires.First(d => d.Label == DesireType.Visit); var dateDesire = desires.First(d => d.Label == DesireType.Date); var maxBudgetDesire = desires.First(d => d.Label == DesireType.Budget); var citiesToVisit = visitDesire.AttitudeRepresentation["visiting"].Split(","); var dateFrom = dateDesire.AttitudeRepresentation["from"]; var days = int.Parse(dateDesire.AttitudeRepresentation["days"]); var maxBudget = double.Parse(maxBudgetDesire.AttitudeRepresentation["max"]); var tourPackages = Beliefs.Where(b => b.Label == BeliefType.TourPackages); var result = new List <Attitude <IntentionType, T> >(); foreach (var tourPackage in tourPackages) { var data = tourPackage.AttitudeRepresentation; var starts = data["starts"]; var daysTour = int.Parse(data["days"]); var cities = data["cities"].Split(','); var price = double.Parse(data["price"]); if (daysTour <= days && cities.Intersect(citiesToVisit).Count() == cities.Length && starts == dateFrom && price < maxBudget) { result.Add(new Attitude <IntentionType, T>(IntentionType.BookTourPackage, tourPackage.AttitudeRepresentation)); } } return(result); }
public bool HasReasonFor(Subject s, Beliefs b, Intention i) { if (!new Halt().HasReasonFor(s, b, i)) { if (b.Sees.Agents.ContainsKey('0')) { if (b.Sees.Agents.Count > 1 && (b.Sees.Agents.ContainsKey('0') && !b.ToM['0'].Sees.Agents.ContainsKey(s.ID) && Util.GetAgentSpeed('0') != (int)Speed.VeryFast)) { foreach (Subject subj in b.Sees.Agents.Values) { if (Util.IsChild(subj.ID) && b.ToM[subj.ID].Sees.Agents.ContainsKey('0') && !b.ToM[subj.ID].Sees.Agents.ContainsKey(s.ID)) { return(true); } } } } } return(false); }
public override Queue <Location> ExtractPlan(Subject s, Intention i, Beliefs b, List <Location> path) { Queue <Location> plan = new Queue <Location>(); plan.Enqueue(s.Location); return(plan); }
public override bool PostPerform() { GWorld.Instance.GetWorld().ModifyState("Waiting", 1); GWorld.Instance.AddPatient(this.gameObject); //Adds Itself to the Waiting Que Beliefs.ModifyState("AtHospital", 1); return(true); }
public override bool PostPerform() { GWorld.Instance.GetWorld().ModifyState("Treated", 1); Beliefs.ModifyState("IsCured", 1); //For Patients Inventory.RemoveGameObject(Target); return(true); }
protected override bool Reconsider(Intention i, Beliefs b) { // If not currently fleeing from the nearest child, reconsider intention. if ((i.Name == "flee") && (b.Sees.Agents.Count > 0 || b.Hears.Agents.Count > 0)) { List <Subject> perceived = Util.Merge(b.Hears.Agents, b.Sees.Agents).Values.ToList(); if (i.ID != Util.NearestAgent(perceived.ToList(), Location).ID) { return(true); } } // If hears or sees a child agent and not currently fleeing or waiting, // reconsider current intention. if ((b.Sees.Agents.Count > 0 || b.Hears.Agents.Count > 0) && !(i.Name == "wait" || i.Name == "flee")) { return(true); } // If not waiting or fleeing and sees food and the current intention // is not to eat, reconsider intention. if (!(i.Name == "wait" || i.Name == "flee") && i.ID != 'F' && b.Sees.Foods.Count > 0) { return(true); } // If current intention is nothing and all rooms are searched, but food // remains, re-fill rooms and reconsider intention. if ((i.Name == "none") && b.Rooms.Count == 0 && Manager.Board.Foods.Count > 0) { b.Rooms = Manager.Board.Rooms.ToDictionary(x => x.Key, x => x.Value.Clone()); return(true); } // If waiting and hears a child or sees a child in close proximity, // reconsider current intention. if (i.Name == "wait") { Subject nearest = Util.NearestAgent(b.Sees.Agents.Values.ToList(), Location); if (((b.Sees.Agents.Count > 0 && Util.L1Distance(Location, nearest.Location) < 3) || b.Hears.Agents.Count > 0)) { return(true); } } return(false); }
public static IEnumerable<Mobbing> Discover(Beliefs beliefs) { foreach (var zom in beliefs.Entities.Where(x => x.Type == EntityType.Zombie)) { if (beliefs.Entity.World.Difference(beliefs.Entity.Position2D, zom.LastPos).LengthSquared > MobRadius * MobRadius) continue; if (ShouldMob(beliefs.Entity, zom)) { yield return new Mobbing(zom); } } }
public Intention ExtractIntention(Beliefs b, Subject s) { Intention i = new Intention("search"); Room room = Util.NearestRoom(b.Rooms, s.Location); i.ID = room.ID; return(i); }
protected override Beliefs BRF(Beliefs b, List <IPercept> p) { b = base.BRF(b, p); // The recursive higher-order observation reasoner updates the agent's // higher-order beliefs. tom.UpdateToM(this, b, b.Sees.Locations, 3); return(b); }
public static long CreateBelief(BeliefDTO belief) { Beliefs beliefs = new Beliefs(); beliefs.Belief = belief.Belief; beliefs.TopicId = belief.TopicId; context.Add <Beliefs>(beliefs); context.SaveChanges(); return(beliefs.Id); }
public Intention ExtractIntention(Beliefs b, Subject s) { Intention i = new Intention("ambush"); Room room = Util.GetRoom(b.Agents['0'].Location); i.ID = room.ID; return(i); }
public Intention ExtractIntention(Beliefs b, Subject s) { Intention i = new Intention("goto"); if (b.Sees.Agents.ContainsKey('0')) { i.ID = '0'; } return(i); }
public Expression Listen(Statement statement, string speakerName) { if (!CharacterSentiment.Keys.Contains(speakerName)) { CharacterSentiment.Add(speakerName, new Feelings()); } var belief = Beliefs.Accept(statement, CharacterSentiment[speakerName].Faith, speakerName); return(CalculateExpression(belief, speakerName)); }
private void OnTriggerExit(Collider other) { if (other.CompareTag(Tags.Victim)) { GameObject victim = Inventory.GetItem(VictimKey); if (victim == other.gameObject) { Inventory.RemoveItem(VictimKey); Beliefs.RemoveState(FoundVictimKey); } } }
public bool HasReasonFor(Subject s, Beliefs b, Intention i) { if (!new Eat().HasReasonFor(s, b, i)) { if (b.Sees.Agents.Count == 0 && b.Rooms.Count > 0) { return(true); } } return(false); }
public bool HasReasonFor(Subject s, Beliefs b, Intention i) { if (!new Ambush().HasReasonFor(s, b, i)) { if (b.Sees.Agents.ContainsKey('0')) { return(true); } } return(false); }
public bool HasReasonFor(Subject s, Beliefs b, Intention i) { if (!new Search().HasReasonFor(s, b, i)) { if (!b.Sees.Agents.ContainsKey('0') && b.Rooms.Count == 0) { return(true); } } return(false); }
public static IEnumerable<Barricading> Discover(Beliefs beliefs) { var blockBeliefs = beliefs.GetBlock(beliefs.Entity.Block); var resources = beliefs.Entities .Where(x => x.Type == EntityType.PlankPile || x.Type == EntityType.PlankSource) .Where(x => x.LastBlock == blockBeliefs.Block) .Sum(x => x.Type == EntityType.PlankPile ? x.Entity.GetComponent<WoodPile>().Count : x.Entity.GetComponent<WoodenBreakable>().AveragePlanks); if (!blockBeliefs.Block.Enclosed && blockBeliefs.Resources + resources > 10) { yield return new Barricading(blockBeliefs); } }
public static IEnumerable<Migration> Discover(Beliefs beliefs) { var agent = beliefs.Entity; var pos = agent.Position2D; var curUtil = beliefs.Blocks.First(x => x.Block == agent.Block).Utility; var best = beliefs.Blocks .Where(x => x.Utility > curUtil) .OrderByDescending(x => x.Utility / Math.Max(1f, agent.World.Difference(pos, x.Block.GetNearestPosition(pos)).Length)) .FirstOrDefault(); if (best != null && best.Block != agent.Block) { yield return new Migration(best); } }
public static IEnumerable<ThreatAvoidance> Discover(Beliefs beliefs) { var ents = new List<EntityBeliefs>(); foreach (var zom in beliefs.Entities.Where(x => x.Type == EntityType.Zombie)) { var diff = beliefs.Entity.World.Difference(zom.LastPos, beliefs.Entity.Position2D); if (diff.LengthSquared < 0.25f || diff.LengthSquared >= 64f) continue; ents.Add(zom); } if (ents.Count > 0) { yield return new ThreatAvoidance(ents); } }
public Barricading(Desires.Barricading desire, Beliefs beliefs, BlockBeliefs blockBeliefs) : base(desire, beliefs) { _blockBeliefs = blockBeliefs; _destTiles = new List<Tile>(); var block = _blockBeliefs.Block; var dirs = new[] { Face.North, Face.East, Face.South, Face.West }; for (int x = 1; x < block.Width - 1; ++x) { for (int y = 1; y < block.Height - 1; ++y) { var tile = block[block.X + x, block.Y + y]; if (tile.IsInterior) continue; foreach (var dir in dirs) { if (tile.IsWallSolid(dir)) continue; var n = dir.GetNormal(); int xn = x + (int) n.X, yn = y + (int) n.Y; var neighbour = block[block.X + xn, block.Y + yn]; if (neighbour.IsInterior) { _destTiles.Add(tile); break; } } } } _pendingTiles = _destTiles.Where(x => x.StaticEntities.Count() == 0).ToArray(); }
public Migration(Desires.Migration desire, Beliefs beliefs) : base(desire, beliefs) { _destBlock = desire.Destination; var size = new Vector2(_destBlock.Width, _destBlock.Height); int tries = 16; do { _destPos = new Vector2(_destBlock.X, _destBlock.Y) + Vector2.Multiply(size, new Vector2( Tools.Random.NextSingle(0.4f, 0.6f), Tools.Random.NextSingle(0.4f, 0.6f))); _destPos.X = (float) Math.Round(_destPos.X - 0.5f) + 0.5f; _destPos.Y = (float) Math.Round(_destPos.Y - 0.5f) + 0.5f; } while (--tries > 0 && !Beliefs.Entity.World.IsPositionNavigable(_destPos)); if (tries <= 0) { _destPos = _destBlock.GetNearestPosition(Entity.Position2D); _destPos += (_destBlock.Center - _destPos).Normalized() * 2f; } _nav = new RouteNavigator(Entity, _destPos); }
public override Intention GetIntention(Beliefs beliefs) { return new Intentions.Barricading(this, beliefs, _blockBeliefs); }
public override Intention GetIntention(Beliefs beliefs) { return new Intentions.PlayerMovementCommand(this, beliefs); }
public PlayerMovementCommand(Desires.PlayerMovementCommand desire, Beliefs beliefs) : base(desire, beliefs) { _nav = new RouteNavigator(Entity, desire.Destination); }
public static IEnumerable<WallAvoidance> Discover(Beliefs beliefs) { yield return new WallAvoidance(); }
public override Intention GetIntention(Beliefs beliefs) { throw new NotImplementedException(); }
public override Intention GetIntention(Beliefs beliefs) { return new Intentions.WallAvoidance(this, beliefs); }
public override Intention GetIntention(Beliefs beliefs) { return new Intentions.PlayerSpecifiedBarricading(this, beliefs); }
public static IEnumerable<PlanBarricade> Discover(Beliefs beliefs) { yield break; }
public PlayerSpecifiedBarricading(Desires.PlayerSpecifiedBarricading desire, Beliefs beliefs) : base(desire, beliefs) { }
public Mobbing(Desires.Mobbing desire, Beliefs beliefs) : base(desire, beliefs) { Target = desire.Target; }
public override Intention GetIntention(Beliefs beliefs) { return new Intentions.Migration(this, beliefs); }
public PlanBarricade(Desires.PlanBarricade desire, Beliefs beliefs) : base(desire, beliefs) { }
public Wander(Desires.Wander desire, Beliefs beliefs) : base(desire, beliefs) { Randomize(); }
public static IEnumerable<Wander> Discover(Beliefs beliefs) { yield return new Wander(); }
public override Intention GetIntention(Beliefs beliefs) { return new Intentions.Wander(this, beliefs); }