65
1 A Project Report on Sudoku Submitted in partial fulfillment of the requirements for the award of the degree of Bachelor of Technology in Computer Science & Engineering From IMSEC, Ghaziabad DR. APJ ABDUL KALAM Technical University Lucknow

Project Report on Sudoku

Embed Size (px)

Citation preview

Page 1: Project Report on Sudoku

1

A

Project Report on

Sudoku Submitted in partial fulfillment of the requirements for the award of the

degree of Bachelor of Technology in Computer Science & Engineering From

IMSEC, Ghaziabad

DR. APJ ABDUL KALAM Technical University Lucknow

(Session 2015-16)

By: Tarun Kumar(1314310112)

Page 2: Project Report on Sudoku

2

TABLE OF CONTENT

SERIAL N0 TOPIC PAGE NO[1] Annexure I 3

[2] Abstract 4[3] Introduction

5-7 [4] Objective8 [5] Tools & Platform

9 [6] Scope of Project10 [7] Project

Limitation 11 [8] Solving Methods 12-15 [9] Research Methodology 16-19 [10]

Implementation Technique 20-25 [11]Implementation(Program Code) 26-46 [12]

Output of Implementation 47-49[13] Conclusion 50

[14] Suggestion for future Improvement 51[15] References

52

Page 3: Project Report on Sudoku

3

Annexure I

IMS Engineering College,

Ghaziabad

This is to certify that the project entitled “Sudoku Game” submitted

by “Tarun Kumar” ROLL NO “(1314310112)” in partial fulfillment of the

requirements for the award of the Degree Bachelor of Technology in

“Computer Science & Engineering” in “7th Semester” is a Bonafide

record of the work carried out under my guidance and supervision at

“IMS Engineering College Ghaziabad”.

Page 4: Project Report on Sudoku

4

ABSTRACT

In this report, we present the detailed development and

implementation of simple Sudoku game. The Sudoku game consists of

graphical user interface, solver and puzzle generator; implemented

using java and java swings. The solver and generator is implemented

using efficient algorithm. The solver finds the solution to the puzzles

generated by the generator as well as to the puzzles entered by the

user. Generator creates various number of different Sudoku puzzles.

This project gives an insight in to the different aspects of java

programming.

Page 5: Project Report on Sudoku

5

INTRODUCTION

Sudoku is the Japanese abbreviation of a phrase meaning the digits

must remain single, also known as Number Place, where Su means

number, doku which translates as single or bachelor. Sudoku is not a

mathematical or arithmetical puzzle. It works just as well if the

numbers are substituted with letters or some other symbols, but

numbers work best. The aim of the puzzle is to enter a numerical digit

from 1 through 9 in each cell of a 9×9 grid made up of 3×3 subsquares

or subgrids, starting with various digits given in some cells; each row,

column, and subsquares region must contain each of the numbers 1 to

9 exactly once.

Throughout this document we refer to the whole puzzle as the

grid/game board, a 3x3 subgrid as a block and the individual grids that

contains the number as a cell.

Page 6: Project Report on Sudoku

6

Figure : Sample Sudoku game

History

The first Sudoku puzzle was created in 1979. In New York City the

Sudoku puzzle appear first, which was published by the specialist puzzle

publisher Dell Magazines in their magazine Dell Pencil Puzzles and word

Games. First it was printed under the name “number place”. Howard

Garns, a retired architect and freelance puzzle constructor designed

this first puzzle. This mathematical construction is inspired by the Latin

square, invention of Leonhard Euler. Later the puzzle was introduced in

Japan by Nikoli during 1984 as "Suji wa dokushin ni kagiru", which can

be translated as "the numbers must be single" or "the numbers must

occur only once", later it abbreviated as Sudoku. The Sudoku puzzle

can use symbols or colors instead of numerals.Sudoku is still a

Page 7: Project Report on Sudoku

7

trademark owned by Nikoli. The the game's popularity really took off

in 2005; it can now be found in many newspapers and magazines

around the world.

Rules

Solving a Sudoku puzzle can be rather tricky, but the rules of the game

are quite simple. Solving a sudoku puzzle does not require knowledge

of mathematics; simple logic suffices. The objective of sudoku is to

enter a digit from 1 through 9 in each cell, in such a way that:

