diff --git a/LibAutomaton/matrix.c b/LibAutomaton/matrix.c index 19b1c1b..05c25f6 100644 --- a/LibAutomaton/matrix.c +++ b/LibAutomaton/matrix.c @@ -475,101 +475,120 @@ void FreeBooleanMatrix(BooleanMatrix matrix){ } -Matrix basicRule(Matrix m, int incrh, int incrv){ +Matrix matrixFromRules(Matrix m, int n, int rules[]){ int i; int j; - bool a; - bool b; + + bool * bools = NULL; Matrix result = CreateMatrix(); + if (rules == NULL){ + result.colCount = 0; + result.rowCount = 0; + return result; + } + result.colCount = m.colCount; result.rowCount = m.rowCount; for (i=0; i < m.rowCount; i++){ for (j = 0; j < m.colCount; j++){ - a = GetCellValue(m, j, i); - b = ErrorToFalse(GetCellValue(m, j + incrh, i + incrv)); - if (XOR(a, b)){ - SetCellValue(result, j, i, true); + bools = GetFromRules(m, j, i, n, rules); + if (bools != NULL){ + if (MXOR(n, bools)){ + SetCellValue(result, j, i, true); + } + free(bools); } } } return result; } -Matrix leftRule(Matrix m){ - Matrix result = CreateMatrix(); +bool MXOR(int n, bool bools[]){ int i; - int j; - - result.colCount = m.colCount; - result.rowCount = m.rowCount; - - for (i=1;i