Esempio n. 1
0
        public void FindScaffoldPath(List <Point> validPath, RobotPosition currentPosition)
        {
            RobotPosition newPosition = currentPosition;

            while ((newPosition = newPosition.Move(position => validPath.Contains(position))) != null)
            {
                validPath.Remove(newPosition.Position);
            }

            newPosition = currentPosition;

            Console.WriteLine();

            while (newPosition != null)
            {
                if (newPosition.NextPosition != null)
                {
                    if (newPosition.Direction != newPosition.NextPosition.Direction)
                    {
                        Console.Write(newPosition.GetTurn());
                    }
                    Console.Write("1,");
                }
                //Console.SetCursorPosition(newPosition.Position.Y, newPosition.Position.X);
                //Console.Write(newPosition.Direction);

                newPosition = newPosition.NextPosition;
            }
        }
Esempio n. 2
0
        public RobotPosition Move(Func <Point, bool> isValidPosition)
        {
            NextPosition = Movements
                           .Where(rp => isValidPosition(rp.Position))
                           .OrderByDescending(p => p.Direction == Direction)
                           .FirstOrDefault();

            return(NextPosition);
        }
Esempio n. 3
0
        public Scaffold()
        {
            computer.LoadProgram(FileUtils.LoadDataFor(17))
            .SetOutput(CameraOutput)
            .Run();

            FindIntersections();

            //Print(true);

            RobotPosition currentPosition = screen.Where(s => !(s.Value == '#' || s.Value == '.')).Select(s => new RobotPosition(s.Value, s.Key)).FirstOrDefault();
            List <Point>  scaffoldPath    = screen.Where(s => s.Value == 35).Select(s => s.Key).ToList();

            scaffoldPath.AddRange(intersections);

            FindScaffoldPath(scaffoldPath, currentPosition);

            Console.WriteLine(GetDust());
        }