Simple sudoku implementation, JAVA Programming

SudCell and Simple Sudoku Implementation

We describe, fully, the SudCell class that will represent each of the 81 cells or boxes in a Sudoku puzzle.  Then we will see a simple version of the Sudoku class.  Make sure you have read and understood the general introduction to the SudCell and Sudoku class in the main assignment page.  I have laid out every detail of the class members and methods for you, so although this is a long document, it should be actually easier than assignments which are shorter but less specific.

SudCell Class Specification

 Create a class called SudCell that has the following private members:

  • boolean digits[] - an array of nine booleans, each representing the digits 1 through 9.  If digits[0] is true, that means this cell might contain a 1.  If digits[1] is true, it might contain a 2, and so on.  This is private.
  • boolean completed - a private boolean telling our higher level classes whether or not we are done exploiting this cell.  All SudCell objects start with completed = false, even those for which we are given the final value, because for those "givens" we still have not utilized that fact yet.  Once we do, we turn this cell off (set completed to true).

The following public static members will allow us to turn this into a 4x4 or  16x16 Sudoku with a few keystrokes -- we'll use these constants throughout the code and never have a 1 through 9 literal in any part of our program.

  • static final int MIN_VAL = 1
  • static final int MAX_VAL = 9
  • static final int NUM_VALS = 9
  • static final int SQRT_NUM_VALS = 3
  • static final int NOT_FINAL_YET = -1    (used to signal whether or not we have narrowed down the boolean digits[] array to one value -- different from completed if you think about it).

You should supply all of the following public methods (at a minimum):

Basic Stuff:

  • Constructor - just one, default, that allocates digits[], sets the digits to all true and completed to false.
  • ToString() - a method that will return a String that is a " - " if the cell has more than one true, or a digit (surrounded by spaces) if the cell is narrowed down to just one (true) value. Since the Sudoku class will  need to build a 9x9 matrix on the display, this should not contain any newline ('\n') character -- just three chars, the two spaces and the middle digit or '-'.  This is used for end-user output.
  • ToStringReveal() - This returns a string that contains all the values that this cell might still be.  In other words, if you have not ruled out 3, 5 or 9, it would return the string " 359 " (with spaces at both ends).  If you have narrowed it down to 9, it will return " 9 ".  If you have not narrowed it down at all, it would return " 123456789 ".   (I could have combined ToString() and ToStringReveal() into one method that took a boolean parameter, but I chose to make these two different methods.)  In a console based application, printing all the cells using ToStringReveal() might result in a raggedy matrix, since each cell will have a different length, but that's not too critical.  You could make the return values of ToStringReveal() all the same length by padding with spaces, but from two weeks of debugging I have found that it is better to let the 9x9 array that displays these "revealed" strings be jagged, because it helps to more easily determine whether two successive outputs of an in-progress Sudoku are the same or different.


Posted Date: 2/16/2013 5:16:49 AM | Location : United States

Related Discussions:- Simple sudoku implementation, Assignment Help, Ask Question on Simple sudoku implementation, Get Answer, Expert's Help, Simple sudoku implementation Discussions

Write discussion on Simple sudoku implementation
Your posts are moderated
Related Questions
there are N nodes in a graph, the graph isuni directional with M edges of these M nodes in a graph, there are K nodes which are important nodes. given initial position I within thi

Explain the term - Garbage Collection Java  performs  garbage  collection  and  eliminates  the  need  to  free  objects  explicitly.  When an object  has  no references   to

A string S is said to be "Super ASCII", if it contains the character frequency equal to their ascii values. String will contain only lower case alphabets (''''a''''-''''z'''') and

How can you define a consistent web design? Why is it needed? A consistent excellent designed website is generated for common public which permits users to attain what they nee

RMI is a set of APIs that permits to build distributed applications. RMI uses interfaces to describe remote objects to turn local method invocations into remote method invocations.

How we Declaring Arrays in java language? Like all other variables in Java, an array must have a exact type such as byte, int, String or double. Just variables of the appropria

#include float start_point, /* GLOBAL VARIABLES */ end_point, total_area; int numtraps; main( ) { void input( void );

Java is increasingly used for middleware applications to communicate among Server and clients. Java has features like multithreading, portability and networking capabilities. Chang

How to Creating Arrays in java? Declaring arrays merely says what type of values the array will hold. It does not form them. Java arrays are objects, and such as any other obje

A Queue of Cards You are going to parallel the development done in the lesson on inheritance where we constructed some base classes, StackNode and Stack, and derived  Floa