// Done! #region .Ctor public IDAStar(T start, T goal, AgentCharacter agentCharacter) { this.start = new CognitiveState <T>(start, agentCharacter); this.goal = new CognitiveState <T>(goal, agentCharacter); this.agentCharacter = agentCharacter; // Vamos definir um nivel de corte! cutOff = (int)Math.Ceiling(start.GetHeuristic(start, goal)); }
// Done! public float GetCost(MapNode destination, AgentCharacter ac) { var c = destination.Exits[0].Constraints; const float factor = 4.0f; var d = GetCost(destination); var m = (c.Memory.Value * ac.Memory * d / factor); // Apply Time! var t = (r.NextDouble() * ac.Temperamental * d / factor); // Apply Time! var e = -(Math.Abs(c.Memory.Value) * ac.Explore * d / (2 * (c.Memory.Value > 0 ? 2 : 1.3))); // Apply Time! var g = (c.Speed.Value * ac.Greedy * d / factor); // Apply Time! var p = ((1 - c.Transitable.Value) * ac.Bold * d / factor); // Apply Time! var nd = d - m - t - e - p - g; return((float)nd); }
// Done! #region ICognitiveLayout<MapNode> Members // Done! public IList <MapNode> Children(AgentCharacter ac) { if (this.NodeType == NodeType.Exit) { return(this.Exits[0].Children()); } IList <MapNode> data = new List <MapNode>(); for (int i = 0; i < this.Exits.Count; ++i) { //var x = this.Character.Bold*this.Exits[i].Exits[0].Passable; data.Add(this.Exits[i]); } return(data); }
// Done! public static void FilterAdd <T>(this PriorityQueue <CognitiveState <T> > list, IDictionary <int, CognitiveState <T> > other, CognitiveState <T> node, CognitiveState <T> goal, AgentCharacter agentCharacter) where T : class, ICognitiveLayout <T> { // Expandir o estado actual! IList <T> childreen = node.Children(node, agentCharacter); int count = childreen.Count; for (int i = 0; i < count; ++i) { T c = childreen[i]; // Adicionar à lista somente se não existir na lista de fechados. if (other.ContainsKey(c.GetHashCode())) { continue; } CognitiveState <T> s = new CognitiveState <T>(c, node, agentCharacter); list.Enqueue(s.Cost + CognitiveState <T> .Estimate(node, c, goal), s); } }
// Done! #region .Ctor public CognitiveAStar(T start, T goal, AgentCharacter agentCharacter) { this.start = new CognitiveState <T>(start, agentCharacter); this.goal = new CognitiveState <T>(goal, agentCharacter); this.agentCharacter = agentCharacter; }
public IList <T> Children(CognitiveState <T> node, AgentCharacter ac) { return(Layout.Children(ac)); }
// State without a parent public CognitiveState(T layout, AgentCharacter agentCharacter) : this(layout, null, agentCharacter) { }
} // Custo Real #endregion // Done! #region .Ctor // Normal and most used ctor public CognitiveState(T layout, CognitiveState <T> parent, AgentCharacter agentCharacter) { Parent = parent; Layout = layout; Cost = parent == null ? 0 : parent.Cost + parent.Layout.GetCost(layout, agentCharacter); }