I. Each horizontal row contains each digit exactly once

II. Each vertical column contains each digit exactly once

III. Each subgrid or region contains each digit exactly once

Page 8: Project Report on Sudoku

8

OBJECTIVE

Undergraduate research project work is very demanding of students, of tutors and of resources and many students and the transition from traditional practical work difficult. In particular, they have unrealistic expectations of what can be achieved. In order to prepare students for their project work, some second-year courses include mini-projects.This paper reports on a case study of one such mini-project: it was effective in preparing students for their project work but most students were unaware of this and as a result, many felt demoralized by their experience. A number of factors which might improve the effectiveness of mini-projects and reduce the students' negative feelings were identified including: making the aims and objectives unambiguous, achievable and explicit; recognising the nature and difficulty of the demands which are being made of students; and providing sufficient time, support and guidance for students.

Page 9: Project Report on Sudoku

9

TOOLS & PLATFORM

Minimum Requirment:

Processor: Pentium 4/1.2 Ghz Celeron/Duron processor

CPU Speed: 1.4 GHz

RAM: 512 MB

Hard Disk: 80 GB

OS: Windows 98/ 2000/XP

Mouse:

Keyboard:

Sound Card: NO

Language: Java 5.0

Server : Apache Tomcat 4.1

Page 10: Project Report on Sudoku

10

SCOPE OF PROJECT

The objectives of the proposed Project is to increase the Thinking Capability.

The Game having all the records which u perform in playing you can Select Easy, hard level according to your choice. You can make your own Sudoku and at any Step you can go back to One Step as well as you can see the Solution of it.

It is manually a very difficult job to perform and its need a lot of recalling , reminding and mathematical calculation. The game of “Sudoku” helps to increase mental thinking , vision e.t.c

PROJECT LIMITATION

Page 11: Project Report on Sudoku

11

The Problem Faced by this System “Sudoku Game” is this that it only run in desktop.

If you want to access this game then you must have java 5.0 installed in your desktop. The Limitation of this project that you not access it in your Mobile device or in android device .

SOLVING METHODS

Page 12: Project Report on Sudoku

12

Brute Force Solving Method

A simple way to solve a Sudoku puzzle is to simply try filling each blank square with the numbers 1 to 9 until a valid solution is found. I ended up devising three different implementations of this method, as shown below.

Method 1 The first and most naïve solver starts at the top‐left square and moves from left to right,‐ ‐ top tobottom,‐ filling each blank square with a number 1 to 9 until the grid is invalid (that is, a number is duplicated in a row, column or 3×3 region) or until the grid is filled and valid (that is, solved). If the grid is invalid, the solver will backtrack until it is valid and continue forward again.

Page 13: Project Report on Sudoku

13

Page 14: Project Report on Sudoku

14

Method 2 The second implementation introduces the concept of ‘domains’. Each square in a grid has a domain of up to 9 values (1 to 9) that is reduced according to numbers already present in the intersecting row, column and region.

In this grid, we can reduce the domain of the top left‐ square to {1,4} since 2 and 3 already appear in the first column.

Likewise, we can restrict the domain of the top right‐ square to {2}, since 3 and 1 occur in the rightmost column and 4 appears in the top‐right region.

This solver acts in the same way as the previous implementation except that it restricts the domains of the grid before it starts, only using numbers present in the initial domains. While the domain restriction requires computation, it should result in significantly less backtracking to find the solution of a grid..Illustrating the process:

Page 15: Project Report on Sudoku

15

RESEARCH METHODOLOGY

Requriment for User:

The basic requirement was to create a simple Sudoku game, where user

can able to get different puzzles, able to check and get solution for

those puzzles, able to get solution for their own puzzles. Considering

this requirement a simple 9x9 grid layout has been made and discussed

with the users to find out what exactly they expect the user interface to

be. Some of the questions which are raised during the discussion are.

I. Layout

II. Interaction either from mouse or keyboard

III. Type of menus

IV. Resizable window or not

V. Kind of help/support

VI. Timer

Page 16: Project Report on Sudoku

16

Logic Behind Sudoku:

The Generator is for creating qualified Sudoku arrays. Combining with

the Solver, we could start to make our own Sudoku puzzles. The main

technique in this algorithm is using permutations, based on one

