private void Grid_MouseUp(object sender, MouseButtonEventArgs e)
        {
            if (!_AddMode)
            {
                return;
            }
            _AddMode = false;
            _ConnectorLine.Visibility = System.Windows.Visibility.Hidden;

            //Add the one we picked
            var oldLoc = new OldLocation();

            Canvas.SetLeft(oldLoc, Canvas.GetLeft(primarySegment));
            Canvas.SetTop(oldLoc, Canvas.GetTop(primarySegment));
            DrawCanvas.Children.Add(oldLoc);

            //Add a line connecting old to new
            var newestLine = new Line();

            newestLine.Visibility = System.Windows.Visibility.Visible;

            newestLine.Stroke = new SolidColorBrush(Colors.Brown);

            newestLine.X1 = _ConnectorLine.X1;
            newestLine.Y1 = _ConnectorLine.Y1;
            newestLine.X2 = _ConnectorLine.X2 + 40;
            newestLine.Y2 = _ConnectorLine.Y2 + 50;
            DrawCanvas.Children.Add(newestLine);

            //Move the active/primary to the new location
            Canvas.SetLeft(primarySegment, e.GetPosition(this).X);
            Canvas.SetTop(primarySegment, e.GetPosition(this).Y);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Enacts agent behavior based on neural network outputs. Movement uses instant/reactive turning and acceleration-based movement (hybrid approach) to encourage robots to move at the same (maximum) Velocity.
        /// </summary>
        /// <param name="outputs">Neural network outputs.</param>
        /// <param name="Timestep">The current timestep.</param>
        public void decideAction(float[] outputs, double timeStep)
        {
            Velocity += (outputs[1] - 0.5) * 2.0;
            if (Velocity > 6.0)
            {
                Velocity = 6.0;
            }
            if (Velocity < -6.0)
            {
                Velocity = (-6.0);
            }
            Heading += (outputs[0] - 0.5) * 0.2094395104 * 2;

            // Position updating code below this point ---------------
            TempDistance      = (float)OldLocation.squaredDistance(Location);
            DistanceTraveled += TempDistance;

            OldLocation.X = Location.X;
            OldLocation.Y = Location.Y;

            // Update current coordinates (may be revoked if new position forces collision)
            if (!Stopped)
            {
                double dx = Math.Cos(Heading) * Velocity * timeStep;
                double dy = Math.Sin(Heading) * Velocity * timeStep;
                Location.X += dx;
                Location.Y += dy;
            }
        }
Ejemplo n.º 3
0
        private Rect GetMovedAreaRect()
        {
            var halfSize = HalfSize;
            var rect     = Rect.CreateFromPoints(OldLocation.ToPoint() + halfSize, Location.ToPoint() + halfSize);

            rect.X      -= halfSize.X;
            rect.Y      -= halfSize.Y;
            rect.Width  += Size.X;
            rect.Height += Size.Y;
            return(rect);
        }