diff --git a/.github/translations/en/documentation.md b/.github/translations/en/documentation.md index a58369a..5d15f24 100644 --- a/.github/translations/en/documentation.md +++ b/.github/translations/en/documentation.md @@ -1,4 +1,4 @@ -# Code Documentation +# Code documentation This document provides a series of templates and examples to document the [structures](#structures), [functions](#functions), and [macros](#macros) of the application. @@ -21,10 +21,7 @@ The documentation must follow these rules: * . */ typedef struct { - /** - * @brief . - */ - DataType01 member01; + DataType01 member01; /** . */ // ... } MyStruct; @@ -42,15 +39,8 @@ _For example..._ * representing the x and y coordinates. */ typedef struct { - /** - * @brief The x-coordinate of the point. - */ - int x; - - /** - * @brief The y-coordinate of the point. - */ - int y; + int x; /** The x-coordinate of the point. */ + int y; /** The y-coordinate of the point. */ } Point2D; ``` @@ -116,7 +106,9 @@ int factorial(int n) { * @def * @brief . * - * @warning . + * . + * + * @warning . */ #define MY_MACRO value ``` diff --git a/.github/translations/en/requirements.md b/.github/translations/en/requirements.md index 342763a..bef23ac 100644 --- a/.github/translations/en/requirements.md +++ b/.github/translations/en/requirements.md @@ -3,13 +3,13 @@ > [!CAUTION] > 2 grades are required in the subject, the practical work (PW) must be submitted and defended individually in parts 1 and 2 before the midterm exam. The defense will be individual, and you must demonstrate mastery of the tools in general and the practical work in particular. For the PW to be archived, it must be submitted by the deadline indicated by the teachers in the following format: `ID_LASTNAME_FIRSTNAME_PW.zip`, e.g., `41127133_PEREZ_MARIA_PIA_PW.zip`. Note that it is a `.zip`, not `.rar` or `.7z`, respect the submission format. The PW as a suffix indicates it is practical work. Attach the statement and remove the `bin` and `obj` folders, as you are sharing programs, and for obvious reasons, the servers will delete compressed files containing binaries or executables. -## Necessary Knowledge +## Necessary knowledge - **Part 1**: Structured programming and arrays. - **Part 2**: Dynamic memory. - **Part 3**: Files. -## General Guidelines and Statement +## General guidelines and statement Develop the following work in groups of 3 to 5 people. Submission and defense are mandatory. Parts 1 and 2 will be required to take the midterm exam. Keep in mind that the solution must be executable in the laboratories of the [UNLaM](https://www.unlam.edu.ar/), so it must be compatible with the **MinGW 64-bit** compiler. For richer and lag-free visualization, it is recommended to use the [SDL (Simple DirectMedia Layer)](https://www.libsdl.org/) library, the teachers will provide a project with the library included. You will only need to know the functions that allow drawing the elements of the work (_Illustration 1_). diff --git a/.github/translations/es/README.md b/.github/translations/es/README.md index 692cfc7..df3d398 100644 --- a/.github/translations/es/README.md +++ b/.github/translations/es/README.md @@ -40,9 +40,16 @@ Este repositorio contiene el trabajo práctico de la materia Tópicos de Program ## Características +- Confirmaciones siguiendo la guía de los [Commits Convencionales](https://www.conventionalcommits.org/es/v1.0.0/) +- Control de entradas utilizando validaciones - Convenciones y estándares de código +- Despliegue de entregables +- Diseño responsivo - Documentación del código utilizando la sintaxis de [Doxygen](https://www.doxygen.nl/) +- Implementación de argumentos del programa +- Implementación de la libraría [Simple DirectMedia Layer (SDL)](https://www.libsdl.org/) - Integración continua con [GitHub Actions](https://docs.github.com/es/actions) +- Lectura e interpretación de archivos - Memoria dinámica - Planificación de la arquitectura - Planificación del flujo de trabajo del equipo (ramas, etiquetas y versionado) @@ -57,7 +64,27 @@ Este repositorio contiene el trabajo práctico de la materia Tópicos de Program 4. Selecciona el proyecto [src.cbp](./src/src.cbp) (proyecto principal) y ejecútalo en modo Release para disfrutar del Juego de la Vida de Conway. -## Problemas conocidos +### Argumentos del programa + +| Argumento | Descripción | Valor/es aceptado/s | Valor por defecto | Ejemplo | +| :--------------------- | :----------------------------------------------------- | :--------------------------------------------------------------------- | :---------------------------------------------------- | ---------------------------------------------------- | +| `--dashboard-rows` | Cantidad de filas que tendrá el tablero. | `int` (0, valor por defecto] | `( / 10) * 0.93` | `--dashboard-rows=28` | +| `--dashboard-cols` | Cantidad de columnas que tendrá el tablero. | `int` (0, valor por defecto] | `( / 10) * 0.99` | `--dashboard-cols=55` | +| `--pattern` | Patrón a dibujar en el centro del tablero. | `"glider"`, `"toad"`, `"press"` ó `"glider cannon"` | `""` | `--pattern="glider cannon"` | +| `--maximum-generation` | Generaciones máximas. | `int` (un valor menor a `0` se interpreta como generaciones infinitas) | `0` | `--maximum-generation=-1` | +| `--delay` | Tiempo de espera para generar la siguiente generación. | `int` [0, 1000] | `0` | `--delay=50` | +| `--platform` | Plataforma en donde se dibujara el tablero. | `"console"` ó `"sdl"` | `""` | `--platform="sdl"` | +| `--initial-state-file` | Ruta a un archivo con el estado inicial del tablero. | Cualquier ruta a un archivo con extensión `.txt` ó `.csv` | `""` | `--initial-state-file="./statics/initial-state.csv"` | + +> [¿Cómo defino los argumentos del programa?](https://www.youtube.com/watch?v=9Mi_TTOml94) (opcional). + +> [!IMPORTANT] +> Todos los argumentos (exceptuando `--dashboard-rows`, `--dashboard-cols` y `--initial-state-file`) serán solicitados por consola si no son definidos o acepados. Además, el parámetro `--pattern` sera ignorado si se declara un parámetro `--initial-state-file` válido. + +> [!WARNING] +> El contenido del archivo apuntado por el parámetro `--initial-state-file` debe seguir un formato especifico como puede observar en el archivo [initial-state.csv](../../../src/statics/initial-state.csv). + +### Problemas conocidos | Problema | Solución | | :-------------------------------------------------------------------- | :------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | @@ -70,6 +97,7 @@ C-Practical-Work-2024/ │ ├── .github/ │ ├── statics/ +│ │ ├── demo.mp4 │ │ ├── illustration-01.png │ │ ├── illustration-02.png │ │ └── preview.png @@ -85,14 +113,8 @@ C-Practical-Work-2024/ │ │ └── requirements.md │ │ │ └── workflows/ +│ ├── format-code-on-pr.yml │ └── format-code.yml -│ -├── src/ -│ ├── main.c -│ ├── src.cbp -│ │ -│ └── statics/ -│ └── initial-state.txt | ├── libs/ │ ├── libs.cbp @@ -103,6 +125,13 @@ C-Practical-Work-2024/ │ ├── validators.c │ ├── validators.h | | +│ ├── game/ +| | ├── macros.h +| | ├── main.h +| | ├── methods.c +| | ├── methods.h +| | └── structs.h +| | │ └── patterns/ │ ├── constructors.c │ ├── constructors.h @@ -111,6 +140,27 @@ C-Practical-Work-2024/ │ ├── methods.c │ ├── methods.h │ └── structs.h +│ +├── src/ +│ ├── macros.h +│ ├── main.c +│ ├── src.cbp +│ ├── structs.h +│ ├── utilities.c +│ ├── utilities.h +│ ├── validators.c +│ ├── validators.h +│ │ +│ ├── sdl/ +│ │ ├── main.h +│ │ ├── methods.c +│ │ ├── methods.h +│ │ │ +│ │ └── SDL2/ +│ │ └── ( ... ) +│ │ +│ └── statics/ +│ └── initial-state.csv | ├── .clang-format ├── .gitignore @@ -124,35 +174,57 @@ C-Practical-Work-2024/ - **[translations](./.github/translations)** - Traducciones de los archivos con extensión `.md` (Markdown). - **[workflows](./.github/workflows)** - Flujos de trabajo de las GitHub Actions. -- **[src](./src)** - Proyecto principal de la aplicación. - - - **[main.c](./src/main.c)** - Archivo de ejecución principal. - - **[src.cbp](./src/src.cbp)** - Archivo de configuración del proyecto. - - - **[statics](./src/statics)** - Archivos (imágenes, videos, diagramas, etc.). - - - **[initial-state.txt](./src/statics/initial-state.txt)** - Archivo con el estado inicial de la aplicación. - - **[libs](./libs)** - Proyecto con las librerías necesarias para la ejecución del proyecto principal de aplicación. - **[libs.cbp](./libs/libs.cbp)** - Archivo de configuración del proyecto. - **[macros.h](./libs/macros.h)** - Archivo con las macros esenciales del proyecto. - **[main.h](./libs/main.h)** - Archivo que indexa todos los archivos `.h` del proyecto. - **[utilities.c](./libs/utilities.c)** - Archivo con el desarrollo de los prototipos de función presentes en `utilities.h`. - - **[utilities.h](./libs/utilities.h)** - Archivo con las estructuras y los prototipos de función de uso común. + - **[utilities.h](./libs/utilities.h)** - Archivo con los prototipos de función de uso común. - **[validators.c](./libs/validators.c)** - Archivo con el desarrollo de los prototipos de función presentes en `validators.h`. - **[validators.h](./libs/validators.h)** - Archivo con prototipos de funciones relacionadas con procesos de validación. + - **[game](./libs/game)** - Funciones y estructuras para crear e interactuar con el Juego de la Vida de Conway. + + - **[macros.h](./libs/game/macros.h)** - Archivo con macros. + - **[main.h](./libs/game/main.h)** - Archivo que indexa todos los archivos `.h` dentro de la carpeta `games`. + - **[methods.c](./libs/game/methods.c)** - Archivo con el desarrollo de los prototipos de función presentes en `methods.h`. + - **[methods.h](./libs/game/methods.h)** - Archivo con los prototipos de función relacionados a los métodos del Juego de la Vida de Conway. + - **[structs.h](./libs/game/methods.h)** - Archivo con estructuras. + - **[patterns](./libs/patterns)** - Funciones y estructuras para crear patrones con células. - **[constructors.c](./libs/patterns/constructors.c)** - Archivo con el desarrollo de los prototipos de función presentes en `constructors.h`. - - **[constructors.h](./libs/patterns/constructors.h)** - Archivo con las estructuras y los prototipos de función relacionados a la creación de patrones. - - **[macros.h](./libs/macros.h)** - Archivo con macros. - - **[main.h](./libs/main.h)** - Archivo que indexa todos los archivos `.h` dentro de la carpeta `patterns`. + - **[constructors.h](./libs/patterns/constructors.h)** - Archivo con los prototipos de función relacionados a la creación de patrones. + - **[macros.h](./libs/patterns/macros.h)** - Archivo con macros. + - **[main.h](./libs/patterns/main.h)** - Archivo que indexa todos los archivos `.h` dentro de la carpeta `patterns`. - **[methods.c](./libs/patterns/methods.c)** - Archivo con el desarrollo de los prototipos de función presentes en `methods.h`. - **[methods.h](./libs/patterns/methods.h)** - Archivo con los prototipos de función relacionados a los métodos de los patrones. - **[structs.h](./libs/patterns/methods.h)** - Archivo con estructuras. +- **[src](./src)** - Proyecto principal de la aplicación. + + - **[macros.h](./src/macros.h)** - Archivo con las principales macros del proyecto. + - **[main.c](./src/main.c)** - Archivo de ejecución principal. + - **[src.cbp](./src/src.cbp)** - Archivo de configuración del proyecto. + - **[structs.h](./src/structs.h)** - Archivo con las principales estructuras para configurar el proyecto. + - **[utilities.c](./src/utilities.c)** - Archivo con el desarrollo de los prototipos de función presentes en `utilities.h`. + - **[utilities.h](./src/utilities.h)** - Archivo con los prototipos de función para configurar el proyecto. + - **[validators.c](./src/validators.c)** - Archivo con el desarrollo de los prototipos de función presentes en `utilities.h`. + - **[validators.h](./src/validators.h)** - Archivo con los prototipos de función para validar los argumentos del proyecto. + + - **[sdl](./src/sdl)** - Funciones para interactuar con la librería SDL2. + + - **[SDL2](./src/sdl/SDL2)** - Librería SDL2. + + - **[main.h](./src/sdl/main.h)** - Archivo que indexa todos los archivos `.h` dentro de la carpeta `sdl`. + - **[methods.c](./src/sdl/methods.c)** - Archivo con el desarrollo de los prototipos de función presentes en `methods.h`. + - **[methods.h](./src/sdl/methods.h)** - Archivo con los prototipos de función que permiten interactuar con la librería SDL2. + + - **[statics](./src/statics)** - Archivos (imágenes, videos, diagramas, etc.). + + - **[initial-state.csv](./src/statics/initial-state.txt)** - Archivo con el estado inicial de la aplicación. + - **[.clang-format](./.clang-format)** - Archivo de configuración de la herramienta de formateo de código `clang-format`. - **[.gitignore](./.gitignore)** - Archivo de configuración de Git para evitar el rastreo de archivos no deseados. - **[LICENSE](./LICENSE)** - Licencia del proyecto. diff --git a/.github/translations/es/documentation.md b/.github/translations/es/documentation.md index cb6d2b8..d29146e 100644 --- a/.github/translations/es/documentation.md +++ b/.github/translations/es/documentation.md @@ -21,10 +21,7 @@ Las documentaciones que se realicen deben seguir las siguientes reglas: * . */ typedef struct { - /** - * @brief . - */ - DataType01 member01; + DataType01 member01; /** . */ // ... } MyStruct; @@ -42,15 +39,8 @@ _Por ejemplo..._ * representing the x and y coordinates. */ typedef struct { - /** - * @brief The x-coordinate of the point. - */ - int x; - - /** - * @brief The y-coordinate of the point. - */ - int y; + int x; /** The x-coordinate of the point. */ + int y; /** The y-coordinate of the point. */ } Point2D; ``` @@ -116,7 +106,9 @@ int factorial(int n) { * @def * @brief . * - * @warning . + * . + * + * @warning . */ #define MY_MACRO value ``` diff --git a/README.md b/README.md index 5d77718..67217c1 100644 --- a/README.md +++ b/README.md @@ -43,8 +43,15 @@ This repository contains the practical work for the Programming Topics course at - Architecture planning - Code conventions and standards - Code documentation using [Doxygen](https://www.doxygen.nl/) syntax +- Commits following the [Conventional Commits](https://www.conventionalcommits.org/en/v1.0.0/) - Continuous integration with [GitHub Actions](https://docs.github.com/en/actions) +- Deployment of releases - Dynamic memory +- File reading and interpretation +- Implementation of program arguments +- Implementation of the [Simple DirectMedia Layer (SDL)](https://www.libsdl.org/) library +- Input control using validations +- Responsive design - Team Workflow planning (branches, tags, and releases) ## Installation @@ -57,19 +64,40 @@ This repository contains the practical work for the Programming Topics course at 4. Select the [src.cbp](./src/src.cbp) project (main project) and run it in Release mode to enjoy Conway's Game of Life. -## Known Issues +### Program arguments + +| Argument | Description | Accepted value(s) | Default value | Example | +| :--------------------- | :------------------------------------------------------ | :------------------------------------------------------- | :----------------------------------------- | ---------------------------------------------------- | +| `--dashboard-rows` | Number of rows for the dashboard. | `int` (0, default value] | `( / 10) * 0.93` | `--dashboard-rows=28` | +| `--dashboard-cols` | Number of columns for the dashboard. | `int` (0, default value] | `( / 10) * 0.99` | `--dashboard-cols=55` | +| `--pattern` | Pattern to draw in the center of the dashboard. | `"glider"`, `"toad"`, `"press"` or `"glider cannon"` | `""` | `--pattern="glider cannon"` | +| `--maximum-generation` | Maximum number of generations. | `int` (a value less than `0` means infinite generations) | `0` | `--maximum-generation=-1` | +| `--delay` | Delay to generate the next generation. | `int` [0, 1000] | `0` | `--delay=50` | +| `--platform` | Platform where the dashboard will be rendered. | `"console"` or `"sdl"` | `""` | `--platform="sdl"` | +| `--initial-state-file` | Path to a file with the initial state of the dashboard. | Any path to a file with a `.txt` or `.csv` extension | `""` | `--initial-state-file="./statics/initial-state.csv"` | + +> [How do I define the program arguments?](https://www.youtube.com/watch?v=9Mi_TTOml94) (optional). + +> [!IMPORTANT] +> All arguments (except for `--dashboard-rows`, `--dashboard-cols`, and `--initial-state-file`) will be requested via the console if not defined or accepted. Additionally, the `--pattern` parameter will be ignored if a valid `--initial-state-file` is provided. + +> [!WARNING] +> The content of the file targeted by the `--initial-state-file` parameter must follow a specific format, as seen in the file [initial-state.csv](./src/statics/initial-state.csv). + +### Known issues | Issue | Solution | | :---------------------------------------------------------- | :--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | | **[src.cbp](./src/src.cbp) (main project) doesn't compile** | _Select the [libs.cbp](./libs/libs.cbp) project (library project) and compile it in Release mode and Debug mode. Then, select the [src.cbp](./src/src.cbp) project (main project), right-click on it, choose `Build Options`, and go to the `Linker settings` tab. There, add the `libs.a` files located in the `libs/bin/Debug` and `libs/bin/Release` folders. Finally, try compiling the main project again._ | -## Application Structure +## Application structure ```plaintext C-Practical-Work-2024/ │ ├── .github/ │ ├── statics/ +│ │ ├── demo.mp4 │ │ ├── illustration-01.png │ │ ├── illustration-02.png │ │ └── preview.png @@ -85,14 +113,8 @@ C-Practical-Work-2024/ │ │ └── requirements.md │ │ │ └── workflows/ +│ ├── format-code-on-pr.yml │ └── format-code.yml -│ -├── src/ -│ ├── main.c -│ ├── src.cbp -│ │ -│ └── statics/ -│ └── initial-state.txt | ├── libs/ │ ├── libs.cbp @@ -103,6 +125,13 @@ C-Practical-Work-2024/ │ ├── validators.c │ ├── validators.h | | +│ ├── game/ +| | ├── macros.h +| | ├── main.h +| | ├── methods.c +| | ├── methods.h +| | └── structs.h +| | │ └── patterns/ │ ├── constructors.c │ ├── constructors.h @@ -111,6 +140,27 @@ C-Practical-Work-2024/ │ ├── methods.c │ ├── methods.h │ └── structs.h +│ +├── src/ +│ ├── macros.h +│ ├── main.c +│ ├── src.cbp +│ ├── structs.h +│ ├── utilities.c +│ ├── utilities.h +│ ├── validators.c +│ ├── validators.h +│ │ +│ ├── sdl/ +│ │ ├── main.h +│ │ ├── methods.c +│ │ ├── methods.h +│ │ │ +│ │ └── SDL2/ +│ │ └── ( ... ) +│ │ +│ └── statics/ +│ └── initial-state.csv | ├── .clang-format ├── .gitignore @@ -124,41 +174,63 @@ C-Practical-Work-2024/ - **[translations](./.github/translations)** - Translations of `.md` (Markdown) files. - **[workflows](./.github/workflows)** - GitHub Actions workflows. -- **[src](./src)** - Main project of the application. - - - **[main.c](./src/main.c)** - Main execution file. - - **[src.cbp](./src/src.cbp)** - Project configuration file. - - - **[statics](./src/statics)** - Files (images, videos, diagrams, etc.). - - - **[initial-state.txt](./src/statics/initial-state.txt)** - File with the initial state of the application. - - **[libs](./libs)** - Project containing the libraries necessary for the execution of the main application project. - **[libs.cbp](./libs/libs.cbp)** - Project configuration file. - **[macros.h](./libs/macros.h)** - File with essential project macros. - **[main.h](./libs/main.h)** - File indexing all `.h` files of the project. - **[utilities.c](./libs/utilities.c)** - File with the implementation of the function prototypes found in `utilities.h`. - - **[utilities.h](./libs/utilities.h)** - File with common structures and function prototypes. + - **[utilities.h](./libs/utilities.h)** - File with common function prototypes. - **[validators.c](./libs/validators.c)** - File with the implementation of the function prototypes found in `validators.h`. - **[validators.h](./libs/validators.h)** - File with functions prototypes related to validation process. + - **[game](./libs/game)** - Functions and structures to create and interact with Conway's Game of Life. + + - **[macros.h](./libs/game/macros.h)** - File containing macros. + - **[main.h](./libs/game/main.h)** - File that indexes all `.h` files within the `games` folder. + - **[methods.c](./libs/game/methods.c)** - File containing the implementation of the function prototypes found in `methods.h`. + - **[methods.h](./libs/game/methods.h)** - File containing the function prototypes related to Conway's Game of Life methods. + - **[structs.h](./libs/game/structs.h)** - File containing structures. + - **[patterns](./libs/patterns)** - Functions and structures for create patterns with cells. - **[constructors.c](./libs/patterns/constructors.c)** - File with the implementation of the function prototypes found in `constructors.h`. - - **[constructors.h](./libs/patterns/constructors.h)** - File with structures and function prototypes related to patterns creation. - - **[macros.h](./libs/macros.h)** - File with macros. - - **[main.h](./libs/main.h)** - File indexing all `.h` files inside `patterns` folder. + - **[constructors.h](./libs/patterns/constructors.h)** - File with function prototypes related to patterns creation. + - **[macros.h](./libs/patterns/macros.h)** - File with macros. + - **[main.h](./libs/patterns/main.h)** - File indexing all `.h` files inside `patterns` folder. - **[methods.c](./libs/patterns/methods.c)** - File with the implementation of the function prototypes found in `methods.h`. - **[methods.h](./libs/patterns/methods.h)** - File with function prototypes related to pattern methods. - **[structs.h](./libs/patterns/methods.h)** - File with structs. +- **[src](./src)** - Main project of the application. + + - **[macros.h](./src/macros.h)** - File with the project's main macros. + - **[main.c](./src/main.c)** - Main execution file. + - **[src.cbp](./src/src.cbp)** - Project configuration file. + - **[structs.h](./src/structs.h)** - File with the main structures for configuring the project. + - **[utilities.c](./src/utilities.c)** - File with the implementation of the function prototypes found in `utilities.h`. + - **[utilities.h](./src/utilities.h)** - File with the function prototypes for configuring the project. + - **[validators.c](./src/validators.c)** - File with the implementation of the function prototypes found in `utilities.h`. + - **[validators.h](./src/validators.h)** - File with the function prototypes for validating the project's arguments. + + - **[sdl](./src/sdl)** - Functions for interacting with the SDL2 library. + + - **[SDL2](./src/sdl/SDL2)** - SDL2 library. + + - **[main.h](./src/sdl/main.h)** - File indexing all `.h` files inside `sdl` folder. + - **[methods.c](./src/sdl/methods.c)** - File with the implementation of the function prototypes found in `methods.h`. + - **[methods.h](./src/sdl/methods.h)** - File with the function prototypes to interact with the SDL2 library. + + - **[statics](./src/statics)** - Files (images, videos, diagrams, etc.). + + - **[initial-state.txt](./src/statics/initial-state.txt)** - File with the initial state of the application. + - **[.clang-format](./.clang-format)** - Configuration file for the `clang-format` code formatting tool. - **[.gitignore](./.gitignore)** - Git configuration file to avoid tracking unwanted files. - **[LICENSE](./LICENSE)** - Project license. - **[README.md](./README.md)** - Markdown file with the general documentation for the application and repository. -## Team Workflow +## Team workflow ```mermaid %%{init: { 'logLevel': 'debug', 'theme': 'dark', 'gitGraph': {'showBranches': true, 'showCommitLabel': true, 'mainBranchName': 'Master', 'parallelCommits': true}} }%% @@ -207,7 +279,7 @@ C-Practical-Work-2024/ > The other branches are fictional and represent individual contributions from each member to the `develop` branch. -## Development Team +## Development team - [Giannotti Tiago](https://github.com/TiagoGiannotti) - [Hoz Lucas](https://github.com/hozlucas28) @@ -215,7 +287,7 @@ C-Practical-Work-2024/ - [Linares Guido](https://www.linkedin.com/in/guido-linares-25859b209/) - [Quiroga Ferney Santiago](https://github.com/Ferny1011) -## Additional Material +## Additional material - [Code Documentation](./.github/translations/en/documentation.md) - [Practical Work Requirements](./.github/translations/en/requirements.md) diff --git a/libs/game/macros.h b/libs/game/macros.h index 5b6c798..687bc02 100644 --- a/libs/game/macros.h +++ b/libs/game/macros.h @@ -1,31 +1,6 @@ #ifndef LIBS_GAME_MACROS_H_INCLUDED #define LIBS_GAME_MACROS_H_INCLUDED - -/** - * @def DASHBOARD_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 `DASHBOARD_COLS` macro to define - * the size of a grid. - * - * @warning The value of `DASHBOARD_ROWS` must be a positive integer. - */ -#define DASHBOARD_ROWS 56 - -/** - * @def DASHBOARD_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 `DASHBOARD_ROWS` macro to define - * the size of a grid. - * - * @warning The value of `DASHBOARD_COLS` must be a positive integer. - */ -#define DASHBOARD_COLS 110 - /** * @def ALIVE_CELL * @brief Represents a live cell. diff --git a/libs/game/methods.c b/libs/game/methods.c index 64ca270..5c93738 100644 --- a/libs/game/methods.c +++ b/libs/game/methods.c @@ -5,20 +5,21 @@ #include #include "../patterns/main.h" +#include "../utilities.h" #include "./macros.h" #include "./structs.h" -int countAliveNeighbors(TGame* pGame, int cellRow, int cellCol, int radius) { +int countAliveNeighbors(TGame* pGame, const int cellRow, const int cellCol, const int radius) { int i; int j; - int startRow = cellRow - radius; - int startCol = cellCol - radius; + const int startRow = cellRow - radius; + const int startCol = cellCol - radius; - int endRow = cellRow + radius + 1; - int endCol = cellCol + radius + 1; + const int endRow = cellRow + radius + 1; + const int endCol = cellCol + radius + 1; - int aliveNeighbors = 0; + size_t aliveNeighbors = 0; for (i = startRow; i < endRow; i++) { if (i > pGame->rows - 1) break; @@ -38,7 +39,7 @@ int countAliveNeighbors(TGame* pGame, int cellRow, int cellCol, int radius) { return aliveNeighbors; } -void drawPattern(TGame* pGame, char* pattern) { +void drawPattern(TGame* pGame, const char* pattern) { TPattern SPattern; fillDashboard(pGame, DEAD_CELL); @@ -67,14 +68,14 @@ void drawPattern(TGame* pGame, char* pattern) { } void drawPatternInDashboard(TGame* pGame, TPattern* pPattern) { - int i; - int j; + size_t i; + size_t j; - int pI = 0; - int pJ = 0; + size_t pI = 0; + size_t pJ = 0; - int startRow = pGame->center[0] - pPattern->center[0]; - int startCol = pGame->center[1] - pPattern->center[1]; + const int startRow = pGame->center[0] - pPattern->center[0]; + const int startCol = pGame->center[1] - pPattern->center[1]; for (i = startRow; pI < pPattern->rows; i++) { if (i < 0) continue; @@ -93,9 +94,9 @@ void drawPatternInDashboard(TGame* pGame, TPattern* pPattern) { } } -void fillDashboard(TGame* pGame, char with) { - int i; - int j; +void fillDashboard(TGame* pGame, const char with) { + size_t i; + size_t j; for (i = 0; i < pGame->rows; i++) { for (j = 0; j < pGame->cols; j++) { @@ -105,10 +106,10 @@ void fillDashboard(TGame* pGame, char with) { } void generateNextGeneration(TGame* pGame) { - int i; - int j; + size_t i; + size_t j; - int aliveNeighbors; + size_t aliveNeighbors; for (i = 0; i < pGame->rows; i++) { for (j = 0; j < pGame->cols; j++) { @@ -145,8 +146,8 @@ void generateNextGeneration(TGame* pGame) { } void printDashboardByConsole(TGame* pGame) { - int i; - int j; + size_t i; + size_t j; for (i = 0; i < pGame->rows; i++) { printf("\n"); @@ -158,8 +159,8 @@ void printDashboardByConsole(TGame* pGame) { } void printGameByConsole(TGame* pGame) { - int i; - int j; + size_t i; + size_t j; // Print header for (i = 0; i < pGame->cols + 2; i++) printf("-"); @@ -195,16 +196,16 @@ void printGameByConsole(TGame* pGame) { } void setDashboardCenter(TGame* pGame) { - int row = pGame->rows / 2; - int col = pGame->cols / 2; + const int row = pGame->rows / 2; + const int col = pGame->cols / 2; pGame->center[0] = row; pGame->center[1] = col; } -void startGameByConsole(TGame* pGame, int maxGeneration, int delayBetweenGenerations) { - int generation = 0; - int isToInfinity = maxGeneration == INT_MAX; +void startGameByConsole(TGame* pGame, const int maxGeneration, const int delayBetweenGenerations) { + size_t generation = 0; + unsigned char isToInfinity = maxGeneration == INT_MAX; pGame->generation = 0; pGame->maximumGeneration = maxGeneration; @@ -227,4 +228,4 @@ void startGameByConsole(TGame* pGame, int maxGeneration, int delayBetweenGenerat printGameByConsole(pGame); if (generation != maxGeneration) sleep(delayBetweenGenerations); } -} \ No newline at end of file +} diff --git a/libs/game/methods.h b/libs/game/methods.h index 954b02f..8734d56 100644 --- a/libs/game/methods.h +++ b/libs/game/methods.h @@ -21,7 +21,7 @@ * * @warning This function assumes that `pGame` has been properly initialized. */ -int countAliveNeighbors(TGame* pGame, int row, int col, int radius); +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. @@ -31,7 +31,7 @@ int countAliveNeighbors(TGame* pGame, int row, int col, int radius); * * @warning The pattern must be `glider`, `toad`, `press`, or `glider cannon`. */ -void drawPattern(TGame* pGame, char* pattern); +void drawPattern(TGame* pGame, const char* pattern); /** * @brief Draws a specified pattern on a Conway's Game of Life board. @@ -54,7 +54,7 @@ void drawPatternInDashboard(TGame* pGame, TPattern* pPattern); * @warning This function assumes that `pGame` has been * properly initialized. */ -void fillDashboard(TGame* pGame, char with); +void fillDashboard(TGame* pGame, const char with); /** * @brief Generates the next generation of a Conway's Game of Life. @@ -108,6 +108,6 @@ void setDashboardCenter(TGame* pGame); * * @warning This function assumes that `pGame` has been properly initialized. */ -void startGameByConsole(TGame* pGame, int maxGeneration, int delayBetweenGenerations); +void startGameByConsole(TGame* pGame, const int maxGeneration, const int delayBetweenGenerations); #endif // LIBS_GAME_MAIN_H_INCLUDED \ No newline at end of file diff --git a/libs/game/structs.h b/libs/game/structs.h index 06191cd..ecba237 100644 --- a/libs/game/structs.h +++ b/libs/game/structs.h @@ -2,8 +2,6 @@ #ifndef LIBS_GAME_STRUCTS_H_INCLUDED #define LIBS_GAME_STRUCTS_H_INCLUDED -#include "../main.h" - /** * @struct TGame * @brief Represents a Conway's Game of Life structure. @@ -25,4 +23,4 @@ typedef struct { int delayBetweenGenerations; /** Delay time in milliseconds for processed the next generation.*/ } TGame; -#endif // LIBS_GAME_STRUCTS_H_INCLUDED \ No newline at end of file +#endif // LIBS_GAME_STRUCTS_H_INCLUDED diff --git a/libs/macros.h b/libs/macros.h index 93645ff..b73ad24 100644 --- a/libs/macros.h +++ b/libs/macros.h @@ -2,10 +2,20 @@ #ifndef LIBS_MACROS_H_INCLUDED #define LIBS_MACROS_H_INCLUDED -// TODO: Documentation +/** + * @def MAX + * @brief Returns the maximum value between two values. + * + * @warning The value of `a` and `b` parameters must be an integer or float. + */ #define MAX(a, b) a > b ? a : b; -// TODO: Documentation +/** + * @def MIN + * @brief Returns the minimum value between two values. + * + * @warning The value of `a` and `b` parameters must be an integer or float. + */ #define MIN(a, b) a > b ? b : a; /** diff --git a/libs/patterns/constructors.c b/libs/patterns/constructors.c index 87cd95c..558d840 100644 --- a/libs/patterns/constructors.c +++ b/libs/patterns/constructors.c @@ -2,6 +2,7 @@ #include "./constructors.h" #include "../game/main.h" +#include "../utilities.h" #include "./methods.h" #include "./structs.h" diff --git a/libs/patterns/methods.c b/libs/patterns/methods.c index c8c542f..a3f05ee 100644 --- a/libs/patterns/methods.c +++ b/libs/patterns/methods.c @@ -5,9 +5,9 @@ #include "./structs.h" -void fillPattern(TPattern* pPattern, char with) { - int i; - int j; +void fillPattern(TPattern* pPattern, const char with) { + size_t i; + size_t j; for (i = 0; i < pPattern->rows; i++) { for (j = 0; j < pPattern->cols; j++) { @@ -17,8 +17,8 @@ void fillPattern(TPattern* pPattern, char with) { } void printPatternByConsole(TPattern* pPattern) { - int i; - int j; + size_t i; + size_t j; for (i = 0; i < pPattern->rows; i++) { for (j = 0; j < pPattern->cols; j++) { @@ -30,8 +30,8 @@ void printPatternByConsole(TPattern* pPattern) { } void setPatternCenter(TPattern* pPattern) { - int row = pPattern->rows / 2; - int col = pPattern->cols / 2; + const int row = pPattern->rows / 2; + const int col = pPattern->cols / 2; pPattern->center[0] = row; pPattern->center[1] = col; diff --git a/libs/patterns/methods.h b/libs/patterns/methods.h index 62bc634..821833c 100644 --- a/libs/patterns/methods.h +++ b/libs/patterns/methods.h @@ -12,7 +12,7 @@ * * @warning This function assumes that `pPattern` has been properly initialized. */ -void fillPattern(TPattern* pPattern, char with); +void fillPattern(TPattern* pPattern, const char with); /** * @brief Prints the `arr` field of a pattern structure by console. diff --git a/libs/utilities.c b/libs/utilities.c index 79a560f..8919bda 100644 --- a/libs/utilities.c +++ b/libs/utilities.c @@ -7,10 +7,11 @@ #include #include +#include "./macros.h" #include "./patterns/main.h" -void destroy2DArray(char** arr, int rows, int cols) { - int i; +void destroy2DArray(char** arr, const int rows, const int cols) { + size_t i; for (i = 0; i < rows; i++) { free(*(arr + i)); @@ -19,8 +20,105 @@ void destroy2DArray(char** arr, int rows, int cols) { free(arr); } -char* getUserInputStr(char* message, char* onInvalidMessage, int strLength, - int (*validator)(char* userInput)) { +int setDashboardFromFile(const char* filePath, TGame* pGame, const int minRows, const int minCols) { + FILE* pf; + TPattern pattern; + + char* line; + const size_t lineLength = 100; + + char* row; + char* col; + char* sep; + + int rowInt; + int colInt; + + int rows = minRows; + int cols = minCols; + + int patternRows = 0; + int patternCols = 0; + + pf = fopen(filePath, "rt"); + if (pf == NULL) return 0; + + line = malloc(sizeof(char) * (lineLength + 1)); + if (line == NULL) { + fclose(pf); + return 0; + }; + *(line + lineLength) = '\0'; + + fgets(line, lineLength, pf); + + while (fgets(line, lineLength, pf)) { + row = line; + sep = strrchr(line, ';'); + if (sep == NULL) continue; + + *sep = '\0'; + col = sep + 1; + + sscanf(row, "%d", &rowInt); + sscanf(col, "%d", &colInt); + + patternRows = MAX(rowInt, patternRows); + patternCols = MAX(colInt, patternCols); + } + + rows = MAX(patternRows, rows); + cols = MAX(patternCols, cols); + + pGame->dashboard = new2DArray(rows, cols); + pGame->rows = rows; + pGame->cols = cols; + pGame->cellsAlive = 0; + pGame->generation = 0; + + setDashboardCenter(pGame); + + fillDashboard(pGame, DEAD_CELL); + + pattern.arr = new2DArray(patternRows, patternCols); + pattern.rows = patternRows; + pattern.cols = patternCols; + + setPatternCenter(&pattern); + + fillPattern(&pattern, DEAD_CELL); + + rewind(pf); + fgets(line, lineLength, pf); + + while (fgets(line, lineLength, pf)) { + row = line; + sep = strrchr(line, ';'); + if (sep == NULL) continue; + + *sep = '\0'; + col = sep + 1; + + sscanf(row, "%d", &rowInt); + sscanf(col, "%d", &colInt); + + pattern.arr[rowInt - 1][colInt - 1] = ALIVE_CELL; + pGame->cellsAlive++; + } + + pGame->cellsDead = (cols * rows) - pGame->cellsAlive; + + drawPatternInDashboard(pGame, &pattern); + destroy2DArray(pattern.arr, pattern.rows, pattern.cols); + + fclose(pf); + free(line); + + return 1; +} + +char* getUserInputStr(const char* message, const char* onInvalidMessage, const int strLength, + unsigned char (*validator)(const char* userInput)) { char* userInput = malloc(strLength * sizeof(char)); if (userInput == NULL) { printf("Memory allocation failed!\n"); @@ -43,8 +141,8 @@ char* getUserInputStr(char* message, char* onInvalidMessage, int strLength, return userInput; } -int isStrIn(char* str, char* arr[], int size) { - int i; +int isStrIn(const char* str, const char* arr[], const int size) { + size_t i; for (i = 0; i < size; i++) { if (strcmpi(str, *(arr + i)) == 0) return 1; @@ -53,13 +151,11 @@ int isStrIn(char* str, char* arr[], int size) { return 0; } -char** new2DArray(int rows, int cols) { - char** bidimensionalArr; - - int i; - int j; +char** new2DArray(const int rows, const int cols) { + size_t i; + size_t j; - bidimensionalArr = malloc(rows * sizeof(char*)); + char** bidimensionalArr = malloc(rows * sizeof(char*)); if (bidimensionalArr == NULL) { printf("Memory allocation failed!\n"); exit(EXIT_FAILURE); @@ -78,16 +174,16 @@ char** new2DArray(int rows, int cols) { } void sleep(int miliseconds) { - clock_t startTime = clock(); + const clock_t startTime = clock(); while (clock() < (startTime + miliseconds)) ; } int strcmpi(const char* str01, const char* str02) { - int i; + size_t i; - int lengthStr01 = strlen(str01); - int lengthStr02 = strlen(str02); + const size_t lengthStr01 = strlen(str01); + const size_t lengthStr02 = strlen(str02); char charStr01; char charStr02; @@ -112,11 +208,11 @@ void trimStr(char* str) { } void trimLeftStr(char* str) { - int i; - int j; - int strLength = strlen(str); + size_t i; + size_t j; + size_t strLength = strlen(str); - int counter = 0; + size_t counter = 0; for (i = 0; i < strLength; i++) { if (!isspace(*(str + i))) break; @@ -131,10 +227,10 @@ void trimLeftStr(char* str) { } void trimRightStr(char* str) { - int i; - int strLength = strlen(str); + size_t i; + size_t strLength = strlen(str); - int counter = 0; + size_t counter = 0; for (i = strLength - 1; i > 0; i--) { if (!isspace(*(str + i))) break; diff --git a/libs/utilities.h b/libs/utilities.h index 1c590f8..ae8ed73 100644 --- a/libs/utilities.h +++ b/libs/utilities.h @@ -4,6 +4,7 @@ #include +#include "./game/main.h" #include "./macros.h" #include "./patterns/main.h" @@ -21,7 +22,23 @@ * @warning Ensure that the array has been dynamically allocated and that the number of rows and * columns are correctly specified to avoid undefined behavior. */ -void destroy2DArray(char** arr, int rows, int cols); +void destroy2DArray(char** arr, const int rows, const int cols); + +/** + * @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 Gets user input as a string. @@ -42,8 +59,8 @@ void destroy2DArray(char** arr, int rows, int cols); * @warning Ensure to free the returned pointer after use with the appropriate deallocation * functions to avoid memory leaks. */ -char* getUserInputStr(char* message, char* onInvalidMessage, int strLength, - int (*validator)(char* userInput)); +char* getUserInputStr(const char* message, const char* onInvalidMessage, const int strLength, + unsigned char (*validator)(const char* userInput)); /** * @brief Checks if a string is present in an array of strings. @@ -56,7 +73,7 @@ char* getUserInputStr(char* message, char* onInvalidMessage, int strLength, * * @return 1 if the string is found in the array, 0 otherwise. */ -int isStrIn(char* str, char* arr[], int arrLength); +int isStrIn(const char* str, const char* arr[], const int arrLength); /** * @brief Initializes a 2D array of characters. @@ -72,14 +89,14 @@ int isStrIn(char* str, char* arr[], int arrLength); * @warning Ensure to free the allocated memory using appropriate deallocation functions to avoid * memory leaks. */ -char** new2DArray(int rows, int cols); +char** new2DArray(const int rows, const int cols); /** * @brief Pauses the execution of the program. * * @warning The actual delay may be longer than specified due to system timer. */ -void sleep(int milliseconds); +void sleep(const int milliseconds); /** * @brief Compares two strings case-insensitively. @@ -134,4 +151,4 @@ void trimLeftStr(char* str); */ void trimRightStr(char* str); -#endif // LIBS_UTILITIES_H_INCLUDED \ No newline at end of file +#endif // LIBS_UTILITIES_H_INCLUDED diff --git a/libs/validators.c b/libs/validators.c index 07e0e97..7e649f4 100644 --- a/libs/validators.c +++ b/libs/validators.c @@ -9,10 +9,10 @@ #include "./macros.h" #include "./utilities.h" -int validateDelay(char* delay) { - int i; +unsigned char validateDelay(const char* delay) { + size_t i; int delayInt; - int delayLength = strlen(delay); + size_t delayLength = strlen(delay); for (i = 0; i < delayLength; i++) { if (!isdigit(*(delay + i))) return 0; @@ -22,10 +22,10 @@ int validateDelay(char* delay) { return delayInt >= MINIMUM_DELAY && delayInt <= MAXIMUM_DELAY; } -int validateGeneration(char* generation) { - int i; +unsigned char validateGeneration(const char* generation) { + size_t i; int generationInt; - int generationLength = strlen(generation); + size_t generationLength = strlen(generation); for (i = 0; i < generationLength; i++) { if (*(generation + i) != '-' && !isdigit(*(generation + i))) return 0; @@ -35,13 +35,13 @@ int validateGeneration(char* generation) { return generationInt >= INT_MIN && generationInt <= INT_MAX; } -int validatePattern(char* pattern) { - char* options[] = {"glider", "toad", "press", "glider cannon"}; +unsigned char validatePattern(const char* pattern) { + const char* options[] = {"glider", "toad", "press", "glider cannon"}; return isStrIn(pattern, options, 4); } -int validatePlatform(char* userInput) { - char* options[] = {"console", "simple directmedia layer (sdl)", "simple directmedia layer", - "sdl"}; +unsigned char validatePlatform(const char* userInput) { + const char* options[] = {"console", "simple directmedia layer (sdl)", + "simple directmedia layer", "sdl"}; return isStrIn(userInput, options, 4); } \ No newline at end of file diff --git a/libs/validators.h b/libs/validators.h index cf37427..5e318aa 100644 --- a/libs/validators.h +++ b/libs/validators.h @@ -12,7 +12,7 @@ * * @return 1 if the delay is valid, 0 otherwise. */ -int validateDelay(char* delay); +unsigned char validateDelay(const char* delay); /** * @brief Validates a generation. @@ -24,7 +24,7 @@ int validateDelay(char* delay); * * @return 1 if the generation is valid, 0 otherwise. */ -int validateGeneration(char* generation); +unsigned char validateGeneration(const char* generation); /** * @brief Validates a pattern. @@ -36,7 +36,7 @@ int validateGeneration(char* generation); * * @return 1 if the pattern is valid, 0 otherwise. */ -int validatePattern(char* pattern); +unsigned char validatePattern(const char* pattern); /** * @brief Validates a platform. @@ -48,6 +48,6 @@ int validatePattern(char* pattern); * * @return 1 if the platform is valid, 0 otherwise. */ -int validatePlatform(char* platform); +unsigned char validatePlatform(const char* platform); #endif // LIBS_VALIDATORS_H_INCLUDED diff --git a/src/macros.h b/src/macros.h index 092e773..5315f40 100644 --- a/src/macros.h +++ b/src/macros.h @@ -1,7 +1,11 @@ #ifndef SRC_MACROS_H_INCLUDED #define SRC_MACROS_H_INCLUDED -// TODO: Documentation +/** + * @def CELL_SIZE + * + * @warning The value of `CELL_SIZE` must be a positive integer. + */ #define CELL_SIZE 10 #endif // SRC_MACROS_H_INCLUDED diff --git a/src/main.c b/src/main.c index d4a0f13..3ba42a9 100644 --- a/src/main.c +++ b/src/main.c @@ -9,7 +9,7 @@ #include "./structs.h" #include "./utilities.h" -int main(int argc, char* argv[]) { +int main(const int argc, char* argv[]) { TMainArguments mainArguments; TGame game; @@ -32,38 +32,52 @@ int main(int argc, char* argv[]) { rows = mainArguments.dashboardRows; cols = mainArguments.dashboardCols; - dashboard = new2DArray(rows, cols); - game.dashboard = dashboard; - game.rows = rows; - game.cols = cols; - game.cellsAlive = 0; - game.cellsDead = cols * rows; - game.generation = 0; + /* ----------------------------- Request Pattern ---------------------------- */ - setDashboardCenter(&game); + if (*mainArguments.initialStateFile == '\0') { + dashboard = new2DArray(rows, cols); - fillDashboard(&game, DEAD_CELL); + game.dashboard = dashboard; + game.rows = rows; + game.cols = cols; + game.cellsAlive = 0; + game.cellsDead = cols * rows; + game.generation = 0; - /* ----------------------------- Request Pattern ---------------------------- */ + setDashboardCenter(&game); + + fillDashboard(&game, DEAD_CELL); + + if (*mainArguments.pattern == '\0') { + requestedPattern = getUserInputStr( + "> Which pattern do you want? ('Glider','Toad', 'Press', or 'Glider cannon'): ", + "> Invalid pattern! Try again...", 50, &validatePattern); + + printf("> Pattern received: '%s'.\n\n", requestedPattern); - if (strcmp(mainArguments.pattern, "") == 0) { - requestedPattern = getUserInputStr( - "> Which pattern do you want? ('Glider','Toad', 'Press', or 'Glider cannon'): ", - "> Invalid pattern! Try again...", 50, &validatePattern); + drawPattern(&game, requestedPattern); - printf("> Pattern received: '%s'.\n\n", requestedPattern); + free(requestedPattern); + } else { + requestedPattern = mainArguments.pattern; - drawPattern(&game, requestedPattern); + printf("> Pattern received: '%s'.\n\n", requestedPattern); - free(requestedPattern); + drawPattern(&game, requestedPattern); + }; } else { - requestedPattern = mainArguments.pattern; + /* --------------------------- Draw Initial State --------------------------- */ - printf("> Pattern received: '%s'.\n\n", requestedPattern); + if (!setDashboardFromFile(mainArguments.initialStateFile, &game, rows, cols)) { + printf( + "> An error occurred on set the initial state of the dashboard! Please check the " + "file path with the initial state (received %s) and it's content.\n", + mainArguments.initialStateFile); - drawPattern(&game, requestedPattern); - }; + exit(EXIT_FAILURE); + } + } /* ----------------------- Request Maximum Generation ----------------------- */ @@ -121,7 +135,7 @@ int main(int argc, char* argv[]) { /* ---------------------------- Request Platform ---------------------------- */ - if (strcmp(mainArguments.platform, "") == 0) { + if (*mainArguments.platform == '\0') { platformSelected = getUserInputStr( "> In which platform do you want to start the Conway's Game of Life game? (console, or " "Simple DirectMedia Layer (SDL)): ", diff --git a/src/sdl/methods.c b/src/sdl/methods.c index 1b0fd23..ce49acb 100644 --- a/src/sdl/methods.c +++ b/src/sdl/methods.c @@ -31,14 +31,15 @@ int getScreenResolution(int* width, int* height) { return 1; } -int startGameBySDL(TGame* pGame, int maxGeneration, int delayBetweenGenerations) { - int i; - int j; +unsigned char startGameBySDL(TGame* pGame, const int maxGeneration, + const int delayBetweenGenerations) { + size_t i; + size_t j; - int cellSize = CELL_SIZE; - int generation = 0; - int isToInfinity = maxGeneration == INT_MAX; - int userRequestClose = 0; + const size_t cellSize = CELL_SIZE; + size_t generation = 0; + const unsigned char isToInfinity = maxGeneration == INT_MAX; + unsigned char userRequestClose = 0; SDL_Window* window = NULL; SDL_Renderer* renderer = NULL; @@ -47,9 +48,9 @@ int startGameBySDL(TGame* pGame, int maxGeneration, int delayBetweenGenerations) // Window configuration char windowCaption[256]; - int windowWidth = cellSize * (pGame->cols + 2); - int windowHeight = cellSize * (pGame->rows + 2); - Uint32 windowFlags = SDL_WINDOW_SHOWN | SDL_WINDOW_RESIZABLE; + const int windowWidth = cellSize * (pGame->cols + 2); + const int windowHeight = cellSize * (pGame->rows + 2); + const Uint32 windowFlags = SDL_WINDOW_SHOWN | SDL_WINDOW_RESIZABLE; // SDL initialization if (SDL_Init(SDL_INIT_VIDEO) != 0) { diff --git a/src/sdl/methods.h b/src/sdl/methods.h index 6799f86..a258de5 100644 --- a/src/sdl/methods.h +++ b/src/sdl/methods.h @@ -3,7 +3,14 @@ #include "../../libs/main.h" -// TODO: Documentation +/** + * @brief Gets the current screen resolution. + * + * @param width Pointer to store the screen width. + * @param height Pointer to store the screen height. + * + * @return Returns `1` if the screen resolution was successfully obtained, or `0` if it was not. + */ int getScreenResolution(int* width, int* height); /** @@ -15,6 +22,7 @@ int getScreenResolution(int* width, int* height); * * @warning This function assumes that `pGame` has been properly initialized. */ -int startGameBySDL(TGame* pGame, int maxGeneration, int delayBetweenGenerations); +unsigned char startGameBySDL(TGame* pGame, const int maxGeneration, + const int delayBetweenGenerations); #endif // SDL_METHODS_H_INCLUDED diff --git a/src/src.cbp b/src/src.cbp index c9a891c..cf358f5 100644 --- a/src/src.cbp +++ b/src/src.cbp @@ -11,7 +11,6 @@