public DF8Resolver()
 {
     Dice = new RollDice();
     evaluator = new SoftCircuits.Eval();
     evaluator.ProcessSymbol += ProcessSymbol;
     evaluator.ProcessFunction += ProcessFunction;
 }
 public static int Main(string[] args)
 {
     if (args.Length == 0)
         return -1;
     string arg = "";
     arg = String.Concat(args);
     var myRoller = new RollDice(arg);
     Console.WriteLine("{0}.", myRoller);
     return 0;
 }
        public double roll(string line)
        {
            //^((?:\d+)?[dD](?:\d+|[%fF]))\s*(?:([\-+xX*/bBwW])(\d+.*))?
            int[] throws = new int[0];

            string pattern = @"^((?:\d+)?[dD](?:\d+|[%fF]))\s*(?:([\-+xX*/bBwW])(\d+.*))?";
            Match matcher = Regex.Match(line, pattern);

            if( ! matcher.Success ) {
                Console.WriteLine("{0} is not a valid dice string!", line );
                return 0;
            }

            string diceString = matcher.Groups[1].Value;
            sign = matcher.Groups[2].Value;
            string offsetString = matcher.Groups[3].Value;

            offset = 0;

            string typeString = matcher.Groups[2].Value;

            pattern = @"d";
            matcher = Regex.Match(offsetString, pattern);
            var OffsetRoll = new RollDice();
            if (matcher.Success) {
                OffsetRoll.roll_array(offsetString);
                offset = OffsetRoll.Sum;
                Console.WriteLine("Resolved {0} to {1}", offsetString, offset);
            } else {
                double NumTest = 0;
                bool isNum = double.TryParse(offsetString, out NumTest);

                if (isNum){
                    offset = NumTest;
                }
            }

            throws = roll_array(diceString);

            if (throws.Length == 0)
                return 0;

            if (sign.Equals("b", StringComparison.OrdinalIgnoreCase)){
                // keep highest X dice
                sign = null;
            } else if  (sign.Equals("w", StringComparison.OrdinalIgnoreCase)){
                // keep lowest/worst X dice
                sign = null;
            }

            switch(sign)
            {
                case "+":
                    Sum += offset;
                    break;
                case "-":
                    Sum -= offset;
                    break;
                case "*":
                    Sum *= offset;
                    break;
                case @"/":
                    Sum /= offset;
                    break;
                default:
                    break;
            }

            Rolls = throws;
            //if (OffsetRoll.Rolls.Length > 0){
            //	int rollcount = rolls.Length;
            //	Array.Resize<int>(ref rolls, rollcount + OffsetRoll.Rolls.Length);
            //	Array.Copy(OffsetRoll.Rolls, 0, rolls, rollcount, OffsetRoll.Rolls.Length);
            //}
            return Sum;
        }