COMP2017 / COMP9017
MAX_ADJACENT is a constant integer that will be available as a preprocessor #define when your
code is tested, representing the maximum space to store cells adjacent to the given cell. This may be
less than the actual number of adjacent cells depending on the dimensionality of the game; however
you are always guaranteed enough space to store pointers to adjacent cells.
MAX_DIM is a constant integer that will be available as a preprocessor #define when your code is
tested, representing the maximum space to store coordinates representing a cell. The actual number
of coordinates required is equal to the number of dimensions of the game; however you are always
guaranteed enough space to store coordinates.
mined is an integer that is either 0 (no mine present at this cell) or 1 (mine present).
selected is an integer that is either 0 (not selected) or 1 (selected). It represents whether the cell
has been selected, whether by the player or automatically.
num_adjacent is an integer equal to the number of cells adjacent to this one.
adjacent is an array of pointers to the structs representing all adjacent cells to this one, in arbitrary
order.
coords is an array of integers representing the coordinates of the current cell.
hint is an integer that represents the number of adjacent mined cells to the current cell.
Implement the following functions for your ND-Minesweeper game. Do not write any main() func-
tion; your code will be tested by directly calling the functions you implement.
Initialisation
void init_game(struct cell * game, int dim, int * dim_sizes, int num_mines,
int ** mined_cells);
This function will be called first, exactly once at the start of the game.
dim provides you with the number of dimensions of this game, and dim_sizes is an array of dim
integers representing the size of the grid (i.e. number of cells) in each respective dimension.
mined_cells is a num_mines sized array of dim sized integer arrays, which represents a num_mines
sized array of coordinates of cells that contain mines.
Using the example grid above, the parameters would be: dim = 2, dim_sizes = {6,4},
num_mines = 2, mined_cells = {{1,3}, {2,2}}.
Your function must write a struct cell for each cell in the grid to the array game, which is guar-
anteed to have enough memory for the number of cells in the grid. You do not have to add structs
into the array in any defined order, but there must not be any empty array entries between structs.
For a suggestion on how to order the game array, see the Notes and Hints section at the end of this
document. However you must ensure the following values for struct fields:
All cells must be initialised to selected = 0.
Mined cells must have mined = 1, all others mined = 0.
adjacent must contain the correct pointers to all the struct cells in the game array representing
adjacent cells of a given cell. This depends on where you store the corresponding struct cells
in the array game, which is up to you. You must also ensure the num_adjacent field contains
Page 5 of 8