qualified pattern to enumerate qualified Sudoku arrays. Here, we only

use Band permutations (3! times variations), Row permutations within

a band (3! ³ times variations), Stack permutations (3! times variations),

and Column permutations within a stack (3! ³ times variations) to get

the arrays. Finally, put the qualified Sudoku array into a text file. (Ex: 3!

=3*2*1= 6 ---123,132,213,231,312,321).

Figure: illustrates the different types of permutations used in this work.

Page 17: Project Report on Sudoku

17

Figure: Different types of permutations

Sudoku Database:

This part of the system comprises the collection of puzzles

obtained from different sources in a text file. The system also

allows the user to store and retrieve their unfinished puzzles.

The block diagram of Sudoku game is shown in the figure.

Page 18: Project Report on Sudoku

18

Creator

Solver

Puzzle Database

User Interface(GUI)

Sudoku Game

Figure: Block diagram of Sudoku game

IMPLEMENTATION TECHNIQUE

Page 19: Project Report on Sudoku

19

Language of Implementation For this project I chose to use Java as the programming language. This was simply due to it being the language I had been using most recently. A Constraint Programming language like Prolog would probably have been better suited to this task since such languages include the ability to do some of the solving work automatically. However, I have no experience in using this programming paradigm.

Measurement Limitations -

Generator Implementation

Remarks The generator demonstrates that the number of hints given in a puzzle is not necessarily a good measure of how difficult a puzzle is for a huma

Page 20: Project Report on Sudoku

20

n player is can be -the example Easy grid below has only 24 hints and yet requires no techniques other than the basic unique/singleton domain methods, while the example Hard grid has 26 hints and requires the other techniques to be used several times.

Generating a Grid

Generating the Filled Grid Creating a filled grid turned out to be an easy task simply running the brute force solver on an empty (0 squares filled) grid will produce a valid solved grid. However, in the original implementation the solver would produce the same grid every time (since it runs from left to right,‐ ‐ top to bottom‐ ‐ always). By instead taking a random path through the grid a random solved Sudoku grid may be produced.

First Square Removal Attempt My first attempt to progressively remove squares from the filled grid did not fully succeed. My method was to remove a square, reset the domains of the row, column and 3×3 region intersecting that square and then check if the value of that square was still deducible by logic. This worked for hint counts‐ of about 35 and upwards, but never produced any grids with fewer hints. Furthermore, the grids produced were always ‘easy’ that is to say, they never required the more advanced logic techniques (pointing pairs, etc.) to be solved.

Second Square Removal Attempt My second approach was to simply remove numbers and check with the brute force solver whether the grid still had a unique solution – if it did, another number would be removed, if not, a different number would be removed. The process would repeat until the desired number of filled squares was reached.

Page 21: Project Report on Sudoku

21

This method worked reasonably well it produced grids with a relatively small number of hints (down to about 25). Unfortunately, the time taken to produce a grid was extremely variable anywhere from a few seconds to many minutes. The variation is caused by the random path that the the decision as to which square to remove is entirely random. Thus the generator might ‘get lucky’ and happen to successively pick hints that maintain a unique solution, quickly finding an empty puzzle, or the generator might do the reverse and consistently pick squares which cannot be emptied without increasing the solution count. Furthermore, the brute force solver was being run again and again, increasing the time taken to find a grid.

Third Square Removal Attempt This time, instead of using the brute force solver to check whether the generated grid had a unique solution, the logic solver was used to check if the grid was solvable. Since the logic solver is nearly always faster than the brute force solver, this should decrease the time taken to find a grid. However, the variability remainsof the generator still removes squares at random.

Different Grid Varieties

Difficulty Level The generator provides 2 different difficulty levels: easy and hard. Easy grids are solvable by using only the unique and singleton domain techniques (see the Logic Solver section of this report), while hard grids require at least one use of the other techniques.

Symmetry The Sudoku puzzles published in The Age and The Australian have their hints distributed in a symmetric pattern across the board for aesthetic r

Page 22: Project Report on Sudoku

22

easons. The generator provides the option of generating such grids. However, the number of possible empty grids that can be made from a filled grid is smaller if symmetry is required, so using the symmetrical option can slow down generation.

