import java.io.File;
import java.util.Scanner;

/**
 * Driver class for navigating a robot grid.
 *   @author Dave Reed
 *   @version 8/17/17
 */
public class RoboDriver {

    public static void main(String[] args) {
        Scanner input = new Scanner(System.in);
        System.out.print("Enter the grid file name: ");
        String filename = input.next();

        try {
            Scanner infile = new Scanner(new File(filename));

            RoboGrid grid = new RoboGrid(infile.nextInt(), infile.nextInt());
            while (infile.hasNextInt()) {
                grid.addObstacle(infile.nextInt(), infile.nextInt(),
                                 infile.nextInt(), infile.nextInt());
            }

            System.out.println("\n" + grid);

            System.out.print("Enter a row and column: ");
            int row = input.nextInt();
            int col = input.nextInt();
            while (row != 0 || col != 0) {
                if (row <= 0 || row > grid.getNumRows() || 
                    col <= 0 || col > grid.getNumCols()) {
                    System.out.println("    (" + row + "," + col +") IS OUTSIDE THE GRID.");
                }
                else if (grid.isInObstacle(row, col)) {
                    System.out.println("    (" + row + "," + col +") IS WITHIN AN OBSTACLE.");
                }
                else {
                    System.out.println("    (" + row + "," + col +") IS VACANT IN THE GRID.");
                }
                
                System.out.print("Enter a row and col (zeros to end): ");
                row = input.nextInt();
                col = input.nextInt();
            }
            System.out.println("    DONE");
        } catch (java.io.FileNotFoundException e) {
            System.out.println("File not found.");
        }
    }
}
