-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPlaySudoku.java
More file actions
31 lines (31 loc) · 868 Bytes
/
PlaySudoku.java
File metadata and controls
31 lines (31 loc) · 868 Bytes
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
/* Matthew Digman
Matthew Digman
plays a game of sudoku
if the puzzle isnt complete after rule 4, it is either entered incorrectly or impossible*/
import java.util.Scanner;
import java.io.*;
public class PlaySudoku{
private static int backtracks;
public static void main(String[] args) throws IOException{
Sudoku puzzle= new Sudoku(args[0]);
solve(puzzle);
System.out.print(puzzle);
}
private static void solve(Sudoku puzzle){
int numZeros=puzzle.countNumberOfZeros();
int oldNumZeros=numZeros+1;
while(numZeros<oldNumZeros){
oldNumZeros=numZeros;
puzzle.rule1();
puzzle.rule2();
puzzle.rule3();
if(puzzle.countNumberOfZeros()==0)
return;
numZeros=puzzle.countNumberOfZeros();
}
//in case of emergency, break glass
if(puzzle.countNumberOfZeros()!=0){
backtracks=puzzle.breakGlass();
}
}
}