Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // ConsoleApplication18.cpp : Defines the entry point for the console application.
- //
- #include "stdafx.h"
- #include <iostream>
- int main()
- {
- int temp[10] = {};
- int gameBoard[9][9] = {
- { 0,0,4,1,0,0,0,0,2 },
- { 0,7,6,0,0,8,3,0,0 },
- { 0,1,0,0,3,2,0,0,0 },
- { 0,6,7,2,0,3,0,0,0 },
- { 0,2,8,4,0,1,7,6,0 },
- { 0,0,0,8,0,7,2,3,0 },
- { 0,0,0,3,2,0,0,9,0 },
- { 0,0,2,7,0,0,1,5,0 },
- { 5,0,0,0,0,9,4,0,0 }
- };
- int counter = 0;
- int asdf = 0;
- int q = 0;
- std::cout << "Start\n";
- do {
- for (int i = 0; i < 9; i++) { // For row'
- for (int j = 0; j < 9; j++) { // For column
- if (gameBoard[i][j] == 0) { // Only run on empty spots
- for (int n = 0; n < 9; n++) { // Gets the full row and column of the current position
- if (gameBoard[i][n]) ++temp[gameBoard[i][n]]; // Adds existing numbers from rows to temp array
- if (gameBoard[n][j]) ++temp[gameBoard[n][j]]; // Adds existing numbers from columns to temp array
- }
- if (((i % 3) == 0) && ((j % 3) == 0)) {
- if (gameBoard[i + 1][j + 1]) ++temp[gameBoard[i + 1][j + 1]];
- if (gameBoard[i + 2][j + 1]) ++temp[gameBoard[i + 2][j + 1]];
- if (gameBoard[i + 1][j + 2]) ++temp[gameBoard[i + 1][j + 2]];
- if (gameBoard[i + 2][j + 2]) ++temp[gameBoard[i + 2][j + 2]];
- }
- else if (((i % 3) == 0) && ((j % 3) == 1)) {
- if (gameBoard[i + 1][j - 1]) ++temp[gameBoard[i + 1][j - 1]];
- if (gameBoard[i + 2][j - 1]) ++temp[gameBoard[i + 2][j - 1]];
- if (gameBoard[i + 1][j + 1]) ++temp[gameBoard[i + 1][j + 1]];
- if (gameBoard[i + 2][j + 1]) ++temp[gameBoard[i + 2][j + 1]];
- }
- else if (((i % 3) == 0) && ((j % 3) == 2)) {
- if (gameBoard[i + 1][j - 1]) ++temp[gameBoard[i + 1][j - 1]];
- if (gameBoard[i + 2][j - 1]) ++temp[gameBoard[i + 2][j - 1]];
- if (gameBoard[i + 1][j - 2]) ++temp[gameBoard[i + 1][j - 2]];
- if (gameBoard[i + 2][j - 2]) ++temp[gameBoard[i + 2][j - 2]];
- }
- else if (((i % 3) == 1) && ((j % 3) == 0)) {
- if (gameBoard[i + 1][j + 1]) ++temp[gameBoard[i + 1][j + 1]];
- if (gameBoard[i - 1][j + 1]) ++temp[gameBoard[i - 1][j + 1]];
- if (gameBoard[i + 1][j + 2]) ++temp[gameBoard[i + 1][j + 2]];
- if (gameBoard[i - 1][j + 2]) ++temp[gameBoard[i - 1][j + 2]];
- }
- else if (((i % 3) == 1) && ((j % 3) == 1)) {
- if (gameBoard[i + 1][j + 1]) ++temp[gameBoard[i + 1][j + 1]];
- if (gameBoard[i - 1][j - 1]) ++temp[gameBoard[i - 1][j - 1]];
- if (gameBoard[i + 1][j - 1]) ++temp[gameBoard[i + 1][j - 1]];
- if (gameBoard[i - 1][j + 1]) ++temp[gameBoard[i - 1][j + 1]];
- }
- else if (((i % 3) == 1) && ((j % 3) == 2)) {
- if (gameBoard[i + 1][j - 1]) ++temp[gameBoard[i + 1][j - 1]];
- if (gameBoard[i - 1][j - 1]) ++temp[gameBoard[i - 1][j - 1]];
- if (gameBoard[i + 1][j - 2]) ++temp[gameBoard[i + 1][j - 2]];
- if (gameBoard[i - 1][j - 2]) ++temp[gameBoard[i - 1][j - 2]];
- }
- else if (((i % 3) == 2) && ((j % 3) == 0)) {
- if (gameBoard[i - 1][j + 1]) ++temp[gameBoard[i - 1][j + 1]];
- if (gameBoard[i - 1][j + 2]) ++temp[gameBoard[i - 1][j + 2]];
- if (gameBoard[i - 2][j + 1]) ++temp[gameBoard[i - 2][j + 1]];
- if (gameBoard[i - 2][j + 2]) ++temp[gameBoard[i - 2][j + 2]];
- }
- else if (((i % 3) == 2) && ((j % 3) == 1)) {
- if (gameBoard[i - 1][j + 1]) ++temp[gameBoard[i - 1][j + 1]];
- if (gameBoard[i - 1][j - 1]) ++temp[gameBoard[i - 1][j - 1]];
- if (gameBoard[i - 2][j + 1]) ++temp[gameBoard[i - 2][j + 1]];
- if (gameBoard[i - 2][j - 1]) ++temp[gameBoard[i - 2][j - 1]];
- }
- else if (((i % 3) == 2) && ((j % 3) == 2)) {
- if (gameBoard[i - 1][j - 1]) ++temp[gameBoard[i - 1][j - 1]];
- if (gameBoard[i - 1][j - 2]) ++temp[gameBoard[i - 1][j - 2]];
- if (gameBoard[i - 2][j - 1]) ++temp[gameBoard[i - 2][j - 1]];
- if (gameBoard[i - 2][j - 2]) ++temp[gameBoard[i - 2][j - 2]];
- }
- for (int c = 0; c <= 9; c++) { // Loops through temp to find used numbers
- if (temp[c] > 0)
- counter++; // Count unavailable numbers
- else
- asdf = c; // Save the available number
- temp[c] = 0; // Clear temp[]
- }
- if (counter ==8) gameBoard[i][j] = asdf;
- counter = 0;
- }
- }
- }
- q++;
- } while (q < 81);
- int asdfdsa = 0;
- for (int i = 0; i < 9; i++) {
- for (int j = 0; j < 9; j++) {
- if (gameBoard[i][j]) ++asdfdsa;
- std::cout << gameBoard[i][j] << " ";
- }
- std::cout << std::endl;
- }
- std::cout << asdfdsa << " \n";
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement