public SubRotatingRobot(string [] filepath) : base(filepath[0]) { if (filepath.Length != 11) { return; } Grid3D grid = new Grid3D(filepath); submersible = new Submersible(grid); }
public Submersible(Grid3D grid3D) { state = true; Sensors = new Dictionary <Direction3D, Sensor3D>() { { Direction3D.LevelDown, new Sensor3D() }, { Direction3D.LevelUp, new Sensor3D(Direction3D.LevelUp) } }; this.Actuator = new Actuator3D(); this.Grid3D = grid3D; CurrentLevel = 0; posR = DEFAULT_POS; posC = DEFAULT_POS; }
// PreConditions: // PostConditions: Changes battery level (discharges) public bool isValid(Grid3D grid3D, int posR, int posC, int level) { if (State) { if (BatteryLevel < DischargeRate) { return(false); } else if (BatteryLevel < 100) { State = false; return(false); } else { BatteryLevel -= DischargeRate; switch (SensorDirection) { case Direction3D.LevelDown: if (level == 10) { return(false); } Grid temp = grid3D.getGrid(level + 1); return(temp.isPath(posR, posC)); case Direction3D.LevelUp: if (level == 0) { return(false); } Grid temp2 = grid3D.getGrid(level - 1); return(temp2.isPath(posR, posC)); } } } return(false); }