Data structure in Sudoku game

Hello!
I want to know if you have made Sudoku game in c++, which kind of data structure did you use? please explain shortly, which part of the game did you use for?
[Array, Stack, Queue, Linked List, Binary Search Tree]
I haven't, but an array makes the most sense to me.
i would use a dimentional short array:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
short a,b,c,d,e,f,g,h,i;
    
    short a1,a2,a3 , a4,a5,a6 , a7,a8,a9,
          b1,b2,b3 , b4,b5,b6 , b7,b8,b9,
          c1,c2,c3 , c4,c5,c6 , c7,c8,c9,
          
          d1,d2,d3 , d4,d5,d6 , d7,d8,d9,
          e1,d2,d3 , d4,d5,d6 , d7,d8,d9,
          f1,f2,f3 , f4,f5,f6 , f7,f8,f9,
          
          g1,g2,g3 , g4,g5,g6 , g7,g8,g9,
          h1,h2,h3 , h4,h5,h6 , h7,h8,h9,
          i1,i2,i3 , i4,i5,i6 , i7,i8,a9};
          
    short SudokuArray [a] [b] [c] [d] [e] [f] [g] [h] [i] = {a1,a2,a3 , a4,a5,a6 , a7,a8,a9},
                                                            {b1,b2,b3 , b4,b5,b6 , b7,b8,b9},
                                                            {c1,c2,c3 , c4,c5,c6 , c7,c8,c9},
                                                            
                                                            {d1,d2,d3 , d4,d5,d6 , d7,d8,d9},
                                                            {e1,d2,d3 , d4,d5,d6 , d7,d8,d9},
                                                            {f1,f2,f3 , f4,f5,f6 , f7,f8,f9},
                                                            
                                                            {g1,g2,g3 , g4,g5,g6 , g7,g8,g9},
                                                            {h1,h2,h3 , h4,h5,h6 , h7,h8,h9},
                                                            {i1,i2,i3 , i4,i5,i6 , i7,i8,a9};
@miladrahimi93

I used two int arrays. Created and zeroed them.
1
2
int sudoku_board[9][9] = {0};
int start_board[9][9] = {0};


I first put the starting numbers into the start_board array, so they cannot be changed later in the game. After finishing the initial game board, then copy those numbers into the actual sudoku_board. Before allowing any changes in the playing board, you check to make sure it's legal by checking that square in the start_board. If there is a number, other than zero, no additions or changes are allowed in the sudoku_board.
I think it would be better to use chars than ints because then you can set blank squares to ' ' and when you print out the board you can just print out the chars.
I think that you can create an array with 3 dimensions, something like that:

short sod[3][3][9] , the structure of the matrix must to be like this:

0 0 0-----0 0 0------0 0 0
0 0 0-----0 0 0------0 0 0
0 0 0-----0 0 0------0 0 0
| | | | | | | | |
0 0 0-----0 0 0------0 0 0
0 0 0-----0 0 0------0 0 0
0 0 0-----0 0 0------0 0 0
| | | | | | | | |
0 0 0-----0 0 0------0 0 0
0 0 0-----0 0 0------0 0 0
0 0 0-----0 0 0------0 0 0

with a simple code, you can sequentially do all the necessary checks as the player enters the data.

TO Yay295: That's correct, but the data storage will be more difficult, you can create an if verification with the zeros (white spaces in the sudoku):

1
2
3
4
if(sod[i][j][k]==0)
{
     printf("%c",32)
}
Last edited on
Topic archived. No new replies allowed.