Esempio n. 1
0
 public RotatingRobot()
 {
     sL = new Sensor(LEFT);
     sR = new Sensor(RIGHT);
     actuatorDirection = 0;
     facing            = 0;
 }
Esempio n. 2
0
 //Pre: Current robot position and direction that the robot is facing
 //Post: Updated position of the robot in the grid, triggering a move.
 public bool moveForward(int[] pos, robotDirection x)
 {
     if (x == robotDirection.Forward)
     {
         pos[row] -= MOVE;
         return(true);
     }
     else if (x == robotDirection.Backward)
     {
         pos[row] += MOVE;
         return(true);
     }
     else if (x == robotDirection.Left)
     {
         pos[column] -= MOVE;
         return(true);
     }
     else if (x == robotDirection.Right)
     {
         pos[column] += MOVE;
         return(true);
     }
     else
     {
         return(false);
     }
 }
Esempio n. 3
0
 public RotatingRobot(string filename)
 {
     sL = new Sensor(LEFT);
     sR = new Sensor(RIGHT);
     actuatorDirection = 0;
     facing            = 0;
     getGrid(filename);
 }
Esempio n. 4
0
 public Robot(string filename)
 {
     s           = new Sensor();
     a           = new Actuator(0);
     robotDir    = 0;
     count_moves = 0;
     getGrid(filename);
 }
Esempio n. 5
0
        public Robot()
        {
            s = new Sensor();
            a = new Actuator(0);

            for (uint i = 0; i < ARR_SIZE; i++)
            {
                position[i] = START_POSITION;
            }
            robotDir = 0;
            //getGrid();
        }
Esempio n. 6
0
        public override bool isValid()
        {
            if (s.isValid(position, grid, this))
            {
                nextDirection = (robotDirection)robotDir;
                return(true);
            }
            if (sR.isValid(position, grid, this))
            {
                nextDirection = (robotDirection)robotDir;
                return(true);
            }

            if (sL.isValid(position, grid, this))
            {
                nextDirection = (robotDirection)robotDir;
                return(true);
            }
            return(false);
        }
Esempio n. 7
0
 //Pre:Current direction of sensors and the direction of the robot.
 //Post: Fully updated direction of the robot, actuator, and sensors
 //for the robot to continue moving throughout the grid.
 public void Rotate(robotDirection change)
 {
     if (facing == robotDirection.Forward)
     {
         if (change == robotDirection.Right)
         {
             facing = robotDirection.Right;
             s.changeDirection(facing);
             sR.changeDirection(robotDirection.Backward);
             sL.changeDirection(robotDirection.Forward);
             a.changeDirection(facing);
         }
         else if (change == robotDirection.Left)
         {
             facing = robotDirection.Left;
             s.changeDirection(facing);
             sR.changeDirection(robotDirection.Forward);
             sL.changeDirection(robotDirection.Backward);
             a.changeDirection(facing);
         }
     }
     else if (facing == robotDirection.Left)
     {
         if (change == robotDirection.Forward)
         {
             facing = robotDirection.Forward;
             s.changeDirection(facing);
             sR.changeDirection(robotDirection.Right);
             sL.changeDirection(robotDirection.Left);
             a.changeDirection(facing);
         }
         else if (change == robotDirection.Backward)
         {
             facing = robotDirection.Backward;
             s.changeDirection(facing);
             sR.changeDirection(robotDirection.Left);
             sL.changeDirection(robotDirection.Right);
             a.changeDirection(facing);
         }
     }
     else if (facing == robotDirection.Backward)
     {
         if (change == robotDirection.Right)
         {
             facing = robotDirection.Right;
             s.changeDirection(facing);
             sR.changeDirection(robotDirection.Forward);
             sL.changeDirection(robotDirection.Backward);
             a.changeDirection(facing);
         }
         else if (change == robotDirection.Left)
         {
             facing = robotDirection.Left;
             s.changeDirection(facing);
             sR.changeDirection(robotDirection.Backward);
             sL.changeDirection(robotDirection.Forward);
             a.changeDirection(facing);
         }
     }
     else if (facing == robotDirection.Right)
     {
         if (change == robotDirection.Backward)
         {
             facing = robotDirection.Backward;
             s.changeDirection(facing);
             sR.changeDirection(robotDirection.Left);
             sL.changeDirection(robotDirection.Right);
             a.changeDirection(facing);
         }
         else if (change == robotDirection.Forward)
         {
             facing = robotDirection.Forward;
             s.changeDirection(facing);
             sR.changeDirection(robotDirection.Right);
             sL.changeDirection(robotDirection.Left);
             a.changeDirection(facing);
         }
     }
 }
Esempio n. 8
0
 //Pre: next valid direction to move in the grid
 //Post: updated direction for the sensor to move with the robot.
 public void changeDirection(robotDirection newDir)
 {
     sdir = (SensorDirection)newDir;
 }
Esempio n. 9
0
 //Pre: Current direction that the robot is facing.
 //Post: Updated direction if the robot needs to rotate.
 public void changeDirection(robotDirection newDir)
 {
     robotDir = newDir;
 }
Esempio n. 10
0
 //Pre:Current direction that the robot is facing
 //Post:Updated actuator direction to match that of the robot.
 public void changeDirection(robotDirection newDir)
 {
     direction = (Direction)newDir;
 }