Skip to content
Permalink
master
Switch branches/tags

Name already in use

A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?
Go to file
 
 
Cannot retrieve contributors at this time
#include <iostream>
using namespace std;
int field [8][8]; ///creating a two dimensional array containing 81 entries
/// This is the layout of the game,
/// the "\033[36m" is baically a way to colour the different sections of the grid,
/// for better visibility.
/// I am puting one array in each empty square,
/// so that later on I can actually make a sudoku generator!
void sudokuLayout()
{
cout <<"\033c"<<"\033[35m"<< "C\\R| 0 | 1 | 2 || 3 | 4 | 5 || 6 | 7 | 8 |"<< endl;
cout <<"\033[35m"<<"---"<< "\033[36m"<< "+---+---+---+"<<"\033[33m"<<"+---+---+---+"<<"\033[36m"<<"+---+---+---+"<< endl;
cout <<"\033[35m"<<" 0 "<< "\033[36m"<< "| "<< field[0][0] <<" | "<< field[0][1] <<" | "<< field[0][2] <<" |"<<"\033[33m"<<"| "<< field[0][3] <<" | "<< field[0][4] <<" | "<< field[0][5] <<" |"<<"\033[36m"<<"| "<< field[0][6] <<" | "<< field[0][7] <<" | "<< field[0][8] <<" |" << endl;
cout <<"\033[35m"<<"---"<< "\033[36m"<< "+---+---+---+"<<"\033[33m"<<"+---+---+---+"<<"\033[36m"<<"+---+---+---+" << endl;
cout <<"\033[35m"<<" 1 "<< "\033[36m"<< "| "<< field[1][0] <<" | "<< field[1][1] <<" | "<< field[1][2] <<" |"<<"\033[33m"<<"| "<< field[1][3] <<" | "<< field[1][4] <<" | "<< field[1][5] <<" |"<<"\033[36m"<<"| "<< field[1][6] <<" | "<< field[1][7] <<" | "<< field[1][8] <<" |" << endl;
cout <<"\033[35m"<<"---"<< "\033[36m"<< "+---+---+---+"<<"\033[33m"<<"+---+---+---+"<<"\033[36m"<<"+---+---+---+" << endl;
cout <<"\033[35m"<<" 2 "<< "\033[36m"<< "| "<< field[2][0] <<" | "<< field[2][1] <<" | "<< field[2][2] <<" |"<<"\033[33m"<<"| "<< field[2][3] <<" | "<< field[2][4] <<" | "<< field[2][5] <<" |"<<"\033[36m"<<"| "<< field[2][6] <<" | "<< field[2][7] <<" | "<< field[2][8] <<" |" << endl;
cout <<"\033[35m"<<"---"<< "\033[36m"<< "+---+---+---+"<<"\033[33m"<<"+---+---+---+"<<"\033[36m"<<"+---+---+---+" << endl;
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
cout <<"\033[35m"<<"---"<< "\033[33m"<< "+---+---+---+"<<"\033[36m"<<"+---+---+---+"<<"\033[33m"<<"+---+---+---+" << endl;
cout <<"\033[35m"<<" 3 "<< "\033[33m"<< "| "<< field[3][0] <<" | "<< field[3][1] <<" | "<< field[3][2] <<" |"<<"\033[36m"<<"| "<< field[3][3] <<" | "<< field[3][4] <<" | "<< field[3][5] <<" |"<<"\033[33m"<<"| "<< field[3][6] <<" | "<< field[3][7] <<" | "<< field[3][8] <<" |" << endl;
cout <<"\033[35m"<<"---"<< "\033[33m"<< "+---+---+---+"<<"\033[36m"<<"+---+---+---+"<<"\033[33m"<<"+---+---+---+" << endl;
cout <<"\033[35m"<<" 4 "<< "\033[33m"<< "| "<< field[4][0] <<" | "<< field[4][1] <<" | "<< field[4][2] <<" |"<<"\033[36m"<<"| "<< field[4][3] <<" | "<< field[4][4] <<" | "<< field[4][5] <<" |"<<"\033[33m"<<"| "<< field[4][6] <<" | "<< field[4][7] <<" | "<< field[4][8] <<" |" << endl;
cout <<"\033[35m"<<"---"<< "\033[33m"<< "+---+---+---+"<<"\033[36m"<<"+---+---+---+"<<"\033[33m"<<"+---+---+---+" << endl;
cout <<"\033[35m"<<" 5 "<< "\033[33m"<< "| "<< field[5][0] <<" | "<< field[5][1] <<" | "<< field[5][2] <<" |"<<"\033[36m"<<"| "<< field[5][3] <<" | "<< field[5][4] <<" | "<< field[5][5] <<" |"<<"\033[33m"<<"| "<< field[5][6] <<" | "<< field[5][7] <<" | "<< field[5][8] <<" |" << endl;
cout <<"\033[35m"<<"---"<< "\033[33m"<< "+---+---+---+"<<"\033[36m"<<"+---+---+---+"<<"\033[33m"<<"+---+---+---+" << endl;
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
cout <<"\033[35m"<<"---"<< "\033[36m"<< "+---+---+---+"<<"\033[33m"<<"+---+---+---+"<<"\033[36m"<<"+---+---+---+" << endl;
cout <<"\033[35m"<<" 6 "<< "\033[36m"<< "| "<< field[6][0] <<" | "<< field[6][1] <<" | "<< field[6][2] <<" |"<<"\033[33m"<<"| "<< field[6][3] <<" | "<< field[6][4] <<" | "<< field[6][5] <<" |"<<"\033[36m"<<"| "<< field[6][6] <<" | "<< field[6][7] <<" | "<< field[6][8] <<" |" << endl;
cout <<"\033[35m"<<"---"<< "\033[36m"<< "+---+---+---+"<<"\033[33m"<<"+---+---+---+"<<"\033[36m"<<"+---+---+---+" << endl;
cout <<"\033[35m"<<" 7 "<< "\033[36m"<< "| "<< field[7][0] <<" | "<< field[7][1] <<" | "<< field[7][2] <<" |"<<"\033[33m"<<"| "<< field[7][3] <<" | "<< field[7][4] <<" | "<< field[7][5] <<" |"<<"\033[36m"<<"| "<< field[7][6] <<" | "<< field[7][7] <<" | "<< field[7][8] <<" |" << endl;
cout <<"\033[35m"<<"---"<< "\033[36m"<< "+---+---+---+"<<"\033[33m"<<"+---+---+---+"<<"\033[36m"<<"+---+---+---+" << endl;
cout <<"\033[35m"<<" 8 "<< "\033[36m"<< "| "<< field[8][0] <<" | "<< field[8][1] <<" | "<< field[8][2] <<" |"<<"\033[33m"<<"| "<< field[8][3] <<" | "<< field[8][4] <<" | "<< field[8][5] <<" |"<<"\033[36m"<<"| "<< field[8][6] <<" | "<< field[8][7] <<" | "<< field[8][8] <<" |" << endl;
cout <<"\033[35m"<<"---"<< "\033[36m"<< "+---+---+---+"<<"\033[33m"<<"+---+---+---+"<<"\033[36m"<<"+---+---+---+" <<"\033[0m"<< endl;
}
/// The next function will print the rules of sudoku and it is also coloured with
/// the uppermentioned method!
void rulesOfSudoku()
{
cout <<"\033[35m"<< " The objective is to fill the grid so that each column, each row, and each of the nine 3x3 boxes \n contains the digits from 1 to 9. Remember thare cannot be repeating digits in any of the columns, rows and 3 by 3 boxes. \n Good Luck!" <<"\033[0m"<< endl;
}
/// This function checks if the user input for ROW is correct
///
int inputRowChecker(string row)
{
if(stoi(row)<0 || stoi(row)>8)
{
cout << "Please enter a valid row!" << endl;
return -69;
}
else
{
return stoi(row);
}
}
/// This function checks if the user input for COLUMN is correct
///
int inputColumnChecker(string column)
{
if(stoi(column)<0 || stoi(column)>8)
{
cout << "Please enter a valid column!" << endl;
return -69;
}
else
{
return stoi(column);
}
}
/// This function checks if the user input for NUMBER IN GRID is correct
///
int inputPlayerChecker(string playerInput)
{
if(stoi(playerInput)>0 && stoi(playerInput)<=9)
{
return stoi(playerInput);
}
else
{
cout << "Please enter a valid number!" << endl;
return -69;
}
}
/// This function checks the finished grid
/// It is called only when the grid is filled with numbers different than 0's
bool gameFinishCheck()
{
/// for (int i = 0; i <8 ; i++)/// this for loop is checking rows
int sum=0;
int field[8][8] = {1, 2, 3, 4, 5, 6, 7, 8, 9};
for (int b=0; b<9; b++)
{
sum+=field[0][b];
}
}
void kindaMainFunctionButNotQuite()
{
sudokuLayout();
cout<<endl;
cout<<endl;
rulesOfSudoku();
string badNameForPlayerInputNumberTwo; /// number that player wants to insert into the grid.
string input_row; /// id if the rowl that the answer needs to be inserted.
string input_column; /// id of the column that the answer needs to be inserted
bool won = false;
while (won == false)
{
cout<<endl;
cout<<endl;
cout << "\033[1m" <<"Row:" << endl;
getline(cin,input_row);
int row = inputRowChecker(input_row);
if(row == -69)
{
continue;
}
cout << "\033[1m" <<"Column:" << endl;
getline(cin,input_column);
int column = inputColumnChecker(input_column);
if(column == -69)
{
continue;
}
cout << "\033[1m" <<"Number:"<<endl;
getline(cin, badNameForPlayerInputNumberTwo);
int playerInput = inputPlayerChecker(badNameForPlayerInputNumberTwo);
if(playerInput == -69)
{
continue;
}
if(field[stoi(input_row)][stoi(input_column)] == 0)
{
field[stoi(input_row)][stoi(input_column)] = stoi(badNameForPlayerInputNumberTwo);
sudokuLayout();
for (int i = 0; i < 8; i++)
{
for (int j = 0; j < 8; j++)
{
if (field[i][j] == 0)
{
break;
}
else
{
gameFinishCheck();
}
}
}
continue;
}
else
{
sudokuLayout();
cout <<"\033[1m\033[31m"<< "Wrong cell! This cell has number in it already. Plaese try again:" <<"\033[0m"<< endl;
}
}
}