Measurements As mentioned above, even in its final implementation the generator is extremely variable as to how long it takes to generate a grid with a given number of hints as it clears squares in a random order. As such a simple average is not an appropriate measure. Instead, I ran the generator 10 times for various grid types and recorded the times.

Page 23: Project Report on Sudoku

23

Page 24: Project Report on Sudoku

24

IMPLEMENTATION (PROGRAM CODE)

import java.awt.BorderLayout;

import java.awt.Color;

import java.awt.Dimension;

import java.awt.FlowLayout;

import java.awt.Font;

import java.awt.Graphics;

import java.awt.event.ActionEvent;

import java.awt.event.ActionListener;

Page 25: Project Report on Sudoku

25

import java.awt.event.MouseAdapter;

import java.awt.event.MouseEvent;

import javax.swing.JPanel;

public class DisplayPanel extends JPanel implements ActionListener

{

private static final long serialVersionUID = 1L;

private int DisplayWidth = 557;

private int DisplayHeight = 580;

private int ButtonsWidth = 200;

private final Color LB = new Color(0xD2,0x69,0x1E);

private final Color DB = new Color(0xA5,0x2A,0x2A);

private final Color P = new Color(0x80,0, 0x80);

public DisplayPanel()

{

addMouseListener(new MouseAdapter()

{

public void mousePressed(MouseEvent e)

{

selectNumber(e.getX(),e.getY());

Page 26: Project Report on Sudoku

26

}

});

this.setLayout(new BorderLayout());

JPanel pb = new JPanel();

pb.setPreferredSize(new Dimension(ButtonsWidth,DisplayHeight));

pb.setBackground(LB);

FlowLayout FL = new FlowLayout();

FL.setVgap(55);

FL.setHgap(100); //set the flow layout to give symmetric display

pb.setLayout(FL);

SButton EYS = new SButton("Enter Sudoku", "EYS");

EYS.addActionListener(this);

pb.add(EYS);

SButton SES = new SButton("Easy Level", "SES");

SES.addActionListener(this);

pb.add(SES);

SButton SHS = new SButton("Hard Level", "SHS");

SHS.addActionListener(this);

Page 27: Project Report on Sudoku

27

pb.add(SHS);

SButton GBS = new SButton("GOBack One Step", "GBS");

GBS.addActionListener(this);

pb.add(GBS);

SButton STS = new SButton("Solution", "STS");

STS.addActionListener(this);

pb.add(STS);

this.add(pb,BorderLayout.WEST);

}

private void selectNumber(int x, int y)

{

int NumberPosition[] = {3,63,124,187,248,309,372,433,494}; //number position

final byte pSNumberY = 19; //the spacing for the numbers

if( x < ButtonsWidth + NumberPosition[0])

return;

x -= ButtonsWidth - NumberPosition[0];

byte count;

byte Xposition = 0; //the position of the selected box 0 - 8 in X

for(count = 0; count < 9; count++) //check to find position

Page 28: Project Report on Sudoku

28

{

if(x > NumberPosition[count])

Xposition = count;

}

byte Yposition = 0;

for(count = 0; count < 9; count++) //check to find position

{

if(y > NumberPosition[count])

Yposition = count;

}

byte position = (byte) (Xposition + Yposition*9);

byte Xnumber = 0;

x -= NumberPosition[Xposition];

for(count = 0; count < 3; count++)

{

if(x > pSNumberY*count)

Xnumber = count;}

byte Ynumber = 0;

y -= NumberPosition[Yposition];

for(count = 0; count < 3; count++)

Page 29: Project Report on Sudoku

29

{

if(y > pSNumberY*count)

Ynumber = count;

}

byte number = (byte) (Xnumber + Ynumber*3);

MySudoku.step = Smethods.select(MySudoku.sudoku, number, position, MySudoku.step);

repaint(ButtonsWidth,0, DisplayWidth,DisplayHeight);

}

public Dimension getPreferredSize() //set the preferred size of display panel

{

return new Dimension(DisplayWidth + ButtonsWidth,DisplayHeight);

}

protected void paintComponent(Graphics g)

{

final byte Foot = 24; //the height of the foot for sudoku

final byte NumberX = 11;

final byte NumberY = 54;

final byte blanksize = 59;

Page 30: Project Report on Sudoku

30

final byte pNumberX = 4;

final byte pNumberY = 18;

final byte pSNumberX = 20;

final byte pSNumberY = 19;

final int FootMessageX = 96;

final int FootMessageY = 574;

final int FootNumberX = 211;

final int FootNumberY = 574;

int BigLines[] = {0, 184, 369, 554, 577};

int SmallLines[] = {62, 123, 247, 308, 432, 493};

int NumberPosition[] = {3,63,124,187,248,309,372,433,494};

Font fontSelected = new Font("SansSerif", Font.ROMAN_BASELINE, 70);

Font fontFoot = new Font("SansSerif", Font.ROMAN_BASELINE, 20);

Font fontPencil = new Font("SansSerif", Font.ROMAN_BASELINE, 20);

super.paintComponent(g);

g.setColor(DB);

g.setFont(fontPencil);

byte count;

Page 31: Project Report on Sudoku

31

for(count = 0; count < 5; count++)

g.fillRect(0, BigLines[count], DisplayWidth + ButtonsWidth, 3);

for(count = 0; count < 6; count++)

g.drawLine(0, SmallLines[count], DisplayWidth + ButtonsWidth, SmallLines[count]);

g.fillRect(BigLines[0] + ButtonsWidth , 0, 3, DisplayHeight);

g.fillRect(BigLines[1] + ButtonsWidth , 0, 3, DisplayHeight - Foot);

g.fillRect(BigLines[2] + ButtonsWidth , 0, 3, DisplayHeight - Foot);

g.fillRect(BigLines[3] + ButtonsWidth , 0, 3, DisplayHeight);

for(count = 0; count < 6; count++)

g.drawLine(SmallLines[count] + ButtonsWidth, 0, SmallLines[count] + ButtonsWidth, DisplayHeight -Foot);

//foot text

g.setFont(fontFoot);

g.drawString("This is Step in the Sudoku Solution", FootMessageX + ButtonsWidth, FootMessageY);

g.drawString(String.valueOf(MySudoku.step), FootNumberX + ButtonsWidth, FootNumberY);

byte numbercount;

for(numbercount = 0; numbercount < 81; numbercount++)

Page 32: Project Report on Sudoku

32

{

g.setColor(DB);

byte zeros = 0;

byte outercount;

for(outercount = 0; outercount < 3; outercount++)

{

for(count = 0; count < 3; count++)

{

byte pencilnumber = MySudoku.sudoku[count + outercount*3 + numbercount*9][ MySudoku.step];

if(pencilnumber > 0)

{

if(pencilnumber < 10)

{

g.setFont(fontPencil);

g.drawString(String.valueOf(pencilnumber ), NumberPosition[numbercount%9] + (count*pSNumberX) + pNumberX + ButtonsWidth, NumberPosition[numbercount/9] + outercount*pSNumberY + pNumberY);

}

else

Page 33: Project Report on Sudoku

33

{

g.setFont(fontSelected);

g.drawString(String.valueOf(pencilnumber - 10), NumberPosition[numbercount%9] + ButtonsWidth + NumberX, NumberPosition[numbercount/9] + NumberY);

}

}

else

zeros += 1;

}

}

if(zeros == 9)

{

g.setColor(P);

g.fillRect(NumberPosition[numbercount%9] + ButtonsWidth, NumberPosition[numbercount/9], blanksize, blanksize);

}

}

}

Page 34: Project Report on Sudoku

34

public void actionPerformed(ActionEvent e)

{

if(e.getActionCommand() == "EYS")

MySudoku.step = 0; //nothing is selected

else if(e.getActionCommand() == "STS")

{

Smethods.trysudoku(MySudoku.sudoku, MySudoku.step);

}

else if(e.getActionCommand() == "GBS")

{

if(MySudoku.step > 0)

MySudoku.step -= 1;

}

else if(e.getActionCommand() == "SES")

{

Smethods.trysudoku(MySudoku.sudoku, (byte) 0);

MySudoku.step = 30;

}

else if(e.getActionCommand() == "SHS")

Page 35: Project Report on Sudoku

35

{

Smethods.trysudoku(MySudoku.sudoku, (byte) 0);

MySudoku.step = 10;

}

repaint(ButtonsWidth,0, DisplayWidth,DisplayHeight);

}

}

