mirror of
https://gitlab.com/klmp200/LO27.git
synced 2024-11-05 10:38:04 +00:00
348 lines
8.8 KiB
C
348 lines
8.8 KiB
C
#ifndef MTRXGAUD_H
|
|
#define MTRXGAUD_H
|
|
|
|
#include <CellElement.h>
|
|
#include <list.h>
|
|
|
|
/*---Matrix---
|
|
*Abstract type that describe a boolean matrix
|
|
*
|
|
*@colCount : the number of columns of the matrix
|
|
*@rowIndex : the number of rows of the matrix
|
|
*
|
|
*@rows : pointer on the first row that contains a true value
|
|
*@cols : pointer on the first col that contains a true value
|
|
*
|
|
*/
|
|
typedef struct Matrix {
|
|
|
|
int colCount;
|
|
int rowCount;
|
|
|
|
List *cols;
|
|
List *rows;
|
|
|
|
}Matrix;
|
|
|
|
|
|
/**
|
|
* Abstract type for a matrix of booleans
|
|
* @param rows number of rows of the matrix
|
|
* @param cols numbers of columns of the matrix
|
|
* @param data the matrix
|
|
* @see CreateBooleanMatrix to create one
|
|
*/
|
|
typedef struct {
|
|
int rows;
|
|
int cols;
|
|
|
|
bool **data;
|
|
|
|
} BooleanMatrix;
|
|
|
|
/**
|
|
* Function creating an empty boolean matrix
|
|
* @param cols number of cols
|
|
* @param rows number of rows
|
|
* @return booleanmatrix a new matrix
|
|
*/
|
|
BooleanMatrix CreateBooleanMatrix(int cols, int rows);
|
|
|
|
/**
|
|
* Randomize a BooleanMatrix
|
|
* @param matrix a BooleanMatrix
|
|
* @return booleanmatrix the processed matrix
|
|
*/
|
|
BooleanMatrix RandomizeBooleanMatrix(BooleanMatrix matrix);
|
|
|
|
/**
|
|
* Free a BooleanMatrix
|
|
* @param matrix a BooleanMatrix
|
|
* @return
|
|
*/
|
|
void FreeBooleanMatrix(BooleanMatrix matrix);
|
|
|
|
/**
|
|
* Create a Matrix from its array-based representation
|
|
* @param bmatrix BooleanMatrix
|
|
* @return m Matrix
|
|
*/
|
|
Matrix newMatrix(BooleanMatrix bmatrix);
|
|
|
|
/*---applyRules---
|
|
*A function tha allows you to apply some rules n times on the matrix and returns it
|
|
*
|
|
*@matrix : A matrix on whitch you would apply the rules
|
|
*
|
|
*@Rules : Integer describing the rules
|
|
*
|
|
*@N : number of time the rules will be applied
|
|
*
|
|
*/
|
|
Matrix applyRules(Matrix matrix,int Rules, int N);
|
|
|
|
/**
|
|
*Create a void Matrix
|
|
*
|
|
*@return a matrix
|
|
*
|
|
*/
|
|
Matrix CreateMatrix();
|
|
|
|
/**
|
|
*Find and return the cell in the given matrix
|
|
*
|
|
*@param matrix the Matrix where we search
|
|
*@param ColPos an int indicating the column of the cell
|
|
*@param RowPos an int indicating the row of the cell
|
|
*
|
|
*@return a cellElement
|
|
*
|
|
*/
|
|
cellElement * FindMatrixElem(Matrix matrix, int ColPos, int RowPos);
|
|
|
|
/**
|
|
*Create the cell in the given matrix
|
|
*
|
|
*@param matrix the Matrix
|
|
*@param ColPos an int indicating the column of the cell
|
|
*@param RowPos an int indicating the row of the cell
|
|
*
|
|
*@return a bool (error code)
|
|
*
|
|
*/
|
|
bool CreateMatrixElem(Matrix matrix, int ColPos, int RowPos);
|
|
|
|
/**
|
|
*Delete the cell in the given matrix
|
|
*
|
|
*@param matrix the Matrix
|
|
*@param ColPos an int indicating the column of the cell
|
|
*@param RowPos an int indicating the row of the cell
|
|
*
|
|
*@return an error code (int)
|
|
*
|
|
*/
|
|
int SupprMatrixElem(Matrix matrix, int ColPos, int RowPos);
|
|
|
|
/**
|
|
*Delete or create the cell in the given matrix to fit the value
|
|
*
|
|
*@param matrix the Matrix
|
|
*@param ColPos an int indicating the column of the cell
|
|
*@param RowPos an int indicating the row of the cell
|
|
*
|
|
*@return an error code (bool)
|
|
*
|
|
*/
|
|
bool SetCellValue(Matrix matrix, int ColPos, int RowPos, bool value);
|
|
|
|
/**
|
|
*Checks out the value of the cell in the given matrix
|
|
*
|
|
*@param matrix the Matrix
|
|
*@param ColPos an int indicating the column of the cell
|
|
*@param RowPos an int indicating the row of the cell
|
|
*
|
|
*@return the value (bool)
|
|
*
|
|
*/
|
|
bool GetCellValue(Matrix matrix, int ColPos, int RowPos);
|
|
|
|
/**
|
|
*Set the number of columns and rows of the matrix and returns it
|
|
*
|
|
*@param matrix the Matrix
|
|
*@param nbCols an int indicating the number of columns
|
|
*@param nbRows an int indicating the number of rows
|
|
*
|
|
*@return the matrix
|
|
*
|
|
*/
|
|
Matrix SetMatrixDim(Matrix matrix,int nbCols,int nbRows);
|
|
|
|
/**
|
|
*Basically print the Matrix in the standard output
|
|
*
|
|
*@param matrix the Matrix
|
|
*
|
|
*@return void
|
|
*
|
|
*/
|
|
void BasicPrintMatrix(Matrix matrix);
|
|
|
|
bool RecursiveFreeCol(Matrix matrix, cellElement * elem);
|
|
|
|
Matrix freeMatrix(Matrix matrix);
|
|
|
|
/**
|
|
* Given an input matrix with M rows and N columns, computes a matrix with
|
|
* M rows and N-1 columns were each element corresponds to the operator boolean operation
|
|
* between two successive horizontal elements in the input matrix
|
|
* @param m a Matrix
|
|
* @param operator a function
|
|
* @return Matrix the copmuted matrix
|
|
*/
|
|
Matrix colSequenceOnMatrix(Matrix m, bool (operator)(bool, bool));
|
|
|
|
/**
|
|
* Given an input matrix with M rows and N columns, computes a matrix with
|
|
* M-1 rows and N columns were each element corresponds to the operator boolean operation
|
|
* between two succesive vertical elements in the input matrix
|
|
* @param m a Matrix
|
|
* @param operator a function
|
|
* @return Matrix the copmuted matrix
|
|
*/
|
|
Matrix rowSequenceOnMatrix(Matrix m, bool (operator)(bool, bool));
|
|
|
|
/**
|
|
* Given an input matrix with M rows and N columns, computes a matrix with
|
|
* M rows and N-1 columns were each element corresponds to the AND boolean operation
|
|
* between two successive horizontal elements in the input matrix
|
|
* @param m a Matrix
|
|
* @return Matrix the copmuted matrix
|
|
*/
|
|
Matrix andColSequenceOnMatrix(Matrix m);
|
|
|
|
/**
|
|
* Given an input matrix with M rows and N columns, computes a matrix with
|
|
* M rows and N-1 columns were each element corresponds to the OR boolean operation
|
|
* between two successive horizontal elements in the input matrix
|
|
* @param m a Matrix
|
|
* @return Matrix the copmuted matrix
|
|
*/
|
|
Matrix orColSequenceOnMatrix(Matrix m);
|
|
|
|
/**
|
|
* Given an input matrix with M rows and N columns, computes a matrix with
|
|
* M-1 rows and N columns were each element corresponds to the AND boolean operation
|
|
* between two succesive vertical elements in the input matrix
|
|
* @param m a Matrix
|
|
* @return Matrix the copmuted matrix
|
|
*/
|
|
Matrix andRowSequenceOnMatrix(Matrix m);
|
|
|
|
/**
|
|
* Given an input matrix with M rows and N columns, computes a matrix with
|
|
* M-1 rows and N columns were each element corresponds to the OR boolean operation
|
|
* between two succesive vertical elements in the input matrix
|
|
* @param m a Matrix
|
|
* @return Matrix the copmuted matrix
|
|
*/
|
|
Matrix orRowSequenceOnMatrix(Matrix m);
|
|
|
|
/**
|
|
* Apply a given set of rules
|
|
* @param m a matrix
|
|
* @param n the number of rules
|
|
* @param rules an array of rules
|
|
* @return Matrix a new modified matrix
|
|
*/
|
|
Matrix matrixFromRules(Matrix m, int n, int rules[]);
|
|
|
|
/**
|
|
* Apply XOR to a given number of bools
|
|
* @param n the number of bool
|
|
* @param bools an array of bool
|
|
* @return bool the processed bool
|
|
*/
|
|
bool MXOR(int n, bool bools[]);
|
|
|
|
/**
|
|
* Get a cell with first rule
|
|
* @param m a matrix
|
|
* @param ColPos collumn pos of the current cell
|
|
* @param RowPos row pos of the current cell
|
|
* @return bool the value of the cell got by the rule
|
|
*/
|
|
bool firstRule(Matrix m, int ColPos, int RowPos);
|
|
|
|
/**
|
|
* Get a cell with right rule
|
|
* @param m a matrix
|
|
* @param ColPos collumn pos of the current cell
|
|
* @param RowPos row pos of the current cell
|
|
* @return bool the value of the cell got by the rule
|
|
*/
|
|
bool rightRule(Matrix m, int ColPos, int RowPos);
|
|
|
|
/**
|
|
* Get a cell with left rule
|
|
* @param m a matrix
|
|
* @param ColPos collumn pos of the current cell
|
|
* @param RowPos row pos of the current cell
|
|
* @return bool the value of the cell got by the rule
|
|
*/
|
|
bool leftRule(Matrix m, int ColPos, int RowPos);
|
|
|
|
/**
|
|
* Get a cell with top rule
|
|
* @param m a matrix
|
|
* @param ColPos collumn pos of the current cell
|
|
* @param RowPos row pos of the current cell
|
|
* @return bool the value of the cell got by the rule
|
|
*/
|
|
bool topRule(Matrix m, int ColPos, int RowPos);
|
|
|
|
/**
|
|
* Get a cell with bottom rule
|
|
* @param m a matrix
|
|
* @param ColPos collumn pos of the current cell
|
|
* @param RowPos row pos of the current cell
|
|
* @return bool the value of the cell got by the rule
|
|
*/
|
|
bool bottomRule(Matrix m, int ColPos, int RowPos);
|
|
|
|
/**
|
|
* Get a cell with top_left rule
|
|
* @param m a matrix
|
|
* @param ColPos collumn pos of the current cell
|
|
* @param RowPos row pos of the current cell
|
|
* @return bool the value of the cell got by the rule
|
|
*/
|
|
bool top_leftRule(Matrix m, int ColPos, int RowPos);
|
|
|
|
/**
|
|
* Get a cell with top_right rule
|
|
* @param m a matrix
|
|
* @param ColPos collumn pos of the current cell
|
|
* @param RowPos row pos of the current cell
|
|
* @return bool the value of the cell got by the rule
|
|
*/
|
|
bool top_rightRule(Matrix m, int ColPos, int RowPos);
|
|
|
|
/**
|
|
* Get a cell with bottom_left rule
|
|
* @param m a matrix
|
|
* @param ColPos collumn pos of the current cell
|
|
* @param RowPos row pos of the current cell
|
|
* @return bool the value of the cell got by the rule
|
|
*/
|
|
bool bottom_leftRule(Matrix m, int ColPos, int RowPos);
|
|
|
|
/**
|
|
* Get a cell with bottom_right rule
|
|
* @param m a matrix
|
|
* @param ColPos collumn pos of the current cell
|
|
* @param RowPos row pos of the current cell
|
|
* @return bool the value of the cell got by the rule
|
|
*/
|
|
bool bottom_rightRule(Matrix m, int ColPos, int RowPos);
|
|
|
|
/**
|
|
* Get a list of bool from a given set of rules
|
|
* @param m a Matrix
|
|
* @param ColPos colon position of the point
|
|
* @param RowPos colon position of the point
|
|
* @param n number of rules
|
|
* @param rules[] an array of rules
|
|
* @return bool[] an array of bool
|
|
*/
|
|
bool * GetFromRules(Matrix m, int ColPos, int RowPos, int n, int rules[]);
|
|
|
|
Matrix sumMatrix(Matrix matrix1,Matrix matrix2);
|
|
Matrix mulMatrix(Matrix matrix1,Matrix matrix2);
|
|
|
|
#endif
|
|
|