Advertisement
Guest User

Untitled

a guest
Feb 21st, 2018
67
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.79 KB | None | 0 0
  1. // ConsoleApplication18.cpp : Defines the entry point for the console application.
  2. //
  3.  
  4. #include "stdafx.h"
  5. #include <iostream>
  6.  
  7.  
  8. int main()
  9. {
  10. int temp[10] = {};
  11. int gameBoard[9][9] = {
  12. { 0,0,4,1,0,0,0,0,2 },
  13. { 0,7,6,0,0,8,3,0,0 },
  14. { 0,1,0,0,3,2,0,0,0 },
  15. { 0,6,7,2,0,3,0,0,0 },
  16. { 0,2,8,4,0,1,7,6,0 },
  17. { 0,0,0,8,0,7,2,3,0 },
  18. { 0,0,0,3,2,0,0,9,0 },
  19. { 0,0,2,7,0,0,1,5,0 },
  20. { 5,0,0,0,0,9,4,0,0 }
  21. };
  22. int counter = 0;
  23. int asdf = 0;
  24. int q = 0;
  25. std::cout << "Start\n";
  26. do {
  27. for (int i = 0; i < 9; i++) { // For row'
  28. for (int j = 0; j < 9; j++) { // For column
  29. if (gameBoard[i][j] == 0) { // Only run on empty spots
  30.  
  31. for (int n = 0; n < 9; n++) { // Gets the full row and column of the current position
  32. if (gameBoard[i][n]) ++temp[gameBoard[i][n]]; // Adds existing numbers from rows to temp array
  33. if (gameBoard[n][j]) ++temp[gameBoard[n][j]]; // Adds existing numbers from columns to temp array
  34. }
  35.  
  36. if (((i % 3) == 0) && ((j % 3) == 0)) {
  37. if (gameBoard[i + 1][j + 1]) ++temp[gameBoard[i + 1][j + 1]];
  38. if (gameBoard[i + 2][j + 1]) ++temp[gameBoard[i + 2][j + 1]];
  39. if (gameBoard[i + 1][j + 2]) ++temp[gameBoard[i + 1][j + 2]];
  40. if (gameBoard[i + 2][j + 2]) ++temp[gameBoard[i + 2][j + 2]];
  41. }
  42. else if (((i % 3) == 0) && ((j % 3) == 1)) {
  43. if (gameBoard[i + 1][j - 1]) ++temp[gameBoard[i + 1][j - 1]];
  44. if (gameBoard[i + 2][j - 1]) ++temp[gameBoard[i + 2][j - 1]];
  45. if (gameBoard[i + 1][j + 1]) ++temp[gameBoard[i + 1][j + 1]];
  46. if (gameBoard[i + 2][j + 1]) ++temp[gameBoard[i + 2][j + 1]];
  47. }
  48. else if (((i % 3) == 0) && ((j % 3) == 2)) {
  49. if (gameBoard[i + 1][j - 1]) ++temp[gameBoard[i + 1][j - 1]];
  50. if (gameBoard[i + 2][j - 1]) ++temp[gameBoard[i + 2][j - 1]];
  51. if (gameBoard[i + 1][j - 2]) ++temp[gameBoard[i + 1][j - 2]];
  52. if (gameBoard[i + 2][j - 2]) ++temp[gameBoard[i + 2][j - 2]];
  53. }
  54. else if (((i % 3) == 1) && ((j % 3) == 0)) {
  55. if (gameBoard[i + 1][j + 1]) ++temp[gameBoard[i + 1][j + 1]];
  56. if (gameBoard[i - 1][j + 1]) ++temp[gameBoard[i - 1][j + 1]];
  57. if (gameBoard[i + 1][j + 2]) ++temp[gameBoard[i + 1][j + 2]];
  58. if (gameBoard[i - 1][j + 2]) ++temp[gameBoard[i - 1][j + 2]];
  59. }
  60. else if (((i % 3) == 1) && ((j % 3) == 1)) {
  61. if (gameBoard[i + 1][j + 1]) ++temp[gameBoard[i + 1][j + 1]];
  62. if (gameBoard[i - 1][j - 1]) ++temp[gameBoard[i - 1][j - 1]];
  63. if (gameBoard[i + 1][j - 1]) ++temp[gameBoard[i + 1][j - 1]];
  64. if (gameBoard[i - 1][j + 1]) ++temp[gameBoard[i - 1][j + 1]];
  65. }
  66. else if (((i % 3) == 1) && ((j % 3) == 2)) {
  67. if (gameBoard[i + 1][j - 1]) ++temp[gameBoard[i + 1][j - 1]];
  68. if (gameBoard[i - 1][j - 1]) ++temp[gameBoard[i - 1][j - 1]];
  69. if (gameBoard[i + 1][j - 2]) ++temp[gameBoard[i + 1][j - 2]];
  70. if (gameBoard[i - 1][j - 2]) ++temp[gameBoard[i - 1][j - 2]];
  71. }
  72. else if (((i % 3) == 2) && ((j % 3) == 0)) {
  73. if (gameBoard[i - 1][j + 1]) ++temp[gameBoard[i - 1][j + 1]];
  74. if (gameBoard[i - 1][j + 2]) ++temp[gameBoard[i - 1][j + 2]];
  75. if (gameBoard[i - 2][j + 1]) ++temp[gameBoard[i - 2][j + 1]];
  76. if (gameBoard[i - 2][j + 2]) ++temp[gameBoard[i - 2][j + 2]];
  77. }
  78. else if (((i % 3) == 2) && ((j % 3) == 1)) {
  79. if (gameBoard[i - 1][j + 1]) ++temp[gameBoard[i - 1][j + 1]];
  80. if (gameBoard[i - 1][j - 1]) ++temp[gameBoard[i - 1][j - 1]];
  81. if (gameBoard[i - 2][j + 1]) ++temp[gameBoard[i - 2][j + 1]];
  82. if (gameBoard[i - 2][j - 1]) ++temp[gameBoard[i - 2][j - 1]];
  83. }
  84. else if (((i % 3) == 2) && ((j % 3) == 2)) {
  85. if (gameBoard[i - 1][j - 1]) ++temp[gameBoard[i - 1][j - 1]];
  86. if (gameBoard[i - 1][j - 2]) ++temp[gameBoard[i - 1][j - 2]];
  87. if (gameBoard[i - 2][j - 1]) ++temp[gameBoard[i - 2][j - 1]];
  88. if (gameBoard[i - 2][j - 2]) ++temp[gameBoard[i - 2][j - 2]];
  89. }
  90.  
  91. for (int c = 0; c <= 9; c++) { // Loops through temp to find used numbers
  92. if (temp[c] > 0)
  93. counter++; // Count unavailable numbers
  94. else
  95. asdf = c; // Save the available number
  96. temp[c] = 0; // Clear temp[]
  97. }
  98.  
  99. if (counter ==8) gameBoard[i][j] = asdf;
  100.  
  101. counter = 0;
  102. }
  103. }
  104. }
  105.  
  106. q++;
  107. } while (q < 81);
  108.  
  109. int asdfdsa = 0;
  110. for (int i = 0; i < 9; i++) {
  111. for (int j = 0; j < 9; j++) {
  112. if (gameBoard[i][j]) ++asdfdsa;
  113. std::cout << gameBoard[i][j] << " ";
  114. }
  115. std::cout << std::endl;
  116. }
  117. std::cout << asdfdsa << " \n";
  118. return 0;
  119. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement