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   

Designing Sudoku

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

Joined: 07 Mar 2009
Posts: 1
:

Items
PostPosted: Wed Mar 11, 2009 10:04 am    Post subject: Designing Sudoku Reply with quote

Hi,
first post, was just wondering what the best way to design a sudoku GUI is? (Netbeans, using a grid and text boxes?)

Any advice would be great.

Cheers

M
Back to top
View user's profile Send private message
Lunatic

Joined: 11 Mar 2007
Posts: 166
:
Location: Ghent - Belgium

Items
PostPosted: Wed Mar 11, 2009 11:18 am    Post subject: Reply with quote

Hi, welcome,

Most solvers are using a grid with textboxes. My solver has a pencilmarked grid whereof the cell solution is assigned with left mouseclick and impossible values can be rejected with right mouseclick.
_________________
Marc
~~~<><~~~<><~~~<><~~~<><~~~
Back to top
View user's profile Send private message Send e-mail Visit poster's website
hobiwan

Joined: 11 Feb 2008
Posts: 83
:

Items
PostPosted: Fri Mar 13, 2009 4:32 pm    Post subject: Reply with quote

I wouldnt use textboxes (mainly because if every cell is a textbox you cant easily use the cursor keys to switch cells).

I personally use a JPanel and do the drawing myself.
Back to top
View user's profile Send private message
raoheal

Joined: 18 Mar 2009
Posts: 1
:

Items
PostPosted: Wed Mar 18, 2009 1:04 pm    Post subject: help with soduku solver Reply with quote

Hello,
Please i need someone to explain to me what is the algorithm used in this code and also how i can add a function that can generate initial state of soduku.

#include "stdafx.h"
#include <iostream>
#include<stdlib>

using namespace std;
void main()

{
int k[9][9],K[9][9];
int i,j,i1,j1,i2,j2;
int error,temp;
int count=0;

cout <<"Welcome! Please Enter your puzzle";
for(i=0;i<9;i++)
for(j=0;j<9;j++)
K[i][j]=0;

for(i=0;i<9;i++)
for(j=0;j<9>>K[i][j];
k[i][j]=K[i][j];
}
cout<<"O.K.? (Enter 0 if OK): ";
cin>>error;
if(error==0)
goto matrixvalidation;




matrixupdation:
while(1)
{
//cout<<"Enter Row, Col, Revised number:(0 to exit) " <<endl>>i;
if(i==0) break;
cin>>j>>temp;
if(i>0&&j>0&&temp>=0&&i<10&&j<10&&temp<10)
{
K[i-1][j-1]=temp;
k[i-1][j-1]=temp;
}
//else
//cout<<"Enter row/column 1 to 9 & number 0 to 9 only." <<endl;
}

matrixvalidation:
cout<< "Input matrix:" <<endl;
for(i=0;i<9;i++)
{
for(j=0;j<9;j++)
cout<<k[i][j]<<" " ;
cout<< " " << endl;

}

for(i=0;i<9;i++)
for(j=0;j<9;j++)
if(k[i][j]<0>9)
{
//cout<<" "<<i+1<<" "<<j+1<<" "<<k[i][j];
cout<< "Input matrix error." ;
cout<<"Numbers should be 1 to 9 only.";

//goto matrixupdation;
}

for(i=0;i<9;i++)
for(j=0;j<9;j++)
{
if(k[i][j]==0)continue;
error=0;
for(i1=0;i1<9;i1++)
if(i!=i1&&k[i][j]==k[i1][j])
{
error=1;
i2=i1;
j2=j;
}
for(j1=0;j1<9;j1++)
if(j!=j1&&k[i][j]==k[i][j1])
{
error=1;
i2=i;
j2=j1;
}
for(i1=0;i1<9;i1++)
for(j1=0;j1<9;j1++)
if((i!=i1||j!=j1)&&i/3==i1/3&&j/3==j1/3&&k[i][j]==k[i1][j1])
{
error=1;
i2=i1;
j2=j1;
}
if(error)
{
//cout<<" "<<i+1<<" "<<j+1<<" "<<k[i][j];
//cout<<" "<<i2+1<<" "<<j2+1<<" "<<k[i2][j2];
cout<< "Input matrix error." <<endl;
cout<< "A number has been repeated in the same row, col or block." <<endl ;

goto matrixupdation;
}
}

/* Logic starts: */
for(i=0;i<9;i++)
for(j=0;j<9>0) goto chksol;
for(k[i][j]++;k[i][j]<=9;k[i][j]++)
{
error=0;
for(i1=0;i1<9;i1++)
if(i!=i1&&k[i][j]==k[i1][j])error=1;
for(j1=0;j1<9;j1++)
if(j!=j1&&k[i][j]==k[i][j1])error=1;
for(i1=0;i1<9;i1++)
for(j1=0;j1<9>9)
{
k[i][j]=0;
do
{
if(i==0&&j==0)goto nomoresol;
if(j>0)j--;else{j=8;i--;}
}while(K[i][j]>0);
j--;
}
chksol: if(i==8&&j==8)
{
cout<<" Solution:"<<endl <<" "<<endl;
++count;

for(i1=0;i1<9;i1++)
{
for(j1=0;j1<9;j1++)
cout<<k[i1][j1]<<" ";
cout<<" "<<endl;
}
if(count==50)
{
cout<<"Too many solutions.Not checking for more solutions.";
return;
}

while(K[i][j]>0)
{
if(i==0&&j==0)goto nomoresol;
if(j>0)j--;else{j=8;i--;}
}
k[i][j]=0;
do
{
if(i==0&&j==0)goto nomoresol;
if(j>0)j--;else{j=8;i--;}
}while(K[i][j]>0);
j--;
}
}
nomoresol:
if(count>0)
cout<<"No more solutions." ;
else
cout<<"No solution.";
}
Back to top
View user's profile Send private message
Pete

