mirror of
https://gitlab.com/klmp200/LO27.git
synced 2024-11-22 21:53:19 +00:00
Renommage complet des fonctions
This commit is contained in:
parent
28021951b4
commit
d763abfc80
30
LibGui/gui.c
30
LibGui/gui.c
@ -27,7 +27,7 @@
|
|||||||
#include <termios.h>
|
#include <termios.h>
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
|
|
||||||
void SetPixel(SDL_Renderer *renderer, int x, int y, bool value){
|
void setPixel(SDL_Renderer *renderer, int x, int y, bool value){
|
||||||
|
|
||||||
if (value){
|
if (value){
|
||||||
SDL_SetRenderDrawColor(renderer, 255, 255, 255, 255);
|
SDL_SetRenderDrawColor(renderer, 255, 255, 255, 255);
|
||||||
@ -37,7 +37,7 @@ void SetPixel(SDL_Renderer *renderer, int x, int y, bool value){
|
|||||||
SDL_RenderDrawPoint(renderer, x, y);
|
SDL_RenderDrawPoint(renderer, x, y);
|
||||||
}
|
}
|
||||||
|
|
||||||
void DisplayMatrixSDL(SCREEN *screen, Matrix m){
|
void displayMatrixSDL(SCREEN *screen, Matrix m){
|
||||||
int i;
|
int i;
|
||||||
int j;
|
int j;
|
||||||
|
|
||||||
@ -46,13 +46,13 @@ void DisplayMatrixSDL(SCREEN *screen, Matrix m){
|
|||||||
|
|
||||||
for (i=0;i<m.rowCount;i++){
|
for (i=0;i<m.rowCount;i++){
|
||||||
for (j=0;j<m.colCount;j++){
|
for (j=0;j<m.colCount;j++){
|
||||||
SetPixel(screen->renderer, i, j, GetCellValue(m, j, i));
|
setPixel(screen->renderer, i, j, getCellValue(m, j, i));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
SDL_RenderPresent(screen->renderer);
|
SDL_RenderPresent(screen->renderer);
|
||||||
}
|
}
|
||||||
|
|
||||||
void WaitUntilEnter(SCREEN * screen){
|
void waitUntilEnter(SCREEN * screen){
|
||||||
int keypress = 0;
|
int keypress = 0;
|
||||||
|
|
||||||
while (!keypress){
|
while (!keypress){
|
||||||
@ -72,7 +72,7 @@ void WaitUntilEnter(SCREEN * screen){
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
int NewWindowFromMatrix(Matrix m){
|
int newWindowFromMatrix(Matrix m){
|
||||||
SCREEN screen;
|
SCREEN screen;
|
||||||
|
|
||||||
screen.WIDTH = m.colCount;
|
screen.WIDTH = m.colCount;
|
||||||
@ -92,9 +92,9 @@ int NewWindowFromMatrix(Matrix m){
|
|||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
DisplayMatrixSDL(&screen, m);
|
displayMatrixSDL(&screen, m);
|
||||||
|
|
||||||
WaitUntilEnter(&screen);
|
waitUntilEnter(&screen);
|
||||||
|
|
||||||
SDL_DestroyRenderer(screen.renderer);
|
SDL_DestroyRenderer(screen.renderer);
|
||||||
SDL_DestroyWindow(screen.window);
|
SDL_DestroyWindow(screen.window);
|
||||||
@ -104,12 +104,12 @@ int NewWindowFromMatrix(Matrix m){
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool YesOrNo(char message[]){
|
bool inputYesOrNo(char message[]){
|
||||||
char response;
|
char response;
|
||||||
|
|
||||||
printf("%s (Y/n)\n", message);
|
printf("%s (Y/n)\n", message);
|
||||||
response = getchar();
|
response = getchar();
|
||||||
ClearBuffer();
|
clearBuffer();
|
||||||
|
|
||||||
if (response == 'n'){
|
if (response == 'n'){
|
||||||
return false;
|
return false;
|
||||||
@ -119,33 +119,33 @@ bool YesOrNo(char message[]){
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void ClearBuffer(){
|
void clearBuffer(){
|
||||||
char c;
|
char c;
|
||||||
while ((c = getchar()) != '\n' && c != EOF) { }
|
while ((c = getchar()) != '\n' && c != EOF) { }
|
||||||
}
|
}
|
||||||
|
|
||||||
void DisplayMatrixGUI(Matrix m, bool useSDL){
|
void displayMatrixGUI(Matrix m, bool useSDL){
|
||||||
if (useSDL){
|
if (useSDL){
|
||||||
printf("Press ENTER or the red cross to exit the window and continue.\n");
|
printf("Press ENTER or the red cross to exit the window and continue.\n");
|
||||||
NewWindowFromMatrix(m);
|
newWindowFromMatrix(m);
|
||||||
} else {
|
} else {
|
||||||
printMatrix(m);
|
printMatrix(m);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
int SafeNumberInput(int min, int max){
|
int safeNumberInput(int min, int max){
|
||||||
char str[30];
|
char str[30];
|
||||||
int input;
|
int input;
|
||||||
|
|
||||||
fgets(str, 29, stdin);
|
fgets(str, 29, stdin);
|
||||||
ClearBuffer();
|
clearBuffer();
|
||||||
|
|
||||||
input = atoi(str);
|
input = atoi(str);
|
||||||
|
|
||||||
while (input < min || input > max){
|
while (input < min || input > max){
|
||||||
printf("The number should be between %d and %d\n", min, max);
|
printf("The number should be between %d and %d\n", min, max);
|
||||||
fgets(str, 29, stdin);
|
fgets(str, 29, stdin);
|
||||||
ClearBuffer();
|
clearBuffer();
|
||||||
input = atoi(str);
|
input = atoi(str);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
16
LibGui/gui.h
16
LibGui/gui.h
@ -41,7 +41,7 @@ typedef struct {
|
|||||||
* @param value display white if true and black if false
|
* @param value display white if true and black if false
|
||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
void SetPixel(SDL_Renderer *renderer, int x, int y, bool value);
|
void setPixel(SDL_Renderer *renderer, int x, int y, bool value);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Display an entire matrix on a given screen
|
* Display an entire matrix on a given screen
|
||||||
@ -49,28 +49,28 @@ void SetPixel(SDL_Renderer *renderer, int x, int y, bool value);
|
|||||||
* @param m a Matrix
|
* @param m a Matrix
|
||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
void DisplayMatrixSDL(SCREEN *screen, Matrix m);
|
void displayMatrixSDL(SCREEN *screen, Matrix m);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Wait until the user press the enter key
|
* Wait until the user press the enter key
|
||||||
* @param screen the screen where the renderer is
|
* @param screen the screen where the renderer is
|
||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
void WaitUntilEnter(SCREEN * screen);
|
void waitUntilEnter(SCREEN * screen);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Print a matrix in a new SDL window
|
* Print a matrix in a new SDL window
|
||||||
* @param Matrix the matrix to display
|
* @param Matrix the matrix to display
|
||||||
* @return int error code
|
* @return int error code
|
||||||
*/
|
*/
|
||||||
int NewWindowFromMatrix(Matrix m);
|
int newWindowFromMatrix(Matrix m);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Display a message and ask for yes or no to the user
|
* Display a message and ask for yes or no to the user
|
||||||
* @param message the message to display
|
* @param message the message to display
|
||||||
* @return bool the answer
|
* @return bool the answer
|
||||||
*/
|
*/
|
||||||
bool YesOrNo(char message[]);
|
bool inputYesOrNo(char message[]);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Display matrix choosing the right function
|
* Display matrix choosing the right function
|
||||||
@ -78,7 +78,7 @@ bool YesOrNo(char message[]);
|
|||||||
* @param useSDL a bool
|
* @param useSDL a bool
|
||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
void DisplayMatrixGUI(Matrix m, bool useSDL);
|
void displayMatrixGUI(Matrix m, bool useSDL);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get a number from the user safely
|
* Get a number from the user safely
|
||||||
@ -86,12 +86,12 @@ void DisplayMatrixGUI(Matrix m, bool useSDL);
|
|||||||
* @param max the maximal authorized number
|
* @param max the maximal authorized number
|
||||||
* @return int the input number
|
* @return int the input number
|
||||||
*/
|
*/
|
||||||
int SafeNumberInput(int min, int max);
|
int safeNumberInput(int min, int max);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Clears the buffer of stdin
|
* Clears the buffer of stdin
|
||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
void ClearBuffer();
|
void clearBuffer();
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
@ -51,7 +51,6 @@ Matrix applyRules (Matrix matrix,int Rules, int N){
|
|||||||
tempMatrix1 = matrixFromRules(matrix, i, RulesMatrix);
|
tempMatrix1 = matrixFromRules(matrix, i, RulesMatrix);
|
||||||
|
|
||||||
for (j=1;j<N;j++){
|
for (j=1;j<N;j++){
|
||||||
printf("Tourne\n");
|
|
||||||
tempMatrix2 = matrixFromRules(tempMatrix1,i, RulesMatrix);
|
tempMatrix2 = matrixFromRules(tempMatrix1,i, RulesMatrix);
|
||||||
freeMatrix(tempMatrix1);
|
freeMatrix(tempMatrix1);
|
||||||
|
|
||||||
@ -63,7 +62,7 @@ Matrix applyRules (Matrix matrix,int Rules, int N){
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
Matrix CreateMatrix(){
|
Matrix createMatrix(){
|
||||||
Matrix matrix;
|
Matrix matrix;
|
||||||
matrix.colCount = 0;
|
matrix.colCount = 0;
|
||||||
matrix.rowCount = 0;
|
matrix.rowCount = 0;
|
||||||
@ -72,13 +71,13 @@ Matrix CreateMatrix(){
|
|||||||
return matrix;
|
return matrix;
|
||||||
}
|
}
|
||||||
|
|
||||||
Matrix SetMatrixDim(Matrix matrix,int nbCols,int nbRows){
|
Matrix setMatrixDim(Matrix matrix,int nbCols,int nbRows){
|
||||||
matrix.colCount = nbCols;
|
matrix.colCount = nbCols;
|
||||||
matrix.rowCount = nbRows;
|
matrix.rowCount = nbRows;
|
||||||
return matrix;
|
return matrix;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool CreateMatrixElem(Matrix matrix, int ColPos, int RowPos){
|
bool createMatrixElem(Matrix matrix, int ColPos, int RowPos){
|
||||||
ListElement * Row = NULL;
|
ListElement * Row = NULL;
|
||||||
ListElement * Col = NULL;
|
ListElement * Col = NULL;
|
||||||
int error = 0;
|
int error = 0;
|
||||||
@ -153,7 +152,7 @@ bool CreateMatrixElem(Matrix matrix, int ColPos, int RowPos){
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
cellElement * FindMatrixElem(Matrix matrix, int ColPos, int RowPos){
|
cellElement * findMatrixElem(Matrix matrix, int ColPos, int RowPos){
|
||||||
ListElement * Row = NULL;
|
ListElement * Row = NULL;
|
||||||
cellElement * elem = NULL;
|
cellElement * elem = NULL;
|
||||||
|
|
||||||
@ -170,14 +169,14 @@ cellElement * FindMatrixElem(Matrix matrix, int ColPos, int RowPos){
|
|||||||
return elem;
|
return elem;
|
||||||
}
|
}
|
||||||
|
|
||||||
int SupprMatrixElem(Matrix matrix, int ColPos, int RowPos){
|
int deleteMatrixElem(Matrix matrix, int ColPos, int RowPos){
|
||||||
cellElement * elem = NULL;
|
cellElement * elem = NULL;
|
||||||
cellElement * tmp = NULL;
|
cellElement * tmp = NULL;
|
||||||
|
|
||||||
ListElement * Row = NULL;
|
ListElement * Row = NULL;
|
||||||
ListElement * Col = NULL;
|
ListElement * Col = NULL;
|
||||||
|
|
||||||
elem = FindMatrixElem(matrix,ColPos,RowPos);
|
elem = findMatrixElem(matrix,ColPos,RowPos);
|
||||||
if (elem == NULL){
|
if (elem == NULL){
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
@ -240,22 +239,22 @@ int SupprMatrixElem(Matrix matrix, int ColPos, int RowPos){
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
bool GetCellValue(Matrix matrix, int ColPos, int RowPos){
|
bool getCellValue(Matrix matrix, int ColPos, int RowPos){
|
||||||
if (matrix.colCount <= ColPos || matrix.rowCount <= RowPos){
|
if (matrix.colCount <= ColPos || matrix.rowCount <= RowPos){
|
||||||
return ERROR;
|
return ERROR;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (FindMatrixElem(matrix,ColPos,RowPos) == NULL){
|
if (findMatrixElem(matrix,ColPos,RowPos) == NULL){
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool SetCellValue(Matrix matrix, int ColPos, int RowPos,bool value){
|
bool setCellValue(Matrix matrix, int ColPos, int RowPos,bool value){
|
||||||
if (value == true){
|
if (value == true){
|
||||||
return CreateMatrixElem(matrix,ColPos,RowPos);
|
return createMatrixElem(matrix,ColPos,RowPos);
|
||||||
}else{
|
}else{
|
||||||
if ( SupprMatrixElem(matrix,ColPos,RowPos) >= 0 ){
|
if ( deleteMatrixElem(matrix,ColPos,RowPos) >= 0 ){
|
||||||
return true;
|
return true;
|
||||||
}else{
|
}else{
|
||||||
return false;
|
return false;
|
||||||
@ -275,7 +274,7 @@ void printMatrix(Matrix matrix){
|
|||||||
printf("| ");
|
printf("| ");
|
||||||
for (j=0;j<matrix.colCount;j++){
|
for (j=0;j<matrix.colCount;j++){
|
||||||
|
|
||||||
b = GetCellValue(matrix,j,i);
|
b = getCellValue(matrix,j,i);
|
||||||
if (b == true){
|
if (b == true){
|
||||||
printf("1 ");
|
printf("1 ");
|
||||||
}else if (b == false){
|
}else if (b == false){
|
||||||
@ -299,7 +298,7 @@ Matrix freeMatrix(Matrix matrix){
|
|||||||
for (i=0;i<matrix.rowCount;i++){
|
for (i=0;i<matrix.rowCount;i++){
|
||||||
for (j=0;j<matrix.colCount;j++){
|
for (j=0;j<matrix.colCount;j++){
|
||||||
|
|
||||||
SetCellValue(matrix,j,i,false);
|
setCellValue(matrix,j,i,false);
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
@ -312,15 +311,15 @@ Matrix freeMatrix(Matrix matrix){
|
|||||||
}
|
}
|
||||||
|
|
||||||
Matrix opMatrix(Matrix matrix1,Matrix matrix2,bool (operator)(bool, bool)){
|
Matrix opMatrix(Matrix matrix1,Matrix matrix2,bool (operator)(bool, bool)){
|
||||||
Matrix SumMatrix = CreateMatrix();
|
Matrix SumMatrix = createMatrix();
|
||||||
int i =0;
|
int i =0;
|
||||||
int j = 0;
|
int j = 0;
|
||||||
|
|
||||||
if (matrix1.colCount == matrix2.colCount && matrix1.rowCount == matrix2.rowCount){
|
if (matrix1.colCount == matrix2.colCount && matrix1.rowCount == matrix2.rowCount){
|
||||||
SumMatrix = SetMatrixDim(SumMatrix,matrix2.colCount,matrix1.rowCount);
|
SumMatrix = setMatrixDim(SumMatrix,matrix2.colCount,matrix1.rowCount);
|
||||||
for (i=0;i<SumMatrix.colCount;i++){
|
for (i=0;i<SumMatrix.colCount;i++){
|
||||||
for (j=0;j<SumMatrix.rowCount;j++){
|
for (j=0;j<SumMatrix.rowCount;j++){
|
||||||
SetCellValue(SumMatrix,i,j,operator(GetCellValue(matrix1,i,j),GetCellValue(matrix2,i,j)));
|
setCellValue(SumMatrix,i,j,operator(getCellValue(matrix1,i,j),getCellValue(matrix2,i,j)));
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -349,7 +348,7 @@ Matrix colSequenceOnMatrix(Matrix m, bool (operator)(bool, bool)){
|
|||||||
bool b;
|
bool b;
|
||||||
int i;
|
int i;
|
||||||
int j;
|
int j;
|
||||||
Matrix newM = CreateMatrix();
|
Matrix newM = createMatrix();
|
||||||
|
|
||||||
|
|
||||||
newM.rowCount = m.rowCount;
|
newM.rowCount = m.rowCount;
|
||||||
@ -361,10 +360,10 @@ Matrix colSequenceOnMatrix(Matrix m, bool (operator)(bool, bool)){
|
|||||||
|
|
||||||
for (i=0;i < m.colCount - 1;i++){
|
for (i=0;i < m.colCount - 1;i++){
|
||||||
for (j=0;j < m.rowCount;j++){
|
for (j=0;j < m.rowCount;j++){
|
||||||
a = GetCellValue(m, i, j);
|
a = getCellValue(m, i, j);
|
||||||
b = GetCellValue(m, i + 1, j);
|
b = getCellValue(m, i + 1, j);
|
||||||
if (operator(a, b)){
|
if (operator(a, b)){
|
||||||
SetCellValue(newM, i, j, true);
|
setCellValue(newM, i, j, true);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -376,7 +375,7 @@ Matrix rowSequenceOnMatrix(Matrix m, bool (operator)(bool, bool)){
|
|||||||
bool b;
|
bool b;
|
||||||
int i;
|
int i;
|
||||||
int j;
|
int j;
|
||||||
Matrix newM = CreateMatrix();
|
Matrix newM = createMatrix();
|
||||||
|
|
||||||
newM.colCount = m.colCount;
|
newM.colCount = m.colCount;
|
||||||
if (m.rowCount <= 1){
|
if (m.rowCount <= 1){
|
||||||
@ -387,10 +386,10 @@ Matrix rowSequenceOnMatrix(Matrix m, bool (operator)(bool, bool)){
|
|||||||
|
|
||||||
for (i=0; i < m.colCount;i++){
|
for (i=0; i < m.colCount;i++){
|
||||||
for (j=0;j < m.rowCount - 1;j++){
|
for (j=0;j < m.rowCount - 1;j++){
|
||||||
a = GetCellValue(m, i, j);
|
a = getCellValue(m, i, j);
|
||||||
b = GetCellValue(m, i, j + 1);
|
b = getCellValue(m, i, j + 1);
|
||||||
if (operator(a, b)){
|
if (operator(a, b)){
|
||||||
SetCellValue(newM, i, j, true);
|
setCellValue(newM, i, j, true);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -414,7 +413,7 @@ Matrix orRowSequenceOnMatrix(Matrix m){
|
|||||||
}
|
}
|
||||||
|
|
||||||
Matrix newMatrix(BooleanMatrix bmatrix){
|
Matrix newMatrix(BooleanMatrix bmatrix){
|
||||||
Matrix m = CreateMatrix();
|
Matrix m = createMatrix();
|
||||||
int i;
|
int i;
|
||||||
int j;
|
int j;
|
||||||
|
|
||||||
@ -424,7 +423,7 @@ Matrix newMatrix(BooleanMatrix bmatrix){
|
|||||||
for (i=0; i < m.rowCount ; i++){
|
for (i=0; i < m.rowCount ; i++){
|
||||||
for (j=0; j < m.colCount; j++){
|
for (j=0; j < m.colCount; j++){
|
||||||
if (bmatrix.data[i][j]){
|
if (bmatrix.data[i][j]){
|
||||||
SetCellValue(m, j, i, true);
|
setCellValue(m, j, i, true);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -432,7 +431,7 @@ Matrix newMatrix(BooleanMatrix bmatrix){
|
|||||||
return m;
|
return m;
|
||||||
}
|
}
|
||||||
|
|
||||||
BooleanMatrix CreateBooleanMatrix(int cols, int rows){
|
BooleanMatrix createBooleanMatrix(int cols, int rows){
|
||||||
BooleanMatrix matrix;
|
BooleanMatrix matrix;
|
||||||
int i;
|
int i;
|
||||||
|
|
||||||
@ -448,7 +447,7 @@ BooleanMatrix CreateBooleanMatrix(int cols, int rows){
|
|||||||
return matrix;
|
return matrix;
|
||||||
}
|
}
|
||||||
|
|
||||||
BooleanMatrix RandomizeBooleanMatrix(BooleanMatrix matrix){
|
BooleanMatrix randomizeBooleanMatrix(BooleanMatrix matrix){
|
||||||
int i;
|
int i;
|
||||||
int j;
|
int j;
|
||||||
int r;
|
int r;
|
||||||
@ -469,7 +468,7 @@ BooleanMatrix RandomizeBooleanMatrix(BooleanMatrix matrix){
|
|||||||
return matrix;
|
return matrix;
|
||||||
}
|
}
|
||||||
|
|
||||||
void FreeBooleanMatrix(BooleanMatrix matrix){
|
void freeBooleanMatrix(BooleanMatrix matrix){
|
||||||
int i;
|
int i;
|
||||||
for (i=0; i < matrix.rows; i++){
|
for (i=0; i < matrix.rows; i++){
|
||||||
free(matrix.data[i]);
|
free(matrix.data[i]);
|
||||||
@ -483,7 +482,7 @@ Matrix matrixFromRules(Matrix m, int n, int rules[]){
|
|||||||
int j;
|
int j;
|
||||||
|
|
||||||
bool * bools = NULL;
|
bool * bools = NULL;
|
||||||
Matrix result = CreateMatrix();
|
Matrix result = createMatrix();
|
||||||
|
|
||||||
if (rules == NULL){
|
if (rules == NULL){
|
||||||
result.colCount = 0;
|
result.colCount = 0;
|
||||||
@ -496,10 +495,10 @@ Matrix matrixFromRules(Matrix m, int n, int rules[]){
|
|||||||
|
|
||||||
for (i=0; i < m.rowCount; i++){
|
for (i=0; i < m.rowCount; i++){
|
||||||
for (j = 0; j < m.colCount; j++){
|
for (j = 0; j < m.colCount; j++){
|
||||||
bools = GetFromRules(m, j, i, n, rules);
|
bools = getFromRules(m, j, i, n, rules);
|
||||||
if (bools != NULL){
|
if (bools != NULL){
|
||||||
if (MXOR(n, bools)){
|
if (MXOR(n, bools)){
|
||||||
SetCellValue(result, j, i, true);
|
setCellValue(result, j, i, true);
|
||||||
}
|
}
|
||||||
free(bools);
|
free(bools);
|
||||||
}
|
}
|
||||||
@ -518,42 +517,42 @@ bool MXOR(int n, bool bools[]){
|
|||||||
}
|
}
|
||||||
|
|
||||||
bool firstRule(Matrix m, int ColPos, int RowPos){
|
bool firstRule(Matrix m, int ColPos, int RowPos){
|
||||||
return ErrorToFalse(GetCellValue(m, ColPos, RowPos));
|
return ErrorToFalse(getCellValue(m, ColPos, RowPos));
|
||||||
}
|
}
|
||||||
|
|
||||||
bool leftRule(Matrix m, int ColPos, int RowPos){
|
bool leftRule(Matrix m, int ColPos, int RowPos){
|
||||||
return ErrorToFalse(GetCellValue(m, ColPos + 1, RowPos));
|
return ErrorToFalse(getCellValue(m, ColPos + 1, RowPos));
|
||||||
}
|
}
|
||||||
|
|
||||||
bool rightRule(Matrix m, int ColPos, int RowPos){
|
bool rightRule(Matrix m, int ColPos, int RowPos){
|
||||||
return ErrorToFalse(GetCellValue(m, ColPos - 1, RowPos));
|
return ErrorToFalse(getCellValue(m, ColPos - 1, RowPos));
|
||||||
}
|
}
|
||||||
|
|
||||||
bool topRule(Matrix m, int ColPos, int RowPos){
|
bool topRule(Matrix m, int ColPos, int RowPos){
|
||||||
return ErrorToFalse(GetCellValue(m, ColPos, RowPos + 1));
|
return ErrorToFalse(getCellValue(m, ColPos, RowPos + 1));
|
||||||
}
|
}
|
||||||
|
|
||||||
bool bottomRule(Matrix m, int ColPos, int RowPos){
|
bool bottomRule(Matrix m, int ColPos, int RowPos){
|
||||||
return ErrorToFalse(GetCellValue(m, ColPos, RowPos - 1));
|
return ErrorToFalse(getCellValue(m, ColPos, RowPos - 1));
|
||||||
}
|
}
|
||||||
|
|
||||||
bool top_leftRule(Matrix m, int ColPos, int RowPos){
|
bool topLeftRule(Matrix m, int ColPos, int RowPos){
|
||||||
return ErrorToFalse(GetCellValue(m, ColPos + 1, RowPos + 1));
|
return ErrorToFalse(getCellValue(m, ColPos + 1, RowPos + 1));
|
||||||
}
|
}
|
||||||
|
|
||||||
bool top_rightRule(Matrix m, int ColPos, int RowPos){
|
bool topRightRule(Matrix m, int ColPos, int RowPos){
|
||||||
return ErrorToFalse(GetCellValue(m, ColPos - 1, RowPos + 1));
|
return ErrorToFalse(getCellValue(m, ColPos - 1, RowPos + 1));
|
||||||
}
|
}
|
||||||
|
|
||||||
bool bottom_leftRule(Matrix m, int ColPos, int RowPos){
|
bool bottomLeftRule(Matrix m, int ColPos, int RowPos){
|
||||||
return ErrorToFalse(GetCellValue(m, ColPos + 1, RowPos - 1));
|
return ErrorToFalse(getCellValue(m, ColPos + 1, RowPos - 1));
|
||||||
}
|
}
|
||||||
|
|
||||||
bool bottom_rightRule(Matrix m, int ColPos, int RowPos){
|
bool bottomRightRule(Matrix m, int ColPos, int RowPos){
|
||||||
return ErrorToFalse(GetCellValue(m, ColPos - 1, RowPos - 1));
|
return ErrorToFalse(getCellValue(m, ColPos - 1, RowPos - 1));
|
||||||
}
|
}
|
||||||
|
|
||||||
bool * GetFromRules(Matrix m, int ColPos, int RowPos, int n, int rules[]){
|
bool * getFromRules(Matrix m, int ColPos, int RowPos, int n, int rules[]){
|
||||||
bool * bools = (bool *)malloc(sizeof(bool) * n);
|
bool * bools = (bool *)malloc(sizeof(bool) * n);
|
||||||
int i;
|
int i;
|
||||||
|
|
||||||
@ -573,16 +572,16 @@ bool * GetFromRules(Matrix m, int ColPos, int RowPos, int n, int rules[]){
|
|||||||
bools[i] = rightRule(m, ColPos, RowPos);
|
bools[i] = rightRule(m, ColPos, RowPos);
|
||||||
break;
|
break;
|
||||||
case 4:
|
case 4:
|
||||||
bools[i] = top_leftRule(m, ColPos, RowPos);
|
bools[i] = topLeftRule(m, ColPos, RowPos);
|
||||||
break;
|
break;
|
||||||
case 16:
|
case 16:
|
||||||
bools[i] = top_rightRule(m, ColPos, RowPos);
|
bools[i] = topRightRule(m, ColPos, RowPos);
|
||||||
break;
|
break;
|
||||||
case 256:
|
case 256:
|
||||||
bools[i] = bottom_leftRule(m, ColPos, RowPos);
|
bools[i] = bottomLeftRule(m, ColPos, RowPos);
|
||||||
break;
|
break;
|
||||||
case 34:
|
case 34:
|
||||||
bools[i] = bottom_rightRule(m, ColPos, RowPos);
|
bools[i] = bottomRightRule(m, ColPos, RowPos);
|
||||||
break;
|
break;
|
||||||
case 1:
|
case 1:
|
||||||
bools[i] = firstRule(m, ColPos, RowPos);
|
bools[i] = firstRule(m, ColPos, RowPos);
|
||||||
@ -653,7 +652,7 @@ bool equalsMatrix(Matrix m1, Matrix m2){
|
|||||||
if (m1.colCount == m2.colCount && m1.rowCount == m2.rowCount){
|
if (m1.colCount == m2.colCount && m1.rowCount == m2.rowCount){
|
||||||
for (i=0;i<m2.colCount;i++){
|
for (i=0;i<m2.colCount;i++){
|
||||||
for (j=0;j<m1.rowCount;j++){
|
for (j=0;j<m1.rowCount;j++){
|
||||||
if (GetCellValue(m1,i,j)!=GetCellValue(m2,i,j)){
|
if (getCellValue(m1,i,j)!=getCellValue(m2,i,j)){
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -33,7 +33,7 @@
|
|||||||
* @param rows is pointer on the first row that contains a true value
|
* @param rows is pointer on the first row that contains a true value
|
||||||
* @param cols is pointer on the first col that contains a true value
|
* @param cols is pointer on the first col that contains a true value
|
||||||
*
|
*
|
||||||
* @see CreateMatrix to allocate one
|
* @see createMatrix to allocate one
|
||||||
* @see freeMatrix to free one
|
* @see freeMatrix to free one
|
||||||
*/
|
*/
|
||||||
typedef struct Matrix {
|
typedef struct Matrix {
|
||||||
@ -54,7 +54,7 @@ typedef struct Matrix {
|
|||||||
* @param cols numbers of columns of the matrix
|
* @param cols numbers of columns of the matrix
|
||||||
* @param data the matrix
|
* @param data the matrix
|
||||||
*
|
*
|
||||||
* @see CreateBooleanMatrix to create one
|
* @see createBooleanMatrix to create one
|
||||||
*/
|
*/
|
||||||
typedef struct {
|
typedef struct {
|
||||||
int rows;
|
int rows;
|
||||||
@ -72,7 +72,7 @@ typedef struct {
|
|||||||
*
|
*
|
||||||
* @return booleanmatrix a new matrix
|
* @return booleanmatrix a new matrix
|
||||||
*/
|
*/
|
||||||
BooleanMatrix CreateBooleanMatrix(int cols, int rows);
|
BooleanMatrix createBooleanMatrix(int cols, int rows);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Randomize a BooleanMatrix
|
* Randomize a BooleanMatrix
|
||||||
@ -81,7 +81,7 @@ BooleanMatrix CreateBooleanMatrix(int cols, int rows);
|
|||||||
*
|
*
|
||||||
* @return booleanmatrix the processed matrix
|
* @return booleanmatrix the processed matrix
|
||||||
*/
|
*/
|
||||||
BooleanMatrix RandomizeBooleanMatrix(BooleanMatrix matrix);
|
BooleanMatrix randomizeBooleanMatrix(BooleanMatrix matrix);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Free a BooleanMatrix
|
* Free a BooleanMatrix
|
||||||
@ -90,7 +90,7 @@ BooleanMatrix RandomizeBooleanMatrix(BooleanMatrix matrix);
|
|||||||
*
|
*
|
||||||
* @return void
|
* @return void
|
||||||
*/
|
*/
|
||||||
void FreeBooleanMatrix(BooleanMatrix matrix);
|
void freeBooleanMatrix(BooleanMatrix matrix);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Create a Matrix from its array-based representation
|
* Create a Matrix from its array-based representation
|
||||||
@ -118,7 +118,7 @@ Matrix applyRules(Matrix matrix,int Rules, int N);
|
|||||||
* @return a matrix
|
* @return a matrix
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
Matrix CreateMatrix();
|
Matrix createMatrix();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Find and return the cell in the given matrix
|
* Find and return the cell in the given matrix
|
||||||
@ -130,7 +130,7 @@ Matrix CreateMatrix();
|
|||||||
* @return a cellElement
|
* @return a cellElement
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
cellElement * FindMatrixElem(Matrix matrix, int ColPos, int RowPos);
|
cellElement * findMatrixElem(Matrix matrix, int ColPos, int RowPos);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Create the cell in the given matrix
|
* Create the cell in the given matrix
|
||||||
@ -142,7 +142,7 @@ cellElement * FindMatrixElem(Matrix matrix, int ColPos, int RowPos);
|
|||||||
* @return a bool (error code)
|
* @return a bool (error code)
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
bool CreateMatrixElem(Matrix matrix, int ColPos, int RowPos);
|
bool createMatrixElem(Matrix matrix, int ColPos, int RowPos);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Delete the cell in the given matrix
|
* Delete the cell in the given matrix
|
||||||
@ -154,7 +154,7 @@ bool CreateMatrixElem(Matrix matrix, int ColPos, int RowPos);
|
|||||||
* @return an error code (int)
|
* @return an error code (int)
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
int SupprMatrixElem(Matrix matrix, int ColPos, int RowPos);
|
int deleteMatrixElem(Matrix matrix, int ColPos, int RowPos);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Delete or create the cell in the given matrix to fit the value
|
* Delete or create the cell in the given matrix to fit the value
|
||||||
@ -166,7 +166,7 @@ int SupprMatrixElem(Matrix matrix, int ColPos, int RowPos);
|
|||||||
* @return an error code (bool)
|
* @return an error code (bool)
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
bool SetCellValue(Matrix matrix, int ColPos, int RowPos, bool value);
|
bool setCellValue(Matrix matrix, int ColPos, int RowPos, bool value);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Checks out the value of the cell in the given matrix
|
* Checks out the value of the cell in the given matrix
|
||||||
@ -178,7 +178,7 @@ bool SetCellValue(Matrix matrix, int ColPos, int RowPos, bool value);
|
|||||||
* @return the value (bool)
|
* @return the value (bool)
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
bool GetCellValue(Matrix matrix, int ColPos, int RowPos);
|
bool getCellValue(Matrix matrix, int ColPos, int RowPos);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Set the number of columns and rows of the matrix and returns it
|
* Set the number of columns and rows of the matrix and returns it
|
||||||
@ -190,7 +190,7 @@ bool GetCellValue(Matrix matrix, int ColPos, int RowPos);
|
|||||||
* @return the matrix
|
* @return the matrix
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
Matrix SetMatrixDim(Matrix matrix,int nbCols,int nbRows);
|
Matrix setMatrixDim(Matrix matrix,int nbCols,int nbRows);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Basically print the Matrix in the standard output
|
* Basically print the Matrix in the standard output
|
||||||
@ -364,7 +364,7 @@ bool bottomRule(Matrix m, int ColPos, int RowPos);
|
|||||||
*
|
*
|
||||||
* @return bool the value of the cell got by the rule
|
* @return bool the value of the cell got by the rule
|
||||||
*/
|
*/
|
||||||
bool top_leftRule(Matrix m, int ColPos, int RowPos);
|
bool topLeftRule(Matrix m, int ColPos, int RowPos);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get a cell with top_right rule
|
* Get a cell with top_right rule
|
||||||
@ -375,7 +375,7 @@ bool top_leftRule(Matrix m, int ColPos, int RowPos);
|
|||||||
*
|
*
|
||||||
* @return bool the value of the cell got by the rule
|
* @return bool the value of the cell got by the rule
|
||||||
*/
|
*/
|
||||||
bool top_rightRule(Matrix m, int ColPos, int RowPos);
|
bool topRightRule(Matrix m, int ColPos, int RowPos);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get a cell with bottom_left rule
|
* Get a cell with bottom_left rule
|
||||||
@ -386,7 +386,7 @@ bool top_rightRule(Matrix m, int ColPos, int RowPos);
|
|||||||
*
|
*
|
||||||
* @return bool the value of the cell got by the rule
|
* @return bool the value of the cell got by the rule
|
||||||
*/
|
*/
|
||||||
bool bottom_leftRule(Matrix m, int ColPos, int RowPos);
|
bool bottomLeftRule(Matrix m, int ColPos, int RowPos);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get a cell with bottom_right rule
|
* Get a cell with bottom_right rule
|
||||||
@ -397,7 +397,7 @@ bool bottom_leftRule(Matrix m, int ColPos, int RowPos);
|
|||||||
*
|
*
|
||||||
* @return bool the value of the cell got by the rule
|
* @return bool the value of the cell got by the rule
|
||||||
*/
|
*/
|
||||||
bool bottom_rightRule(Matrix m, int ColPos, int RowPos);
|
bool bottomRightRule(Matrix m, int ColPos, int RowPos);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get a list of bool from a given set of rules
|
* Get a list of bool from a given set of rules
|
||||||
@ -410,7 +410,7 @@ bool bottom_rightRule(Matrix m, int ColPos, int RowPos);
|
|||||||
*
|
*
|
||||||
* @return bool[] an array of bool
|
* @return bool[] an array of bool
|
||||||
*/
|
*/
|
||||||
bool * GetFromRules(Matrix m, int ColPos, int RowPos, int n, int rules[]);
|
bool * getFromRules(Matrix m, int ColPos, int RowPos, int n, int rules[]);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Allows you to use boolean operators between two matrices
|
* Allows you to use boolean operators between two matrices
|
||||||
|
22
matrixmain.c
22
matrixmain.c
@ -37,31 +37,31 @@ int main(){
|
|||||||
Matrix m2;
|
Matrix m2;
|
||||||
BooleanMatrix bmatrix;
|
BooleanMatrix bmatrix;
|
||||||
|
|
||||||
useSDL = YesOrNo("Do you want to use SDL library for matrix display ?");
|
useSDL = inputYesOrNo("Do you want to use SDL library for matrix display ?");
|
||||||
printf("A random matrix will be generated\n");
|
printf("A random matrix will be generated\n");
|
||||||
printf("Enter the number of columns of this matrix\n");
|
printf("Enter the number of columns of this matrix\n");
|
||||||
col = SafeNumberInput(1, 30000);
|
col = safeNumberInput(1, 30000);
|
||||||
printf("Enter the number of rows of this matrix\n");
|
printf("Enter the number of rows of this matrix\n");
|
||||||
row = SafeNumberInput(1, 30000);
|
row = safeNumberInput(1, 30000);
|
||||||
bmatrix = CreateBooleanMatrix(col, row);
|
bmatrix = createBooleanMatrix(col, row);
|
||||||
|
|
||||||
bmatrix = RandomizeBooleanMatrix(bmatrix);
|
bmatrix = randomizeBooleanMatrix(bmatrix);
|
||||||
m1 = newMatrix(bmatrix);
|
m1 = newMatrix(bmatrix);
|
||||||
FreeBooleanMatrix(bmatrix);
|
freeBooleanMatrix(bmatrix);
|
||||||
|
|
||||||
DisplayMatrixGUI(m1, useSDL);
|
displayMatrixGUI(m1, useSDL);
|
||||||
|
|
||||||
while (cont){
|
while (cont){
|
||||||
printf("What rule do you want to apply to this matrix ?\n");
|
printf("What rule do you want to apply to this matrix ?\n");
|
||||||
rule = SafeNumberInput(1, 481);
|
rule = safeNumberInput(1, 481);
|
||||||
printf("How many times do you want the rule to be applied ?\n");
|
printf("How many times do you want the rule to be applied ?\n");
|
||||||
times = SafeNumberInput(1, 100000);
|
times = safeNumberInput(1, 100000);
|
||||||
m2 = applyRules(m1,rule,times);
|
m2 = applyRules(m1,rule,times);
|
||||||
freeMatrix(m1);
|
freeMatrix(m1);
|
||||||
|
|
||||||
DisplayMatrixGUI(m2, useSDL);
|
displayMatrixGUI(m2, useSDL);
|
||||||
|
|
||||||
cont = YesOrNo("Do you want to apply other rules on this matrix ?");
|
cont = inputYesOrNo("Do you want to apply other rules on this matrix ?");
|
||||||
m1 = m2;
|
m1 = m2;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -21,7 +21,7 @@ Every function and data type are described in the documentation given with the p
|
|||||||
|
|
||||||
# Algorithmic
|
# Algorithmic
|
||||||
|
|
||||||
The most interesting function are *GetCellValue* and *SetCellValue*. Those are the one we rely on the most. They are our way of dealing with our complex data structure allowing us to avoid to store false values. They are the functions that need the more computational power on the long run but are really useful due to their level of abstraction and their high level.
|
The most interesting function are *getCellValue* and *setCellValue*. Those are the one we rely on the most. They are our way of dealing with our complex data structure allowing us to avoid to store false values. They are the functions that need the more computational power on the long run but are really useful due to their level of abstraction and their high level.
|
||||||
|
|
||||||
```C
|
```C
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user