Advertisement
Guest User

Untitled

a guest
Oct 20th, 2019
102
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.04 KB | None | 0 0
  1. private static void gameMake(int n){
  2. int wrong = 0;
  3. int right = 0;
  4. int unsolvable = 0;
  5. int[][] newBoard;
  6.  
  7. System.out.println("How many empty cells per board?");
  8. Scanner in = new Scanner(System.in);
  9. int x = in.nextInt();
  10. long start = System.currentTimeMillis();
  11. int i =1;
  12. while(n >= i){
  13. newBoard = makeBoard(x);
  14. int[][] newBoard2 = new int[9][9];
  15. for(int k =0; k < newBoard.length; k++){
  16. for(int m = 0; m < newBoard.length; m++){
  17. newBoard2[k][m] = newBoard[k][m];
  18. }
  19. }
  20. if (!isValidBoard(newBoard)) {
  21. wrong++;
  22. } else if (isSolvableBoard(newBoard)) {
  23. System.out.println("Board #" + i);
  24. for (int k = 0; k < newBoard2.length; k++) {
  25. for (int m = 0; m < newBoard2.length; m++) {
  26. System.out.print(newBoard2[k][m] + " ");
  27. }
  28. System.out.println();
  29. }
  30. System.out.println("The solution of Board #" + i);
  31. for (int k = 0; k < newBoard.length; k++) {
  32. for (int m = 0; m < newBoard.length; m++) {
  33. System.out.print(newBoard[k][m] + " ");
  34. }
  35. System.out.println();
  36. }
  37. System.out.println();
  38. right++;
  39. i++;
  40. } else if(!isSolvableBoard(newBoard2)){
  41. unsolvable++;
  42. }
  43. }
  44. long end = System.currentTimeMillis();
  45. float sec = (end - start) / 1000F;
  46. System.out.println("Empty cells per board : "+ x);
  47. System.out.println("Valid boards created : "+ right);
  48. System.out.println("Invalid boards created : "+ wrong);
  49. System.out.println("Unsolvable boards created : "+ unsolvable);
  50. System.out.println("Elapsed time in seconds : "+ sec);
  51.  
  52. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement