public void RobotMovesOffGrid() { _grid = new Grid(30, 30); _coord = new Coordinate(0, 0); _robot = new Robot(_coord, Orientation.S, _grid); _robot.Move(Instruction.M, _grid); }
public void CreateRobot() { _grid = new Grid(30, 30); _coord = new Coordinate(10, 11); _robot = new Robot(_coord, Orientation.N, _grid); Assert.AreEqual(_coord.X, _robot.Pos.X); Assert.AreEqual(_coord.Y, _robot.Pos.Y); Assert.AreEqual(Orientation.N, _robot.Or); }
public Robot(Coordinate pos, Orientation or, Grid grid) { if (!grid.IsValid(pos)) { throw new Exception("Robot placed outside of grid"); } _pos = pos; _or = or; }
public void Move(Instruction inst, Grid grid) { switch (inst) { //Modulus used to cycle orientations. Limited definition of modulus with reference to negative //numbers result in initial incrementation by setsize to guarantee positive result case Instruction.R: _or = (Orientation)Enum.ToObject(typeof(Orientation), (((int)_or + NumOrientations + 1) % NumOrientations)); break; case Instruction.L: _or = (Orientation)Enum.ToObject(typeof(Orientation), (((int)_or + NumOrientations - 1) % NumOrientations)); break; case Instruction.M: Coordinate newPos; switch (_or) { case Orientation.N: newPos = new Coordinate(_pos.X, _pos.Y + 1); break; case Orientation.E: newPos = new Coordinate(_pos.X + 1, _pos.Y); break; case Orientation.S: newPos = new Coordinate(_pos.X, _pos.Y - 1); break; case Orientation.W: newPos = new Coordinate(_pos.X - 1, _pos.Y); break; default: newPos = new Coordinate(-1, -1); break; } if (grid.IsValid(newPos)) { _pos = newPos; } else { throw new InvalidOperationException(); } break; } }
public void FirstRobotMovementTest() { //1 2 N //LMLMLMLMM _grid = new Grid(5, 5); _robot = new Robot(new Coordinate(1, 2), Orientation.N, _grid); _robot.Move(Instruction.L, _grid); _robot.Move(Instruction.M, _grid); _robot.Move(Instruction.L, _grid); _robot.Move(Instruction.M, _grid); _robot.Move(Instruction.L, _grid); _robot.Move(Instruction.M, _grid); _robot.Move(Instruction.L, _grid); _robot.Move(Instruction.M, _grid); _robot.Move(Instruction.M, _grid); Assert.AreEqual(1, _robot.Pos.X); Assert.AreEqual(3, _robot.Pos.Y); Assert.AreEqual(Orientation.N, _robot.Or); }
public void TestIsValidTrue() { var grid = new Grid(30,30); Assert.IsTrue(grid.IsValid(new Coordinate(30,1))); }
public void TestIsValidFalseTooHigh() { var grid = new Grid(30,30); Assert.IsFalse(grid.IsValid(new Coordinate(31,3))); }
public void TestIsValidFalseNeg() { var grid = new Grid(30,30); Assert.IsFalse(grid.IsValid(new Coordinate(20,-1))); }
public void CreateRobotInvalidPosition() { _grid = new Grid(30, 30); _coord = new Coordinate(1, -1); _robot = new Robot(_coord, Orientation.N, _grid); }
/// <summary> /// Static method creates singleton grid of specified width and height /// </summary> private static void CreateGrid(int width, int height) { _grid = new Grid(width, height); }