-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathGenerate.java
More file actions
33 lines (31 loc) · 809 Bytes
/
Generate.java
File metadata and controls
33 lines (31 loc) · 809 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
32
33
import java.util.*;
public class Generate {
public Board genBoard() {
Random rand = new Random();
String board = "";
while(board.length() < 9) {
String num = Integer.toString(rand.nextInt(9));
if (!board.contains(num)) {
board += num;
}
}
return new Board(board);
}
public boolean validateBoard(Board board) {
int count = 0;
char[] boardArray = board.getAll().toCharArray();
int[] boardToInt = new int[9];
for (int i = 0; i < boardArray.length; i++) {
boardToInt[i] = Character.getNumericValue(boardArray[i]);
}
for (int i = 0; i < boardToInt.length; i++) {
for (int j = i + 1; j < boardToInt.length; j++) {
if (boardToInt[j] != 0) {
if (boardToInt[i] > boardToInt[j]) count++;
}
}
}
if (count % 2 == 0) return true;
else return false;
}
}