Click here to Skip to main content
15,849,494 members
Please Sign up or sign in to vote.
4.00/5 (1 vote)
See more:
Hello,

First time posting a question:

I am trying to code a simple Sudoku game that is 4x4 instead of the 9x9, such that it has 4 rows and 4 columns that are divided into 4 2x2 sections.

I can generate random numbers fine, but I need to code it so that no number in a row, column and section are duplicated.

The variable for the individual tiles is Dim'd As Integer, and set up as follows:

Dim int13A As Integer

The design is: int(Row)(Column)(Section) so "int13A" is located at Row 1, Column 3,
Section A.

My code for each array is this, with appropriate names for each:


Dim arrRow1(3) As Integer
    arrRow1(0) = int11A
    arrRow1(1) = int12A
    arrRow1(2) = int13B
    arrRow1(3) = int14B
    Array.Sort(arrRow1)

If arrRow1(0) = 1 And arrRow1(1) = 2 And arrRow1(2) = 3 And arrRow1(3) = 4 Then
    blnRow1 = True
Else
    blnRow1 = False
End If


I have a Do - Loop Until blnValidGrid = True that looks for True for each row 1-4, then each column 1-4 and then each block 1-4; if all return true, I get the blnValidGrid = True. If not, it regenerates the grid and attempts to validate again.

I am missing something somewhere cause it just goes into an infinite loop... :(

Any thoughts??

Thanks,

Hank
Posted
Updated 12-Mar-13 4:13am
v3

I'll be honest, first time using this so I am not sure what you mean by "hashtable"... Pretty novice, but getting better every day!
 
Share this answer
 
Comments
Darkness_07 12-Mar-13 9:55am    
Try to use Randomize

And do this...instead of declaring the array one by one

Dim arrow1() as integer
Dim x as integer
Dim y as integer

Randomize

for x=0 to 3
for y=0 to 3
arrow1(x,y)=int(4 * Rnd +1)
next y
next x

4 is you rows and columns and the range of your sudoku number.
(Suggestion)
hi HenryCasch
you can hashtable for insert data
 
Share this answer
 
Comments
[no name] 12-Mar-13 9:14am    
and how will it solve the problem?

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900