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   

Help on populating grid

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

Joined: 09 Dec 2008
Posts: 3
:

Items
PostPosted: Tue Dec 09, 2008 11:05 pm    Post subject: Help on populating grid Reply with quote

Hi there, 1st post. I've been given the task to create a sudoku game/solver.

I have been able to print out a grid from a string and now i have started to generate my own grid. At the moment I can only populate the grid with one number can someone help? I know this may sound a bit basic but my programming skills are the bees knees.

Here's the code where the String is converted

Code:

public void initializeFromString(final String boardStr) {
       
        clear();  // Clear all values from the board.
       
        //int full =81; // parameter used
       
       
        row = 0;
        col = 0;
        for (int i = 0; i <boardStr>= '1' && c <='9') {
                if (row > 9 || col > 9) {
                    throw new IllegalArgumentException("SudokuModel: "
                            + " Attempt to initialize outside 1-9 "
                            + " at row " + (row+1) + " and col " + (col+1));
                }
                _board[row][col] = c - '0';  // Translate digit to int.
                col++;
            }
            else if (c == '.')
            {
                setVal(row,col,rand);
                col++;
            }
            else if (c == '/') {
                row++;
                col = 0;
            }
            else if (c == ','){
                col++;
            }
            else
            {
                throw new IllegalArgumentException("SudokuModel: Character '" + c
                        + "' not allowed in board specification");
            }
        }
    }



I use a random to be generated but i want to know the best method on how to change the value on each pass. Any help greatly appreciated
Back to top
View user's profile Send private message
ukelebear

Joined: 09 Dec 2008
Posts: 3
:

Items
PostPosted: Tue Dec 09, 2008 11:12 pm    Post subject: Reply with quote

Its ok I have sorted it out now.
In the outest loop of the for loop I have simply put the code:

rand = generator.nextInt(9) + 1;
so it randomly generates a new number on each pass
Back to top
View user's profile Send private message
Lunatic

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

Items
PostPosted: Wed Dec 10, 2008 11:30 am    Post subject: Reply with quote

You can take a look at http://www.setbb.com/phpbb/viewtopic.php?p=10541&mforum=sudoku#10541
_________________
Marc
~~~<><~~~<><~~~<><~~~<><~~~
Back to top
View user's profile Send private message Send e-mail Visit poster's website
Display posts from previous:   
Post new topic   Reply to topic    Sudoku Programmers Forum Index -> Setting 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