package com.tagadvance.sudoku;

import java.io.IOException;
import java.util.List;
import java.util.stream.Collectors;
import java.util.stream.IntStream;

import com.google.common.collect.ImmutableSet;
import com.tagadvance.geometry.Dimension;
import com.tagadvance.geometry.ImmutableDimension;

public class Main {

	public static void main(String[] args)
			throws UnsolvableException, IOException, InterruptedException {
		List<Integer> range = IntStream.rangeClosed(1, 9).boxed().collect(Collectors.toList());
		ImmutableSet<Integer> values = ImmutableSet.copyOf(range);

		int width = 9, height = 9;
		ImmutableDimension size = new Dimension(width, height);
		CellFactory<Integer> cellFactory = new EmptyCellFactory<>();
		Grid<Integer> grid = new FixedSizeGrid<>(size, cellFactory);
		ScopeFactory scopeFactory = new SquareRootScopeFactory();
		ImmutableSet<Scope<Integer>> scopes = scopeFactory.createScopes(grid);
		Sudoku<Integer> sudoku = new CompositeSudoku<>(values, scopes);

		SudokuParser<Integer> parser = new IntegerSudokuParser();
		String puzzle =
				"?????64?9?3?2???1???6?7?????7???2??5?4?????2?9??6???3?????9?1???9???3?7?3?54?????";
		parser.populateSudokuFromString(grid, puzzle);
		System.out.println(grid);
		System.out.println();
		System.out.println();

		SudokuSolver solver = new SimpleSudokuSolver();
		Grid<Integer> result = solver.solve(sudoku, grid);
		System.out.println(result);
		System.out.println("**********");
	}

}

@@ -60,634 +60,211 @@
 n;%0D%0A
-import java.util.List;%0D%0Aimport java.util.stream.Collectors;%0D%0Aimport java.util.stream.IntStream;%0D%0A%0D%0Aimport com.google.common.collect.ImmutableSet;%0D%0Aimport com.tagadvance.geometry.Dimension;%0D%0Aimport com.tagadvance.geometry.ImmutableDimension;%0D%0A%0D%0Apublic class Main %7B%0D%0A%0D%0A%09public static void main(String%5B%5D args)%0D%0A%09%09%09throws UnsolvableException, IOException, InterruptedException %7B%0D%0A%09%09List%3CInteger%3E range = IntStream.rangeClosed(1, 9).boxed().collect(Collectors.toList());%0D%0A%09%09ImmutableSet%3CInteger%3E values = ImmutableSet.copyOf(range);%0D%0A%0D%0A%09%09int width = 9, height = 9;%0D%0A%09%09ImmutableDimension size = new Dimension(width, height);%0D%0A%09%09Cell
+%0D%0Aimport com.tagadvance.sudoku.SudokuBuilder.SudokuFactory;%0D%0A%0D%0Apublic class Main %7B%0D%0A%0D%0A%09public static void main(String%5B%5D args)%0D%0A%09%09%09throws UnsolvableException, IOException, InterruptedException %7B%0D%0A%09%09Sudoku
 Fact
@@ -276,21 +276,17 @@
 nteger%3E 
-cellF
+f
 actory =
@@ -290,180 +290,74 @@
 y = 
-new EmptyCellFactory%3C%3E();%0D%0A%09%09Grid%3CInteger%3E grid = new FixedSizeGrid%3C%3E(size, cellFactory);%0D%0A%09%09ScopeFactory scopeFactory = new SquareRootScopeFactory();%0D%0A%09%09ImmutableSet%3CScope
+SudokuBuilder.newBuilder().createClassicSudokuFactory();%0D%0A%09%09Sudoku
 %3CInt
@@ -365,116 +365,90 @@
 ger%3E
-%3E
  s
-copes = scopeFactory.createScopes(grid);%0D%0A%09%09Sudoku%3CInteger%3E sudoku = new CompositeSudoku%3C%3E(values, scopes
+udoku = factory.createSudoku();%0D%0A%09%09Grid%3CInteger%3E grid = factory.createEmptyGrid(
 );%0D%0A
@@ -726,33 +726,8 @@
 ();%0D
-%0A%09%09System.out.println();%0D
 %0A%0D%0A%09

refactor to use SudokuBuilder