06 Feb 2011, 05:57
Generic-user-small

Evan Clark (1 post)

Here are some changes I made to the Sudoku app to prevent one of the originally given numbers from being changed or deleted. It’s not a big deal but someone might accidentally do that and cause the whole puzzle to become unsolvable.

In the method “private int[] getPuzzle(int diff)”
-First, I made a class variable “origPuz”
-Then, when puz was set as either hardPuzzle, mediumPuzzle, or easyPuzzle, i also set origPuz (this way, you can change numbers you added in a puzzle that is being continued)

I also changed the “showKeypadOrError” method (lines I added are denoted by ~~)

protected void showKeypadOrError(int x, int y) {
        int tiles[] = getUsedTiles(x, y);
     ~~ int n = y*9+x;
        if (tiles.length == 9) {
            Toast toast = Toast.makeText(this, R.string.no_moves_label, Toast.LENGTH_SHORT);
            toast.setGravity(Gravity.CENTER, 0, 0);
            toast.show();
        }
        else {
         ~~ if (origPuz.substring(n, n+1).equals("0")) {
                Log.d(TAG, "showKeypad: used =" + toPuzzleString(tiles));
                Dialog v = new Keypad(this, tiles, puzzleView);
                v.show();
            }
        }
    }

All this does is make it so the keypad box does not pop up on one of the numbers originally given.

07 Feb 2011, 14:41
Burnette_ed_pragsmall

Ed Burnette (1316 posts)

Looks good. Marshal Farrier has been working on a similar change here:

The biggest enhancement that the program needs is to be able to either fetch games from the Internet or make random games. If anybody finds a Sudoku game web service I’d really like to know about it.

15 Feb 2011, 00:15
Generic-user-small

Austin Warren (13 posts)

Nice and simple way to accomplish this.

The way I managed to do it was to create a function called getStartLocations, which takes the original puzzle as an input.
It then updates a local Variable called startingLocations.

In order for this to work, I created a function that scans the original puzzle for anything thats not a zero, and converts it’s coordinate from the one dimensional puzzle array into a 2 dimensional tile location, X and Y.

This way the starting numbers only get computed once, when the new puzzle is created. The showKeypadOrError function then doesnt have to run through the entire puzzle every time. The showKeypadOrError calls my isStartLocation function which scans my array of starting locations and returns a boolean.

The only one thing i need to figure out, is that currently my startLocations array is a constant size of [50]. I don’t know how i could make is dynamic to how many start locations there are. Any ideas for this?

Not that running through an array of size 81 is very memory intensive, I’m just trying to practice efficient code.

Cheers,

Austin

15 Feb 2011, 20:29
Generic-user-small

Austin Warren (13 posts)

I also just realized that your code will not stop you from changing tiles when using the d-pad, as there is no dialog box when using the d-pad.

A way to get around this is to modify the setTileIfValid or whatever its called. All you need to do is make a check in there,

if(isStartTile(x,y))
     return false;
  You must be logged in to comment