Hey guys, I am writing a C++ Sodoku Solver and Checker. This is the code I have so far
CODE
#include <iostream>
#include <string>
#include <math.h>
#include <conio.h>
#include <windows.h>
#include <ctime>
#include <cstdlib>
#pragma comment(lib,"kernel32.lib")
using namespace std;
unsigned char currPlayer = 1, p=179;
int firstPrint = 1;
bool moveLegal(char board[9][9], int row, int column)
{
return NULL;
}
void printBoard(char board[9][9])
{
for (int Alpha=0; Alpha<9; Alpha++)
{
for (int Bravo=0; Bravo<9; Bravo++)
{
cout << board[Alpha][Bravo];
if (Bravo<9)
cout << p;
}
cout << "\n";
if (Alpha<10)
{
for (int Delta=0; Delta<18; Delta++)
cout << "_";
cout << "\n";
}
}
}
bool spaceEmpty(char board[9][9], int row, int column)
{
if (board[(row-1)][(column-1)]==NULL)
return true;
return false;
}
void inputStuff(char board[9][9], int row, int column)
{
system("CLS");
if (spaceEmpty(board, row, column))
{
board[(row-1)][(column-1)]=currPlayer;
printBoard(board);
}
else
cout<<"Space is filled\n";
}
void main()
{
char board[9][9]={ ' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' '};
int row, column, playAgain=1, numTie=0;
while (playAgain==1)
{
for (int Zulu=0; Zulu<9; Zulu++)
{
for(int Romeo=0; Romeo<9; Romeo++)
board[Zulu][Romeo]=NULL;
}
while (playAgain == 1)
{
if(firstPrint == 1)
{
printBoard(board);
firstPrint = 2;
}
cout <<"What number is next?";
cin >> currPlayer;
cout <<"\nWhere would you like to put the next number?\n";
cin >> row >> column;
inputStuff(board, row, column);
}
}
}
this is what it has to do
CODE
Sudoku Checker
There are two parts to the program that you must design: the setup and the checker.
Setup: Your program will start by setting up a Sudoku board that the player has by asking for the placement of the numbers. Ask to place all 1’s first then all 2’s and so on. When they are done with each number output the board so far and confirm that the most recent numbers input are in the correct position.
For example:
Do you have anymore 1’s? (Y or N) Y
Column? 3
Row? 5
Do you have anymore 1’s? (Y or N) N
| |
| |
| |
__________
| |
5| |
| |
__________
| |
| |
| |
Are all 1’s in correct position? (Y or N) Y
Checker: Once all numbers have been put into position ask the user what number and where they would like to play. Check and make sure that the move is legal so far for the row, column, and 3X3 box. If the move is legal place it on the board. If not tell the user why the move is illegal. Then give the user the option of moving on from there or clearing the board back to the original and start placing numbers again. Your program should stop and congratulate the player when all spaces are filled and there are no conflicts in any row, column, or 3X3 box.
For example:
What number would you like to place next? 4
In what row would you like to place a 4? 2
In what column would you like to place a 4? 7
Move is legal!
| |
| |4
| |
__________
| |
5| |
| |
__________
| |
| |
| |
What number would you like to place next? 5
In what row would you like to place a 5? 9
In what column would you like to place a 5? 3
Illegal move. There is already a 5 in that column. Would you like to clear the board and start guessing again? Y
I have been working on this for a while and have yet to discover a way I can check if the move is legal. But the worst part is I don't know how to play sodoku. lol... If anyone could help, Thanks.