Added input file support; user must put the file location as first argument when...
authorstephey <stephey>
Sat, 10 Apr 2010 07:26:56 +0000 (07:26 +0000)
committerstephey <stephey>
Sat, 10 Apr 2010 07:26:56 +0000 (07:26 +0000)
Robust/src/Tests/mlp/stephen/Parser.java [new file with mode: 0644]
Robust/src/Tests/mlp/stephen/Test.java

diff --git a/Robust/src/Tests/mlp/stephen/Parser.java b/Robust/src/Tests/mlp/stephen/Parser.java
new file mode 100644 (file)
index 0000000..f9438c9
--- /dev/null
@@ -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;
+       }
+}
index d76e7d91912f0c1b0a9e8b07df9642bac222b0c8..04a6655c77dcc9156f9d98510fa6c9bff3074fbb 100755 (executable)
@@ -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