Import java.awt.BorderLayout

import java.awt.Color;

import java.awt.Dimension;

import java.awt.image.BufferedImage;

import java.io.File;

import java.io.IOException;

import javax.imageio.ImageIO;

import javax.swing.JFrame;

import javax.swing.SwingUtilities;

Page 36: Project Report on Sudoku

36

public class MySudoku

{

public static byte[][] sudoku = new byte[729][82];

public static byte step = 0;

private static final int WindowWidth = 2000;

private static final int WindowHeight = 1500;

public static void ShowGUI()

{

Smethods.start(sudoku);

final byte border = 20;

JFrame f = new JFrame("MySudoku");

f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

BufferedImage image = null;

try {

image = ImageIO.read(new File("sudoku.png"));

} catch (IOException e) {

}

Page 37: Project Report on Sudoku

37

f.setResizable(false);

f.setIconImage(image);

f.setSize(WindowWidth, WindowHeight);

f.setLocation(0, 0);

f.setLayout(new BorderLayout()); //north south east west and centre

f.add(new SPanel(new Dimension(WindowWidth,border)), BorderLayout.NORTH);

f.add(new SPanel(new Dimension(WindowWidth,border)), BorderLayout.SOUTH);

f.add(new SPanel(new Dimension(border,WindowHeight)), BorderLayout.EAST);

f.add(new SPanel(new Dimension(0,WindowHeight)), BorderLayout.WEST);

DisplayPanel dp =new DisplayPanel();

dp.setBackground(Color.GREEN);

f.add(dp, BorderLayout.CENTER);

f.setVisible(true);

}

Page 38: Project Report on Sudoku

38

public static void main(String[] args) {

SwingUtilities.invokeLater(new Runnable() {

public void run() {

ShowGUI();

}

});

}

}

