コード例 #1
0
        internal static Rotation[][][] GetRandomRotations(RotationOptions options)
        {
            var output   = new List <List <Rotation> > [options.RotationCount];
            var allAxies = InteractScript.allAxies.Take(options.Dimension);

            for (int i = 0; i < options.RotationCount; i++)
            {
                output[i] = new List <List <Rotation> >();
                var possibleAxies = new Stack <Axis>(allAxies.ToArray().Shuffle());

                for (int j = 0; j < options.MinRotations ||
                     (j < options.MaxRotations && possibleAxies.Count >= options.MinLengthPerRotation &&
                      (Rnd.Range(0, 1f) <= options.ChanceToRepeat || j == 0)); j++)
                {
                    AddRandomRotations(output, possibleAxies, options, ref i, ref j);
                }
            }

            return(output.Select(a => a.Select(b => b.ToArray())).Select(a => a.ToArray()).ToArray());
        }
コード例 #2
0
        private static void AddRandomRotations(List <List <Rotation> >[] output, Stack <Axis> possibleAxies, RotationOptions options, ref int i, ref int j)
        {
            output[i].Add(new List <Rotation>());

            int rnd = Rnd.Range(options.MinLengthPerRotation,
                                Math.Min(Math.Min(possibleAxies.Count, options.MaxLengthPerRotation), possibleAxies.Count() - options.MinRotations + 1) + 1);

            for (int k = 0; k < rnd; k++)
            {
                output[i][j].Add(new Rotation(Rnd.Range(0, 1f) > options.ChanceForNegativeRotation, possibleAxies.Pop()));
            }

            switch (output[i][j].Count)
            {
            case 1:     // Positive 1-cycle rotations are the same as 0-cycle rotations.
                output[i][j][0].IsNegative = true;
                break;

            case 2:     // Equal 2-cycle rotations are the same as 2 1-cycle rotations.
                if (output[i][j][0].IsNegative == output[i][j][1].IsNegative)
                {
                    output[i][j][0].IsNegative = !output[i][j][0].IsNegative;
                }
                break;
            }
        }