6 5 9 4 1 3 2 8 7
7 4 3 2 9 8 1 6 5
1 8 2 5 6 7 9 4 3
9 1 4 3 2 5 8 7 6
3 7 8 6 4 9 5 1 2
2 6 5 7 8 1 4 3 9
4 3 7 1 5 2 6 9 8
5 9 1 8 3 6 7 2 4
0 0 0 0 0 0 0 0 0
Of course this is a simple sudoku, its just a test, but anyways, after reading from the txt file, the program will put this into the 9X9 grid, and the zeros represent blank squares that need to be filled in.
The program will allow the player to add numbers, and check to see if it is still possible to win after each addition. When all 81 cells are filled in, the program will say whether the player has won or not. The Sudoku class should have a constructor, and a “read” function that reads in the file “Sudoku_game.txt,” a 9 by 9 matrix of digits from 0 to 9. (Zero indicates that no number has been put in that cell.) The class should also have a print function, a test for whether the current state of the game is one that cannot work (violating some of the constraints, such as two 3‟s in the same box), a test to tell whether all the cells have been filled with a number, and a function that would allow a player to enter numbers in the open cells of the game. The main function should create an empty game, read a file into the game, print the current state of the game board, and then allow the player to add numbers (using row and column numbers) to complete the puzzle. After each number entered, the game should decide if the game is still winnable (that is, whether any of the constraints have already been violated.) If the last number entered won‟t work, print an error message and change the number back to zero. If the player successfully completes the game, entering the last number without violating the rules, the program should print a congratulatory message and quit. If the last cell is filled with a number, but the solution is not correct, the game should print a sympathetic message.
I really need some help on this, so any help will be appreciated. Thanks!
#include <iostream>
#include <cstdlib>
using namespace std;
//class
class Sudoku {
private:
public:
int value;
ofstream Numbers;
Numbers.open("sudoku.txt");
Numbers >> value;
void Print(char game[0][9]){
cout << "\t+---+---+---+---+---+---+---+---+---+" << endl;
for (int a=0; a<9; a++) {
cout << "\t| ";
for (int b=0; b<9; b++)
cout << game[a][b] << " | ";
cout << endl;
cout << "\t+---+---+---+---+---+---+---+---+---+" << endl;
}
}
void generation(char game[9][9]) //generation function with arg
{
int randV;
int r,c;
for(int a=0;a<81;a++)
{
for( r=0;r<9;r++)
{
for(c=0;c<9;c++)
{
randV=(rand()%9)+1;
if(game[r][c]==0)
{
game[r][c]=randV;
if(!isLegal()) //check for invalid then
{
game[r][c]=0; //make sqr=0;
}
}
}
}
}
}
};
void MakeMove(char game[][9], int, int, char);
int main ( ) {
char game[9][9];
for (int a=0; a<9; a++) // initialize board
for (int b=0; b<9; b++)
game[a][b] = ' ';
int done = 0, count = 0, row, col, num;
while ( done == 0 ) {
if (count%2 == 0) {
cout << "Enter a number (r,c,n): ";
cin >> row >> col >> num;
MakeMove (game, row, col, num); }
//else {
// cout << "Enter move (r c) for O : ";
// cin >> row >> col;
// MakeMove (game, row, col, 'O'); }
//done = CheckWinner (game);
//PrintBoard (game);
Print (game);
count++;
}
if (done == 1)
cout << "Winner" << endl;
else if (done == 2)
cout << "Winner" << endl;
else // done == 3
cout << "Tie – cat’s game" << endl;
return 0;
}
void MakeMove (char game[ ][3], int r, int c, char ch) {
if (game[r][c] == ' ')
game[r][c] = ch;
else
cout << "Illegal move, turn is lost!" << endl;
}
This post has been edited by Ertxz18: 15 November 2008 - 09:24 PM

New Topic/Question
Reply




MultiQuote





|