Esempio n. 1
0
        private void TurnRobotToFaceTheCorrectSide()
        {
            int diffInX = _algorithmEssentials.Robot.GetCurrentCell().X - _algorithmEssentials.Room.MinCoOrdinate.X;
            int diffInY = _algorithmEssentials.Robot.GetCurrentCell().Y - _algorithmEssentials.Room.MinCoOrdinate.Y;

            if (diffInX > 0)
            {
                //turn to the left side
                RobotUtility.TurnToFaceLeft(_algorithmEssentials);
            }

            if (diffInX == 0)
            {
                if (diffInY > 0)
                {
                    //turn to the top side
                    RobotUtility.TurnToFaceUp(_algorithmEssentials);
                }
                if (diffInY < 0)
                {
                    //turn to the bottom side
                    RobotUtility.TurnToFaceDown(_algorithmEssentials);
                }
            }

            if (diffInX < 0)
            {
                //turn to the right side
                RobotUtility.TurnToFaceRight(_algorithmEssentials);
            }
        }
        public override CleanStatus Clean()
        {
            _algorithmEssentials.RobotVisitMonitor.AddCurrentPositionToVisitList();

            RobotUtility.TurnLeft(_algorithmEssentials);

            bool canMove = true;

            while (canMove)
            {
                canMove = _handlerManager.HandleNextMove();
            }

            Status = CleanStatus.Complete;

            return(CleanStatus.Complete);
        }
Esempio n. 3
0
        public bool HandleMovement()
        {
            //If can't handle the move operation then give the control to the ObstacleHandler.

            if (RobotUtility.CanRobotMoveForward(_algorithmEssentials, _canReUseVisitedCells))
            {
                RobotUtility.MoveForward(_algorithmEssentials);
                return(true);
            }

            if ((null != _nextHandler))
            {
                return(_nextHandler.HandleMovement());
            }

            return(false);
        }
Esempio n. 4
0
        public static void TurnToFaceUp(AlgorithmEssentials inAlgorithmEssentials)
        {
            // Turn to the top side.
            switch (inAlgorithmEssentials.Robot.FaceTo)
            {
            case 0:
                RobotUtility.TurnLeft(inAlgorithmEssentials);
                break;

            case 1:
                RobotUtility.TurnRight(inAlgorithmEssentials);
                RobotUtility.TurnRight(inAlgorithmEssentials);
                break;

            case 2:
                RobotUtility.TurnRight(inAlgorithmEssentials);
                break;
            }
        }
        public bool HandleMovement()
        {
            // Handle the obstacle by turning right. If 3 right turns can't find a way,
            // then the Robot completed cleaning the room.

            RobotUtility.TurnRight(_algorithmEssentials);

            if (RobotUtility.CanRobotMoveForward(_algorithmEssentials, _canReUseVisitedCells))
            {
                return(true);
            }

            if ((null != _nextHandler))
            {
                return(_nextHandler.HandleMovement());
            }

            return(false);
        }