Ejemplo n.º 1
0
        public StoryVar shuffled(params StoryVar[] vals)
        {
            // http://stackoverflow.com/questions/273313/randomize-a-listt-in-c-sharp
            var array = new HarloweArray(vals);
            int n     = array.Length;

            while (n > 1)
            {
                n--;
                int      k     = shuffleRandomizer.Next(n + 1);
                StoryVar value = array.Values[k];
                array.Values[k] = array.Values[n];
                array.Values[n] = value;
            }

            return(array);
        }
Ejemplo n.º 2
0
 protected bool TryGetMemberArray(StoryVar member, out StoryVar val)
 {
     // Special case when member is an array
     if (member.Value is HarloweArray)
     {
         var        memberArray = (HarloweArray)member.Value;
         StoryVar[] valueArray  = new StoryVar[memberArray.Length];
         for (int i = 0; i < memberArray.Length; i++)
         {
             valueArray[i] = GetMember(memberArray.Values[i]);
         }
         val = new HarloweArray(valueArray);
         return(true);
     }
     else
     // Anything else treat as a property
     {
         val = default(StoryVar);
         return(false);
     }
 }
Ejemplo n.º 3
0
        public StoryVar rotated(int shift, params StoryVar[] vals)
        {
            var original = new HarloweArray(vals);
            var copy     = new HarloweArray(original.Values);

            for (int i = 0; i < original.Length; i++)
            {
                int j = i + shift;
                if (j < 0)
                {
                    j += original.Length;
                }
                else if (j > original.Length - 1)
                {
                    j -= original.Length;
                }
                copy.Values[j] = original.Values[i];
            }

            return(copy);
        }