Sudoku Help
Hi
Im new to java and im curently building a sudoku game.
At the minute i have a gui class which builds my gui with 81 text fields and a few jbuttons to load save etc.
im planning on using a 2d array. i want to be able to load a puzzle into a 2d array and then for the puzzle to be displayed in my 81 textfields.
Hope this makes sense??
any help appreciated.
Thanks.
whats the best way then?? i want to keep it as simple
as possible."simple" is not a simple concept ;-)
If by "simple" you mean "the smalles amount of files to handle" then your approach would be the simplest, but that's usually not a usefull definition.
If by simple you mean "easy to understand" then producing seperate classes to handle seperate tasks is usually the better approach.
The problem is that some of those seperations are very simple if you've got your head around them but can be confusing if you're very new. But you should really work at climbing that barrier, as it allows you to handle much larger problems without getting confused.
Similar Messages
-
Complete newcomer to java!!
I want to create a sudoku java game using a gui. How do i go about this?? Whats the best way to start??Check this site for core java code to solve sudoku:
http://kulandai.blogspot.com/2006/10/sudoku-puzzle-java-source.html -
Hi
I want to develop a Java program to solve Sudoku puzzles
My program must be able to:
�Read in a puzzle (from the predefined file format � see below)
�Display the unsolved puzzle
�Solve the puzzle
�Display the solved puzzle
File Format
The file consists of a number of integers.
The first integer signifies the size of the puzzle e.g. a 2 indicates a 4x4 puzzle, a 3 indicates a 9x9 puzzle, a 4 indicates a 16x16 puzzle and so on.
The remaining numbers are one integer for each square of the puzzle (e.g. 81 integers for a 9x9 puzzle) and should be read left to right and top row to bottom row. A zero means that the square is empty. A non-zero indicates the number in that square.> Hi
I want to develop a Java program to solve Sudoku
puzzles
My program must be able to:
non-zero indicates the number in that square.
And your question is? -
Java program for Sudoku puzzle
I basically need to list the possible solutions to every blank space in a sudoku puzzle. I can make my puzzle in a .txt file and then just run that in my program.
Here's an example of a line I would create in my.txt file:
5 3 _ _ 7 _ _ _ _ (So possible solutions for the third spot would be 1,2, or 4. Then you'd continue down the line)
So to get started I need to create a 9x9 array to store my .txt file. Read in my input one line at a time, then use a StringTokenizer to break apart each value in the line. So basically I need help starting that beginning part of my program. I'm a pretty slow learner with this stuff so a little help getting me started helps out a lot, then I tend to catch on to what is going on and I can finish up from there.
Thanks GuysI still need to loop through and rows, columns, and grid to find possible solutions but I didn't ask for help on that. I know how to set up a 2d array, but when I set it up it's not reading out my .txt file. I was going to use 'char' in my array, but I don't know how I'm going to read from that .txt file, charAt I was thinking. Then for the stringTokenizer I'm really confused on how I would break apart each value from my .txt file.So, it looks like you're panicking and trying to do everything all at once. Maybe that's why you aren't getting anywhere. You need to start small. Don't try to write the whole program in one go, but instead start with a simpler program that doesn't do the whole business. In fact, start with a really simple program that does just one thing.
What's the first thing that's necessary? You have to read your input data from a file, one line at a time. (Yes, then you have to break each of the lines into pieces, but don't get ahead of yourself.) So write a little program that only reads your input file one line at a time. To check that it's working, just write each of the lines out to the console.
Then when that's working, add another feature. That would be splitting the lines into pieces. Again, for now just write the pieces out to the console to check that it's working. Then carry on from there. -
Error message when trying to access the free Sudoku game I downloaded from Blackberry Owners' Forum
I downloaded the free Sudoku game from the Blackberry Owners' Lounge (at http://na.blackberry.com/eng/ownerslounge/downloads/games.jsp) to my PC and then used the Blackberry Desktop Manager to transfer it to my Blackberry Curve 8300.
But, when I try to open it from my Curve, I get the following error message: Application terminated: Sudoku has been denied the "Interprocess Communication" permission".
Any idea what I've done wrong and/or how to correct the problem?Hi and Welcome to the Community!
With the hundreds of possibilities, it's a pity you didn't provide the actual error message that you are seeing. Please provide the complete and exact error message, including all punctuation.
Thanks!
Occam's Razor nearly always applies when troubleshooting technology issues!
If anyone has been helpful to you, please show your appreciation by clicking the button inside of their post. Please click here and read, along with the threads to which it links, for helpful information to guide you as you proceed. I always recommend that you treat your BlackBerry like any other computing device, including using a regular backup schedule...click here for an article with instructions.
Join our BBM Channels
BSCF General Channel
PIN: C0001B7B4 Display/Scan Bar Code
Knowledge Base Updates
PIN: C0005A9AA Display/Scan Bar Code -
I don't know why this is not working. Could someone please help ASAP. THe problem is that the sudoku board is printing some zeros.
public class Sudoku {
private int[][] Board = {
{0,5,0,0,1,0,0,4,0},
{1,0,7,0,4,0,6,0,2},
{0,0,0,9,0,5,0,0,0},
{2,0,8,6,3,0,5,0,1},
{0,4,0,0,7,0,0,2,0},
{9,0,1,0,8,0,4,0,6},
{0,0,0,4,0,1,0,0,0},
{3,0,4,0,5,8,7,0,9},
{0,2,0,0,6,0,0,1,0}
public boolean row_Col(int row, int col, int num)
for(int count=0; count<9; count++)
if(Board[count][col]==num || Board[row][count]==num)
return false;
return true;
public boolean box(int row, int col, int num)
for(int count1=0; count1<3; count1++)
for(int count2=0; count2<3; count2++)
if(Board[count1+row/3*3][count2+col/3*3]==num)
return false;
return true;
public boolean solve()
for(int row=0; row<9; row++)
for(int col=0; col<9; col++)
if(Board[row][col]==0)
//find next possible value
for(int num=1; num<=9; num++)
if(row_Col(row,col,num))
Board[row][col] = num;
if(solve())
return true;
else
//Backtracking
Board[row][col] = 0;
}//end if
return true;
public String print()
String ans="------------------\n";
for(int count=0; count<9; count++)
for(int count1=0; count1<9; count1++)
ans += Board[count][count1] + "|";
ans += "\n------------------\n";
return ans;
//Programm entry
public static void main(String args[])
Sudoku s = new Sudoku();
String strans;
System.out.println("Sudoku is solving...");
if(s.solve())
strans="Solved\n";
strans+=s.print();
else
strans="No solution\n";
strans+=s.print();
System.out.println(strans);
}go in your printables and adjust day or time
-
Daily Sudoku Will No Longer Print Out
Daily Sudoku worked great for several days after I first got my HP printer. Now it will no longer work--I've tried to set it up again several times to no avail. Please help!
The last thing I want to do is remove web services. It may fix your problem but it will remove your email address so let's try some other steps first. I was able to print the Easy Sudoku and it seems to be up-to-date.
Press the ePrint button and then go into the "Settings." Scroll down until you see "Turn ePrint Off" and follow the prompts to simply turn it off. You should still be in the ePrint Settings so then "Turn ePrint On." It immediately goes back on when you press that so there should be no prompts.
Press the ePrint button again because the back arrow takes you to the main screen. Now "Print Info" page in order to complete the steps to trick the ePrint to communicate with the app. Print Apps are third-party software and it is somewhat difficult to work with them because it's hard to tell if there is a problem on their end.
Try to print the Daily Suduko again and if that does not work, turn the printer off and back on again with the power button. At this point, if you are still having problems let me know what happens when you try to print it and it doesn't work. For example, do you get an error message or does the printer freeze up, etc.?
Don't forgot to say thanks by giving "Kudos" if I helped solve your problem.
When a solution is found please mark the post that solves your issue.
Every problem has a solution! -
How to download sudoku software for 6275 CDMA ?
I wish to download sudoku software for 6275 CDMA.
Please tell me from where ?Hi surrendernot,
It is possible that either a) you were using different scanning software other than HP software for scanning, or b) the HP software is different on Windows 7, than on Windows XP, as they are completely different Operating Systems, and could be a newer version of the software.
Some other methods of scanning can be found within this How to Scan guide, HP Multifunction Printers - How to Scan: Windows 7, you can try scanning without HP software as well.
Hope this answers your question!
RnRMusicMan
I work on behalf of HP
Please click “Accept as Solution ” if you feel my post solved your issue, it will help others find the solution.
Click the “Kudos Thumbs Up" to say “Thanks” for helping! -
Hi Friends ,
I wish to design sudoku internal matrix in gui how to start with any help from u people.
or any link which can teach me how to build a 9 by 9 matrix in graphics and.
Regards,
weakinjavaCan't you just lay out 9 by 9 JLabel fields?Or JTextFields. Then you can actually insert values.
-
Hey am trying to create a GUI for my Sudoku board.
Here is how it currently looks: (See code below)
There are two things I wanna change
1. How do I center align the number so they are not stuck to the right edge as they are now?
2. How do I add a bolder line around blocks/boxes(e.g. the 3*3 sections). Im sure these are pretty easy but havent been able to figure it out as of yet!
Any help would be greatly appreciated.
Code:
package proj.sudoku.gui;
import java.awt.Color;
import java.awt.Component;
import java.awt.Cursor;
import java.awt.Font;
import java.awt.GridBagConstraints;
import java.awt.GridBagLayout;
import java.awt.Insets;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.InputMethodEvent;
import java.awt.event.InputMethodListener;
import java.beans.PropertyChangeEvent;
import java.beans.PropertyChangeListener;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JTable;
import javax.swing.JTextArea;
import javax.swing.JTextField;
import javax.swing.SwingConstants;
import javax.swing.table.AbstractTableModel;
import javax.swing.table.DefaultTableCellRenderer;
import proj.sudoku.representation.Board;
import proj.sudoku.representation.Square;
import proj.sudoku.ui.Sudoku;
public class SudokuGUI extends JFrame implements ActionListener{
private JTextField unfilledSquaresTextField;
private JTextArea messagesTextArea;
private JTable boardTable;
private Board board;
private Sudoku sudoku = new Sudoku();
private int noOfUnfilledSquares = 20;
private static final long serialVersionUID = 1L;
class BoardTableTableModel extends AbstractTableModel {
public final String[] COLUMN_NAMES = { "Row 0", "Row 1", "Row 2", "Row 3", "Row 4", "Row 5", "Row 6", "Row 7", "Row 8"};
public int getRowCount() {
return 9;
public int getColumnCount() {
return COLUMN_NAMES.length;
public String getColumnName(int columnIndex) {
return COLUMN_NAMES[columnIndex];
public Object getValueAt(int rowIndex, int columnIndex) {
int squareValue = board.getSquare(rowIndex, columnIndex).getSquareValue();
if(squareValue == 0){
return null;
}else{
return new Integer(squareValue);
public boolean isCellEditable(int row, int col){
return true;
public void setValueAt(Object value, int row, int col) {
int intValue = ((Integer)value).intValue();
if((intValue >= 0) && (intValue < 10)){
Square square = board.getSquare(row, col);
square.setSquareValue(((Integer)value).intValue());
board.setSquare(square, row, col);
fireTableCellUpdated(row, col);
public Class getColumnClass(int c) {
return Integer.class;
* Create the frame
public SudokuGUI(Board newBoard) {
super();
getContentPane().setBackground(new Color(128, 128, 255));
board = newBoard;
getContentPane().setLayout(new GridBagLayout());
setTitle("Sudoku Sudokme");
setBounds(100, 100, 607, 456);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
final JPanel tablePanel = new JPanel();
tablePanel.setLayout(new GridBagLayout());
final GridBagConstraints gridBagConstraints = new GridBagConstraints();
gridBagConstraints.weighty = 0.5;
gridBagConstraints.weightx = 1;
getContentPane().add(tablePanel, gridBagConstraints);
boardTable = new JTable();
boardTable.setRowHeight(40); // TODO This line has been changed
boardTable.setFont(new Font("", Font.PLAIN, 20));// TODO This line has been changed
boardTable.setCursor(Cursor.getPredefinedCursor(Cursor.TEXT_CURSOR));
boardTable.setRowSelectionAllowed(false);
boardTable.setShowGrid(true);
boardTable.setModel(new BoardTableTableModel());
final GridBagConstraints gridBagConstraints_2 = new GridBagConstraints();
gridBagConstraints_2.gridx = 0;
gridBagConstraints_2.gridy = 0;
gridBagConstraints_2.insets = new Insets(0, -265, 0, 0);// TODO This line has been changed
//gridBagConstraints_2.insets = new Insets(5, -265, 5, 0);
tablePanel.add(boardTable, gridBagConstraints_2);
final JPanel messagesPanel = new JPanel();
messagesPanel.setLayout(new GridBagLayout());
final GridBagConstraints gridBagConstraints_6 = new GridBagConstraints();
gridBagConstraints_6.weighty = 0.3;
gridBagConstraints_6.weightx = 1.0;
gridBagConstraints_6.gridy = 1;
gridBagConstraints_6.gridx = 0;
getContentPane().add(messagesPanel, gridBagConstraints_6);
messagesTextArea = new JTextArea();
messagesTextArea.setAlignmentY(Component.BOTTOM_ALIGNMENT);
messagesPanel.add(messagesTextArea, new GridBagConstraints());
messagesTextArea.setText(board.getMessage());
messagesTextArea.setEditable(false);
final JPanel generateButtonPanel = new JPanel();
generateButtonPanel.setLayout(new GridBagLayout());
final GridBagConstraints gridBagConstraints_3 = new GridBagConstraints();
gridBagConstraints_3.gridy = 2;
gridBagConstraints_3.gridx = 0;
getContentPane().add(generateButtonPanel, gridBagConstraints_3);
final JButton generateEmptyBoardButton = new JButton();
generateEmptyBoardButton.addActionListener(this);
generateEmptyBoardButton.setText("Generate Empty Board");
final GridBagConstraints gridBagConstraints_9 = new GridBagConstraints();
gridBagConstraints_9.gridy = 0;
gridBagConstraints_9.gridx = 0;
generateButtonPanel.add(generateEmptyBoardButton, gridBagConstraints_9);
final JButton generateBoardButton = new JButton();
generateBoardButton.addActionListener(this);
generateBoardButton.setText("Generate Board");
final GridBagConstraints gridBagConstraints_10 = new GridBagConstraints();
gridBagConstraints_10.gridx = 2;
generateButtonPanel.add(generateBoardButton, gridBagConstraints_10);
final JLabel unfilledSquaresLabel = new JLabel();
unfilledSquaresLabel.setText("Unfilled Squares");
final GridBagConstraints gridBagConstraints_11 = new GridBagConstraints();
gridBagConstraints_11.gridy = 0;
gridBagConstraints_11.gridx = 3;
generateButtonPanel.add(unfilledSquaresLabel, gridBagConstraints_11);
unfilledSquaresTextField = new JTextField();
unfilledSquaresTextField.setFont(new Font("", Font.BOLD, 14));
unfilledSquaresTextField.addActionListener(this);
unfilledSquaresTextField.setText(new Integer(noOfUnfilledSquares).toString());
unfilledSquaresTextField.setBackground(Color.WHITE);
final GridBagConstraints gridBagConstraints_12 = new GridBagConstraints();
gridBagConstraints_12.gridy = 0;
gridBagConstraints_12.gridx = 4;
unfilledSquaresLabel.setLabelFor(unfilledSquaresTextField);
generateButtonPanel.add(unfilledSquaresTextField, gridBagConstraints_12);
final JPanel solveButtonsPanel = new JPanel();
solveButtonsPanel.setRequestFocusEnabled(false);
solveButtonsPanel.setLayout(new GridBagLayout());
final GridBagConstraints gridBagConstraints_1 = new GridBagConstraints();
gridBagConstraints_1.weighty = 0.1;
gridBagConstraints_1.weightx = 1;
gridBagConstraints_1.gridy = 3;
gridBagConstraints_1.gridx = 0;
getContentPane().add(solveButtonsPanel, gridBagConstraints_1);
final JButton heuristicsSolveButton = new JButton();
heuristicsSolveButton.addActionListener(this);
heuristicsSolveButton.setText("Heuristics Solve");
final GridBagConstraints gridBagConstraints_4 = new GridBagConstraints();
gridBagConstraints_4.gridx = 0;
solveButtonsPanel.add(heuristicsSolveButton, gridBagConstraints_4);
final JButton bruteForceSolveButton = new JButton();
bruteForceSolveButton.addActionListener(this);
bruteForceSolveButton.setText("Brute Force Solve");
final GridBagConstraints gridBagConstraints_7 = new GridBagConstraints();
gridBagConstraints_7.gridx = 1;
solveButtonsPanel.add(bruteForceSolveButton, gridBagConstraints_7);
final JButton hybridSolveButton = new JButton();
hybridSolveButton.addActionListener(this);
hybridSolveButton.setText("Hybrid Solve");
final GridBagConstraints gridBagConstraints_8 = new GridBagConstraints();
gridBagConstraints_8.gridx = 2;
solveButtonsPanel.add(hybridSolveButton, gridBagConstraints_8);
final JPanel testButtonsPanel = new JPanel();
testButtonsPanel.setLayout(new GridBagLayout());
final GridBagConstraints gridBagConstraints_5 = new GridBagConstraints();
gridBagConstraints_5.weighty = 0.1;
gridBagConstraints_5.weightx = 1.0;
gridBagConstraints_5.gridy = 4;
gridBagConstraints_5.gridx = 0;
getContentPane().add(testButtonsPanel, gridBagConstraints_5);
final JButton checkIfValidButton = new JButton();
checkIfValidButton.addActionListener(this);
checkIfValidButton.setText("Check If Valid");
testButtonsPanel.add(checkIfValidButton, new GridBagConstraints());
final JButton checkIfLegalButton = new JButton();
checkIfLegalButton.addActionListener(this);
checkIfLegalButton.setText("Check If Legal");
testButtonsPanel.add(checkIfLegalButton, new GridBagConstraints());
public static void main(String args[]) {
try {
SudokuGUI frame = new SudokuGUI(new Board());
frame.setVisible(true);
//frame.pack();
} catch (Exception e) {
e.printStackTrace();
public void actionPerformed(ActionEvent arg0) {
if(arg0.getSource().getClass().getName().equals("javax.swing.JTextField")){
noOfUnfilledSquares = new Integer(((JTextField)arg0.getSource()).getText()).intValue();
this.repaint();
}else{
try{
board = sudoku.processGUICommands(board, arg0.getActionCommand(), noOfUnfilledSquares);
messagesTextArea.setText(board.getMessage());
this.repaint();
}catch(Exception e){
e.printStackTrace();
}1) Use the [url http://forum.java.sun.com/help.jspa?sec=formatting]Code Formatting Tags when posting code so the code is readable
2) The code you posted isn't compileable or executable so we see exactly what you layout looks like
3) If you have a Grid type layout, then I would think a GridLayout would be more appropriate to use then the GridBagLayout. Read the Swing tutorial on [url http://java.sun.com/docs/books/tutorial/uiswing/layout/visual.html]How to Use Layout Managers for more information.
How do I add a bolder line around blocks/boxes[url http://java.sun.com/docs/books/tutorial/uiswing/misc/border.htmlHow to Use Borders[/url]
If you need further help then you need to create a [url http://homepage1.nifty.com/algafield/sscce.html]Short, Self Contained, Compilable and Executable, Example Program that demonstrates the incorrect behaviour, because I can't guess exactly what you are doing based on the information provided. -
How should the grid helpers in sudoku be used? I don't know how to select the helper icons at the bottom right of the screen. (Not that I'd need to use the feature, tho, this just bugs me
It's possible that those puzzles are based on Flash, which won't work on the iPad's Safari.
You can look for other browsers, like iSwiffer or Photon that support flash and see if that helps. the easier and possibly cheaper way would be to look if that site has an app, which would allow access to the puzzles without needing flash (if that is indeed the issue) -
Sudoku and Mahjong Error mesages
5th Gen iPod 80Gb with video
software ver: 1.2.3 (current)
Win XP Pro w/SP2
iTunes ver: 7.6.0.29 (Current)
Problem: Sudoku and Mahjong
Both games have worked well in the past. No problems! Lately they will not even load /run on the iPod.
I constantly receive the following:
ERROR
This game cannot be played. Connect your iPod to iTunes and reinstall the
game. For additional information, please visit
http://apple.com/support/ipod/
I had somehow managed to get them going once since my last Apple help assist in Jan of 2008.
Now they will not load at all.
Tried:
Any and all combinations of Sync Games (games won't work)
Re-install iTunes (games won't work)
Restore iPod (games won't work)
Re-install iTunes and Restore iPod (games won't work)
Authorize computer (games won't work)
Re-install iTunes and authorize computer (games won't work)
Restore iPod and authorize computer (games won't work)
Re-install iTunes, restore iPod, authorize computer (games won't work)
Reset iPod w/SELECT+MENU (games won't work)
Reset iPod w/SELECT+MENU and then SELECT+PREVIOUS (games won't work)
Other functions:
All other functions work as intended.
i.e., Calendar, Notes, Music, Podcasts, Movies . . . Even the built-in games. All work fine! (Sudoku and Mahjong games won't work)
What am I doing wrong?!?Nobody knows.
-
Yesterday I've played Sudoku on my Nokia 1650 for the first time. Only played game 1/100. Did get a high score off course, but I was wondering what it meant ;-)
It says e.g.:
#0-24-3:50
I know 3:50 is the time it took me and 24 is the number of moves (puzzle 1 has 24 open squares to fill in). But what does the 0 mean?It's possible that those puzzles are based on Flash, which won't work on the iPad's Safari.
You can look for other browsers, like iSwiffer or Photon that support flash and see if that helps. the easier and possibly cheaper way would be to look if that site has an app, which would allow access to the puzzles without needing flash (if that is indeed the issue) -
Came up with this sudoku game, thought I would share :-) Enjoy
Form1's code:
Option Strict On
Option Explicit On
Option Infer Off
Public Class Form1
Private gameNumbers As New List(Of Integer) From {5, 3, 0, 0, 7, 0, 0, 0, 0, 6, 0, 0, 1, 9, 5, 0, 0, 0, 0, 9, _
8, 0, 0, 0, 0, 6, 0, 8, 0, 0, 0, 6, 0, 0, 0, 3, 4, 0, 0, 8, _
0, 3, 0, 0, 1, 7, 0, 0, 0, 2, 0, 0, 0, 6, 0, 6, 0, 0, 0, 0, _
2, 8, 0, 0, 0, 0, 4, 1, 9, 0, 0, 5, 0, 0, 0, 0, 8, 0, 0, 7, 9}
Private sGame As New SudokuGame(Me, gameNumbers)
Private Sub Form1_SizeChanged(sender As Object, e As EventArgs) Handles Me.SizeChanged
Me.Invalidate()
End Sub
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
Me.DoubleBuffered = True
End Sub
End Class
Sudoku game class
Public Class SudokuGame
Public Property cellHeight As Integer = 20
Public Property cellWidth As Integer = 20
Public Property canvas As Control
Private center As New Point(200, 200)
Private mouseisDown As Boolean = False
Private numbers As New List(Of SudokuGame.NumberCell)
Private numberCells As New List(Of SudokuGame.NumberCell)
Private currentPT As Point = New Point(0, 0)
Private dFont As New Font("segoe script", 12)
Private mousex As Integer
Private mousey As Integer
Friend WithEvents EditTB As New RichTextBox With {.Parent = canvas, .BorderStyle = BorderStyle.None, .Visible = False, .Font = New Font("Consolas", 16), .MaxLength = 1, .Multiline = False, .ForeColor = Color.Red, .BackColor = Color.DarkGoldenrod}
Private editingIndex As Integer = 0
Public Function CanCommitChange(ByRef numbercells As List(Of NumberCell), ByRef numberCell As NumberCell) As Boolean
Dim cellRegionEnum As SudokuRegion = GetCellRegionEnum(numberCell)
Dim cellRegion As List(Of NumberCell) = Me.GetRegion(numbercells, cellRegionEnum)
Dim cellColumn As List(Of NumberCell) = Me.GetColumn(numbercells, numberCell.X)
Dim cellRow As List(Of NumberCell) = Me.GetRow(numbercells, numberCell.Y)
For Each nC As NumberCell In cellRegion
If nC.Value = numberCell.Value Then
If numberCell.Value = 0 Then Continue For
Return False
End If
Next
For Each nC As NumberCell In cellColumn
If nC.Value = numberCell.Value Then
If numberCell.Value = 0 Then Continue For
Return False
End If
Next
For Each nC As NumberCell In cellRow
If nC.Value = numberCell.Value Then
If numberCell.Value = 0 Then Continue For
Return False
End If
Next
Return True
End Function
Function colString(col As List(Of NumberCell)) As String
Dim s As String = String.Empty
For Each n As NumberCell In col
s = s & n.Value
Next
Return s
End Function
Public Function GetCellRegionEnum(numberCell As NumberCell) As SudokuRegion
Dim result As String = String.Empty
Dim tLregion As New List(Of Integer) From {0, 1, 2, 9, 10, 11, 18, 19, 20}
Dim tCregion As New List(Of Integer) From {3, 4, 5, 12, 13, 14, 21, 22, 23}
Dim tRregion As New List(Of Integer) From {6, 7, 8, 15, 16, 17, 24, 25, 26}
Dim cLregion As New List(Of Integer) From {27, 28, 29, 36, 37, 38, 45, 46, 47}
Dim cCregion As New List(Of Integer) From {30, 31, 32, 39, 40, 41, 48, 49, 50}
Dim cRregion As New List(Of Integer) From {33, 34, 35, 42, 43, 44, 51, 52, 53}
Dim bLregion As New List(Of Integer) From {54, 55, 56, 63, 64, 65, 72, 73, 74}
Dim bCregion As New List(Of Integer) From {57, 58, 59, 66, 67, 68, 75, 76, 77}
Dim bRregion As New List(Of Integer) From {60, 61, 62, 69, 70, 71, 78, 79, 80}
Select Case True
Case tLregion.IndexOf(numberCell.ArrayIndex) > -1 : Return SudokuRegion.TopLeft
Case tCregion.IndexOf(numberCell.ArrayIndex) > -1 : Return SudokuRegion.TopCenter
Case tRregion.IndexOf(numberCell.ArrayIndex) > -1 : Return SudokuRegion.TopRight
Case cLregion.IndexOf(numberCell.ArrayIndex) > -1 : Return SudokuRegion.CenterLeft
Case cCregion.IndexOf(numberCell.ArrayIndex) > -1 : Return SudokuRegion.CenterCenter
Case cRregion.IndexOf(numberCell.ArrayIndex) > -1 : Return SudokuRegion.CenterRight
Case bLregion.IndexOf(numberCell.ArrayIndex) > -1 : Return SudokuRegion.BottomLeft
Case bCregion.IndexOf(numberCell.ArrayIndex) > -1 : Return SudokuRegion.BottomCenter
Case bRregion.IndexOf(numberCell.ArrayIndex) > -1 : Return SudokuRegion.BottomRight
End Select
Return Nothing
End Function
Public Function GetColumn(numbercells As List(Of NumberCell), colNumber As Integer) As List(Of NumberCell)
Dim results As New List(Of NumberCell)
For i As Integer = colNumber To 80 Step 9
results.Add(numbercells(i))
Next
Return results
End Function
Public Function GetRow(numbercells As List(Of NumberCell), rowNumber As Integer) As List(Of NumberCell)
Dim start As Integer = rowNumber * 9
Dim results As New List(Of NumberCell)
For I As Integer = start To start + 8
results.Add(numbercells(I))
Next
Return results
End Function
Public Function RegionToString(numbercells As List(Of NumberCell), sRegion As SudokuRegion) As String
Dim region As List(Of NumberCell) = Me.GetRegion(numbercells, sRegion)
Dim sb As New System.Text.StringBuilder
For i As Integer = 1 To region.Count
sb.Append(region(i - 1).Value.ToString)
If i Mod 3 = 0 Then sb.Append(vbCrLf)
Next
Return sb.ToString
End Function
Private Function ZeroCount(s As String) As Integer
Dim result As Integer
For Each c As Char In s
If c = "0"c Then result += 1
Next
Return result
End Function
Public Function GetRegion(numbercells As List(Of NumberCell), region As SudokuRegion) As List(Of NumberCell)
Dim c As List(Of NumberCell) = numbercells
Select Case region
Case SudokuRegion.Top
Case SudokuRegion.TopCenter : Return {c(3), c(4), c(5), c(12), c(13), c(14), c(21), c(22), c(23)}.ToList
Case SudokuRegion.TopRight : Return {c(6), c(7), c(8), c(15), c(16), c(17), c(24), c(25), c(26)}.ToList
Case SudokuRegion.Center
Case SudokuRegion.CenterCenter : Return {c(30), c(31), c(32), c(39), c(40), c(41), c(48), c(49), c(50)}.ToList
Case SudokuRegion.CenterRight : Return {c(33), c(34), c(35), c(42), c(43), c(44), c(51), c(52), c(53)}.ToList
Case SudokuRegion.Bottom
Case SudokuRegion.BottomCenter : Return {c(57), c(58), c(59), c(66), c(67), c(68), c(75), c(76), c(77)}.ToList
Case SudokuRegion.BottomRight : Return {c(60), c(61), c(62), c(69), c(70), c(71), c(78), c(79), c(80)}.ToList
End Select
Return New List(Of NumberCell)
End Function
Public Enum SudokuRegion
TopLeft
TopCenter
TopRight
CenterLeft
CenterCenter
CenterRight
BottomLeft
BottomCenter
BottomRight
End Enum
Public Function renderSudakoCard(g As Graphics, center As Point, frameSize As Size, backColor As Color, numbers As List(Of NumberCell), font As Font) As List(Of NumberCell)
Dim results As New List(Of NumberCell)
Dim boldEveryNLines As Integer = 3
Dim BoldLines As Boolean = True
Dim rowCount As Integer = 9
Dim columnCount As Integer = 9
g.Clear(backColor)
Dim combo As String = "000000"
If rowCount Mod 2 = 1 Then combo = combo & "1" Else combo = combo & "0"
If columnCount Mod 2 = 1 Then combo = combo & "1" Else combo = combo & "0"
If cellHeight Mod 2 = 1 Then cellHeight += 1
If cellWidth Mod 2 = 1 Then cellWidth += 1
Select Case Convert.ToInt32(combo, 2)
Case 0
Dim centerX As Integer = center.X
Dim centerY As Integer = center.Y
Dim topY As Integer = centerY - ((rowCount \ 2) * cellHeight)
Dim bottomY As Integer = centerY + ((rowCount \ 2) * cellHeight)
Dim leftX As Integer = centerX - ((columnCount \ 2) * cellWidth)
Dim rightX As Integer = centerX + ((columnCount \ 2) * cellWidth)
RenderBackGround(g, topY, bottomY, leftX, rightX)
DrawLines(g, leftX, rightX, topY, bottomY, boldEveryNLines, BoldLines)
results.AddRange(DrawNumbers(g, numbers, topY, leftX, font))
Case 1
Dim centerX As Integer = center.X
Dim centerY As Integer = center.Y
Dim topY As Integer = centerY - ((rowCount \ 2) * cellHeight)
Dim bottomY As Integer = centerY + ((rowCount \ 2) * cellHeight)
Dim remainderColumns As Integer = (columnCount - 1) \ 2
Dim leftX As Integer = (centerX - (cellWidth \ 2)) - (remainderColumns * cellWidth)
Dim rightX As Integer = (centerX + (cellWidth \ 2)) + (remainderColumns * cellWidth)
RenderBackGround(g, topY, bottomY, leftX, rightX)
DrawLines(g, leftX, rightX, topY, bottomY, boldEveryNLines, BoldLines)
results.AddRange(DrawNumbers(g, numbers, topY, leftX, font))
Case 2
Dim centerX As Integer = center.X
Dim centerY As Integer = center.Y
Dim remainderRows As Integer = (rowCount - 1) \ 2
Dim topY As Integer = (centerY - (cellHeight \ 2)) - (remainderRows * cellHeight)
Dim bottomY As Integer = (centerY + (cellHeight \ 2)) + (remainderRows * cellHeight)
Dim leftX As Integer = centerX - ((columnCount \ 2) * cellWidth)
Dim rightX As Integer = centerX + ((columnCount \ 2) * cellWidth)
RenderBackGround(g, topY, bottomY, leftX, rightX)
DrawLines(g, leftX, rightX, topY, bottomY, boldEveryNLines, BoldLines)
results.AddRange(DrawNumbers(g, numbers, topY, leftX, font))
Case 3
Dim centerX As Integer = center.X
Dim centerY As Integer = center.Y
Dim remainderRows As Integer = (rowCount - 1) \ 2
Dim topY As Integer = (centerY - (cellHeight \ 2)) - (remainderRows * cellHeight)
Dim bottomY As Integer = (centerY + (cellHeight \ 2)) + (remainderRows * cellHeight)
Dim remainderColumns As Integer = (columnCount - 1) \ 2
Dim leftX As Integer = (centerX - (cellWidth \ 2)) - (remainderColumns * cellWidth)
Dim rightX As Integer = (centerX + (cellWidth \ 2)) + (remainderColumns * cellWidth)
RenderBackGround(g, topY, bottomY, leftX, rightX)
DrawLines(g, leftX, rightX, topY, bottomY, boldEveryNLines, BoldLines)
results.AddRange(DrawNumbers(g, numbers, topY, leftX, font))
End Select
Return results
End Function
Private Sub RenderBackGround(g As Graphics, topY As Integer, bottomY As Integer, LeftX As Integer, RightX As Integer)
Dim left As Integer = LeftX - 5
Dim top As Integer = topY - 5
Dim width As Integer = (RightX - left) + 5
Dim height As Integer = (bottomY - top) + 5
Dim backGround As New Rectangle(left, top, width, height)
g.FillRectangle(Brushes.White, backGround)
End Sub
Public Function GetCellAt(arr As List(Of NumberCell), location As Point) As NumberCell
Dim index As Integer = (location.Y * 9) + location.X
Return arr(index)
End Function
Private Sub DrawLines(g As Graphics, leftX As Integer, rightX As Integer, topY As Integer, bottomY As Integer, boldEveryNLines As Integer, boldLines As Boolean)
Dim cnt As Integer = 0
Dim sudPen As New Pen(Brushes.OliveDrab, 2)
For x As Integer = leftX To rightX Step cellWidth
Dim p1 As New Point(x, topY)
Dim p2 As New Point(x, bottomY)
If cnt Mod boldEveryNLines = 0 AndAlso boldLines = True Then
g.DrawLine(sudPen, p1, p2)
Else
g.DrawLine(Pens.Black, p1, p2)
End If
cnt += 1
Next
cnt = 0
For y As Integer = topY To bottomY Step cellHeight
Dim p1 As New Point(leftX, y)
Dim p2 As New Point(rightX, y)
If cnt Mod boldEveryNLines = 0 AndAlso boldLines = True Then
g.DrawLine(sudPen, p1, p2)
Else
g.DrawLine(Pens.Black, p1, p2)
End If
cnt += 1
Next
End Sub
Private Function DrawNumbers(g As Graphics, numbers As List(Of NumberCell), topY As Integer, leftX As Integer, font As Font) As List(Of NumberCell)
Dim results As New List(Of NumberCell)
Dim counter As Integer = 1
Dim txtY As Integer = topY + (cellHeight \ 2)
Dim locX As Integer = 0
Dim locY As Integer = 0
For I As Integer = 0 To numbers.Count - 1
Dim n As Integer = numbers(I).Value
Dim x As Integer = (leftX - (cellWidth \ 2)) + (cellWidth * counter)
Dim nString As String = n.ToString
Dim textSizeF As SizeF = g.MeasureString(nString, font)
Dim textSize As Size = New Size(CInt(textSizeF.Width), CInt(textSizeF.Height))
Dim nX As Integer = x - (textSize.Width \ 2)
Dim nY As Integer = txtY - (textSize.Height \ 2)
Dim cX As Integer = leftX + (cellWidth * counter) - cellWidth
Dim cy As Integer = txtY - (cellHeight \ 2)
Dim cR As New Rectangle(cX, cy, cellWidth, cellHeight)
Dim nCell As New NumberCell(n, I)
nCell.Locked = numbers(I).Locked
nCell.Bounds = cR
nCell.X = locX
nCell.Y = locY
results.Add(nCell)
locX += 1
counter += 1
If counter Mod 10 = 0 Then
txtY += cellHeight
locY += 1
locX = 0
counter = 1
End If
If n = Nothing OrElse n = 0 Then Continue For
If nCell.Locked = True Then
g.DrawString(nString, font, Brushes.Black, New Point(nX, nY))
Else
g.DrawString(nString, New Font(font.FontFamily, font.Size, FontStyle.Bold), Brushes.Green, New Point(nX, nY))
End If
Next
Return results
End Function
Public Class NumberCell
Public Property Bounds As New Rectangle
Public Property ArrayIndex As Integer
Public Property Value As Integer
Public Property Locked As Boolean = False
Public Property X As Integer
Public Property Y As Integer
Sub New(value As Integer, ArrayIndex As Integer)
Me.Value = value
Me.ArrayIndex = ArrayIndex
If value = 0 Then
Me.Locked = False
Else
Me.Locked = True
End If
End Sub
Public Function IntersectsWith(pt As Point) As Boolean
Return Bounds.IntersectsWith(New Rectangle(pt, New Size(1, 1)))
End Function
Public Shadows Function ToString() As String
Return String.Format("Value={0} ArrayIndex={1} {2} X={3} Y={4}", Me.Value, Me.ArrayIndex, Me.Bounds.ToString, Me.X, Me.Y)
End Function
End Class
Sub AddHandlers()
AddHandler canvas.MouseClick, AddressOf canvas_MouseClick
AddHandler canvas.Paint, AddressOf canvas_Paint
AddHandler canvas.MouseMove, AddressOf canvas_MouseMove
AddHandler canvas.MouseUp, AddressOf canvas_MouseUp
AddHandler canvas.MouseDown, AddressOf canvas_MouseDown
End Sub
Private Sub canvas_MouseClick(sender As Object, e As MouseEventArgs)
If e.Button = Windows.Forms.MouseButtons.Right Then Exit Sub
For Each n As SudokuGame.NumberCell In numberCells
If n.IntersectsWith(currentPT) Then
If Not n.Locked Then
If n.Value > 0 Then
EditTB.Text = n.Value.ToString
Else
EditTB.Text = ""
End If
EditTB.Visible = True
EditTB.Width = n.Bounds.Width - 1
EditTB.Height = n.Bounds.Height - 1
EditTB.Left = n.Bounds.X + 1
EditTB.Top = n.Bounds.Y + 1
EditTB.Focus()
EditTB.SelectionStart = 0
EditTB.SelectionLength = EditTB.Text.Length
editingIndex = n.ArrayIndex
Else
EditTB.Visible = False
End If
canvas.Invalidate()
Exit For
Else
End If
Next
End Sub
Private Sub canvas_Paint(sender As Object, e As PaintEventArgs)
canvas.Text = "Sudoku v0.1 by Paul Ishak"
numberCells = Me.renderSudakoCard(e.Graphics, center, canvas.ClientRectangle.Size, canvas.BackColor, numbers, dFont)
e.Graphics.DrawString("Use the RIGHT mouse button to drag the sudoku grid.", New Font("segoe script", 12), Brushes.Black, New Point(5, 5))
End Sub
Sub CommitChange()
If Not EditTB.Text = "" Then
Try
Dim tmp As SudokuGame.NumberCell = numberCells(editingIndex)
Dim intValue As Integer = 0
Integer.TryParse(EditTB.Text, intValue)
If intValue > 9 Then intValue = 9
Dim newCell As New SudokuGame.NumberCell(intValue, tmp.ArrayIndex)
newCell.Bounds = tmp.Bounds
newCell.Locked = tmp.Locked
newCell.X = tmp.X
newCell.Y = tmp.Y
If Me.CanCommitChange(numberCells, newCell) Then
numbers(editingIndex) = newCell
numberCells(editingIndex) = newCell
EditTB.Text = ""
EditTB.Visible = False
canvas.Invalidate()
Else
EditTB.Text = ""
EditTB.Visible = False
Beep()
canvas.Invalidate()
End If
Catch ex As Exception
MsgBox(ex.Message)
End Try
End If
End Sub
Public Function configureGame(gameNumbers As List(Of Integer)) As List(Of SudokuGame.NumberCell)
Dim result As New List(Of SudokuGame.NumberCell)
For I As Integer = 1 To 81
result.Add(New SudokuGame.NumberCell(gameNumbers(I - 1), I - 1))
Next
Return result
End Function
Private Sub canvas_MouseMove(sender As Object, e As MouseEventArgs)
Dim pt As Point = canvas.PointToClient(Control.MousePosition)
currentPT = pt
If mouseisDown Then
center = pt
canvas.Invalidate()
Else
End If
End Sub
Private Sub canvas_MouseUp(sender As Object, e As MouseEventArgs)
mouseisDown = False
End Sub
Private Sub canvas_MouseDown(sender As Object, e As MouseEventArgs)
If e.Button = Windows.Forms.MouseButtons.Right Then
EditTB.Visible = False
mouseisDown = True
ElseIf e.Button = Windows.Forms.MouseButtons.Left Then
End If
End Sub
Private Sub EditTB_KeyDown(sender As Object, e As KeyEventArgs) Handles EditTB.KeyDown
Select Case True
Case e.KeyCode = Keys.Enter
End Select
End Sub
Private Sub EditTB_KeyUp(sender As Object, e As KeyEventArgs) Handles EditTB.KeyUp
CommitChange()
End Sub
Sub New(canvas As Control, gameNumbers As List(Of Integer))
Me.canvas = canvas
EditTB.Parent = canvas
AddHandlers()
numbers = configureGame(gameNumbers)
End Sub
End Class
“If you want something you've never had, you need to do something you've never done.”
Don't forget to mark
helpful posts and answers
! Answer an interesting question? Write a
new article
about it! My Articles
*This post does not reflect the opinion of Microsoft, or its employees.Have you tried searching for the error message? A few min on google gives some useful advice.
http://stackoverflow.com/questions/14527201/vhdl-assigning-default-values
"All entity inputs must have either a signal driving them, or a default value specified in the entity declaration." -
Hi Guys. I've read most of the posts as far as the 8320 Cruve and installing Sudoku.
I had no problem installing or downloading. Everything went fine.
The first few Sudoku games went well. But now when I try to play the game it shows a blank screen, or it boots up game #0 and I can't seem to do anything but back out (and that's a chore sometiems too).
Anyone else had this problem? I know I downloaded the 8300 series sudoku.
Any help would be great.
DrewThese may help. The Vita/Win& one gives a link for XP.
iTunes for Windows Vista or Windows 7: Troubleshooting unexpected quits, freezes, or launch issues
iPhone, iPad, or iPod touch: Windows displays a blue screen message or restarts when connecting your device
Maybe you are looking for
-
Hello I am familiar with how to combine several pdfs into one pdf, and I love the Bookmarks as a built-in navigation panel for my project. Now I'm trying to integrate the next step. My goal is a cd with 3 items in the navigation panel: book 1 (from
-
Right clicking causes WindowServer hang
Hi there, I'm running an nVidia GTX 285 and a GT 120 in my 2008 Mac Pro, with 32GB RAM and a RAID 0 setup. Lately, on my third screen solely powered by the GT 120, right-clicking has caused a brief flash of white (usually a square the same size as th
-
How to update data and create notification no using isr fm.
Hi, Without creating the scenario in SFP, is it possible to update data directly in ISR_SPECIAL_DATA_SET, i want to use fm ISR_SPECIAL_DATA_GET in my program. i'm trying to achive same using ISR_NOTIFICATION_CREATE and built general, special table an
-
Alternative to native, dynamic sql to return a ref cursor to a client
I'm on Oracle 8.0.4, and would like to pass a string of values like '1,2,7,100,104' that are the primary key for a table. Then use something like: procedure foo( MyCur RefCurType, vKey varchar2) begin open MyCur for 'select names from SomeTable' | |
-
Not Able to Create database objects(Tables, etc) in Oracle 12c
Hello Sir, Recently, I have installed oracle 12c in my PC. And I am able to connect with the ANONYMOUS user and connection name ORCL. But I am not able to create any objects in database like tables creation, it's just showing the error message like-