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; } }
public override void ExecuteStep() { if (m_currentStep >= m_timeplan.Length) { return; } m_currentStep++; base.ExecuteStep(); WrappedWorld.GameObjects.Clear(); if (m_timeplan[m_currentStep] == TimeActions.GiveHint) { PointF p; if (TSHints[TSHintAttributes.IS_VARIABLE_POSITION] >= 1) { p = WrappedWorld.RandomPositionInsideViewport(m_rndGen, m_size); } else { p = m_p; } WrappedWorld.CreateShape(Shape.Shapes.Tent, Color.White, p, m_size); } }
public override void PresentNewTrainingUnit() { m_stepCount = 0; // Scale the noise in the world base on randomness_level { float randomness = TSHints[RANDOMNESS_LEVEL]; WrappedWorld.ImageNoiseStandardDeviation = 7 * randomness * randomness; } int noObjects = (int)TSHints[TSHintAttributes.NUMBER_OF_DIFFERENT_OBJECTS]; // Generate an artificial invisible agent m_agent = WrappedWorld.CreateNonVisibleAgent(); PointF agentPos = m_agent.GetGeometry().Location; m_agent.GameObjectStyle = GameObjectStyleType.None; // Prevent reseting movement vector when colliding with something from the top (default style is Platformer) // Generate shapes around the agent CreateTargets(noObjects, agentPos); // Pick one target and duplicate it in the pow center m_pickIdx = m_rndGen.Next(noObjects); var pick = m_targets[m_pickIdx]; Color color = TSHints[TSHintAttributes.IS_VARIABLE_COLOR] > 0 ? LearningTaskHelpers.RandomVisibleColor(m_rndGen) : pick.ColorMask; m_question = WrappedWorld.CreateShape((Shape.Shapes)m_shapeIdcs[m_pickIdx], color, agentPos, pick.Size); }
public override void PresentNewTrainingUnit() { m_p = WrappedWorld.CreateNonVisibleAgent().GetGeometry().Location; m_currentStep = 0; int rest = m_rndGen.Next(1, (int)TSHints[RHYTHM_MAX_SIZE] + 1); int delay = m_rndGen.Next(0, (int)TSHints[DELAY] + 1); m_timeplan = new TimeActions[(rest + 1) * 3 + delay + 1]; m_timeplan[delay] = TimeActions.GiveHint; m_timeplan[delay + (rest + 1)] = TimeActions.GiveHint; m_timeplan[delay + (rest + 1) * 2] = TimeActions.AskAction; m_timeplan[delay + (rest + 1) * 3] = TimeActions.AskAction; m_size = new Size(20, 20); if (m_timeplan[0] == TimeActions.GiveHint) { PointF p; if (TSHints[TSHintAttributes.IS_VARIABLE_POSITION] >= 1) { p = WrappedWorld.RandomPositionInsideViewport(m_rndGen, m_size); } else { p = m_p; } WrappedWorld.CreateShape(Shape.Shapes.Tent, Color.White, p, m_size); } }
// scale and position the target: private void CreateTarget() { SizeF size; float standardSideSize = WrappedWorld.Viewport.Width / 10; if (TSHints[TSHintAttributes.IS_VARIABLE_SIZE] >= 1) { float side = (float)(standardSideSize + m_rndGen.NextDouble() * standardSideSize); size = new SizeF(side, side); } else { size = new SizeF(standardSideSize, standardSideSize); } PointF position = WrappedWorld.RandomPositionInsideViewport(m_rndGen, size, -1); Shape.Shapes shape; switch (m_rndGen.Next(0, (int)TSHints[TSHintAttributes.NUMBER_OF_DIFFERENT_OBJECTS])) { case 0: default: shape = Shape.Shapes.Circle; break; case 1: shape = Shape.Shapes.Square; break; case 2: shape = Shape.Shapes.Triangle; break; case 3: shape = Shape.Shapes.Mountains; break; } Color color; if (TSHints[TSHintAttributes.IS_VARIABLE_COLOR] >= 1) { color = LearningTaskHelpers.RandomVisibleColor(m_rndGen); } else { color = Color.White; } m_target = WrappedWorld.CreateShape(shape, color, position, size); float distance = m_target.CenterDistanceTo(m_agent); float w = WrappedWorld.Viewport.Width / 2; float h = WrappedWorld.Viewport.Height / 2; float maxDistance = (float)Math.Sqrt(w * w + h * h); m_distance = distance / maxDistance; }
public override void PresentNewTrainingUnit() { WrappedWorld.CreateNonVisibleAgent(); int numberOfObjects = (int)TSHints[TSHintAttributes.NUMBER_OBJECTS]; m_sameObjectetPlaced = m_rndGen.Next(2) == 0; bool placeSameObject = m_sameObjectetPlaced; if (m_sameObjectetPlaced) { numberOfObjects--; } int numberOfShapes = Enum.GetValues(typeof(Shape.Shapes)).Length; List <int> uniqueNumbers = LearningTaskHelpers.UniqueNumbers(m_rndGen, 0, numberOfShapes, numberOfObjects); List <Shape.Shapes> shapes = uniqueNumbers.Select(x => (Shape.Shapes)x).ToList(); foreach (Shape.Shapes shape in shapes) { SizeF s; if (TSHints[TSHintAttributes.IS_VARIABLE_SIZE] >= 1f) { float a = (float)(10 + m_rndGen.NextDouble() * 10); s = new SizeF(a, a); } else { s = new Size(15, 15); } Color color; if (TSHints[TSHintAttributes.IS_VARIABLE_COLOR] >= 1) { color = LearningTaskHelpers.RandomVisibleColor(m_rndGen); } else { color = Color.White; } PointF position; if (placeSameObject) { placeSameObject = false; position = WrappedWorld.RandomPositionInsidePowNonCovering(m_rndGen, s, 2); WrappedWorld.CreateShape(shape, color, position, s); } position = WrappedWorld.RandomPositionInsidePowNonCovering(m_rndGen, s, 2); WrappedWorld.CreateShape(shape, color, position, s); } }
protected void AddShape() { SizeF size = new SizeF(WrappedWorld.GetPowGeometry().Width / 4, WrappedWorld.GetPowGeometry().Height / 4); Color color = Colors.GetRandomColor(RndGen); PointF location = WrappedWorld.RandomPositionInsidePowNonCovering(RndGen, size); ShapeIndex = RndGen.Next(ScConstants.numShapes); Shape.Shapes randomShape = (Shape.Shapes)ShapeIndex; WrappedWorld.CreateShape(randomShape, color, location, size); }
public override void PresentNewTrainingUnit() { WrappedWorld.CreateNonVisibleAgent(); int numberOfShapes = Enum.GetValues(typeof(Shape.Shapes)).Length; List <int> uniqueCouple = LearningTaskHelpers.UniqueNumbers(m_rndGen, 0, numberOfShapes, 2); Shape.Shapes standardShape = (Shape.Shapes)uniqueCouple[0]; Shape.Shapes alternativeShape = (Shape.Shapes)uniqueCouple[1]; int numberOfObjects = (int)TSHints[TSHintAttributes.NUMBER_OBJECTS]; m_diffObjectetPlaced = m_rndGen.Next(2) == 0; bool placeDifferentObj = m_diffObjectetPlaced; 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 Size(15, 15); } Color color; if (TSHints[TSHintAttributes.IS_VARIABLE_COLOR] >= 1f) { color = LearningTaskHelpers.RandomVisibleColor(m_rndGen); } else { color = Color.White; } PointF position = WrappedWorld.RandomPositionInsidePowNonCovering(m_rndGen, size); if (placeDifferentObj) { placeDifferentObj = false; WrappedWorld.CreateShape(alternativeShape, color, position, size); } else { WrappedWorld.CreateShape(standardShape, color, position, size); } } }
protected override void AddShape(int randomLocationIndex) { SizeF size = new SizeF(WrappedWorld.GetPowGeometry().Width / 4, WrappedWorld.GetPowGeometry().Height / 4); Color color = Colors.GetRandomColor(RndGen, out ColorIndex); PointF location = Positions.Positions[randomLocationIndex]; ShapeIndex = RndGen.Next(ScConstants.numShapes); Shape.Shapes randomShape = (Shape.Shapes)ShapeIndex; WrappedWorld.CreateShape(randomShape, color, location, size); GenerationsCheckTable[randomLocationIndex][ColorIndex] = true; }
// scale and position the target: protected void CreateTarget() { // the number of different sizes depends on level: int maxSide = (int)(Math.Max(WrappedWorld.Viewport.Width, WrappedWorld.Viewport.Height) * 0.9); float randomNumber = m_rndGen.Next(1, (int)TSHints[TARGET_SIZE_LEVELS] + 1); m_scale = randomNumber / TSHints[TARGET_SIZE_LEVELS]; float side = maxSide * m_scale; //MyLog.Writer.WriteLine(maxSide); //MyLog.Writer.WriteLine(side); SizeF size = new SizeF(side, side); PointF position = WrappedWorld.RandomPositionInsideViewport(m_rndGen, size, -1); List <Shape.Shapes> shapes = new List <Shape.Shapes>(); switch ((int)TSHints[TSHintAttributes.NUMBER_OF_DIFFERENT_OBJECTS]) { case 3: shapes.Add(Shape.Shapes.Star); goto case 2; case 2: shapes.Add(Shape.Shapes.DoubleRhombus); goto case 1; case 1: shapes.Add(Shape.Shapes.Square); break; } Shape.Shapes shape = shapes[m_rndGen.Next(0, (int)TSHints[TSHintAttributes.NUMBER_OF_DIFFERENT_OBJECTS])]; Color color; if (TSHints[TSHintAttributes.IS_VARIABLE_COLOR] >= 1) { color = LearningTaskHelpers.RandomVisibleColor(m_rndGen); } else { color = Color.White; } WrappedWorld.CreateShape(shape, color, position, size); }
public override void PresentNewTrainingUnit() { WrappedWorld.CreateNonVisibleAgent(); WrappedWorld.IsWorldFrozen = true; // with Pr=.5 show object if (LearningTaskHelpers.FlipCoin(m_rndGen)) { //random size SizeF shapeSize = new SizeF(32, 32); if (TSHints[TSHintAttributes.IS_VARIABLE_SIZE] >= 1.0f) { float side = (float)(10 + m_rndGen.NextDouble() * 38); shapeSize = new SizeF(side, side); } // random position PointF shapePosition = WrappedWorld.Agent.GetGeometry().Location + new Size(20, 0); if (TSHints[TSHintAttributes.IS_VARIABLE_POSITION] >= 1.0f) { shapePosition = WrappedWorld.RandomPositionInsideViewport(m_rndGen, shapeSize, 2); } // random color Color shapeColor = Color.White; if (TSHints[TSHintAttributes.IS_VARIABLE_COLOR] >= 1.0f) { shapeColor = LearningTaskHelpers.RandomVisibleColor(m_rndGen); } // random rotation float rotation = 0; if (TSHints[TSHintAttributes.IS_VARIABLE_ROTATION] >= 1.0f) { rotation = (float)(m_rndGen.NextDouble() * 360); } m_target_type = Shape.GetRandomShape(m_rndGen, (int)TSHints[TSHintAttributes.NUMBER_OF_DIFFERENT_OBJECTS]); m_target = WrappedWorld.CreateShape(m_target_type, shapeColor, shapePosition, shapeSize, rotation); } else { m_target = null; } }
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)); }
public override void PresentNewTrainingUnit() { WrappedWorld.CreateNonVisibleAgent(); m_appears = LearningTaskHelpers.FlipCoin(m_rndGen); if (!m_appears) { return; } SizeF size; if (TSHints[TSHintAttributes.IS_VARIABLE_SIZE] >= 1) { float a = (float)(10 + m_rndGen.NextDouble() * 10); size = new SizeF(a, a); } else { size = new Size(15, 15); } PointF position; if (TSHints[IS_TARGET_MOVING] >= 1) { position = WrappedWorld.RandomPositionInsideViewport(m_rndGen, size); } else { position = WrappedWorld.Agent.GetGeometry().Location; } m_isBlack = LearningTaskHelpers.FlipCoin(m_rndGen); Color color = m_isBlack ? Color.Black : Color.White; WrappedWorld.CreateShape(Shape.Shapes.Square, color, position, size); }
public override void PresentNewTrainingUnit() { m_agent = WrappedWorld.CreateNonVisibleAgent(); SizeF size; if (TSHints[TSHintAttributes.IS_VARIABLE_SIZE] >= 1) { float side = (float)(8 + m_rndGen.NextDouble() * 16); size = new SizeF(side, side); } else { int side = 10; size = new Size(side, side); } PointF position; float radius = Math.Min(WrappedWorld.Viewport.Height, WrappedWorld.Viewport.Width) / 3; if (TSHints[FIXED_DISTANCE] >= 1) { double angle = m_rndGen.NextDouble() * Math.PI * 2; position = new PointF((float)(Math.Cos(angle) * radius), (float)(Math.Sin(angle) * radius)); position += new SizeF(m_agent.Position.X, m_agent.Position.Y); } else { position = WrappedWorld.RandomPositionInsideViewport(m_rndGen, size); } Shape.Shapes shape; if (TSHints[TSHintAttributes.NUMBER_OF_DIFFERENT_OBJECTS] >= 1) { switch (m_rndGen.Next(0, 4)) { case 0: default: shape = Shape.Shapes.Circle; break; case 1: shape = Shape.Shapes.Square; break; case 2: shape = Shape.Shapes.Triangle; break; case 3: shape = Shape.Shapes.Mountains; break; } } else { shape = Shape.Shapes.Circle; } Color color; if (TSHints[TSHintAttributes.IS_VARIABLE_COLOR] >= 1) { color = LearningTaskHelpers.RandomVisibleColor(m_rndGen); } else { color = Color.White; } m_target = WrappedWorld.CreateShape(shape, color, position, size); }
public override void PresentNewTrainingUnit() { int numberOfObjects = (int)TSHints[TSHintAttributes.NUMBER_OF_DIFFERENT_OBJECTS]; List <Shape.Shapes> positiveExamplesRed = new List <Shape.Shapes>(); List <Shape.Shapes> negativeExamplesRed = new List <Shape.Shapes>(); for (int i = 0; i < numberOfObjects / 2; i++) { positiveExamplesRed.Add(m_positiveExamples[i]); negativeExamplesRed.Add(m_negativeExamples[i]); } WrappedWorld.CreateNonVisibleAgent(); SizeF size; float standardSideSize = WrappedWorld.Viewport.Width / 10; if (TSHints[TSHintAttributes.IS_VARIABLE_SIZE] >= 1.0f) { float a = (float)(standardSideSize + m_rndGen.NextDouble() * standardSideSize); size = new SizeF(a, a); } else { size = new SizeF(standardSideSize, standardSideSize); } Color color; if (TSHints[TSHintAttributes.IS_VARIABLE_COLOR] >= 1.0f) { color = LearningTaskHelpers.RandomVisibleColor(m_rndGen); } else { color = Color.White; } PointF position; if (TSHints[TSHintAttributes.IS_VARIABLE_POSITION] >= 1.0f) { position = WrappedWorld.RandomPositionInsideViewport(m_rndGen, size); } else { position = WrappedWorld.Agent.GetGeometry().Location; } m_positiveExamplePlaced = LearningTaskHelpers.FlipCoin(m_rndGen); Shape.Shapes shape; if (m_positiveExamplePlaced) { int randShapePointer = m_rndGen.Next(0, positiveExamplesRed.Count); shape = positiveExamplesRed[randShapePointer]; } else { int randShapePointer = m_rndGen.Next(0, negativeExamplesRed.Count); shape = negativeExamplesRed[randShapePointer]; } WrappedWorld.CreateShape(shape, color, position, size); }
public override void PresentNewTrainingUnit() { WrappedWorld.CreateNonVisibleAgent(); //random size SizeF shapeSize = new SizeF(120, 120); PointF shapePosition = new PointF(WrappedWorld.Scene.Width / 2, WrappedWorld.Scene.Height / 2); Color shapeColor = Color.White; float rotation = 0; Shape nthShape = m_lastNShapes[m_lastNShapes.Length - 2]; // check N steps back, but current is not pushed, so it is N - 1 if (nthShape != null && m_rndGen.NextDouble() < 0.5) { // with probability 0.5 copy the same shapeSize = new SizeF(nthShape.Size.Width, nthShape.Size.Height); shapePosition.X = nthShape.Position.X; shapePosition.Y = nthShape.Position.Y; shapeColor = nthShape.ColorMask; rotation = nthShape.Rotation; m_target_type = nthShape.ShapeType; } else { // with probability 0.5 create a random new one // generate random size if (TSHints[TSHintAttributes.IS_VARIABLE_SIZE] >= 1.0f) { int side = m_rndGen.Next(60, 121); shapeSize = new Size(side, side); } // random position shapePosition.X -= shapeSize.Width / 2; shapePosition.Y -= shapeSize.Height / 2; if (TSHints[TSHintAttributes.IS_VARIABLE_POSITION] >= 1.0f) { shapePosition = WrappedWorld.RandomPositionInsideViewport(m_rndGen, shapeSize); } // random color if (TSHints[TSHintAttributes.IS_VARIABLE_COLOR] >= 1.0f) { shapeColor = LearningTaskHelpers.RandomVisibleColor(m_rndGen); } // random rotation if (TSHints[TSHintAttributes.IS_VARIABLE_ROTATION] >= 1.0f) { rotation = (float)(m_rndGen.NextDouble() * 360); } // random shape m_target_type = Shape.GetRandomShape(m_rndGen, (int)TSHints[TSHintAttributes.NUMBER_OF_DIFFERENT_OBJECTS]); } m_target = (Shape)WrappedWorld.CreateShape(m_target_type, shapeColor, shapePosition, shapeSize, rotation); Push(m_target); }
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); } } }