-
Notifications
You must be signed in to change notification settings - Fork 0
/
methods.h
132 lines (119 loc) · 4.77 KB
/
methods.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
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
#ifndef LIBS_GAME_METHODS_H_INCLUDED
#define LIBS_GAME_METHODS_H_INCLUDED
#include "../patterns/main.h"
#include "./structs.h"
/**
* @brief Counts the number of alive neighbors around a given position inside the `dashboard` field
* of a Conway's Game of Life structure.
*
* This function iterates through the cells within a specified radius around the given cell
* (excluding the cell itself) and counts how many of those cells are alive.
*
* @param pGame Pointer to the Conway's Game of Life structure.
* @param row Row index of the cell.
* @param col Column index of the cell.
* @param radius Radius around the cell to check for alive neighbors.
*
* @return The number of alive neighbors around the specified cell.
*
* @warning This function assumes that `pGame` has been properly initialized.
*/
int countAliveNeighbors(TGame* pGame, const int row, const int col, const int radius);
/**
* @brief Draws a specified pattern on a Conway's Game of Life board.
*
* @param pGame Pointer to the Conway's Game of Life structure where the pattern will be drawn.
* @param pattern Pattern to be drawn.
*
* @warning The pattern must be one of the following: `glider`, `toad`, `beacon`, or `glider
* cannon`. If the number of rows or columns of the Conway's Game of Life board are less than the
* number of rows or columns of the pattern, the board will be resized to match the pattern's
* dimensions.
*/
void drawPattern(TGame* pGame, const char* pattern);
/**
* @brief Draws a specified pattern on a Conway's Game of Life board.
*
* @param pGame Pointer to the Conway's Game of Life structure where the pattern will be drawn.
* @param pPattern Pointer to pattern structure to be drawn.
*
* @warning This functions is intended for internal use only and should not be used outside of this
* library.
*/
void drawPatternInDashboard(TGame* pGame, TPattern* pPattern);
/**
* @brief Fills the dashboard of a Conway's Game of Life structure with a
* specified value.
*
* @param pGame A pointer to the Conway's Game of Life structure.
* @param with The value to fill the dashboard with.
*
* @warning This function assumes that `pGame` has been
* properly initialized.
*/
void fillDashboard(TGame* pGame, const char with);
/**
* @brief Generates the next generation of a Conway's Game of Life.
*
* This function updates the `dashboard` field inside a Conway's Game of Life structure to the next
* generation based on the current state.
*
* @param pGame A pointer to the Conway's Game of Life structure.
*
* @warning This function assumes that `pGame` has been properly initialized.
*/
void generateNextGeneration(TGame* pGame);
/**
* @brief Prints the dashboard of a Conway's Game of Life structure by console.
*
* @param pGame A pointer to the Conway's Game of Life structure.
*
* @warning This function assumes that `pGame` has been properly initialized.
*/
void printDashboardByConsole(TGame* pGame);
/**
* @brief Prints a Conway's Game of Life by console.
*
* This function takes a pointer to a Conway's Game of Life structure and prints its details
* to the console.
*
* @param pGame A pointer to the Conway's Game of Life structure.
*
* @warning This function assumes that `pGame` has been properly initialized.
*/
void printGameByConsole(TGame* pGame);
/**
* @brief Sets the center of a Conway's Game of Life structure.
*
* @param pGame A pointer to the Conway's Game of Life structure.
*
* @warning This function assumes that `pGame` has been properly initialized with valid `rows` and
* `cols` field values.
*/
void setDashboardCenter(TGame* pGame);
/**
* @brief Sets a Conway's Game of Life dashboard based on a file.
*
* This function reads a file content and updates a Conway's Game of Life structure with the parsed
* content to set the dashboard. Also, it modifies the `rows`, `cols`, `center`, `cellsAlive`, and
* `cellsDead` field of the Conway's Game of Life structure.
*
* @param filePath File path with the content to be parsed.
* @param pGame Pointer to the Conway's Game of Life structure.
* @param minRows Minimum number of rows for the dashboard.
* @param minCols Minimum number of columns for the dashboard.
*
* @return Returns `1` on success, otherwise returns `0`.
*/
int setDashboardFromFile(const char* filePath, TGame* pGame, const int minRows, const int minCols);
/**
* @brief Starts a Conway's Game of Life game using the console as the output.
*
* @param pGame Pointer to a Conway's Game of Life structure.
* @param maxGeneration Maximum number of generations.
* @param delayBetweenGenerations Delay in milliseconds between each generation.
*
* @warning This function assumes that `pGame` has been properly initialized.
*/
void startGameByConsole(TGame* pGame, const int maxGeneration, const int delayBetweenGenerations);
#endif // LIBS_GAME_MAIN_H_INCLUDED