Professional Documents
Culture Documents
Hardware Robot Main Room Cleaner
Hardware Robot Main Room Cleaner
using RumbaMumbaRobots.Paths;
using RumbaMumbaRobots.Printing;
using RumbaMumbaRobots.Robot;
#endregion
namespace RumbaMumbaRobots.CleaningAlgorithm
{
/// <summary>
///
/// </summary>
class HardwareRobotMainRoomCleaner : IHardwareRobotRoomCleaner
{
#region Private Variables
/// <summary>
///
/// </summary>
private int _hardwareRobotTotalMovement;
/// <summary>
///
/// </summary>
private readonly RobotPath _parentRobotPath;
/// <summary>
///
/// </summary>
private readonly IHardwareRobotDirection _hardwareRobotDirection;
/// <summary>
///
/// </summary>
private readonly IHardwareRobotMovement _hardwareRobotMovement;
/// <summary>
///
/// </summary>
private readonly IHardwareRobotObstacleDetector
_hardwareRobotObstacleDetector;
/// <summary>
///
/// </summary>
private readonly IRobotMovementPrinter _robotMovementPrinter;
#endregion
/// <summary>
///
/// </summary>
/// <param name="hardwareRobotDirection"></param>
/// <param name="hardwareRobotMovement"></param>
/// <param name="hardwareRobotObstacleDetector"></param>
/// <param name="robotMovementPrinter"></param>
public HardwareRobotMainRoomCleaner(IHardwareRobotDirection
hardwareRobotDirection,
IHardwareRobotMovement
hardwareRobotMovement,
IHardwareRobotObstacleDetector
hardwareRobotObstacleDetector,
IRobotMovementPrinter robotMovementPrinter)
{
_hardwareRobotDirection = hardwareRobotDirection;
_hardwareRobotMovement = hardwareRobotMovement;
_hardwareRobotObstacleDetector = hardwareRobotObstacleDetector;
_robotMovementPrinter = robotMovementPrinter;
#endregion
/// <summary>
///
/// </summary>
public void CleanRoom()
{
var cellNo = 1;
const string cell = "Cell";
//1) Rotate left.
_hardwareRobotDirection.TurnLeft();
//2) If there isn�t an obstacle and the robot was never there, walk.
if (!_hardwareRobotObstacleDetector.IsObstacle())
{
var cellName = cell + cellNo;
if (!_parentRobotPath.IsVisited(cellName))
{
//Check if the robot has been there. if not, walk
_hardwareRobotMovement.Walk();
++cellNo;
}
}
else
{
//3) If not, rotate right.
_hardwareRobotDirection.TurnRight();
}
//4) If there isn�t an obstacle and the robot was never there, walk.
if (!_hardwareRobotObstacleDetector.IsObstacle())
{
var cellName = cell + cellNo;
if (!_parentRobotPath.IsVisited(cellName))
{
//Check if the robot has been there. if not, walk
_hardwareRobotMovement.Walk();
//6) If there isn�t an obstacle and the robot was never there, walk.
if (!_hardwareRobotObstacleDetector.IsObstacle())
{
var cellName = cell + cellNo;
if (!_parentRobotPath.IsVisited(cellName))
{
//Check if the robot has been there. if not, walk
_hardwareRobotMovement.Walk();
++cellNo;
}
}
else
{
//7) If not, the room is cleaned.
}
_hardwareRobotTotalMovement = _hardwareRobotMovement.TotalMovements;
}
/// <summary>
///
/// </summary>
public void PrintPath()
{
//Print the path
_robotMovementPrinter.Print(_parentRobotPath.GetVisitedPathsDetails());
}
/// <summary>
///
/// </summary>
public void PrintTotalMovement()
{
_robotMovementPrinter.Print(string.Format("The Total movements is:
{0}.", _hardwareRobotTotalMovement));
}
#endregion
}
}