Beispiel #1
0
        public virtual void CreateTargets(int noObjects, PointF center)
        {
            SizeF centerSz = new SizeF(center); // Is Size because there is no overload for +(Point,Point)........

            // Pick random unique shapes from the available pool
            Resize(ref m_shapeIdcs, noObjects);
            int shapeCount = Enum.GetValues(typeof(Shape.Shapes)).Length; // noObjects must be at most shapeCount

            MyCombinationBase.GenerateCombinationUnique(new ArraySegment <float>(m_shapeIdcs), m_candidates, 0, shapeCount, m_rndGen);

            // Setup initial shape's positional parameters
            float step  = (float)(2 * Math.PI / noObjects); // rads
            float angle = TSHints[TSHintAttributes.IS_VARIABLE_POSITION] > 0
                ? (float)(m_rndGen.NextDouble() * step) : 0;
            float distance = Math.Min(WrappedWorld.Viewport.Width, WrappedWorld.Viewport.Height) / 3f;

            Resize(ref m_targets, noObjects);

            for (int i = 0; i < m_targets.Length; i++)
            {
                // Determine shape position
                if (TSHints[IS_VARIABLE_DISTANCE] > 0)
                {
                    distance *= 1 + 0.04f * LearningTaskHelpers.GetRandomGaussian(m_rndGen) * TSHints[RANDOMNESS_LEVEL];
                }

                PointF pos = new PointF((float)(Math.Cos(angle) * distance), (float)(Math.Sin(angle) * distance));

                // Determine shape size
                float scale = 1.4f;

                if (TSHints[TSHintAttributes.IS_VARIABLE_SIZE] > 0)
                {
                    scale = scale + 0.2f * LearningTaskHelpers.GetRandomGaussian(m_rndGen) * TSHints[RANDOMNESS_LEVEL];
                }

                SizeF size = new SizeF(16 * scale, 16 * scale);

                // Determine shape rotation
                float rotation = 0;

                if (TSHints[TSHintAttributes.IS_VARIABLE_ROTATION] > 0)
                {
                    rotation = (float)(m_rndGen.NextDouble() * 360);
                }

                // Determine shape color
                Color color = Color.White;

                if (TSHints[TSHintAttributes.IS_VARIABLE_COLOR] > 0)
                {
                    color = LearningTaskHelpers.RandomVisibleColor(m_rndGen);
                }

                // Create the correct shape
                m_targets[i] = WrappedWorld.CreateShape((Shape.Shapes)m_shapeIdcs[i], color, pos + centerSz, size, rotation);

                angle += step;
            }
        }
Beispiel #2
0
        private static int GetSize(float targetSizeStandardDeviation)
        {
            const int DEFAULT_SIZE = 32;
            int       size         = DEFAULT_SIZE;

            if (targetSizeStandardDeviation != 0)
            {
                float scalingFactor = (float)Math.Pow(2, targetSizeStandardDeviation * LearningTaskHelpers.GetRandomGaussian(m_rand));
                size = (int)(scalingFactor * size);
            }

            return(size);
        }