import java.awt.Color;

import java.awt.Dimension;

import javax.swing.BorderFactory;

import javax.swing.JButton;

class SButton extends JButton

{

private static final long serialVersionUID = 1L;

Color DB = new Color(0x8B,0x00,0x00);

Color LB = new Color(0xAD,0xD8, 0xE6);

public SButton(String action, String command)

Page 39: Project Report on Sudoku

39

{

super(action);

this.setBackground(LB);

this.setForeground(DB);

this.setBorder(BorderFactory.createBevelBorder(0, DB, DB));

this.setActionCommand(command);

}

public Dimension getPreferredSize()

{

return new Dimension(130,30);

}

}

public class Smethods

{

public static void start(byte[][] sudoku)

{

int count = 0;

for(count = 0; count < 729; count++)

sudoku[count][0] = (byte) (1 + (count % 9));

}//end of start. 1-9 in 81 spots

Page 40: Project Report on Sudoku

40

public static void trysudoku(byte[][] sudoku, byte startstep)

{

java.util.Random generator = new java.util.Random(System.currentTimeMillis());

byte step = startstep;

int trys = 0;

do

{

trys += 1;

boolean noblanks = true;

step = startstep;

while((step < 81) && (noblanks))

{

byte number = (byte) generator.nextInt(9); // 0 to 8

byte position = (byte) generator.nextInt(81); //0 to 80

step = Smethods.select(sudoku,number,position,step);

boolean standalone = false;

Page 41: Project Report on Sudoku

41

do

{

standalone = false;

byte count;

byte incount;

for(count = 0; count < 81; count++)

{

byte nzeros = 0; //we start with no zero count

for(incount = 0; incount < 9; incount++)

{

if(sudoku[count * 9 + incount][step] == 0)

nzeros += 1;

else

number = (byte) (sudoku[count * 9 + incount][step] - 1);

if(nzeros == 9)

noblanks = false;

}

if((nzeros == 8) && (number < 10))

{

Page 42: Project Report on Sudoku

42

step = Smethods.select(sudoku,number,count,step);

standalone = true;

}

}

}

while(standalone);

}

MySudoku.step = step;

}

while((step != 81) && (trys < 500));

}

public static byte select(byte[][] sudoku, byte number, byte position, byte step)

{

if((sudoku[position*9 + number][step] == 0) || (sudoku[position*9 + number][step] > 9))

return step;

Page 43: Project Report on Sudoku

43

step += 1;

int count = 0;

for(count = 0; count < 729; count++)

sudoku[count][step] = sudoku[count][step - 1];

for(count = 0; count < 9; count++)

sudoku[position*9 + count][step] = 0;

byte row = (byte) (position/9);

for(count = 0; count < 9; count++)

sudoku[row * 81 + count * 9 + number][step] = 0;

byte column = (byte) (position%9);

for(count = 0; count < 9; count++)

sudoku[column * 9 + count * 81 + number][step] = 0;

int brow = (position/27)*243;

column = (byte) (((position%9)/3)*27);

byte incount;

for(incount = 0; incount < 3; incount++)

{

Page 44: Project Report on Sudoku

44

for(count = 0; count < 3; count++)

sudoku[brow + column + count * 9 + incount * 81 + number ][step] = 0;

}

sudoku[position*9 + number][step] = (byte) (number + 11);

return step;

}

}