Joined: 09 Jun 2008
Posts: 18
:
Location: Somerset, NJ

Items
PostPosted: Wed Mar 18, 2009 10:40 pm    Post subject: Reply with quote

marko99,

Welcome aboard!

There are quite a few ways to create a sudoku GUI. Programmers will probably disagree as to which approach is "best." Since you're looking at NetBeans, I would presume that you're using Java.

In my own program, the sudoku grid is just a JPanel that keeps track of its cells. It overrides paintComponent(), which in turn calls paint() for each cell. Each cell is then responsible for painting either its value or its candidates. If you'd care to see some working source code, you can download mine from http://sourceforge.net/projects/dancinglinks/

Here's another approach that I've been considering: Each cell could be a component that uses JLabels to show its candidates. The puzzle grid would still be a panel, though it would use a GridLayout to arrange its cells. I'm rather fond of this idea. Life is busy now, so I can't say for sure when (or even if) I will actually implement it.

My program has no keyboard/cursor support, so there's no notion of a "current" cell and no tabbing between cells. That would be fairly easy to add to either of the above approaches.

Good luck with your program! Please let us know when you have something to show us.

Regards,

Pete
Back to top
View user's profile Send private message AIM Address
lkSudoku

Joined: 16 May 2009
Posts: 60
:

Items
PostPosted: Sat May 16, 2009 10:25 am    Post subject: The GUI for my Sudoku Reply with quote

I have created sudoku using Microsoft Visual C++ MFC classes.

That is, using an MFC view document template

The cells that do not have fixed values are simpy text boxes, the grid is drawn with lines and filled rectangles, fixed cells are drawn with hidden text boxes and regular text drawn
Back to top
View user's profile Send private message Send e-mail
energztm

Joined: 21 Jul 2009
Posts: 6
:

Items
PostPosted: Tue Jul 21, 2009 2:57 pm    Post subject: Reply with quote

Whatever you do, I suggest non flash =]
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    Sudoku Programmers Forum Index -> Programming 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