public static void WritePlansWithBest(List <List <IGOAPReadOnlyAction> > plans, IGOAPCostComparer comparer) { Console.WriteLine(); var bestCost = comparer.BadCost; foreach (var plan in plans) { IGOAPCost fullCost = comparer.ZeroCost; foreach (var action in plan) { fullCost = fullCost.GetSumWith(action.Cost); } int value = comparer.Compare(bestCost, fullCost); if (value < 1) { bestCost = fullCost; } } foreach (var plan in plans) { IGOAPCost fullCost = comparer.ZeroCost; foreach (var action in plan) { fullCost = fullCost.GetSumWith(action.Cost); } int value = comparer.Compare(bestCost, fullCost); if (value > 0) { WritePlan(plan); } } Console.ForegroundColor = ConsoleColor.Green; foreach (var plan in plans) { IGOAPCost fullCost = comparer.ZeroCost; foreach (var action in plan) { fullCost = fullCost.GetSumWith(action.Cost); } int value = comparer.Compare(bestCost, fullCost); if (value == 0) { WritePlan(plan); } } Console.ResetColor(); }
void IXMLSerializable.ReadXML(XElement xElement) { Name = (string)xElement.Attribute("Name"); IsConnector = (bool)xElement.Attribute("IsConnector"); Cost = GOAPCostSerializer.Instance.Deserialize(xElement.Element("Cost")); _effect.ReadXML(xElement.Element("Effect")); _preconditions.ReadXML(xElement.Element("Preconditions")); }
public int Compare(IGOAPCost x, IGOAPCost y) { if (!(x is BaseCost) || !(y is BaseCost)) { throw new InvalidCastException(); } return(Compare((BaseCost)x, (BaseCost)y)); }
public IGOAPCost GetSumWith(IGOAPCost other) { if (!(other is BaseCost)) { throw new InvalidCastException(); } return(new BaseCost(_cost + ((BaseCost)other)._cost)); }
public void Add(IGOAPCost cost) { if (!(cost is BaseCost)) { throw new InvalidCastException(); } Add((BaseCost)cost); }
public int CompareTo(IGOAPCost other) { if (other == null) { throw new NullReferenceException(); } if (!(other is BaseCost)) { throw new InvalidCastException(); } return(CompareTo((BaseCost)other)); }
public void SetCost(IGOAPCost cost) { Cost = cost; }