示例#1
0
        protected override void CanPay(CanPayResult result)
        {
            var childResults = new List <CanPayResult>();

            foreach (var cost in _costs)
            {
                childResults.Add(cost.CanPay());
            }

            result.CanPay(() =>
            {
                foreach (var childResult in childResults)
                {
                    if (!childResult.CanPay().Value)
                    {
                        return(false);
                    }
                }

                return(true);
            });

            result.MaxX(() =>
            {
                int?maxX = null;

                foreach (var childResult in childResults)
                {
                    maxX = childResult.MaxX().Value;

                    if (maxX.HasValue)
                    {
                        break;
                    }
                }

                return(maxX);
            });

            result.MaxRepetitions(() =>
            {
                var maxRepetitions = 1;

                foreach (var childResult in childResults)
                {
                    maxRepetitions = childResult.MaxRepetitions().Value;
                }

                return(maxRepetitions);
            });
        }
示例#2
0
        protected override void CanPay(CanPayResult result)
        {
            // mana checking is an expensive operation
              // so it should only be done when nessesary
              // the following lazy evaluation allows ai
              // to only check mana costs when all the cheaper
              // timing tests are successful

              var evaluator = new PayManaEvaluator(this);

              result.CanPay(evaluator.CanPay);
              result.MaxX(evaluator.MaxX);
              result.MaxRepetitions(evaluator.MaxRepetitions);
        }
示例#3
0
        protected override void CanPay(CanPayResult result)
        {
            // mana checking is an expensive operation
            // so it should only be done when nessesary
            // the following lazy evaluation allows ai
            // to only check mana costs when all the cheaper
            // timing tests are successful

            var evaluator = new PayManaEvaluator(this);

            result.CanPay(evaluator.CanPay);
            result.MaxX(evaluator.MaxX);
            result.MaxRepetitions(evaluator.MaxRepetitions);
        }
示例#4
0
        protected override void CanPay(CanPayResult result)
        {
            var childResults = new List<CanPayResult>();

              foreach (var cost in _costs)
              {
            childResults.Add(cost.CanPay());
              }

              result.CanPay(() =>
            {
              foreach (var childResult in childResults)
              {
            if (!childResult.CanPay().Value)
              return false;
              }

              return true;
            });

              result.MaxX(() =>
            {
              int? maxX = null;

              foreach (var childResult in childResults)
              {
            maxX = childResult.MaxX().Value;

            if (maxX.HasValue)
            {
              break;
            }
              }

              return maxX;
            });

              result.MaxRepetitions(() =>
            {
              var maxRepetitions = 1;

              foreach (var childResult in childResults)
              {
            maxRepetitions = childResult.MaxRepetitions().Value;
              }

              return maxRepetitions;
            });
        }