Exemplo n.º 1
0
        public override Canvass Paint()
        {
            var canvass = PaintServiceCore.Paint(state);

            state.Canvas = canvass;             // todo should be more functional, ie a clone
            return(canvass);
        }
Exemplo n.º 2
0
        public void BoxOutline()
        {
            var res = PaintServiceCore.CalculateBoxOutline(new Box(new Coord(3, 4)));

            Assert.AreEqual(new[] {
                new Coord(2, 3),
                new Coord(4, 3),
                new Coord(2, 5),
                new Coord(4, 5),
                new Coord(3, 3),
                new Coord(3, 5),
                new Coord(2, 4),
                new Coord(4, 4),
            }, res);
        }
Exemplo n.º 3
0
        public static List <Coord> Calculate(Coord from, Coord to, Canvass c, Model model)
        {
            var size      = c.GetSize();
            var solutions = new Solution[size.Item1, size.Item2];
            var unHandled = new SimplePriorityQueue <UnhandledField>();

            unHandled.Enqueue(new UnhandledField(from, new List <Coord>(), 0), 0);

            while (unHandled.Count > 0)
            {
                var current = unHandled.Dequeue();

                var pathForPosition = new List <Coord>(current.Path.Count + 1);
                pathForPosition.AddRange(current.Path);
                pathForPosition.Add(current.Position);

                var solution = new Solution(pathForPosition, current.Distance);

                var ifNoOrWeakerSolution =
                    solution.Distance < (solutions[current.Position.Y, current.Position.X]?.Distance ?? int.MaxValue);
                if (ifNoOrWeakerSolution)
                {
                    solutions[current.Position.Y, current.Position.X] = solution;

                    var currentBestSolutionAtDestination = solutions[to.Y, to.X]?.Distance ?? int.MaxValue;
                    var neighbours = CalculateNSEW(current.Position);
                    var potentials = neighbours
                                     .Where(x => x == to || IsCellFree(c, x, model))
                                     .Select(x =>
                                             new {
                        Neighbour         = x,
                        EstimatedDistance =
                            PaintServiceCore.ManhattenDistance(x, to) + (Vector.IsStraightLine(x, to) ? 0 : WeightOfTurn),
                        Unhandled = new UnhandledField(x, pathForPosition, current.Distance + StepLength)
                    })
                                     .Where(x => current.Distance + x.EstimatedDistance + StepLength < currentBestSolutionAtDestination);

                    potentials.Each(x => unHandled.Enqueue(x.Unhandled, x.EstimatedDistance));
                }
            }

            var shortestPath = solutions[to.Y, to.X];

            return(shortestPath == null ? new List <Coord>() : shortestPath.Path);
        }
Exemplo n.º 4
0
 public static string PaintOneLine(params IPaintable <object>[] p)
 {
     return(PaintServiceCore.PaintModel(new Model(p), false).TrimEndToString());
 }
Exemplo n.º 5
0
        public static string Paint(params IPaintable <object>[] p)
        {
            return(@"
" + PaintServiceCore.PaintModel(p.ToList()).TrimEndToString());
        }