Sudoku Programmers Forum Index

 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister   ProfileProfile   Log inLog in          Games  Calendar

Log in to check your private messagesLog in to check your private messages   

New look for creating of Sudoku.

Post new topic   Reply to topic    Sudoku Programmers Forum Index -> Setting sudoku
View previous topic :: View next topic  
Author Message

Joined: 24 Jun 2007
Posts: 1
Location: Poland - Warsaw

PostPosted: Mon Jun 25, 2007 12:12 am    Post subject: New look for creating of Sudoku. Reply with quote

Hi there. I try to do Sudoku generator in c++ builder. I start my adventure with c++ not long time ago, and I stuck. I`m from Poland so comments are in Polish but You shouldn`t have problems with understand what it does. I can create Only One 3x3 grid, some times Two but not more. Can you give me any sugestions what to do next. This is the code :


#include <vcl>
#pragma hdrstop

#include "Unit1.h"
#include "generator.h"
#include <iostream>
#include <cstdlib>
using namespace std;
#pragma package(smart_init)
#pragma resource "*.dfm"
TForm1 *Form1;
__fastcall TForm1::TForm1(TComponent* Owner)
: TForm(Owner)
void __fastcall TForm1::FormCreate(TObject *Sender)
tablica->GridLineWidth = 1;
void __fastcall TForm1::Button1Click(TObject *Sender)
int tab[9][9];

for (int i=0; i<9; i++)
for (int j=0; j<9>Cells[i][j] = tab[i][j];

and file with functions :

#include "generator.h"
#include <iostream>
#include <cstdlib>
#include <time>
#include <stdio>
using namespace std;
void zeruj(int plansza[9][9])
//Zerowanie tablicy
for (int k=0; k<9; k++)
for (int l=0; l<9; l++)

void generuj(int plansza[9][9], int p1, int p2, int q1, int q2)
srand ( time(NULL) );
int temp;
int tes;
bool gd=true,gd2=true;

bool l1=true;
bool l2=true;
bool l3=true;
bool l4=true;
bool l5=true;
bool l6=true;
bool l7=true;
bool l8=true;
bool l9=true;

// plansza[3][0]=1;
// plansza[3][1]=2;
// plansza[3][2]=3;
// plansza[3][6]=4;
// plansza[3][7]=5;
// plansza[3][8]=6;
for (int k=p1; k<p2; k++)
for (int l=q1; l<q2; l++) {
temp = rand()%9 + 1;
// Sprawdzanie po kwadracie
for (int i=p1; i<p2; i++)
for (int j=q1; j<q2; j++)
switch (tes)
case 1 : l1=false; break;
case 2 : l2=false; break;
case 3 : l3=false; break;
case 4 : l4=false; break;
case 5 : l5=false; break;
case 6 : l6=false; break;
case 7 : l7=false; break;
case 8 : l8=false; break;
case 9 : l9=false; break;
default : gd2=true; break;

switch (temp)
case 1 : {if (l1==false) gd2=false; } break;
case 2 : {if (l2==false) gd2=false; } break;
case 3 : {if (l3==false) gd2=false; } break;
case 4 : {if (l4==false) gd2=false; } break;
case 5 : {if (l5==false) gd2=false; } break;
case 6 : {if (l6==false) gd2=false; } break;
case 7 : {if (l7==false) gd2=false; } break;
case 8 : {if (l8==false) gd2=false; } break;
case 9 : {if (l9==false) gd2=false; } break;
default : gd2=true; break;

// Sprawdzanie po kolumnie
for(int t=0; t<9; t++)
if (plansza[k][t]==temp)
{gd = false; break;}
else gd = true;
// Sprawdzanie po wierszu
if (plansza[t][l]==temp)
{gd = false; break;}
else gd = true;


if (gd==true && gd2==true)
plansza[k][l] = temp;

} while ((gd != true) || (gd2 != true));

Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    Sudoku Programmers Forum Index -> Setting sudoku All times are GMT
Page 1 of 1

Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
Sudoku Programmers topic RSS feed 

Powered by phpBB © 2001, 2005 phpBB Group

Igloo Theme Version 1.0 :: Created By: Andrew Charron