private void RenderCarSimulation(CarSimulation carSimulation, bool isBest)
        {
            var car = carSimulation.Car;

            var color = Brushes.Green;

            if (carSimulation.HasEnded)
            {
                color = Brushes.Red;
            }

            if (isBest)
            {
                color = Brushes.Blue;
            }

            var ellipse = new Ellipse()
            {
                Width           = (double)car.BoundingBox.Size.Width,
                Height          = (double)car.BoundingBox.Size.Height,
                Fill            = Brushes.Transparent,
                Stroke          = color,
                StrokeThickness = 3,
                Opacity         = 1
            };

            Render(ellipse);

            Canvas.SetLeft(ellipse, (double)car.BoundingBox.Location.X);
            Canvas.SetTop(ellipse, (double)car.BoundingBox.Location.Y);

            if (carSimulation.HasEnded)
            {
                return;
            }

            var line = new System.Windows.Shapes.Line()
            {
                X1               = (double)car.BoundingBox.Center.X,
                Y1               = (double)car.BoundingBox.Center.Y,
                X2               = (double)car.BoundingBox.Center.X + ((double)car.ForwardDirectionLine.End.X * (double)car.BoundingBox.Size.Width),
                Y2               = (double)car.BoundingBox.Center.Y + ((double)car.ForwardDirectionLine.End.Y * (double)car.BoundingBox.Size.Height),
                Stroke           = Brushes.Blue,
                StrokeDashOffset = 2,
                StrokeThickness  = 2
            };

            Render(line);

            RenderCarSimulationSensorReadings(carSimulation);
        }
        public void Fitness_GoodSimulationHasSurvivedLonger_GoodSimulationHasSmallerFitness()
        {
            var map = GenerateCircularMap();

            var badSimulation = new CarSimulation(map);

            badSimulation.TicksSurvived = 10;

            var goodSimulation = new CarSimulation(map);

            goodSimulation.TicksSurvived = 20;

            Assert.IsTrue(goodSimulation.Fitness < badSimulation.Fitness);
        }
        public void Fitness_GoodSimulationIsFurtherOnMap_GoodSimulationHasSmallerFitness()
        {
            var map = GenerateCircularMap();

            var badSimulation = new CarSimulation(map);

            badSimulation.CurrentProgressLine = map.Nodes
                                                .SelectMany(x => x.ProgressLines)
                                                .Skip(2)
                                                .First();

            var goodSimulation = new CarSimulation(map);

            goodSimulation.CurrentProgressLine = map.Nodes
                                                 .SelectMany(x => x.ProgressLines)
                                                 .Skip(4)
                                                 .First();

            Assert.IsTrue(goodSimulation.Fitness < badSimulation.Fitness);
        }
        private void RenderCarSimulationSensorReadings(CarSimulation carSimulation)
        {
            return;

            if (carSimulation.HasEnded)
            {
                return;
            }

            var sensorReadings      = carSimulation.SensorReadings;
            var sensorReadingsArray = new[]
            {
                sensorReadings.LeftSensor,
                sensorReadings.CenterSensor,
                sensorReadings.RightSensor
            };

            var car = carSimulation.Car;

            foreach (var sensorReading in sensorReadingsArray)
            {
                if (sensorReading == null)
                {
                    continue;
                }

                var sensorLine = new System.Windows.Shapes.Line()
                {
                    X1              = (double)car.BoundingBox.Center.X,
                    Y1              = (double)car.BoundingBox.Center.Y,
                    X2              = (double)sensorReading.Value.IntersectionPoint.X,
                    Y2              = (double)sensorReading.Value.IntersectionPoint.Y,
                    Stroke          = Brushes.Blue,
                    Opacity         = 0.2,
                    StrokeThickness = 1
                };

                Render(sensorLine);
            }
        }
Пример #5
0
        private void MyTimer_Tick(object sender, EventArgs e)
        {
            form2.pEntrance.BackColor = Color.DarkRed;
            if (Parkingspaces[0] == 1 && Parkingspaces[1] == 1 && Parkingspaces[2] == 1 && Parkingspaces[3] == 1 && Parkingspaces[4] == 1 && Parkingspaces[5] == 1 && Parkingspaces[6] == 1 && Parkingspaces[7] == 1 && Parkingspaces[8] == 1 && Parkingspaces[9] == 1)
            {
                MessageBox.Show("Parking lot is full!!!");
                MyTimer.Stop();
            }
            else
            {
                if (temp < 10)
                {
                    //MessageBox.Show((temp + 1).ToString());
                    switch (temp)
                    {
                    case 0:
                        form2.pSpace1.BackColor = Color.DarkRed;
                        BottomSpace--;
                        break;

                    case 1:
                        form2.pSpace2.BackColor = Color.DarkRed;
                        TopSpace--;
                        break;

                    case 2:
                        form2.pSpace3.BackColor = Color.DarkRed;
                        BottomSpace--;
                        break;

                    case 3:
                        form2.pSpace4.BackColor = Color.DarkRed;
                        RightSpace--;
                        break;

                    case 4:
                        form2.pSpace5.BackColor = Color.DarkRed;
                        TopSpace--;
                        break;

                    case 5:
                        form2.pSpace6.BackColor = Color.DarkRed;
                        TopSpace--;
                        break;

                    case 6:
                        form2.pSpace7.BackColor = Color.DarkRed;
                        BottomSpace--;
                        break;

                    case 7:
                        form2.pSpace8.BackColor = Color.DarkRed;
                        BottomSpace--;
                        break;

                    case 8:
                        form2.pSpace9.BackColor = Color.DarkRed;
                        RightSpace--;
                        break;

                    case 9:
                        form2.pSpace10.BackColor = Color.DarkRed;
                        RightSpace--;
                        break;

                    default:
                        break;
                    }
                    temp++;
                    form2.btnRemove.Enabled = true;
                    Random        random   = new Random();
                    TimeSpan      duration = new TimeSpan(random.Next(0, 12), 0, 0);
                    string        timeIN   = DateTime.Now.ToString("MM/dd/yyyy hh:mm tt");
                    string        TimeOUT  = DateTime.Now.Add(duration).ToString("MM/dd/yyyy hh:mm tt");
                    CarSimulation newCar   = new CarSimulation(0, timeIN, TimeOUT);
                    datahandler.Insert(newCar);
                    form2.lblParkingleftTop.Text    = "Parking Spaces Left: " + (TopSpace);
                    form2.lblParkingLeftBottom.Text = "Parking Spaces Left: " + (BottomSpace);
                    form2.lblParkingLeftRight.Text  = "Parking Spaces Left: " + (RightSpace);
                    MyTimer.Stop();
                }
                else
                {
                    MyTimer.Stop();
                    MessageBox.Show("Parking is full");
                }
            }
        }