From 03a127490d4c7dec55f5905ea4ab47049f719188 Mon Sep 17 00:00:00 2001 From: stephey Date: Sat, 10 Apr 2010 07:26:56 +0000 Subject: [PATCH] Added input file support; user must put the file location as first argument when calling ./test.bin --- Robust/src/Tests/mlp/stephen/Parser.java | 59 ++++++++++++++++++++++++ Robust/src/Tests/mlp/stephen/Test.java | 18 +++++++- 2 files changed, 75 insertions(+), 2 deletions(-) create mode 100644 Robust/src/Tests/mlp/stephen/Parser.java diff --git a/Robust/src/Tests/mlp/stephen/Parser.java b/Robust/src/Tests/mlp/stephen/Parser.java new file mode 100644 index 00000000..f9438c93 --- /dev/null +++ b/Robust/src/Tests/mlp/stephen/Parser.java @@ -0,0 +1,59 @@ + +public class Parser +{ + private File file; + private int[][] preBoard; + + public Parser(String filename) + { + file = new File(filename); + preBoard = new int[9][9]; + } + + public int[][] go() + { + FileInputStream in = new FileInputStream(file.getPath()); + + + for(int row = 0; row < 9; row++) + { + //grabs the row we're on + String temp = in.readLine(); + if(temp == null) + { + System.out.println("Malformed file (not enough lines)"); + return null; + } + + //builds new scanner for the line + StringTokenizer scan = new StringTokenizer(temp); + if(scan.countTokens() < 8) + { + System.out.println("Malformed file (not enough columns"); + return null; + } + + for(int column = 0; column < 9; column++) + { + int num = Integer.parseInt(scan.nextToken()); + + + //we may remove this later so that we can have everything instead of just this.... + if(num > 9 || num < 0) + { + System.out.println("File is malformed"); + return null; +// throw new FatalError("File is malformed"); + } + else + { + preBoard[row][column] = num; + } + + } + } + + System.out.println("Parsing complete, returning result"); + return preBoard; + } +} diff --git a/Robust/src/Tests/mlp/stephen/Test.java b/Robust/src/Tests/mlp/stephen/Test.java index d76e7d91..04a6655c 100755 --- a/Robust/src/Tests/mlp/stephen/Test.java +++ b/Robust/src/Tests/mlp/stephen/Test.java @@ -6,11 +6,25 @@ public class Test System.out.println("# it starts"); Test t = new Test(); - t.doSomeWork(); + t.doSomeWorkSolvingDynamicPuzzle(args[0]); } - public void doSomeWork() + public void doSomeWorkSolvingDynamicPuzzle(String filename) + { + Parser p = new Parser(filename); + int[][] data = p.go(); + + if(data != null) + { + Board b = new Board(data); + Board solved = Solver.go(b); + System.out.println(solved); + } + + } + + public void doSomeWorkSolvingStaticPuzzle() { //hard-coded in board solution: http://www.websudoku.com/?level=4&set_id=1031120945 -- 2.34.1