import java.awt.Color;

import java.awt.Dimension;

import java.awt.Panel;

public class SPanel extends Panel

{

private static final long serialVersionUID = 1L;

Color LB = new Color(0xAD,0xD8, 0xE6);

public SPanel(Dimension set)

{

super();

this.setBackground(LB);

Page 45: Project Report on Sudoku

45

this.setPreferredSize(set);

}

}

OUTPUT OF IMPLEMENTATION

The Snapshot of output of Project :

Page 46: Project Report on Sudoku

46

Page 47: Project Report on Sudoku

47

CONCLUSION

Page 48: Project Report on Sudoku

48

Achievements

Through generating this Sudoku solver and generator I feel I have improved my programming ability. This was perhaps the largest program in terms of time invested and lines of code written that I have created. The code is not of the highest quality, and it is severely lacking in documentation, but some of the problems posed by the project were a good challenge to solve. Writing the solver has demonstrated the advantages of ‘smart’ algorithms over naïve algorithms evidenced in the measurements above. Finally, I have experienced participating in what could be called a small research project (useful for future work).

Project Status

The logic solver portion of the program is sufficient for solving many Sudoku puzzles. However, the implementation could likely be improved to execute faster. Furthermore, there are many logic solving techniques that have not been implemented.

The generator, on the other hand, is currently rather poorly implemented. It works in that it successfully generates grids of a given number of hints, but the variability of the time taken to generate is a significant weakness. Additionally, the generator currently only offers two levels of puzzle difficulty (‘easy’ and ‘hard’) a scale of difficulties would be perhaps more useful.

SUGGESTION FOR FUTURE IMPROVEMENT

Page 49: Project Report on Sudoku

49

These are some of the main suggestions given by the user for

improvement.

I. Instant help by giving hints and users progress while playing.

II. Score system based on time and accuracy, and database to keep

track of top ten record.

R EFERENCES

Page 50: Project Report on Sudoku

50

[1]. http://java.sun.com/docs/books/tutorial/uiswing/[2]. http://www.sudocue.net/glossary.php[3]. http://en.wikipedia.org/wiki/Sudoku[4]. http://www.sudoku.com/[5]. http://sudoku.sourceforge.net/[6]. http://www.scanraid.com/Sudoku.htm[7]. http://www.conceptispuzzles.com/products/sudoku/rules.htm[8]. http://www.setbb.com/phpbb/index.php?mforum=sudoku[9]. http://java.com/en/games/desktop/sudoku.jsp[10]. Java software solutions: foundations of program design, William

Loftus[11]. http://davidbau.com/archives/2006/09/04/

sudoku_generator.html [12]. Stuart, A. (2006, November 21). Sudoku Solver. Retrieved October

24, 2007[13]. http://www.sudocue.net/glossary.php[14]. Devlin, Keith (January 28–29, 2012). "The Numbers Game (book

review of Taking Sudoku Seriously by Jason Rosenhouse et al.)". The Wall Street Journal (Weekend Edition). p. C5.

[15]. H.H. Lin, I-C. Wu. "No 16-clue Sudoku puzzles by sudoku@vtaiwan project", September, 2013.

[16]. Berthier, Denis (December 4, 2009). "Unbiased Statistics of a CSP – A Controlled-Bias Generator". In Elleithy, Khaled. Innovations in Computing Sciences and Software Engineering. pp. 165–170. Retrieved December 4, 2009.

Page 51: Project Report on Sudoku

51

Page 52: Project Report on Sudoku

52