Ejemplo n.º 1
0
        /// <summary>
        /// Move robot and pre-calculate cleaned spaces
        /// Pre-calculation is done for efficiency for crosstesting the solution
        /// </summary>
        public void Move(RobotMove move)
        {
            moves.Add(move);

            // calculate path section and move the robot to new position
            var section = GetSection(Position, move);

            Position = section.BottomLeft == Position ? section.TopRight : section.BottomLeft;

            // get list of previous moves that this move intersects with
            var intersections = new List <PathSection>();

            foreach (var s in sections)
            {
                var common = GetIntersection(section, s);
                if (common != null)
                {
                    intersections.Add(common);
                }
            }

            // squash intersections to prevent for double counting of them
            var squash = Squash(intersections).ToList();

            // calculate new number of cleaned spaces with this move
            CleanedSpaces += section.Coverage - squash.Sum(x => x.Coverage);

            // store this path section to consider it in the future
            sections.Add(section);
        }
Ejemplo n.º 2
0
        public void Move(RobotMove move)
        {
            moves.Add(move);

            var newPosition = GetPosition(Position, move);

            Visit(Position, newPosition);
            Position = newPosition;
        }
Ejemplo n.º 3
0
 /// <summary>
 /// Translate move of the robot from postion into a section on the grid
 /// </summary>
 /// <param name="p">Position of the robot</param>
 /// <param name="move">Robot's move</param>
 /// <returns>Path section on the grid</returns>
 private PathSection GetSection(Point p, RobotMove move)
 {
     return((move.Direction) switch
     {
         RobotMoveDirection.E => new PathSection(p, new Point(p.X + move.Steps, p.Y)),
         RobotMoveDirection.W => new PathSection(new Point(p.X - move.Steps, p.Y), p),
         RobotMoveDirection.N => new PathSection(p, new Point(p.X, p.Y + move.Steps)),
         RobotMoveDirection.S => new PathSection(new Point(p.X, p.Y - move.Steps), p),
         _ => throw new ArgumentException($"Unkown value of direction paramater: {move.Direction}")
     });
Ejemplo n.º 4
0
 private Point GetPosition(Point position, RobotMove move)
 {
     return((move.Direction) switch
     {
         RobotMoveDirection.E => new Point(position.X - move.Steps, position.Y),
         RobotMoveDirection.W => new Point(position.X + move.Steps, position.Y),
         RobotMoveDirection.N => new Point(position.X, position.Y + move.Steps),
         RobotMoveDirection.S => new Point(position.X, position.Y - move.Steps),
         _ => throw new ArgumentException("Unkown value of direction paramater")
     });