Game library

Hello. I want to create sudoku game. I am thinking which game library choose. Maybe Allegro? Anyone know good book/course about creating games in Allegro ? Thanks for answer !
If only there were a tutorials section....
https://liballeg.org/

I start from create matrix 9x9 and I am wondering how to fill this matrix. It is quite hard because in every new game this matrix should be filling new numbers but I can't just fill matrix random numbers because in each matrix 3x3 numbers have to be diffrent
The easiest thing to do is to break the 9x9 array into a 3x3 array of 3x3 arrays.
Here's something to get you started. Not terribly efficient, but generates unique 3x3 grids that add up to 15. Note: A nonet is a 3x3 grid.

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
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
#include <cstdlib>

class nonet
{	int 	m_cells[3][3] = {};

public:
	bool is_legal ();
	void populate ();
};

//	Test if the cells in the 3x3 grid are a legal 3x3 array
bool nonet::is_legal ()
{	int	used[10] = {};	//	0 not used
	int row_sum; 
	int col_sum;
	
	//	Check that each cell is unique
	for (int r=0; r<3; r++)
	{	for (int c=0; c<3; c++)
		{	//	Mark the numbers used
			if (used[m_cells[r][c]])
				return false;
			used[m_cells[r][c]]++;
		}
	}	
	//	Check if the all the rows add up to 15
	for (int r=0; r<3; r++)
	{	row_sum = 0;
		for (int c=0; c<3; c++)
			row_sum += m_cells[r][c];
		if (row_sum != 15)
			return false;
	}
	//	Check that all the columns add up to 15
	for (int c=0; c<3; c++)
	{	col_sum = 0;
		for (int r=0; r<3; r++)
			col_sum += m_cells[r][c];
		if (col_sum != 15)
			return false;	
	}
	//	Passes all the tests
	return true;
}

void nonet::populate ()
{	do	//	iterate until we have a legal nonet 
	{	for (int r=0; r<3; r++)
			for (int c=0; c<3; c++)
				m_cells[r][c] = rand() % 9 + 1;
	} while (! is_legal());
}


The next step is to create a grid class that consts of a 3x3 array of nonets.
Use the same idea to make sure each nonet is unique within the 3x3 array of nonets.
Topic archived. No new replies allowed.