1
0
mirror of https://gitlab.com/klmp200/LO27.git synced 2025-07-17 17:29:23 +00:00

Renommage complet des fonctions

This commit is contained in:
2017-01-01 16:43:40 +01:00
parent 28021951b4
commit d763abfc80
6 changed files with 103 additions and 104 deletions

View File

@ -51,7 +51,6 @@ Matrix applyRules (Matrix matrix,int Rules, int N){
tempMatrix1 = matrixFromRules(matrix, i, RulesMatrix);
for (j=1;j<N;j++){
printf("Tourne\n");
tempMatrix2 = matrixFromRules(tempMatrix1,i, RulesMatrix);
freeMatrix(tempMatrix1);
@ -63,7 +62,7 @@ Matrix applyRules (Matrix matrix,int Rules, int N){
}
Matrix CreateMatrix(){
Matrix createMatrix(){
Matrix matrix;
matrix.colCount = 0;
matrix.rowCount = 0;
@ -72,13 +71,13 @@ Matrix CreateMatrix(){
return matrix;
}
Matrix SetMatrixDim(Matrix matrix,int nbCols,int nbRows){
Matrix setMatrixDim(Matrix matrix,int nbCols,int nbRows){
matrix.colCount = nbCols;
matrix.rowCount = nbRows;
return matrix;
}
bool CreateMatrixElem(Matrix matrix, int ColPos, int RowPos){
bool createMatrixElem(Matrix matrix, int ColPos, int RowPos){
ListElement * Row = NULL;
ListElement * Col = NULL;
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;
cellElement * elem = NULL;
@ -170,14 +169,14 @@ cellElement * FindMatrixElem(Matrix matrix, int ColPos, int RowPos){
return elem;
}
int SupprMatrixElem(Matrix matrix, int ColPos, int RowPos){
int deleteMatrixElem(Matrix matrix, int ColPos, int RowPos){
cellElement * elem = NULL;
cellElement * tmp = NULL;
ListElement * Row = NULL;
ListElement * Col = NULL;
elem = FindMatrixElem(matrix,ColPos,RowPos);
elem = findMatrixElem(matrix,ColPos,RowPos);
if (elem == NULL){
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){
return ERROR;
}
if (FindMatrixElem(matrix,ColPos,RowPos) == NULL){
if (findMatrixElem(matrix,ColPos,RowPos) == NULL){
return false;
}
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){
return CreateMatrixElem(matrix,ColPos,RowPos);
return createMatrixElem(matrix,ColPos,RowPos);
}else{
if ( SupprMatrixElem(matrix,ColPos,RowPos) >= 0 ){
if ( deleteMatrixElem(matrix,ColPos,RowPos) >= 0 ){
return true;
}else{
return false;
@ -275,7 +274,7 @@ void printMatrix(Matrix matrix){
printf("| ");
for (j=0;j<matrix.colCount;j++){
b = GetCellValue(matrix,j,i);
b = getCellValue(matrix,j,i);
if (b == true){
printf("1 ");
}else if (b == false){
@ -299,7 +298,7 @@ Matrix freeMatrix(Matrix matrix){
for (i=0;i<matrix.rowCount;i++){
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 SumMatrix = CreateMatrix();
Matrix SumMatrix = createMatrix();
int i =0;
int j = 0;
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 (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;
int i;
int j;
Matrix newM = CreateMatrix();
Matrix newM = createMatrix();
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 (j=0;j < m.rowCount;j++){
a = GetCellValue(m, i, j);
b = GetCellValue(m, i + 1, j);
a = getCellValue(m, i, j);
b = getCellValue(m, i + 1, j);
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;
int i;
int j;
Matrix newM = CreateMatrix();
Matrix newM = createMatrix();
newM.colCount = m.colCount;
if (m.rowCount <= 1){
@ -387,10 +386,10 @@ Matrix rowSequenceOnMatrix(Matrix m, bool (operator)(bool, bool)){
for (i=0; i < m.colCount;i++){
for (j=0;j < m.rowCount - 1;j++){
a = GetCellValue(m, i, j);
b = GetCellValue(m, i, j + 1);
a = getCellValue(m, i, j);
b = getCellValue(m, i, j + 1);
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 m = CreateMatrix();
Matrix m = createMatrix();
int i;
int j;
@ -424,7 +423,7 @@ Matrix newMatrix(BooleanMatrix bmatrix){
for (i=0; i < m.rowCount ; i++){
for (j=0; j < m.colCount; 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;
}
BooleanMatrix CreateBooleanMatrix(int cols, int rows){
BooleanMatrix createBooleanMatrix(int cols, int rows){
BooleanMatrix matrix;
int i;
@ -448,7 +447,7 @@ BooleanMatrix CreateBooleanMatrix(int cols, int rows){
return matrix;
}
BooleanMatrix RandomizeBooleanMatrix(BooleanMatrix matrix){
BooleanMatrix randomizeBooleanMatrix(BooleanMatrix matrix){
int i;
int j;
int r;
@ -469,7 +468,7 @@ BooleanMatrix RandomizeBooleanMatrix(BooleanMatrix matrix){
return matrix;
}
void FreeBooleanMatrix(BooleanMatrix matrix){
void freeBooleanMatrix(BooleanMatrix matrix){
int i;
for (i=0; i < matrix.rows; i++){
free(matrix.data[i]);
@ -483,7 +482,7 @@ Matrix matrixFromRules(Matrix m, int n, int rules[]){
int j;
bool * bools = NULL;
Matrix result = CreateMatrix();
Matrix result = createMatrix();
if (rules == NULL){
result.colCount = 0;
@ -496,10 +495,10 @@ Matrix matrixFromRules(Matrix m, int n, int rules[]){
for (i=0; i < m.rowCount; i++){
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 (MXOR(n, bools)){
SetCellValue(result, j, i, true);
setCellValue(result, j, i, true);
}
free(bools);
}
@ -518,42 +517,42 @@ bool MXOR(int n, bool bools[]){
}
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){
return ErrorToFalse(GetCellValue(m, ColPos + 1, RowPos));
return ErrorToFalse(getCellValue(m, ColPos + 1, 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){
return ErrorToFalse(GetCellValue(m, ColPos, RowPos + 1));
return ErrorToFalse(getCellValue(m, ColPos, RowPos + 1));
}
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){
return ErrorToFalse(GetCellValue(m, ColPos + 1, RowPos + 1));
bool topLeftRule(Matrix m, int ColPos, int RowPos){
return ErrorToFalse(getCellValue(m, ColPos + 1, RowPos + 1));
}
bool top_rightRule(Matrix m, int ColPos, int RowPos){
return ErrorToFalse(GetCellValue(m, ColPos - 1, RowPos + 1));
bool topRightRule(Matrix m, int ColPos, int RowPos){
return ErrorToFalse(getCellValue(m, ColPos - 1, RowPos + 1));
}
bool bottom_leftRule(Matrix m, int ColPos, int RowPos){
return ErrorToFalse(GetCellValue(m, ColPos + 1, RowPos - 1));
bool bottomLeftRule(Matrix m, int ColPos, int RowPos){
return ErrorToFalse(getCellValue(m, ColPos + 1, RowPos - 1));
}
bool bottom_rightRule(Matrix m, int ColPos, int RowPos){
return ErrorToFalse(GetCellValue(m, ColPos - 1, RowPos - 1));
bool bottomRightRule(Matrix m, int ColPos, int RowPos){
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);
int i;
@ -573,16 +572,16 @@ bool * GetFromRules(Matrix m, int ColPos, int RowPos, int n, int rules[]){
bools[i] = rightRule(m, ColPos, RowPos);
break;
case 4:
bools[i] = top_leftRule(m, ColPos, RowPos);
bools[i] = topLeftRule(m, ColPos, RowPos);
break;
case 16:
bools[i] = top_rightRule(m, ColPos, RowPos);
bools[i] = topRightRule(m, ColPos, RowPos);
break;
case 256:
bools[i] = bottom_leftRule(m, ColPos, RowPos);
bools[i] = bottomLeftRule(m, ColPos, RowPos);
break;
case 34:
bools[i] = bottom_rightRule(m, ColPos, RowPos);
bools[i] = bottomRightRule(m, ColPos, RowPos);
break;
case 1:
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){
for (i=0;i<m2.colCount;i++){
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;
}

View File

@ -33,7 +33,7 @@
* @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
*
* @see CreateMatrix to allocate one
* @see createMatrix to allocate one
* @see freeMatrix to free one
*/
typedef struct Matrix {
@ -54,7 +54,7 @@ typedef struct Matrix {
* @param cols numbers of columns of the matrix
* @param data the matrix
*
* @see CreateBooleanMatrix to create one
* @see createBooleanMatrix to create one
*/
typedef struct {
int rows;
@ -72,7 +72,7 @@ typedef struct {
*
* @return booleanmatrix a new matrix
*/
BooleanMatrix CreateBooleanMatrix(int cols, int rows);
BooleanMatrix createBooleanMatrix(int cols, int rows);
/**
* Randomize a BooleanMatrix
@ -81,7 +81,7 @@ BooleanMatrix CreateBooleanMatrix(int cols, int rows);
*
* @return booleanmatrix the processed matrix
*/
BooleanMatrix RandomizeBooleanMatrix(BooleanMatrix matrix);
BooleanMatrix randomizeBooleanMatrix(BooleanMatrix matrix);
/**
* Free a BooleanMatrix
@ -90,7 +90,7 @@ BooleanMatrix RandomizeBooleanMatrix(BooleanMatrix matrix);
*
* @return void
*/
void FreeBooleanMatrix(BooleanMatrix matrix);
void freeBooleanMatrix(BooleanMatrix matrix);
/**
* Create a Matrix from its array-based representation
@ -118,7 +118,7 @@ Matrix applyRules(Matrix matrix,int Rules, int N);
* @return a matrix
*
*/
Matrix CreateMatrix();
Matrix createMatrix();
/**
* Find and return the cell in the given matrix
@ -130,7 +130,7 @@ Matrix CreateMatrix();
* @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
@ -142,7 +142,7 @@ cellElement * FindMatrixElem(Matrix matrix, int ColPos, int RowPos);
* @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
@ -154,7 +154,7 @@ bool CreateMatrixElem(Matrix matrix, int ColPos, int RowPos);
* @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
@ -166,7 +166,7 @@ int SupprMatrixElem(Matrix matrix, int ColPos, int RowPos);
* @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
@ -178,7 +178,7 @@ bool SetCellValue(Matrix matrix, int ColPos, int RowPos, bool value);
* @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
@ -190,7 +190,7 @@ bool GetCellValue(Matrix matrix, int ColPos, int RowPos);
* @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
@ -364,7 +364,7 @@ bool bottomRule(Matrix m, int ColPos, int RowPos);
*
* @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
@ -375,7 +375,7 @@ bool top_leftRule(Matrix m, int ColPos, int RowPos);
*
* @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
@ -386,7 +386,7 @@ bool top_rightRule(Matrix m, int ColPos, int RowPos);
*
* @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
@ -397,7 +397,7 @@ bool bottom_leftRule(Matrix m, int ColPos, int RowPos);
*
* @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
@ -410,7 +410,7 @@ bool bottom_rightRule(Matrix m, int ColPos, int RowPos);
*
* @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