コード例 #1
0
ファイル: GOAPConsoleWriter.cs プロジェクト: MrHungerrr/EXaM
        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();
        }
コード例 #2
0
ファイル: GOAPAction.cs プロジェクト: MrHungerrr/EXaM
 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"));
 }
コード例 #3
0
        public int Compare(IGOAPCost x, IGOAPCost y)
        {
            if (!(x is BaseCost) || !(y is BaseCost))
            {
                throw new InvalidCastException();
            }

            return(Compare((BaseCost)x, (BaseCost)y));
        }
コード例 #4
0
ファイル: BaseCost.cs プロジェクト: MrHungerrr/EXaM
        public IGOAPCost GetSumWith(IGOAPCost other)
        {
            if (!(other is BaseCost))
            {
                throw new InvalidCastException();
            }

            return(new BaseCost(_cost + ((BaseCost)other)._cost));
        }
コード例 #5
0
ファイル: BaseCost.cs プロジェクト: MrHungerrr/EXaM
        public void Add(IGOAPCost cost)
        {
            if (!(cost is BaseCost))
            {
                throw new InvalidCastException();
            }

            Add((BaseCost)cost);
        }
コード例 #6
0
ファイル: BaseCost.cs プロジェクト: MrHungerrr/EXaM
        public int CompareTo(IGOAPCost other)
        {
            if (other == null)
            {
                throw new NullReferenceException();
            }

            if (!(other is BaseCost))
            {
                throw new InvalidCastException();
            }

            return(CompareTo((BaseCost)other));
        }
コード例 #7
0
ファイル: GOAPAction.cs プロジェクト: MrHungerrr/EXaM
 public void SetCost(IGOAPCost cost)
 {
     Cost = cost;
 }