// Checks the Out Stack to see if it is empty. // If it is, move all Nodes in the In Stack to the Out Stack. private void FillOutIfEmpty() { if (Out.Peek() == null) { while (In.Peek() != null) { Out.Push(In.Pop()); } } }
public void Start() { var lineNumber = 0; var rovers = new List <IRover>(); while (In.Peek() >= 0) { lineNumber++; var line = In.ReadLine(); // end of it if (line == null) { break; } if (plateue.Match(line).Success || mars == null) { var segment = line.Split(" "); var x = Int32.Parse(segment[0]); var y = Int32.Parse(segment[1]); mars = new Plateue(new Point(x, y), new Point(0, 0)); continue; } if (roverInit.Match(line).Success) { // 1 2 N var segment = line.Split(" "); var x = Int32.Parse(segment[0]); var y = Int32.Parse(segment[1]); var d = segment[2]; if (mars != null) { var rover = new Rover(new Point(x, y), Compass.FromChar(d)); rovers.Add(mars.AddRover(rover)); } continue; } if (commands.Match(line).Success) { if (rovers.Count == 0) { throw new Exception("There is not rover which landed on mars!"); } mars.Move(rovers[0], line); Out.WriteLine(rovers[0].GetPosition()); mars.CallStation(rovers[0]); rovers.Remove(rovers[0]); } } Out.Close(); }
/// Peek a characted from the input stream, or return -1 for EOF public int Peek() { return(In.Peek()); }