Example #1
0
        /// <summary>
        /// 如果无解返回null。
        /// </summary>
        /// <param name="act"></param>
        /// <param name="name"></param>
        /// <param name="parameter"></param>
        /// <param name="currentSteps"></param>
        /// <param name="maxStepsToSolution"></param>
        /// <param name="enlargedGrid"></param>
        /// <returns></returns>
        private LinkedList <Action> TestAction(Func <double, Car> act, ActionDirection name, double parameter, int currentSteps, int maxStepsToSolution, bool enlargedGrid)
        {
            Car vc = act(parameter);

            currentSteps++; //执行好act,所以又走了一步了!
            Point center = vc.Center;

            if (center.X > 0 && center.Y > 0 &&
                center.X < Map.Size.Width && center.Y < Map.Size.Height &&
                IsShorterPath(center, vc.Orientation, currentSteps, enlargedGrid))
            {
                //不会碰到其他车
                if (DoesCollide(vc.GetBound()) == false)
                {
                    var list = SolveInternal(vc, currentSteps, maxStepsToSolution);
                    if (list != null) //有解
                    {
                        list.AddFirst(new Action {
                            ActionDirection = name, Parameter = parameter
                        });

                        //if(bestSolution==null)
                        //    bestSolution=list;


                        return(list);
                    }
                }
            }
            return(null);
        }
Example #2
0
        private void Draw(Car car, bool fill, DoubleCollection strokeDashArray)
        {
            //Polygon polygon = new Polygon();
            //polygon.Stroke = Brushes.LightSeaGreen;
            //if (fill)
            //    polygon.Fill = Brushes.LightSeaGreen;
            //polygon.StrokeDashArray = strokeDashArray;

            //polygon.Points.Add(car.GetLeftFrontCorner());
            //polygon.Points.Add(car.GetRightFrontCorner());
            //polygon.Points.Add(car.GetRightBackCorner());
            //polygon.Points.Add(car.GetLeftBackCorner());

            //Canvas.Children.Add(polygon);
            Geometry geo  = car.GetBound();
            Path     path = new Path();

            path.Stroke          = Brushes.LightSeaGreen;
            path.StrokeDashArray = strokeDashArray;
            path.Data            = geo;
            Canvas.Children.Add(path);


            Line arrowLine1 = new Line();

            arrowLine1.Stroke          = Brushes.Red;
            arrowLine1.StrokeThickness = 2;
            arrowLine1.StrokeDashArray = strokeDashArray;
            arrowLine1.X1 = car.Center.X;
            arrowLine1.Y1 = car.Center.Y;

            Matrix m = Matrix.Identity;

            m.Rotate(car.Orientation);
            m.Translate(car.Center.X, car.Center.Y);

            double arrowLength = car.Length / 2 / 3 * 2;
            Point  p           = new Point(0, arrowLength);

            p             = m.Transform(p);
            arrowLine1.X2 = p.X;
            arrowLine1.Y2 = p.Y;

            Canvas.Children.Add(arrowLine1);

            Point pl = new Point(-car.Width / 2 / 4, arrowLength - car.Width / 2 / 3);

            pl = m.Transform(pl);
            Line arrowLine2 = new Line();

            arrowLine2.Stroke          = Brushes.Red;
            arrowLine2.StrokeThickness = 2;
            arrowLine2.StrokeDashArray = strokeDashArray;
            arrowLine2.X1 = p.X;
            arrowLine2.Y1 = p.Y;
            arrowLine2.X2 = pl.X;
            arrowLine2.Y2 = pl.Y;
            Canvas.Children.Add(arrowLine2);

            Point pr = new Point(car.Width / 2 / 4, arrowLength - car.Width / 2 / 3);

            pr = m.Transform(pr);
            Line arrowLine3 = new Line();

            arrowLine3.Stroke          = Brushes.Red;
            arrowLine3.StrokeThickness = 2;
            arrowLine3.StrokeDashArray = strokeDashArray;
            arrowLine3.X1 = p.X;
            arrowLine3.Y1 = p.Y;
            arrowLine3.X2 = pr.X;
            arrowLine3.Y2 = pr.Y;
            Canvas.Children.Add(arrowLine3);
        }