Go4Expert (http://www.go4expert.com/)
-   Game Programming (http://www.go4expert.com/articles/game-programming/)
-   -   Sudoku Solving Program Using 'C' (http://www.go4expert.com/articles/sudoku-solving-program-using-c-t541/)

rai_gandalf 15Mar2006 17:04

Re: Sudoku Solving Program Using 'C'
The GUI in this program is Text-mode based. It is Non-BGI. So, it isn't that very appealing to the eyes, yet reasonably user-friendly & elaborate to use. Download the code & read the documentation to understand the logic of the Text-based GUI of this program.


PS : BGI can be used to develop an actual Graphics interface that is detailed & developed, for this program. :)

"Don't take life too seriously; No one gets out alive."

wizardrycon 14Jul2006 01:41

Re: Sudoku Solving Program Using 'C'
I have also been writing a Sudoku solving program but I have been using C# .NET.

When I clean up the objects that do the solve (it will solve a complete puzzle of mediumn complexity. I need to add other algorhythyms to solve for the harder level puzzles). I will post them on this thread for review/comments.

However in the mean time I need some help with my GUI object for this whole project.

I am pretty new to .NET programming and was hoping someone could tell me why this is not working right.

Any help you guys could give me would be greatly appreciated!!!

Source Notes: I am creating 9 panels which divide the main 9x9 grid into 9 smaller 3x3 grids (just like the Sudoku Puzzle). I am hoping by creating the GUI this way, it will be easier to implement the object connections to the actual cell data that will connected to each grid button.

I am also interested in making the buttons size dynamically depending on how big the form is. If anyone can point me in the right direction to do that I will try to implement that feature as well.

OUTPUT (Note only 1 panel paints the buttons, they all paint the same way and I can't for the life of me figure out why the other 8 panels are missing the buttons!!):



using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;

namespace SudokuGridFormA
        public class SudokuGridForm : System.Windows.Forms.Form
                private System.Windows.Forms.GroupBox groupBox1;
                private System.Windows.Forms.Panel [,] panel = new Panel[3,3];
                private System.Windows.Forms.Button [,] GridBtn = new Button[9,9];
                private int TABINDEXNUM = 0;

                public SudokuGridForm()

                private int TABINDEX()

                private void AddPanel(int panelNumX, int panelNumY, int x1, int x2, int y1, int y2)
                        this.panel[panelNumX,panelNumY].BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle;

                        for(int y=y1; y<=y2; y++)
                                for(int x=x1; x<=x2; x++)
                                        this.GridBtn[x,y] = new System.Windows.Forms.Button();

                        this.panel[panelNumX,panelNumY].Location = new System.Drawing.Point(24+(panelNumX*96),32+(panelNumY*96));
                        this.panel[panelNumX,panelNumY].Name = "panel" + panelNumX.ToString()+panelNumY.ToString();
                        this.panel[panelNumX,panelNumY].Size = new System.Drawing.Size(96, 96);
                        this.panel[panelNumX,panelNumY].TabIndex = TABINDEX();

                        for(int y=y1; y<=y2; y++)
                                for(int x=x1; x<=x2; x++)
                                        this.GridBtn[x,y].Location = new System.Drawing.Point(0+(x*32), 0+(y*32));
                                        string BtnName = "GridBtn"+panelNumX.ToString()+panelNumY.ToString()+x.ToString()+y.ToString();
                                        this.GridBtn[x,y].Name = BtnName;
                                        this.GridBtn[x,y].Size = new System.Drawing.Size(32, 32);
                                        this.GridBtn[x,y].Text = panelNumX.ToString()+panelNumY.ToString()+x.ToString()+y.ToString();
                                        this.GridBtn[x,y].TabIndex = TABINDEX();

                private void InitializeComponent()
                        this.groupBox1 = new System.Windows.Forms.GroupBox();

                        for(int y = 0; y<3; y++)
                                for(int x = 0; x<3; x++)
                                        this.panel[x,y] = new System.Windows.Forms.Panel();

                        for(int y = 0; y<3; y++)
                                for(int x = 0; x<3; x++)
                        this.groupBox1.Location = new System.Drawing.Point(16, 24);
                        this.groupBox1.Name = "groupBox1";
                        this.groupBox1.Size = new System.Drawing.Size(336, 344);
                        this.groupBox1.TabIndex = TABINDEX();
                        this.groupBox1.TabStop = false;

                        for(int y = 0; y<3; y++)
                                for(int x = 0; x<3; x++)
                        this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
                        this.ClientSize = new System.Drawing.Size(368, 382);
                        this.Name = "SudokuGridForm";
                        this.Text = "SudokuGridForm";
                        for(int y = 0; y<3; y++)
                                for(int x = 0; x<3; x++)

wizardrycon 14Jul2006 13:58

Re: Sudoku Solving Program Using 'C'
Nevermind... It was an error in the positioning and not a painting error. I didn't reset it to 0,0 for each panel other than the first one.

Thanks for looking if you were trying to figure it out...

gamehunter101 16Jul2006 11:04

Re: Sudoku Solving Program Using 'C'
Good work man

anshul gupta 17Aug2006 15:41

Re: Sudoku Solving Program Using 'C'
hi rai
even i have worked on a sudoku generator but my basic problem is the time that the problem takes to generate a sudoku.
the logic behind the problem is pretty simple and it is not recurssive in nature .
its like fitting in a solution rather than generatin it.
i will like to take a look at ur basic strategy behind the problem...
plz u can mail me at anshulgolu123@gmail.com

anshul gupta 17Aug2006 15:43

Re: Sudoku Solving Program Using 'C'
by the way excellent work man.....

BlasterBlang 14Nov2006 13:45

Re: Sudoku Solving Program Using 'C'

durgaprasad 24Jan2007 17:02

Re: Sudoku Solving Program Using 'C'
good work gandalf

durgaprasad 24Jan2007 17:10

Re: Sudoku Solving Program Using 'C'
mr.gandalf irequest u to write a program in c that allows the user to play tic tac toe with computer

shabbir 24Jan2007 18:06

Re: Sudoku Solving Program Using 'C'

Originally Posted by durgaprasad
mr.gandalf irequest u to write a program in c that allows the user to play tic tac toe with computer

Why do you want him to write for you when we already have couple of threads having the same.

Tic-Tac-Toe Game in C
TicTacToe in Plain C without using BGI graphics

Also dont jump into some article with your query. Instead try giving your query a new thread with good title to get good responses.

All times are GMT +5.5. The time now is 21:18.