Esempio n. 1
0
        /// <summary>
        /// Applies a random offset in a random direction to a position, ensuring that the final position remains within the boundary of the playfield.
        /// </summary>
        /// <param name="position">The position which the offset should be applied to.</param>
        /// <param name="maxOffset">The maximum offset, cannot exceed 20px.</param>
        /// <param name="rng">The random number generator.</param>
        private static void applyRandomOffset(ref float position, double maxOffset, FastRandom rng)
        {
            bool  right = rng.NextBool();
            float rand  = Math.Min(20, (float)rng.Next(0, Math.Max(0, maxOffset))) / CatchPlayfield.BASE_WIDTH;

            if (right)
            {
                // Clamp to the right bound
                if (position + rand <= 1)
                {
                    position += rand;
                }
                else
                {
                    position -= rand;
                }
            }
            else
            {
                // Clamp to the left bound
                if (position - rand >= 0)
                {
                    position -= rand;
                }
                else
                {
                    position += rand;
                }
            }
        }
Esempio n. 2
0
        public DemoGenerator()
        {
            Random       = new FastRandom();
            SimplexNoise = new OpenSimplexNoise(Random.Next());

            IsNether = Random.NextBool();

            if (IsNether)
            {
                MainBlock   = BlockFactory.GetBlockState("minecraft:netherrack");
                LiquidBlock = BlockFactory.GetBlockState("minecraft:lava");
            }
            else
            {
                MainBlock   = BlockFactory.GetBlockState("minecraft:dirt");
                LiquidBlock = BlockFactory.GetBlockState("minecraft:water");
            }
        }
Esempio n. 3
0
        private IEnumerable <Tuple <List <int>, List <int> > > GetMirrorImagesWithFewChanges(int n, FastRandom rand)
        {
            for (int i = 0; i < n; i++)
            {
                List <int> vector = GetRandom(rand, 1);
                var        mirror = Enumerable.Reverse(vector).ToList();

                // add few changes
                int length  = vector.Count;
                int changes = rand.Next(1, 5 + 1);
                for (int j = 0; j < changes; j++)
                {
                    if (rand.NextBool())
                    {
                        vector[rand.Next(0, length)] = rand.Next(-1000, 1000 + 1);
                    }
                    else
                    {
                        mirror[rand.Next(0, length)] = rand.Next(-1000, 1000 + 1);
                    }
                }
                yield return(new Tuple <List <int>, List <int> >(vector, mirror));
            }
        }
Esempio n. 4
0
 public static bool Bool()
 {
     return(random.NextBool());
 }
        private IntPoint[] GenerateRandomTestCase(int largeBoxRelativePos)
        {
            // Randomly select a position for the small box (the box is a single pixel in size).
            IntPoint smallBoxPos = new IntPoint(_rng.Next(TestFieldResolution), _rng.Next(TestFieldResolution));

            // Large box center is 5 pixels to the right, down or diagonally from the small box.
            IntPoint largeBoxPos = smallBoxPos;

            switch (largeBoxRelativePos)
            {
            case 0:     // Right
                largeBoxPos._x += 5;
                break;

            case 1:     // Down
                largeBoxPos._y += 5;
                break;

            case 2:     // Diagonal
                // Two alternate position get us to exactly 5 pixels distant from the small box.
                if (_rng.NextBool())
                {
                    largeBoxPos._x += 3;
                    largeBoxPos._y += 4;
                }
                else
                {
                    largeBoxPos._x += 4;
                    largeBoxPos._y += 3;
                }
                break;
            }

            // Handle cases where the large box is outside the visual field or overlapping the edge.
            if (largeBoxPos._x > CoordBoundIdx)
            {   // Wrap around.
                largeBoxPos._x -= TestFieldResolution;

                if (0 == largeBoxPos._x)
                {   // Move box fully into the visual field.
                    largeBoxPos._x++;
                }
            }
            else if (CoordBoundIdx == largeBoxPos._x)
            {   // Move box fully into the visual field.
                largeBoxPos._x--;
            }
            else if (0 == largeBoxPos._x)
            {   // Move box fully into the visual field.
                largeBoxPos._x++;
            }


            if (largeBoxPos._y > CoordBoundIdx)
            {   // Wrap around.
                largeBoxPos._y -= TestFieldResolution;

                if (0 == largeBoxPos._y)
                {   // Move box fully into the visual field.
                    largeBoxPos._y++;
                }
            }
            else if (CoordBoundIdx == largeBoxPos._y)
            {   // Move box fully into the visual field.
                largeBoxPos._y--;
            }
            else if (0 == largeBoxPos._y)
            {   // Move box fully into the visual field.
                largeBoxPos._y++;
            }
            return(new IntPoint[] { smallBoxPos, largeBoxPos });
        }