Hey,
been working on a Sudoku project for my university and im really stuck on the code for the 3x3 box check, i would be really appreciated if u could show me the way out of this, even the slightest help or clue would be greatly welcomed so i can continue my project:) thank u in advanced and here the code for the button "Done" Click Event
CODE
void __fastcall TMainFrm::DoneClick(TObject *Sender)
{
bool found=false,number=false;
int i,j,k;
//checks whether there an input other then 1-9
for (i=0;i<StringGrid1->ColCount;i++)
{
for(j=0;j<StringGrid1->RowCount;j++)
{
if((StringGrid1->Cells[i][j]<1)||(StringGrid1->Cells[i][j]>9))
{
MessageBox(NULL,"Input not between 1-9","Wrong Input",MB_OK);
number=true;
break;
}
}
}
//checks wether there's a duplicate number at each row or column
//number has to be within 1-9
if(number==false)
{
for(k=0;k<StringGrid1->ColCount;k++)
{
for (i=0;i<StringGrid1->ColCount;i++)
{
for(j=0;j<StringGrid1->RowCount;j++)
{
if(StringGrid1->Cells[k][i]==StringGrid1->Cells[j+k+1][i])
found=true;
if(StringGrid1->Cells[j][k]==StringGrid1->Cells[j][i+k+1])
found=true;
}
}
}
//this is where the box check is supposed to be
if(found)
MessageBox(NULL,"Theres a duplicate number!!!","WRONG",MB_OK);
else
{
ShowMessage("SUDOKU solved");
int res=MessageBox(NULL,"New Game? (No for exit)","NEW GAME?",MB_YESNOCANCEL);
if(res==IDNO)
Close();
if(res==IDYES)
{
StartClick(Sender);
}
}
}
}
This post has been edited by andystyl: 6 Dec, 2007 - 04:21 PM