From 48f2a3decb21fb9ebf4590b3ab60c73037b17815 Mon Sep 17 00:00:00 2001 From: Guidolinares Date: Sun, 8 Sep 2024 21:07:17 -0300 Subject: [PATCH 01/99] guido first commit --- README.md | 6 +++--- libs/utilities.c | 8 ++++++++ libs/utilities.h | 1 + 3 files changed, 12 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 1b7fbca..3db1835 100644 --- a/README.md +++ b/README.md @@ -156,7 +156,7 @@ C-Practical-Work-2024/ commit commit checkout develop - branch TODO_02 + branch Guidolinares commit commit checkout develop @@ -172,7 +172,7 @@ C-Practical-Work-2024/ commit commit checkout develop - merge TODO_02 + merge Guidolinares merge TODO_01 merge TODO_03 merge TODO_05 @@ -196,7 +196,7 @@ C-Practical-Work-2024/ ## Development Team - [TODO_01](TODO) -- [TODO_02](TODO) +- [Guidolinares](https://www.linkedin.com/in/guido-linares-25859b209/) - [TODO_03](TODO) - [TODO_04](TODO) - [TODO_05](TODO) diff --git a/libs/utilities.c b/libs/utilities.c index 2ef3375..03d7a9c 100644 --- a/libs/utilities.c +++ b/libs/utilities.c @@ -12,3 +12,11 @@ int getStrLength(char* str) { } void sayhi() { printf("hello guys"); } + + + + + +void sayGuido() +{ printf("hello maquinas"); } + diff --git a/libs/utilities.h b/libs/utilities.h index ced1c89..ad53efd 100644 --- a/libs/utilities.h +++ b/libs/utilities.h @@ -18,5 +18,6 @@ int getStrLength(char* str); void sayhi(); +void sayGuido(); #endif // UTILITIES_H_INCLUDED From 01eba8a73a5129509fc66ae55eda0c513dde03d1 Mon Sep 17 00:00:00 2001 From: hozlucas28 Date: Sun, 8 Sep 2024 21:11:50 -0300 Subject: [PATCH 02/99] fix: remove unnecessary functions --- libs/utilities.c | 12 +----------- libs/utilities.h | 3 --- 2 files changed, 1 insertion(+), 14 deletions(-) diff --git a/libs/utilities.c b/libs/utilities.c index 03d7a9c..0ce0795 100644 --- a/libs/utilities.c +++ b/libs/utilities.c @@ -9,14 +9,4 @@ int getStrLength(char* str) { }; return length; -} - -void sayhi() { printf("hello guys"); } - - - - - -void sayGuido() -{ printf("hello maquinas"); } - +} \ No newline at end of file diff --git a/libs/utilities.h b/libs/utilities.h index ad53efd..ccbdd94 100644 --- a/libs/utilities.h +++ b/libs/utilities.h @@ -17,7 +17,4 @@ */ int getStrLength(char* str); -void sayhi(); -void sayGuido(); - #endif // UTILITIES_H_INCLUDED From 0812b52070fb4ddfc38649c2c910340c0cf69876 Mon Sep 17 00:00:00 2001 From: EstefaniaHuergo Date: Tue, 10 Sep 2024 16:03:38 -0300 Subject: [PATCH 03/99] Update utilities.c --- libs/utilities.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/libs/utilities.c b/libs/utilities.c index 0ce0795..2636d2c 100644 --- a/libs/utilities.c +++ b/libs/utilities.c @@ -9,4 +9,10 @@ int getStrLength(char* str) { }; return length; -} \ No newline at end of file +} + +int holaTefi() +{ + printf("hola chicos"); + return 1; +} From d47549eb0d5148755a24fd2df08b0982c60fe634 Mon Sep 17 00:00:00 2001 From: hozlucas28 Date: Tue, 10 Sep 2024 16:09:22 -0300 Subject: [PATCH 04/99] fix: remove unnecessary function --- libs/utilities.c | 8 +------- 1 file changed, 1 insertion(+), 7 deletions(-) diff --git a/libs/utilities.c b/libs/utilities.c index 2636d2c..0ce0795 100644 --- a/libs/utilities.c +++ b/libs/utilities.c @@ -9,10 +9,4 @@ int getStrLength(char* str) { }; return length; -} - -int holaTefi() -{ - printf("hola chicos"); - return 1; -} +} \ No newline at end of file From b2a5c6a19782c134d63abe535ff1410e6c04c8ad Mon Sep 17 00:00:00 2001 From: hozlucas28 Date: Tue, 10 Sep 2024 16:31:42 -0300 Subject: [PATCH 05/99] fix(ci): format code action --- .github/workflows/format-code.yml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.github/workflows/format-code.yml b/.github/workflows/format-code.yml index 73a08f8..290f9b2 100644 --- a/.github/workflows/format-code.yml +++ b/.github/workflows/format-code.yml @@ -23,6 +23,8 @@ jobs: steps: - name: Checkout repository uses: actions/checkout@v4 + with: + ref: ${{github.ref_name}} - name: Install clang-format (formatter tool) run: sudo apt-get install clang-format From e3ecad982fe6dee128f28ec38ee788154c54ec21 Mon Sep 17 00:00:00 2001 From: hozlucas28 Date: Tue, 10 Sep 2024 16:43:44 -0300 Subject: [PATCH 06/99] test(ci): test format-code action --- libs/utilities.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/libs/utilities.c b/libs/utilities.c index 0ce0795..61b7b1d 100644 --- a/libs/utilities.c +++ b/libs/utilities.c @@ -8,5 +8,7 @@ int getStrLength(char* str) { str++; }; + + return length; } \ No newline at end of file From f532fad56759afdbcf962a0c997e5f22f4705a13 Mon Sep 17 00:00:00 2001 From: hozlucas28 Date: Tue, 10 Sep 2024 16:50:47 -0300 Subject: [PATCH 07/99] fix(ci): format code action --- .github/workflows/format-code.yml | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/.github/workflows/format-code.yml b/.github/workflows/format-code.yml index 290f9b2..f1c76bb 100644 --- a/.github/workflows/format-code.yml +++ b/.github/workflows/format-code.yml @@ -23,8 +23,6 @@ jobs: steps: - name: Checkout repository uses: actions/checkout@v4 - with: - ref: ${{github.ref_name}} - name: Install clang-format (formatter tool) run: sudo apt-get install clang-format @@ -42,4 +40,5 @@ jobs: - name: Push changes uses: ad-m/github-push-action@v0.8.0 with: + branch: ${{ github.ref }} github_token: ${{ secrets.GITHUB_TOKEN }} From ef234d9bcfa511191b338b74a3d5da3a1b0dd6b8 Mon Sep 17 00:00:00 2001 From: hozlucas28 Date: Tue, 10 Sep 2024 16:52:03 -0300 Subject: [PATCH 08/99] test(ci): test format-code action --- libs/utilities.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/libs/utilities.c b/libs/utilities.c index 61b7b1d..c8ee07e 100644 --- a/libs/utilities.c +++ b/libs/utilities.c @@ -8,7 +8,9 @@ int getStrLength(char* str) { str++; }; - + + + return length; } \ No newline at end of file From f7ed215d2a0355709534f8d91af40192db90fc08 Mon Sep 17 00:00:00 2001 From: "github-actions[bot]" Date: Tue, 10 Sep 2024 19:52:28 +0000 Subject: [PATCH 09/99] ci: format code --- libs/utilities.c | 4 ---- 1 file changed, 4 deletions(-) diff --git a/libs/utilities.c b/libs/utilities.c index c8ee07e..0ce0795 100644 --- a/libs/utilities.c +++ b/libs/utilities.c @@ -8,9 +8,5 @@ int getStrLength(char* str) { str++; }; - - - - return length; } \ No newline at end of file From ddccb73a2bca7816cccdecb6922d0c60845275c9 Mon Sep 17 00:00:00 2001 From: Tiago Giannotti Date: Tue, 10 Sep 2024 19:15:01 -0300 Subject: [PATCH 10/99] Definition of variables --- libs/utilities.c | 17 ++++++++++++++++- libs/utilities.h | 21 +++++++++++++++++++++ src/main.c | 17 ++++++++++++++--- 3 files changed, 51 insertions(+), 4 deletions(-) diff --git a/libs/utilities.c b/libs/utilities.c index 0ce0795..1d1496d 100644 --- a/libs/utilities.c +++ b/libs/utilities.c @@ -1,4 +1,5 @@ #include +#include "utilities.h" int getStrLength(char* str) { int length = 0; @@ -9,4 +10,18 @@ int getStrLength(char* str) { }; return length; -} \ No newline at end of file +} + +void printDashboard(TGame* pGame){ + +int i,j; + +for(i=0;irows;i++){ + for(j=0;jcols; j++){ + printf("%d ",pGame->dashboard[i][j]); + } + printf("\n"); + } + + +} diff --git a/libs/utilities.h b/libs/utilities.h index ccbdd94..fe06429 100644 --- a/libs/utilities.h +++ b/libs/utilities.h @@ -1,6 +1,25 @@ #ifndef UTILITIES_H_INCLUDED #define UTILITIES_H_INCLUDED +#define ROWS 100 +#define COLS 100 + +typedef struct{ + +int dashboard[ROWS][COLS]; +int rows; +int cols; +int cellAlive; +int cellDead; + +}TGame; + + + + + + + /** * @brief Calculates the length of a string. * @@ -17,4 +36,6 @@ */ int getStrLength(char* str); +void printDashboard(TGame* pGame); + #endif // UTILITIES_H_INCLUDED diff --git a/src/main.c b/src/main.c index 49a8b07..e233979 100644 --- a/src/main.c +++ b/src/main.c @@ -4,10 +4,21 @@ #include int main() { - char str[] = "Hello World!"; - int strLength = getStrLength(str); - printf("> The length of the string \"%s\" is %d.", str, strLength); + int dashboard[ROWS][COLS]; + int rows=ROWS; + int cols=COLS; + int cellAlive; + int cellDead; + TGame game; + + game.dashboard=dashboard; + game.rows=rows; + game.cols=cols; + game.cellAlive=cellAlive; + game.cellDead=cellDead; + + printDashboard(&game); return 0; } From 5434227764a905042ee6fceafd4fc57d9bab0fc7 Mon Sep 17 00:00:00 2001 From: "github-actions[bot]" Date: Tue, 10 Sep 2024 22:15:23 +0000 Subject: [PATCH 11/99] ci: format code --- libs/utilities.c | 18 ++++++++---------- libs/utilities.h | 23 ++++++++--------------- src/main.c | 15 +++++++-------- 3 files changed, 23 insertions(+), 33 deletions(-) diff --git a/libs/utilities.c b/libs/utilities.c index 1d1496d..e338c97 100644 --- a/libs/utilities.c +++ b/libs/utilities.c @@ -1,6 +1,7 @@ -#include #include "utilities.h" +#include + int getStrLength(char* str) { int length = 0; @@ -12,16 +13,13 @@ int getStrLength(char* str) { return length; } -void printDashboard(TGame* pGame){ - -int i,j; +void printDashboard(TGame* pGame) { + int i, j; -for(i=0;irows;i++){ - for(j=0;jcols; j++){ - printf("%d ",pGame->dashboard[i][j]); - } + for (i = 0; i < pGame->rows; i++) { + for (j = 0; j < pGame->cols; j++) { + printf("%d ", pGame->dashboard[i][j]); + } printf("\n"); } - - } diff --git a/libs/utilities.h b/libs/utilities.h index fe06429..1009480 100644 --- a/libs/utilities.h +++ b/libs/utilities.h @@ -4,21 +4,14 @@ #define ROWS 100 #define COLS 100 -typedef struct{ - -int dashboard[ROWS][COLS]; -int rows; -int cols; -int cellAlive; -int cellDead; - -}TGame; - - - - - - +typedef struct { + int dashboard[ROWS][COLS]; + int rows; + int cols; + int cellAlive; + int cellDead; + +} TGame; /** * @brief Calculates the length of a string. diff --git a/src/main.c b/src/main.c index e233979..c31b154 100644 --- a/src/main.c +++ b/src/main.c @@ -4,20 +4,19 @@ #include int main() { - int dashboard[ROWS][COLS]; - int rows=ROWS; - int cols=COLS; + int rows = ROWS; + int cols = COLS; int cellAlive; int cellDead; TGame game; - game.dashboard=dashboard; - game.rows=rows; - game.cols=cols; - game.cellAlive=cellAlive; - game.cellDead=cellDead; + game.dashboard = dashboard; + game.rows = rows; + game.cols = cols; + game.cellAlive = cellAlive; + game.cellDead = cellDead; printDashboard(&game); return 0; From 584d9342e68cdeddd775c1b38f1879a4b8077164 Mon Sep 17 00:00:00 2001 From: hozlucas28 Date: Wed, 11 Sep 2024 00:13:18 -0300 Subject: [PATCH 12/99] fix(vscode): vscode configurations --- .vscode/documentation.code-snippets | 9 --------- .vscode/settings.json | 2 -- 2 files changed, 11 deletions(-) diff --git a/.vscode/documentation.code-snippets b/.vscode/documentation.code-snippets index 0733279..02c834a 100644 --- a/.vscode/documentation.code-snippets +++ b/.vscode/documentation.code-snippets @@ -27,15 +27,6 @@ " */" ] }, - "Document struct field": { - "scope": "c,cpp", - "prefix": "docStructField", - "body": [ - "/**", - " * @brief ${1:}.", - " */" - ] - }, "Document function": { "scope": "c,cpp", "prefix": "docFunction", diff --git a/.vscode/settings.json b/.vscode/settings.json index 715d949..cf91a17 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -6,9 +6,7 @@ "cSpell.caseSensitive": true, "cSpell.language": "en,es-ES,es,en-GB,en-US,lorem", "diffEditor.ignoreTrimWhitespace": true, - "editor.formatOnPaste": true, "editor.formatOnSave": true, - "editor.formatOnType": true, "editor.minimap.renderCharacters": false, "emojisense.unicodeCompletionsEnabled": false, "files.associations": {"*.c": "c", "*.h": "c"}, From 9f030b9543fc1447c2e663c8b0f7bac840f635cc Mon Sep 17 00:00:00 2001 From: hozlucas28 Date: Wed, 11 Sep 2024 00:14:02 -0300 Subject: [PATCH 13/99] feature(macros): add ROWS and COLS --- libs/macros.h | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/libs/macros.h b/libs/macros.h index eb1dd4f..1262168 100644 --- a/libs/macros.h +++ b/libs/macros.h @@ -1,4 +1,28 @@ #ifndef MACROS_H_INCLUDED #define MACROS_H_INCLUDED +/** + * @def ROWS + * @brief Defines the number of rows in a grid. + * + * This macro is used to define the number of rows in a grid. + * It is typically used in conjunction with the COLS macro to define the size of + * a grid. + * + * @warning The value of ROWS should be a positive integer. + */ +#define ROWS 56 + +/** + * @def COLS + * @brief Defines the number of columns in a grid. + * + * This macro is used to define the number of columns in a grid. + * It is typically used in conjunction with the ROWS macro to define the size of + * a grid. + * + * @warning The value of COLS should be a positive integer. + */ +#define COLS 110 + #endif // MACROS_H_INCLUDED From d88e3acce80b4c8adf795d2031b3193e041e41af Mon Sep 17 00:00:00 2001 From: hozlucas28 Date: Wed, 11 Sep 2024 00:28:29 -0300 Subject: [PATCH 14/99] feature: add new utilities functions --- libs/utilities.c | 111 +++++++++++++++++++++++++++++++++++-- libs/utilities.h | 139 +++++++++++++++++++++++++++++++++++++++++------ src/main.c | 28 +++++++--- 3 files changed, 246 insertions(+), 32 deletions(-) diff --git a/libs/utilities.c b/libs/utilities.c index e338c97..dfbbb1a 100644 --- a/libs/utilities.c +++ b/libs/utilities.c @@ -1,16 +1,53 @@ #include "utilities.h" +#include #include +#include +#include -int getStrLength(char* str) { - int length = 0; +void fillDashboard(TGame* pGame, int with) { + int i; + int j; - while (*str != '\0') { - length++; - str++; + for (i = 0; i < pGame->rows; i++) { + for (j = 0; j < pGame->cols; j++) { + pGame->dashboard[i][j] = with; + } + } +} + +char* getUserInputStr(char* message, int strLength, + int (*validator)(char* userInput)) { + char* userInput = malloc(strLength * sizeof(char)); + + printf("%s", message); + fflush(stdin); + fgets(userInput, strLength, stdin); + trimStr(userInput); + + while (!(*validator)(userInput)) { + printf("Invalid input! Try again...\n"); + printf("%s", message); + fflush(stdin); + fgets(userInput, strLength, stdin); + trimStr(userInput); }; - return length; + // TODO + + return userInput; +} + +int isStrIn(char* str, char* arr[], int size) { + int i; + + for (i = 0; i < size; i++) { + if (strcmpi(str, *(arr + i)) == 0) { + return 1; + } + } + + return 0; } void printDashboard(TGame* pGame) { @@ -23,3 +60,65 @@ void printDashboard(TGame* pGame) { printf("\n"); } } + +int strcmpi(const char* str01, const char* str02) { + int i; + + int lengthStr01 = strlen(str01); + int lengthStr02 = strlen(str02); + int shortestLength = lengthStr01 < lengthStr02 ? lengthStr01 : lengthStr02; + + char charStr01; + char charStr02; + int cmp = 1; + + for (i = 0; i < shortestLength; i++) { + charStr01 = toupper(*(str01 + i)); + charStr02 = toupper(*(str02 + i)); + cmp = charStr01 - charStr02; + + if (cmp != 0) { + return cmp; + }; + }; + + return cmp; +} + +void trimStr(char* str) { + trimLeftStr(str); + trimRightStr(str); +} + +void trimLeftStr(char* str) { + int i; + int j; + int strLength = strlen(str); + + int counter = 0; + + for (i = 0; i < strLength; i++) { + if (!isspace(*(str + i))) break; + counter++; + }; + + for (j = 0; j < strLength - counter; j++) { + *(str + j) = *(str + j + counter); + }; + + *(str + strLength - counter) = '\0'; +} + +void trimRightStr(char* str) { + int i; + int strLength = strlen(str); + + int counter = 0; + + for (i = strLength - 1; i > 0; i--) { + if (!isspace(*(str + i))) break; + counter++; + } + + *(str + strLength - counter) = '\0'; +} \ No newline at end of file diff --git a/libs/utilities.h b/libs/utilities.h index 1009480..c306810 100644 --- a/libs/utilities.h +++ b/libs/utilities.h @@ -1,34 +1,139 @@ #ifndef UTILITIES_H_INCLUDED #define UTILITIES_H_INCLUDED -#define ROWS 100 -#define COLS 100 +#include "macros.h" +/** + * @struct TGame + * @brief Represents a game structure. + * + * This structure represents a game in which the player's moves are + * recorded. It contains a dashboard, which is a 2D array representing the + * game board, as well as other properties such as the number of rows and + * columns in the dashboard, and the values to represent alive and dead cells. + */ typedef struct { - int dashboard[ROWS][COLS]; - int rows; - int cols; - int cellAlive; - int cellDead; - + int (*dashboard)[COLS]; /** The game board represented as a 2D array. */ + int rows; /** The number of rows in the game board. */ + int cols; /** The number of columns in the game board. */ + int cellsAlive; /** The value representing an alive cell. */ + int cellsDead; /** The value representing a dead cell. */ } TGame; /** - * @brief Calculates the length of a string. + * @brief Fills the dashboard of a game with a specified value. + * + * This function fills the dashboard of a game with a specified value. The + * dashboard represents the game board where the player's moves are recorded. + * + * @param pGame A pointer to the game structure. + * @param with The value to fill the dashboard with. + * + * @warning This function assumes that the game structure (`pGame`) has been + * properly initialized. + */ +void fillDashboard(TGame* pGame, int with); + +/** + * @brief Gets user input as a string. * - * This function takes a null-terminated string as input and returns the number - * of characters in the string, excluding the null character. + * This function prompts the user with a message and retrieves their input as a + * string. The user's input is validated using the provided validator function. * - * @param str The null-terminated string for which the length needs to be - * calculated. + * @param message The message to display as a prompt to the user. + * @param strLength The maximum length of the string to be inputted by the user. + * @param validator A function pointer to a validator function that takes a + * string as input and returns an integer. The validator function should return + * 1 if the input is valid, and 0 otherwise. * - * @return The length of the string. + * @return A pointer to the string entered by the user. * - * @warning The input string must be null-terminated, otherwise the behavior is - * undefined. + * @warning The returned string may be longer than the specified strLength if + * the user enters more characters. */ -int getStrLength(char* str); +char* getUserInputStr(char* message, int strLength, + int (*validator)(char* userInput)); +/** + * @brief Checks if a string is present in an array of strings. + * + * This function checks if a given string is present in an array of strings. + * + * @param str The string to search for. + * @param arr The array of strings to search in. + * @param size The size of the array. + * + * @return 1 if the string is found in the array, 0 otherwise. + */ +int isStrIn(char* str, char* arr[], int size); + +/** + * @brief Prints the dashboard of a game. + * + * This function prints the dashboard of a game, which represents the game board + * where the player's moves are recorded. + * + * @param pGame A pointer to the game structure. + * + * @warning This function assumes that the game structure (`pGame`) has been + * properly initialized and the dashboard has been filled with values. + */ void printDashboard(TGame* pGame); +/** + * @brief Compares two strings case-insensitively. + * + * This function compares two strings case-insensitively and returns an integer + * indicating their relative order. The comparison is based on the ASCII values + * of the characters in the strings. + * + * @param str01 The first string to compare. + * @param str02 The second string to compare. + * + * @return An integer less than, equal to, or greater than zero if str01 is + * found, respectively, to be less than, to match, or be greater than str02. + * + * @warning This function assumes that the input strings are null-terminated. + */ +int strcmpi(const char* str01, const char* str02); + +/** + * @brief Trims leading and trailing whitespace characters from a string. + * + * This function trims leading and trailing whitespace characters from a string + * by modifying the string in-place. The trimmed string will have no leading or + * trailing whitespace characters. + * + * @param str The string to trim. + * + * @warning This function assumes that the input string is null-terminated. + */ +void trimStr(char* str); + +/** + * @brief Trims leading whitespace characters from a string. + * + * This function trims leading whitespace characters from a string by modifying + * the string in-place. The trimmed string will have no leading whitespace + * characters. + * + * @param str The string to trim. + * + * @warning This function assumes that the input string is null-terminated. + */ +void trimLeftStr(char* str); + +/** + * @brief Trims trailing whitespace characters from a string. + * + * This function trims trailing whitespace characters from a string by modifying + * the string in-place. The trimmed string will have no trailing whitespace + * characters. + * + * @param str The string to trim. + * + * @warning This function assumes that the input string is null-terminated. + */ +void trimRightStr(char* str); + #endif // UTILITIES_H_INCLUDED diff --git a/src/main.c b/src/main.c index c31b154..5c2145a 100644 --- a/src/main.c +++ b/src/main.c @@ -1,23 +1,33 @@ #include "../libs/main.h" -#include -#include +#include "stdio.h" + +int validatePattern(char* userInput) { + char* options[] = {"glider", "toad", "press", "glider cannon"}; + return isStrIn(userInput, options, 2); +} int main() { + TGame game; + int dashboard[ROWS][COLS]; int rows = ROWS; int cols = COLS; - int cellAlive; - int cellDead; + int cellAlive = 0; + int cellDead = 0; - TGame game; + char* requestedPattern; game.dashboard = dashboard; game.rows = rows; game.cols = cols; - game.cellAlive = cellAlive; - game.cellDead = cellDead; + game.cellsAlive = cellAlive; + game.cellsDead = cellDead; + + fillDashboard(&game, 0); - printDashboard(&game); + requestedPattern = getUserInputStr("Which pattern do you want (XXX)? ", 100, + &validatePattern); + printf("\n'%s'", requestedPattern); return 0; -} +} \ No newline at end of file From 2544398d3f2d8d478a72c3a6b1a00cfcd40f4529 Mon Sep 17 00:00:00 2001 From: hozlucas28 Date: Wed, 11 Sep 2024 00:30:45 -0300 Subject: [PATCH 15/99] test(ci): format code action --- src/main.c | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/src/main.c b/src/main.c index 5c2145a..a453c2e 100644 --- a/src/main.c +++ b/src/main.c @@ -26,8 +26,15 @@ int main() { fillDashboard(&game, 0); + + + + + + + requestedPattern = getUserInputStr("Which pattern do you want (XXX)? ", 100, &validatePattern); printf("\n'%s'", requestedPattern); return 0; -} \ No newline at end of file +} From f707280c91fc129c2d30639ae799114001d74919 Mon Sep 17 00:00:00 2001 From: "github-actions[bot]" Date: Wed, 11 Sep 2024 03:31:29 +0000 Subject: [PATCH 16/99] ci: format code --- src/main.c | 7 ------- 1 file changed, 7 deletions(-) diff --git a/src/main.c b/src/main.c index a453c2e..a92cb93 100644 --- a/src/main.c +++ b/src/main.c @@ -26,13 +26,6 @@ int main() { fillDashboard(&game, 0); - - - - - - - requestedPattern = getUserInputStr("Which pattern do you want (XXX)? ", 100, &validatePattern); printf("\n'%s'", requestedPattern); From 9effd9727b4ab6bba02422501e64bb14764fe649 Mon Sep 17 00:00:00 2001 From: hozlucas28 Date: Wed, 11 Sep 2024 00:48:22 -0300 Subject: [PATCH 17/99] doc: add development team --- .github/translations/es/README.md | 30 +++++++++++++++--------------- README.md | 30 +++++++++++++++--------------- 2 files changed, 30 insertions(+), 30 deletions(-) diff --git a/.github/translations/es/README.md b/.github/translations/es/README.md index db61c45..4cc86d1 100644 --- a/.github/translations/es/README.md +++ b/.github/translations/es/README.md @@ -152,31 +152,31 @@ C-Practical-Work-2024/ commit commit tag: "v0.0.1" branch develop - branch TODO_01 + branch "Giannotti Tiago" commit commit checkout develop - branch TODO_02 + branch "Hoz Lucas" commit commit checkout develop - branch TODO_03 + branch "Huergo Estefania" commit commit checkout develop - branch TODO_04 + branch "Linares Guido" commit commit checkout develop - branch TODO_05 + branch "Quiroga Ferney" commit commit checkout develop - merge TODO_02 - merge TODO_01 - merge TODO_03 - merge TODO_05 - merge TODO_04 + merge "Hoz Lucas" + merge "Giannotti Tiago" + merge "Huergo Estefania" + merge "Quiroga Ferney" + merge "Linares Guido" checkout Master merge develop tag: "v1.0.0" ``` @@ -195,11 +195,11 @@ C-Practical-Work-2024/ ## Equipo de desarrollo -- [TODO_01](TODO) -- [TODO_02](TODO) -- [TODO_03](TODO) -- [TODO_04](TODO) -- [TODO_05](TODO) +- [Giannotti Tiago](https://github.com/TiagoGiannotti) +- [Hoz Lucas](https://github.com/hozlucas28) +- [Huergo Estefania](https://github.com/tefhuergo) +- [Linares Guido](https://www.linkedin.com/in/guido-linares-25859b209/) +- [Quiroga Ferney Santiago](https://github.com/Ferny1011) ## Material adicional diff --git a/README.md b/README.md index 3db1835..4ba4049 100644 --- a/README.md +++ b/README.md @@ -152,31 +152,31 @@ C-Practical-Work-2024/ commit commit tag: "v0.0.1" branch develop - branch TODO_01 + branch "Giannotti Tiago" commit commit checkout develop - branch Guidolinares + branch "Hoz Lucas" commit commit checkout develop - branch TODO_03 + branch "Huergo Estefania" commit commit checkout develop - branch TODO_04 + branch "Linares Guido" commit commit checkout develop - branch TODO_05 + branch "Quiroga Ferney" commit commit checkout develop - merge Guidolinares - merge TODO_01 - merge TODO_03 - merge TODO_05 - merge TODO_04 + merge "Hoz Lucas" + merge "Giannotti Tiago" + merge "Huergo Estefania" + merge "Quiroga Ferney" + merge "Linares Guido" checkout Master merge develop tag: "v1.0.0" ``` @@ -195,11 +195,11 @@ C-Practical-Work-2024/ ## Development Team -- [TODO_01](TODO) -- [Guidolinares](https://www.linkedin.com/in/guido-linares-25859b209/) -- [TODO_03](TODO) -- [TODO_04](TODO) -- [TODO_05](TODO) +- [Giannotti Tiago](https://github.com/TiagoGiannotti) +- [Hoz Lucas](https://github.com/hozlucas28) +- [Huergo Estefania](https://github.com/tefhuergo) +- [Linares Guido](https://www.linkedin.com/in/guido-linares-25859b209/) +- [Quiroga Ferney Santiago](https://github.com/Ferny1011) ## Additional Material From 735b99030825c9285dbd24499f3cbf364fd53928 Mon Sep 17 00:00:00 2001 From: hozlucas28 Date: Wed, 11 Sep 2024 01:26:57 -0300 Subject: [PATCH 18/99] doc: improve doxygen documentation --- libs/utilities.c | 2 +- libs/utilities.h | 58 +++++++++++++++++++----------------------------- 2 files changed, 24 insertions(+), 36 deletions(-) diff --git a/libs/utilities.c b/libs/utilities.c index dfbbb1a..b77fdc4 100644 --- a/libs/utilities.c +++ b/libs/utilities.c @@ -50,7 +50,7 @@ int isStrIn(char* str, char* arr[], int size) { return 0; } -void printDashboard(TGame* pGame) { +void printDashboardByConsole(TGame* pGame) { int i, j; for (i = 0; i < pGame->rows; i++) { diff --git a/libs/utilities.h b/libs/utilities.h index c306810..480b20a 100644 --- a/libs/utilities.h +++ b/libs/utilities.h @@ -5,31 +5,29 @@ /** * @struct TGame - * @brief Represents a game structure. + * @brief Represents a Conway's Game of Life structure. * - * This structure represents a game in which the player's moves are - * recorded. It contains a dashboard, which is a 2D array representing the + * This structure represents a Conway's Game of Life in which the cells moves + * are recorded. It contains a dashboard, which is a 2D array representing the * game board, as well as other properties such as the number of rows and * columns in the dashboard, and the values to represent alive and dead cells. */ typedef struct { - int (*dashboard)[COLS]; /** The game board represented as a 2D array. */ - int rows; /** The number of rows in the game board. */ - int cols; /** The number of columns in the game board. */ - int cellsAlive; /** The value representing an alive cell. */ - int cellsDead; /** The value representing a dead cell. */ + int (*dashboard)[COLS]; /** Board (2D array) in which the cells moves. */ + int rows; /** Number of rows in `dashboard`. */ + int cols; /** Number of columns in `dashboard`. */ + int cellsAlive; /** Number of alive cells. */ + int cellsDead; /** Number of dead cells. */ } TGame; /** - * @brief Fills the dashboard of a game with a specified value. + * @brief Fills the dashboard of a Conway's Game of Life structure with a + * specified value. * - * This function fills the dashboard of a game with a specified value. The - * dashboard represents the game board where the player's moves are recorded. - * - * @param pGame A pointer to the game structure. + * @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 the game structure (`pGame`) has been + * @warning This function assumes that `pGame` has been * properly initialized. */ void fillDashboard(TGame* pGame, int with); @@ -47,9 +45,6 @@ void fillDashboard(TGame* pGame, int with); * 1 if the input is valid, and 0 otherwise. * * @return A pointer to the string entered by the user. - * - * @warning The returned string may be longer than the specified strLength if - * the user enters more characters. */ char* getUserInputStr(char* message, int strLength, int (*validator)(char* userInput)); @@ -61,24 +56,20 @@ char* getUserInputStr(char* message, int strLength, * * @param str The string to search for. * @param arr The array of strings to search in. - * @param size The size of the array. + * @param arrLength The arrLength of the array. * * @return 1 if the string is found in the array, 0 otherwise. */ -int isStrIn(char* str, char* arr[], int size); +int isStrIn(char* str, char* arr[], int arrLength); /** - * @brief Prints the dashboard of a game. - * - * This function prints the dashboard of a game, which represents the game board - * where the player's moves are recorded. + * @brief Prints the dashboard of a Conway's Game of Life structure by console. * - * @param pGame A pointer to the game structure. + * @param pGame A pointer to the Conway's Game of Life structure. * - * @warning This function assumes that the game structure (`pGame`) has been - * properly initialized and the dashboard has been filled with values. + * @warning This function assumes that `pGame` has been properly initialized. */ -void printDashboard(TGame* pGame); +void printDashboardByConsole(TGame* pGame); /** * @brief Compares two strings case-insensitively. @@ -90,8 +81,8 @@ void printDashboard(TGame* pGame); * @param str01 The first string to compare. * @param str02 The second string to compare. * - * @return An integer less than, equal to, or greater than zero if str01 is - * found, respectively, to be less than, to match, or be greater than str02. + * @return An integer less than zero if str01 is less than str02, zero if str01 + * matches str02, or greater than zero if str01 is greater than str02. * * @warning This function assumes that the input strings are null-terminated. */ @@ -101,8 +92,7 @@ int strcmpi(const char* str01, const char* str02); * @brief Trims leading and trailing whitespace characters from a string. * * This function trims leading and trailing whitespace characters from a string - * by modifying the string in-place. The trimmed string will have no leading or - * trailing whitespace characters. + * by modifying the string in-place. * * @param str The string to trim. * @@ -114,8 +104,7 @@ void trimStr(char* str); * @brief Trims leading whitespace characters from a string. * * This function trims leading whitespace characters from a string by modifying - * the string in-place. The trimmed string will have no leading whitespace - * characters. + * the string in-place. * * @param str The string to trim. * @@ -127,8 +116,7 @@ void trimLeftStr(char* str); * @brief Trims trailing whitespace characters from a string. * * This function trims trailing whitespace characters from a string by modifying - * the string in-place. The trimmed string will have no trailing whitespace - * characters. + * the string in-place. * * @param str The string to trim. * From 2d9a9e5429bef1de8f88dbfae6e051940c534bcf Mon Sep 17 00:00:00 2001 From: hozlucas28 Date: Wed, 11 Sep 2024 01:36:46 -0300 Subject: [PATCH 19/99] feature: improve `getUserInputStr` function --- libs/utilities.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/libs/utilities.c b/libs/utilities.c index b77fdc4..0d34b96 100644 --- a/libs/utilities.c +++ b/libs/utilities.c @@ -19,6 +19,10 @@ void fillDashboard(TGame* pGame, int with) { char* getUserInputStr(char* message, int strLength, int (*validator)(char* userInput)) { char* userInput = malloc(strLength * sizeof(char)); + if (userInput == NULL) { + printf("Memory allocation failed!\n"); + exit(EXIT_FAILURE); + } printf("%s", message); fflush(stdin); @@ -33,8 +37,6 @@ char* getUserInputStr(char* message, int strLength, trimStr(userInput); }; - // TODO - return userInput; } From 8ed081002f0afdd1359556da2852c978e3335dc4 Mon Sep 17 00:00:00 2001 From: hozlucas28 Date: Wed, 11 Sep 2024 01:58:19 -0300 Subject: [PATCH 20/99] feature: improve functions --- libs/utilities.c | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/libs/utilities.c b/libs/utilities.c index 0d34b96..b7bc093 100644 --- a/libs/utilities.c +++ b/libs/utilities.c @@ -44,9 +44,7 @@ int isStrIn(char* str, char* arr[], int size) { int i; for (i = 0; i < size; i++) { - if (strcmpi(str, *(arr + i)) == 0) { - return 1; - } + if (strcmpi(str, *(arr + i)) == 0) return 1; } return 0; @@ -79,9 +77,7 @@ int strcmpi(const char* str01, const char* str02) { charStr02 = toupper(*(str02 + i)); cmp = charStr01 - charStr02; - if (cmp != 0) { - return cmp; - }; + if (cmp != 0) return cmp; }; return cmp; From e89146091667d7bfa3d50cbf0fb320b78e79e8e8 Mon Sep 17 00:00:00 2001 From: hozlucas28 Date: Wed, 11 Sep 2024 01:58:38 -0300 Subject: [PATCH 21/99] feature: reduce `strLength` --- src/main.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/main.c b/src/main.c index a92cb93..23b5e44 100644 --- a/src/main.c +++ b/src/main.c @@ -26,8 +26,8 @@ int main() { fillDashboard(&game, 0); - requestedPattern = getUserInputStr("Which pattern do you want (XXX)? ", 100, + requestedPattern = getUserInputStr("Which pattern do you want (XXX)? ", 50, &validatePattern); printf("\n'%s'", requestedPattern); return 0; -} +} \ No newline at end of file From 7adbfa9d80ae54cf90cc33b8354c716701f75dd9 Mon Sep 17 00:00:00 2001 From: hozlucas28 Date: Wed, 11 Sep 2024 02:08:12 -0300 Subject: [PATCH 22/99] todo: add new todos (comments) --- libs/utilities.h | 5 +++++ src/main.c | 4 ++++ 2 files changed, 9 insertions(+) diff --git a/libs/utilities.h b/libs/utilities.h index 480b20a..97f949d 100644 --- a/libs/utilities.h +++ b/libs/utilities.h @@ -49,6 +49,8 @@ void fillDashboard(TGame* pGame, int with); char* getUserInputStr(char* message, int strLength, int (*validator)(char* userInput)); +// TODO: Receive an `onInvalidMessage` parameter in `getUserInputStr` function. + /** * @brief Checks if a string is present in an array of strings. * @@ -124,4 +126,7 @@ void trimLeftStr(char* str); */ void trimRightStr(char* str); +// TODO: Create a function to format an array of strings to a string... +// conjunction, or disjunction. + #endif // UTILITIES_H_INCLUDED diff --git a/src/main.c b/src/main.c index 23b5e44..e1923bb 100644 --- a/src/main.c +++ b/src/main.c @@ -2,6 +2,7 @@ #include "stdio.h" +// TODO: Convert `options` variable into a global variable. int validatePattern(char* userInput) { char* options[] = {"glider", "toad", "press", "glider cannon"}; return isStrIn(userInput, options, 2); @@ -26,6 +27,9 @@ int main() { fillDashboard(&game, 0); + // TODO: Replace `XXX` with a formatted version of `options` (global... + // variable). + // TODO: Add `onInvalidMessage` argument. requestedPattern = getUserInputStr("Which pattern do you want (XXX)? ", 50, &validatePattern); printf("\n'%s'", requestedPattern); From dd94d666a851a17d216e1615953bbf32196df1a2 Mon Sep 17 00:00:00 2001 From: hozlucas28 Date: Wed, 11 Sep 2024 14:35:06 -0300 Subject: [PATCH 23/99] feature(getUserInputStr): add `onInvalidMessage` parameter --- libs/utilities.c | 8 ++++---- libs/utilities.h | 4 +--- src/main.c | 8 ++++---- 3 files changed, 9 insertions(+), 11 deletions(-) diff --git a/libs/utilities.c b/libs/utilities.c index b7bc093..239c511 100644 --- a/libs/utilities.c +++ b/libs/utilities.c @@ -16,7 +16,7 @@ void fillDashboard(TGame* pGame, int with) { } } -char* getUserInputStr(char* message, int strLength, +char* getUserInputStr(char* message, char* onInvalidMessage, int strLength, int (*validator)(char* userInput)) { char* userInput = malloc(strLength * sizeof(char)); if (userInput == NULL) { @@ -24,14 +24,14 @@ char* getUserInputStr(char* message, int strLength, exit(EXIT_FAILURE); } - printf("%s", message); + printf(message); fflush(stdin); fgets(userInput, strLength, stdin); trimStr(userInput); while (!(*validator)(userInput)) { - printf("Invalid input! Try again...\n"); - printf("%s", message); + puts(onInvalidMessage); + printf(message); fflush(stdin); fgets(userInput, strLength, stdin); trimStr(userInput); diff --git a/libs/utilities.h b/libs/utilities.h index 97f949d..a1840f6 100644 --- a/libs/utilities.h +++ b/libs/utilities.h @@ -46,11 +46,9 @@ void fillDashboard(TGame* pGame, int with); * * @return A pointer to the string entered by the user. */ -char* getUserInputStr(char* message, int strLength, +char* getUserInputStr(char* message, char* onInvalidMessage, int strLength, int (*validator)(char* userInput)); -// TODO: Receive an `onInvalidMessage` parameter in `getUserInputStr` function. - /** * @brief Checks if a string is present in an array of strings. * diff --git a/src/main.c b/src/main.c index e1923bb..04269b8 100644 --- a/src/main.c +++ b/src/main.c @@ -5,7 +5,7 @@ // TODO: Convert `options` variable into a global variable. int validatePattern(char* userInput) { char* options[] = {"glider", "toad", "press", "glider cannon"}; - return isStrIn(userInput, options, 2); + return isStrIn(userInput, options, 4); } int main() { @@ -29,9 +29,9 @@ int main() { // TODO: Replace `XXX` with a formatted version of `options` (global... // variable). - // TODO: Add `onInvalidMessage` argument. - requestedPattern = getUserInputStr("Which pattern do you want (XXX)? ", 50, - &validatePattern); + requestedPattern = + getUserInputStr("Which pattern do you want (XXX)? ", + "Invalid input! Try again...", 50, &validatePattern); printf("\n'%s'", requestedPattern); return 0; } \ No newline at end of file From e5c40d39a9dbdf9f5672da4d3fa5433bbb20b51a Mon Sep 17 00:00:00 2001 From: hozlucas28 Date: Wed, 11 Sep 2024 15:00:16 -0300 Subject: [PATCH 24/99] fix(strcmpi): function behavior --- libs/utilities.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/libs/utilities.c b/libs/utilities.c index 239c511..6ddc2b5 100644 --- a/libs/utilities.c +++ b/libs/utilities.c @@ -66,13 +66,14 @@ int strcmpi(const char* str01, const char* str02) { int lengthStr01 = strlen(str01); int lengthStr02 = strlen(str02); - int shortestLength = lengthStr01 < lengthStr02 ? lengthStr01 : lengthStr02; char charStr01; char charStr02; int cmp = 1; - for (i = 0; i < shortestLength; i++) { + if (lengthStr01 != lengthStr02) return lengthStr01 > lengthStr02 ? 1 : -1; + + for (i = 0; i < lengthStr01; i++) { charStr01 = toupper(*(str01 + i)); charStr02 = toupper(*(str02 + i)); cmp = charStr01 - charStr02; From 08cddbeb8cf8fcf27b98432496a6e2dca6fb0805 Mon Sep 17 00:00:00 2001 From: hozlucas28 Date: Wed, 11 Sep 2024 15:07:01 -0300 Subject: [PATCH 25/99] fix(ci): prevent commit if there are no changes --- .github/workflows/format-code.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/format-code.yml b/.github/workflows/format-code.yml index f1c76bb..fffce3d 100644 --- a/.github/workflows/format-code.yml +++ b/.github/workflows/format-code.yml @@ -35,7 +35,7 @@ jobs: git config --global user.name 'github-actions[bot]' git config --global user.email 'github-actions[bot]@users.noreply.github.com' git add . - git commit -m "ci: format code" + git diff-index --quiet HEAD || git commit -m "ci: format code" - name: Push changes uses: ad-m/github-push-action@v0.8.0 From 2c79505364fe0364bf4b4adb59af704bc2344795 Mon Sep 17 00:00:00 2001 From: hozlucas28 Date: Wed, 11 Sep 2024 15:14:46 -0300 Subject: [PATCH 26/99] doc(getUserInputStr): add missing parameter --- libs/utilities.h | 1 + 1 file changed, 1 insertion(+) diff --git a/libs/utilities.h b/libs/utilities.h index a1840f6..70fc8b2 100644 --- a/libs/utilities.h +++ b/libs/utilities.h @@ -39,6 +39,7 @@ void fillDashboard(TGame* pGame, int with); * string. The user's input is validated using the provided validator function. * * @param message The message to display as a prompt to the user. + * @param onInvalidMessage The message to display when the user input is invalid. * @param strLength The maximum length of the string to be inputted by the user. * @param validator A function pointer to a validator function that takes a * string as input and returns an integer. The validator function should return From 30e1100a3ae4f689fbfe345a549c47d1ffb9ee02 Mon Sep 17 00:00:00 2001 From: "github-actions[bot]" Date: Wed, 11 Sep 2024 18:15:13 +0000 Subject: [PATCH 27/99] ci: format code --- libs/utilities.h | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/libs/utilities.h b/libs/utilities.h index 70fc8b2..6ce565a 100644 --- a/libs/utilities.h +++ b/libs/utilities.h @@ -39,7 +39,8 @@ void fillDashboard(TGame* pGame, int with); * string. The user's input is validated using the provided validator function. * * @param message The message to display as a prompt to the user. - * @param onInvalidMessage The message to display when the user input is invalid. + * @param onInvalidMessage The message to display when the user input is + * invalid. * @param strLength The maximum length of the string to be inputted by the user. * @param validator A function pointer to a validator function that takes a * string as input and returns an integer. The validator function should return From 35ce4d4494f13e8d1c6af576dc586c7fe7c28abc Mon Sep 17 00:00:00 2001 From: hozlucas28 Date: Wed, 11 Sep 2024 15:46:33 -0300 Subject: [PATCH 28/99] todo: remove overhead todo --- libs/utilities.h | 3 --- 1 file changed, 3 deletions(-) diff --git a/libs/utilities.h b/libs/utilities.h index 6ce565a..3da21a1 100644 --- a/libs/utilities.h +++ b/libs/utilities.h @@ -126,7 +126,4 @@ void trimLeftStr(char* str); */ void trimRightStr(char* str); -// TODO: Create a function to format an array of strings to a string... -// conjunction, or disjunction. - #endif // UTILITIES_H_INCLUDED From 26e897b4ef60c2066afa9bc35657fd05769beb83 Mon Sep 17 00:00:00 2001 From: hozlucas28 Date: Wed, 11 Sep 2024 15:57:14 -0300 Subject: [PATCH 29/99] feature(main): improve `getUserInputStr` function arguments --- src/main.c | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/src/main.c b/src/main.c index 04269b8..d061c95 100644 --- a/src/main.c +++ b/src/main.c @@ -26,12 +26,10 @@ int main() { game.cellsDead = cellDead; fillDashboard(&game, 0); - - // TODO: Replace `XXX` with a formatted version of `options` (global... - // variable). - requestedPattern = - getUserInputStr("Which pattern do you want (XXX)? ", - "Invalid input! Try again...", 50, &validatePattern); - printf("\n'%s'", requestedPattern); + requestedPattern = getUserInputStr( + "> Which pattern do you want " + "('Glider','Toad', 'Press', or 'Glider cannon')? ", + "> Invalid pattern! Try again...", 50, &validatePattern); + printf("> Pattern received: '%s'", requestedPattern); return 0; } \ No newline at end of file From 6d39c5edb020caf2a45b1ac1130eb1ba881b478d Mon Sep 17 00:00:00 2001 From: hozlucas28 Date: Wed, 11 Sep 2024 15:59:13 -0300 Subject: [PATCH 30/99] todo: remove overhead todo --- src/main.c | 1 - 1 file changed, 1 deletion(-) diff --git a/src/main.c b/src/main.c index d061c95..1817543 100644 --- a/src/main.c +++ b/src/main.c @@ -2,7 +2,6 @@ #include "stdio.h" -// TODO: Convert `options` variable into a global variable. int validatePattern(char* userInput) { char* options[] = {"glider", "toad", "press", "glider cannon"}; return isStrIn(userInput, options, 4); From 157a5780eed45f93dd9cc8ce8902385bb6af23bf Mon Sep 17 00:00:00 2001 From: hozlucas28 Date: Wed, 11 Sep 2024 16:01:04 -0300 Subject: [PATCH 31/99] test(ci): format code action --- src/main.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main.c b/src/main.c index 1817543..dfb3fe4 100644 --- a/src/main.c +++ b/src/main.c @@ -18,7 +18,7 @@ int main() { char* requestedPattern; - game.dashboard = dashboard; + game.dashboard = dashboard; game.rows = rows; game.cols = cols; game.cellsAlive = cellAlive; From 55826eb0b879ffbcba4cd55da43de5d09f2c9a43 Mon Sep 17 00:00:00 2001 From: "github-actions[bot]" Date: Wed, 11 Sep 2024 19:01:34 +0000 Subject: [PATCH 32/99] ci: format code --- src/main.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main.c b/src/main.c index dfb3fe4..1817543 100644 --- a/src/main.c +++ b/src/main.c @@ -18,7 +18,7 @@ int main() { char* requestedPattern; - game.dashboard = dashboard; + game.dashboard = dashboard; game.rows = rows; game.cols = cols; game.cellsAlive = cellAlive; From 2b25ae5944768691c242ed8c9fde35896bfeeb0d Mon Sep 17 00:00:00 2001 From: Guidolinares Date: Wed, 11 Sep 2024 17:31:50 -0300 Subject: [PATCH 33/99] functions pattern --- src/main.c | 26 ++++++++++++++++++++++++-- 1 file changed, 24 insertions(+), 2 deletions(-) diff --git a/src/main.c b/src/main.c index 1817543..2541a36 100644 --- a/src/main.c +++ b/src/main.c @@ -15,6 +15,7 @@ int main() { int cols = COLS; int cellAlive = 0; int cellDead = 0; + int invalidPattern; char* requestedPattern; @@ -25,10 +26,31 @@ int main() { game.cellsDead = cellDead; fillDashboard(&game, 0); - requestedPattern = getUserInputStr( + + do{ + requestedPattern = getUserInputStr( "> Which pattern do you want " "('Glider','Toad', 'Press', or 'Glider cannon')? ", "> Invalid pattern! Try again...", 50, &validatePattern); - printf("> Pattern received: '%s'", requestedPattern); + printf("> Pattern received: '%s'", requestedPattern); + + invalidPattern = 0; + + if(strcmpi(requestedPattern,"GLIDER") == 0) + gliderPattern (dashboard); + else if(strcmpi(requestedPattern,"TOAD") == 0) + toadPattern(dashboard); + else if(strcmpi(requestedPattern,"PRESS") == 0) + pressPattern(dashboard); + else if (strcmpi(requestedPattern,"GLIDER CANNON") == 0) + gliderCannonPattern(dashboard); + else{ + puts("INVALID PATTERN, try again... :"); + invalidPattern = 1; + } + + }while(invalidPattern); + + return 0; } \ No newline at end of file From 00ae693d00e0b099d55b55a4039810797b099174 Mon Sep 17 00:00:00 2001 From: "github-actions[bot]" Date: Wed, 11 Sep 2024 20:32:14 +0000 Subject: [PATCH 34/99] ci: format code --- src/main.c | 37 ++++++++++++++++++------------------- 1 file changed, 18 insertions(+), 19 deletions(-) diff --git a/src/main.c b/src/main.c index 2541a36..3acdeb5 100644 --- a/src/main.c +++ b/src/main.c @@ -27,30 +27,29 @@ int main() { fillDashboard(&game, 0); - do{ + do { requestedPattern = getUserInputStr( - "> Which pattern do you want " - "('Glider','Toad', 'Press', or 'Glider cannon')? ", - "> Invalid pattern! Try again...", 50, &validatePattern); + "> Which pattern do you want " + "('Glider','Toad', 'Press', or 'Glider cannon')? ", + "> Invalid pattern! Try again...", 50, &validatePattern); printf("> Pattern received: '%s'", requestedPattern); invalidPattern = 0; - if(strcmpi(requestedPattern,"GLIDER") == 0) - gliderPattern (dashboard); - else if(strcmpi(requestedPattern,"TOAD") == 0) - toadPattern(dashboard); - else if(strcmpi(requestedPattern,"PRESS") == 0) - pressPattern(dashboard); - else if (strcmpi(requestedPattern,"GLIDER CANNON") == 0) - gliderCannonPattern(dashboard); - else{ - puts("INVALID PATTERN, try again... :"); - invalidPattern = 1; - } - - }while(invalidPattern); - + if (strcmpi(requestedPattern, "GLIDER") == 0) + gliderPattern(dashboard); + else if (strcmpi(requestedPattern, "TOAD") == 0) + toadPattern(dashboard); + else if (strcmpi(requestedPattern, "PRESS") == 0) + pressPattern(dashboard); + else if (strcmpi(requestedPattern, "GLIDER CANNON") == 0) + gliderCannonPattern(dashboard); + else { + puts("INVALID PATTERN, try again... :"); + invalidPattern = 1; + } + + } while (invalidPattern); return 0; } \ No newline at end of file From 1ed22ab6c1dc27ab69aa56da438b7d5ce967fdfa Mon Sep 17 00:00:00 2001 From: hozlucas28 Date: Wed, 11 Sep 2024 19:16:09 -0300 Subject: [PATCH 35/99] refactor: move `validatePattern` from `src` project to `libs` project --- libs/utilities.c | 5 +++++ libs/utilities.h | 12 ++++++++++++ src/main.c | 7 +------ 3 files changed, 18 insertions(+), 6 deletions(-) diff --git a/libs/utilities.c b/libs/utilities.c index 6ddc2b5..8fa9e98 100644 --- a/libs/utilities.c +++ b/libs/utilities.c @@ -84,6 +84,11 @@ int strcmpi(const char* str01, const char* str02) { return cmp; } +int validatePattern(char* userInput) { + char* options[] = {"glider", "toad", "press", "glider cannon"}; + return isStrIn(userInput, options, 4); +} + void trimStr(char* str) { trimLeftStr(str); trimRightStr(str); diff --git a/libs/utilities.h b/libs/utilities.h index 3da21a1..17dd4ca 100644 --- a/libs/utilities.h +++ b/libs/utilities.h @@ -90,6 +90,18 @@ void printDashboardByConsole(TGame* pGame); */ int strcmpi(const char* str01, const char* str02); +/** + * @brief Validates the pattern of user input. + * + * This function checks if the user input matches `glider`, `toad`, `press`, or + * `glider cannon` pattern. The comparison is case insensitive. + * + * @param userInput The user input to be validated. + * + * @return 1 if the pattern is valid, 0 otherwise. + */ +int validatePattern(char* userInput); + /** * @brief Trims leading and trailing whitespace characters from a string. * diff --git a/src/main.c b/src/main.c index 3acdeb5..554a293 100644 --- a/src/main.c +++ b/src/main.c @@ -2,11 +2,6 @@ #include "stdio.h" -int validatePattern(char* userInput) { - char* options[] = {"glider", "toad", "press", "glider cannon"}; - return isStrIn(userInput, options, 4); -} - int main() { TGame game; @@ -52,4 +47,4 @@ int main() { } while (invalidPattern); return 0; -} \ No newline at end of file +} From 45b721a0bb28aef75b0d819f1beddc4bb61bb2b5 Mon Sep 17 00:00:00 2001 From: hozlucas28 Date: Wed, 11 Sep 2024 19:48:47 -0300 Subject: [PATCH 36/99] todo: add new todos --- libs/utilities.c | 10 ++++++++++ libs/utilities.h | 14 ++++++++++++++ src/main.c | 30 +++++++----------------------- 3 files changed, 31 insertions(+), 23 deletions(-) diff --git a/libs/utilities.c b/libs/utilities.c index 8fa9e98..f278104 100644 --- a/libs/utilities.c +++ b/libs/utilities.c @@ -5,6 +5,16 @@ #include #include +// TODO +void drawPattern(TGame* pGame, char* pattern) { + printf("%s pattern was drawn!", pattern); +} + +// TODO +void drawPatternInDashboard(TGame* pGame, TPattern* pattern) { + printf("%s pattern was injected!", pattern); +} + void fillDashboard(TGame* pGame, int with) { int i; int j; diff --git a/libs/utilities.h b/libs/utilities.h index 17dd4ca..2c10421 100644 --- a/libs/utilities.h +++ b/libs/utilities.h @@ -20,6 +20,20 @@ typedef struct { int cellsDead; /** Number of dead cells. */ } TGame; +// TODO +typedef struct { + int (*dashboard)[COLS]; + int rows; + int cols; + int center[2]; +} TPattern; + +// TODO +void drawPattern(TGame* pGame, char* pattern); + +// TODO +void drawPatternInDashboard(TGame* pGame, TPattern* pattern); + /** * @brief Fills the dashboard of a Conway's Game of Life structure with a * specified value. diff --git a/src/main.c b/src/main.c index 554a293..cdf7314 100644 --- a/src/main.c +++ b/src/main.c @@ -22,29 +22,13 @@ int main() { fillDashboard(&game, 0); - do { - requestedPattern = getUserInputStr( - "> Which pattern do you want " - "('Glider','Toad', 'Press', or 'Glider cannon')? ", - "> Invalid pattern! Try again...", 50, &validatePattern); - printf("> Pattern received: '%s'", requestedPattern); - - invalidPattern = 0; - - if (strcmpi(requestedPattern, "GLIDER") == 0) - gliderPattern(dashboard); - else if (strcmpi(requestedPattern, "TOAD") == 0) - toadPattern(dashboard); - else if (strcmpi(requestedPattern, "PRESS") == 0) - pressPattern(dashboard); - else if (strcmpi(requestedPattern, "GLIDER CANNON") == 0) - gliderCannonPattern(dashboard); - else { - puts("INVALID PATTERN, try again... :"); - invalidPattern = 1; - } - - } while (invalidPattern); + requestedPattern = getUserInputStr( + "> Which pattern do you want " + "('Glider','Toad', 'Press', or 'Glider cannon')? ", + "> Invalid pattern! Try again...", 50, &validatePattern); + printf("> Pattern received: '%s'", requestedPattern); + + drawPattern(&game, requestedPattern); return 0; } From 78db025d4310b666ed323c26cf2e2ece5238b1ff Mon Sep 17 00:00:00 2001 From: hozlucas28 Date: Wed, 11 Sep 2024 23:28:49 -0300 Subject: [PATCH 37/99] feature(macros): add new macros --- libs/macros.h | 6 ++++++ libs/utilities.h | 2 +- 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/libs/macros.h b/libs/macros.h index 1262168..605f2ac 100644 --- a/libs/macros.h +++ b/libs/macros.h @@ -25,4 +25,10 @@ */ #define COLS 110 +// TODO: Add documentation +#define PATTERN_ROWS 13 + +// TODO: Add documentation +#define PATTERN_COLS 36 + #endif // MACROS_H_INCLUDED diff --git a/libs/utilities.h b/libs/utilities.h index 2c10421..c7ee248 100644 --- a/libs/utilities.h +++ b/libs/utilities.h @@ -22,7 +22,7 @@ typedef struct { // TODO typedef struct { - int (*dashboard)[COLS]; + int (*dashboard)[PATTERN_COLS]; int rows; int cols; int center[2]; From 7293e1e0f6f543f816faff0124609e93dc56bb82 Mon Sep 17 00:00:00 2001 From: hozlucas28 Date: Wed, 11 Sep 2024 23:30:10 -0300 Subject: [PATCH 38/99] fix(gitignore): untrack personal files --- .gitignore | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/.gitignore b/.gitignore index ff22e18..e0a470c 100644 --- a/.gitignore +++ b/.gitignore @@ -1,4 +1,12 @@ +# ---------------------------------------------------------------------------- # +# PERSONAL FILES # +# ---------------------------------------------------------------------------- # + +personal-*.md + + + # ---------------------------------------------------------------------------- # # CODEBLOCKS # # ---------------------------------------------------------------------------- # From 022d5a8fb0d7d46278c685e99be098d86fe5db1a Mon Sep 17 00:00:00 2001 From: hozlucas28 Date: Wed, 11 Sep 2024 23:39:55 -0300 Subject: [PATCH 39/99] refactor: move `validatePattern` function to `validators` files --- libs/libs.cbp | 4 ++++ libs/main.h | 1 + libs/utilities.c | 5 +---- libs/utilities.h | 12 ------------ libs/validators.c | 7 +++++++ libs/validators.h | 16 ++++++++++++++++ 6 files changed, 29 insertions(+), 16 deletions(-) create mode 100644 libs/validators.c create mode 100644 libs/validators.h diff --git a/libs/libs.cbp b/libs/libs.cbp index 170146e..6b1f236 100644 --- a/libs/libs.cbp +++ b/libs/libs.cbp @@ -48,6 +48,10 @@