Пример #1
0
        protected void CreateTeacher()
        {
            List <RogueTeacher.Actions> actions = new List <RogueTeacher.Actions>
            {
                RogueTeacher.GetRandomAction(m_rndGen, (int)TSHints[TSHintAttributes.DEGREES_OF_FREEDOM]),
                RogueTeacher.GetRandomAction(m_rndGen, (int)TSHints[TSHintAttributes.DEGREES_OF_FREEDOM]),
                RogueTeacher.GetRandomAction(m_rndGen, (int)TSHints[TSHintAttributes.DEGREES_OF_FREEDOM]),
                RogueTeacher.GetRandomAction(m_rndGen, (int)TSHints[TSHintAttributes.DEGREES_OF_FREEDOM]),
                RogueTeacher.GetRandomAction(m_rndGen, (int)TSHints[TSHintAttributes.DEGREES_OF_FREEDOM])
            };

            RectangleF restrcitedRectangle = WrappedWorld.GetPowGeometry();

            restrcitedRectangle = LearningTaskHelpers.ResizeRectangleAroundCentre(restrcitedRectangle, 0.8f);

            PointF teachersPoint;

            if ((int)TSHints[TEACHER_ON_DIFF_START_POSITION] != 0)
            {
                teachersPoint = WrappedWorld.RandomPositionInsideRectangleNonCovering(m_rndGen, RogueTeacher.GetDefaultSize(), restrcitedRectangle, 10);
            }
            else
            {
                teachersPoint = new PointF(m_agent.Position.X + WrappedWorld.Viewport.Width / 3, m_agent.Position.Y);
            }

            m_teacher = WrappedWorld.CreateTeacher(teachersPoint, actions) as RogueTeacher;
        }
Пример #2
0
        public virtual void CreateTarget()
        {
            float scaleFactor = 1;

            if (TSHints[TSHintAttributes.IS_VARIABLE_SIZE] >= 1)
            {
                scaleFactor = (float)m_rndGen.NextDouble() * 0.7f + 0.8f;
            }

            m_target = WrappedWorld.CreateTarget(new Point(0, 0), scaleFactor);

            PointF p;

            if ((int)TSHints[TSHintAttributes.DEGREES_OF_FREEDOM] == 1)
            {
                RectangleF POW = WrappedWorld.GetPowGeometry();
                POW.Location = new PointF(POW.X, POW.Y + POW.Height / 2 - m_agent.Size.Height);
                POW.Size     = new SizeF(POW.Width, m_agent.Size.Height * 2);
                p            = WrappedWorld.RandomPositionInsideRectangleNonCovering(m_rndGen, m_target.GetGeometry().Size, POW, 5, 20);
            }
            else
            {
                p = WrappedWorld.RandomPositionInsideViewport(m_rndGen, m_target.GetGeometry().Size, 20);
            }

            m_target.Position = p;
        }
        public void CreateTargets()                                                                                     // Create a number of targets and fill the list(m_gameObjectReferences) of references for the sequence indexing
        {
            currentIndex = 0;
            m_gameObjectReferences.Clear();

            float cumulatedManhattanDistance = 0;

            GameObject previousGameObject = m_agent;

            for (int n = 0; n < (int)TSHints[SEQUENCE_LENGTH]; n++)                                                   // Generate a number of targets corresponding to the length of the sequence
            {
                m_target = new GameObject(GetNumberTargetImage(n), type: GameObjectType.NonColliding);
                WrappedWorld.AddGameObject(m_target);

                m_target.Size.Width  = 10;
                m_target.Size.Height = 15;

                m_gameObjectReferences.Add(m_target);                                                                     // Add the current GameObject to the vector of GameObject references

                // PositionFree = WrappedWorld.RandomPositionInsidePowNonCovering(m_rndGen, m_target.GetGeometry().Size);  // Generate a random point where the corresponding GameObject doesn't cover any other GameObject

                // The generated GameObjects should be close to the agent, close enough so that no objects are outside the screen while following the sequence
                RectangleF r1 = new RectangleF
                {
                    X      = m_agent.Position.X - WrappedWorld.Viewport.Width / 4,
                    Y      = m_agent.Position.Y - WrappedWorld.Viewport.Height / 4,
                    Width  = WrappedWorld.Viewport.Width / 2,
                    Height = WrappedWorld.Viewport.Height / 2
                };

                m_target.Position = WrappedWorld.RandomPositionInsideRectangleNonCovering(m_rndGen, m_target.GetGeometry().Size, r1);

                float estimatedManhattanDistance = Math.Abs(m_gameObjectReferences[n].Position.X - previousGameObject.Position.X)
                                                   + Math.Abs(m_gameObjectReferences[n].Position.Y - previousGameObject.Position.Y);
                estimatedManhattanDistance /= 4;                                                                        // Assuming that agent travels using 1 actuator at a time, (In such case it can move max 4 pixels per step, otherwise it's 8)
                cumulatedManhattanDistance += estimatedManhattanDistance;

                //MyLog.DEBUG.WriteLine("Calculating Manhattan distance between previous Object X,Y: " + previousGameObject.X + ", " + previousGameObject.Y + " AND " + m_gameObjectReferences[n].X + ", " + m_gameObjectReferences[n].Y + " := " + estimatedManhattanDistance);

                previousGameObject = m_gameObjectReferences[n];
            }

            //MyLog.DEBUG.WriteLine("Final estimatedManhattan Distance: " + CumulatedManhattanDistance);

            TSHints[TIMESTEPS_LIMIT] = cumulatedManhattanDistance * TSHints[DISTANCE_BONUS_COEFFICENT];
        }
