public static void main(String[] args) {
Scanner reader = new Scanner(System.in);
System.out.println("Sudoku Game: ");
SudokuPuzzle puzzle = new SudokuPuzzle();
puzzle.initializePuzzle(puzzle);
System.out.print("The puzzle is: \n" + puzzle);
boolean done = false;
while(!done){
System.out.println("What would you like to do? \n" +
"Clear Puzzle(C) Set a square (S) Get possible values (G) Quit (Q) ");
String response = reader.next();
response = response.toLowerCase();
if(response.equals("q")){
System.out.println("Thanks for playing.");
done = true;
} else if(response.equals("s")){
System.out.println("Which row (1-9) and colume (1-9) do you want to change?");
int row = reader.nextInt()-1;
int col = reader.nextInt()-1;
System.out.println("What should the value (1-9) be?");
int value = reader.nextInt();
puzzle.addGuess(row, col, value);
} else if(response.equals("g")){
System.out.println("Which row (1-9) and colume (1-9) do you want to get values for?");
int row = reader.nextInt()-1;
int col = reader.nextInt()-1;
boolean valid[] = puzzle.getAllowedValues(row, col);
System.out.print("Allowed values are: ");
for(int i=0; i<9; i++){
if(valid[i])
System.out.print((i+1)+ " ");
}
System.out.println();
} else if(response.equals("c")){
puzzle.reset();
}
System.out.print("The puzzle is now: \n" + puzzle);
if(!puzzle.checkPuzzle())
System.out.println("You have made an error in the puzzle.");
else if(puzzle.isFull())
System.out.println("Congratulations, you have completed the puzzle.");
Sun | Mon | Tue | Wed | Thu | Fri | Sat |
---|---|---|---|---|---|---|
23 | 24 | 25 | 26 | 27 | 28 | 1 |
2 | 3 | 4 | 5 | 6 | 7 | 8 |
9 | 10 | 11 | 12 | 13 | 14 | 15 |
16 | 17 | 18 | 19 | 20 | 21 | 22 |
23 | 24 | 25 | 26 | 27 | 28 | 29 |
30 | 31 | 1 | 2 | 3 | 4 | 5 |
Get Free Quote!
408 Experts Online