-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgame.h
102 lines (82 loc) · 2.76 KB
/
game.h
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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
#ifndef GAME_H_
#define GAME_H_
#include "parser.h"
/*
* Struct: Cell
* Used to represent a cell in the board.
*
* value: an integer with the cell's current valuel
* isFixed: represents if the cell's value is fixed or not. 1 means it's fixed, 0 means it's not.
*/
typedef struct cell_t{
int value;
int isFixed;
} Cell;
/*
* Struct: Board
* Represents a sudoku board.
*
* current_board: a 2D Cell array, representing the state of the actual board the user tries to solve.
* solution: a 2D Cell array, representing a possible solution to the game board.
* board_size: the dimension of the game board - amount of rows and of columns.
* block_rows: the amount of rows in one block.
* block_cols: the amount of columns in one block.
* num_empty_cells_current: the amount of empty cells the current_board has at given time.
* num_empty_cells_solution: for use while computing initial backtrack solution.
* the amount of empty cells left in solution board.
*/
typedef struct board_t{
Cell** current_board;
Cell** solution;
int board_size; /* number of rows and columns of game board */
int block_rows;
int block_cols;
int num_empty_cells_current;
int num_empty_cells_solution;
} Board;
/*
* Receives dimensions of the wanted board and the blocks in the board.
* Returns a pointer to a Board struct, with the current game board and solution board set to default (all zeros).
*/
Board* create_blank_board(int boardSize,int blockRows, int blockCols);
Cell** copy_game_board(Cell** game_board, int board_size);
/*
* Generates a game board with fixed cells according to user input.
*
* Gets a pointer to an already created blank Board.
* generates a randomized full legal board and stores it in solution.
*/
void generate_user_board(Board *originalBoard);
/*
*Recieves given command from user, and implements it appropriately.
*/
void execute_command(Command* command, Board* board);
/*
* Gets a pointer to a cell, and initializes it with given value.
* fixed == 1 means cell is fixed; fixed == 0 means cell is not fixed
* Initializes as non fixed cell.
*/
void createCell(Cell* cell,int val);
/*
* Destroys properly a given game board, freeing all allocated resources.
*/
void destroy_game_board(Cell** board, int size);
/*
* Destroys properly a given Board, freeing all allocated resources.
*/
void destroyBoard(Board* b);
/*
* Prints the given board.
* if type == 1: prints the board's known solution.
* otherwise, prints board's current state board.
*/
void printBoard(Board* b, int type);
/*
* Creates and returns a duplicate of a given game_board. (the actual matrix of cells, not Board).
*/
Cell** copy_game_board(Cell** game_board, int board_size);
/*
* Exits gracfully from game
*/
void exit_game(Board* board);
#endif