Пример #4
0
        protected Shape CreateTarget(int imageIndex)
        {
            SizeF size = new SizeF(15, 15);

            if (TSHints[TSHintAttributes.IS_VARIABLE_SIZE] >= 1f)
            {
                float a = (float)(10 + m_rand.NextDouble() * 15);
                size = new SizeF(a, a);
            }

            // positions are reduced to keep all objects in POW
            RectangleF r = WrappedWorld.GetPowGeometry();

            r.Location = new PointF(r.X + r.Width / 8, r.Y + r.Height / 8);
            r.Size     = new SizeF(r.Width * 3 / 4, r.Height * 3 / 4);
            PointF p = WrappedWorld.RandomPositionInsideRectangleNonCovering(m_rand, size, r, 10, 18);

            return(WrappedWorld.CreateShape((Shape.Shapes)imageIndex, Color.White, p, size, type: GameObjectType.NonColliding));
        }
Пример #5
0
        public override void PresentNewTrainingUnit()
        {
            WrappedWorld.CreateNonVisibleAgent();

            RectangleF leftPart  = WrappedWorld.GetPowGeometry();
            RectangleF rightPart = WrappedWorld.GetPowGeometry();
            SizeF      shift     = new SizeF(leftPart.Width / 2 + 4, 0);

            leftPart.Width  = leftPart.Width / 2 - 4;
            rightPart.Width = rightPart.Width / 2 - 2;
            rightPart.X    += rightPart.Width + 4;

            WrappedWorld.CreateShape(
                Shape.Shapes.Square,
                Color.Black,
                rightPart.Location - new SizeF(4, 0),
                new SizeF(4, leftPart.Height));

            int numberOfObjects = (int)TSHints[TSHintAttributes.NUMBER_OBJECTS];

            m_diffObjectetPlaced = m_rndGen.Next(2) == 0;

            for (int i = 0; i < numberOfObjects; i++)
            {
                SizeF size;
                if (TSHints[TSHintAttributes.IS_VARIABLE_SIZE] >= 1f)
                {
                    float a = (float)(10 + m_rndGen.NextDouble() * 10);
                    size = new SizeF(a, a);
                }
                else
                {
                    size = new SizeF(15, 15);
                }

                Color color;
                if (TSHints[TSHintAttributes.IS_VARIABLE_COLOR] >= 1f)
                {
                    color = LearningTaskHelpers.RandomVisibleColor(m_rndGen);
                }
                else
                {
                    color = Color.White;
                }

                Shape.Shapes shape = Shape.GetRandomShape(m_rndGen);

                PointF position = WrappedWorld.RandomPositionInsideRectangleNonCovering(m_rndGen, size, leftPart, 2);

                bool placeDifference = m_diffObjectetPlaced;

                if (!placeDifference || i != numberOfObjects - 1)
                {
                    WrappedWorld.CreateShape(shape, color, position, size);
                    WrappedWorld.CreateShape(shape, color, position + shift, size);
                }
                else
                {
                    PointF       positionR = position + shift;
                    Color        colorR    = color;
                    Shape.Shapes shapeR    = shape;
                    SizeF        sizeR     = size;

                    if (LearningTaskHelpers.FlipCoin(m_rndGen) && TSHints[TSHintAttributes.IS_VARIABLE_POSITION] >= 1.0f)
                    {
                        positionR       = WrappedWorld.RandomPositionInsideRectangleNonCovering(m_rndGen, size, rightPart, 2);
                        placeDifference = false;
                    }
                    if (LearningTaskHelpers.FlipCoin(m_rndGen) && TSHints[TSHintAttributes.IS_VARIABLE_COLOR] >= 1f)
                    {
                        colorR          = LearningTaskHelpers.RandomVisibleColor(m_rndGen);
                        placeDifference = false;
                    }
                    if (LearningTaskHelpers.FlipCoin(m_rndGen) && TSHints[TSHintAttributes.IS_VARIABLE_SIZE] >= 1f)
                    {
                        sizeR = size + new Size(5, 5);
                    }
                    if (placeDifference || LearningTaskHelpers.FlipCoin(m_rndGen))
                    {
                        shapeR = Shape.GetRandomShape(m_rndGen);
                    }

                    WrappedWorld.CreateShape(shape, color, position, size);
                    WrappedWorld.CreateShape(shapeR, colorR, positionR, sizeR);
                }
            }
        }