mirror of
				https://gitlab.com/klmp200/LO27.git
				synced 2025-10-31 17:23:07 +00:00 
			
		
		
		
	All rules fixed and working
This commit is contained in:
		| @@ -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<m.colCount;i++){ | ||||
| 		for (j=0;j<m.rowCount;j++){ | ||||
| 			if (GetCellValue(m, i, j)){ | ||||
| 				SetCellValue(result, i - 1, j, true); | ||||
| 			} | ||||
| 		} | ||||
| 	bool r = false; | ||||
| 	for (i=0;i<n;i++){ | ||||
| 		r = XOR(r, bools[i]); | ||||
| 	} | ||||
|  | ||||
| 	return result; | ||||
| 	return r; | ||||
| } | ||||
|  | ||||
| Matrix rightRule(Matrix m){ | ||||
| 	Matrix result = CreateMatrix(); | ||||
| 	int i; | ||||
| 	int j; | ||||
|  | ||||
| 	result.colCount = m.colCount; | ||||
| 	result.rowCount = m.rowCount; | ||||
|  | ||||
| 	for (i=0;i<m.colCount - 1;i++){ | ||||
| 		for (j=0;j<m.rowCount;j++){ | ||||
| 			if (GetCellValue(m, i, j)){ | ||||
| 				SetCellValue(result, i + 1, j, true); | ||||
| 			} | ||||
| 		} | ||||
| 	} | ||||
| 	return result; | ||||
| bool firstRule(Matrix m, int ColPos, int RowPos){ | ||||
| 	return ErrorToFalse(GetCellValue(m, ColPos, RowPos)); | ||||
| } | ||||
|  | ||||
| Matrix topRule(Matrix m){ | ||||
| 	Matrix result = CreateMatrix(); | ||||
| 	int i; | ||||
| 	int j; | ||||
|  | ||||
| 	result.colCount = m.colCount; | ||||
| 	result.rowCount = m.rowCount; | ||||
|  | ||||
| 	for (i=1;i<m.rowCount;i++){ | ||||
| 		for (j=0;j<m.colCount;j++){ | ||||
| 			if (GetCellValue(m, j, i)){ | ||||
| 				SetCellValue(result, j, i - 1, true); | ||||
| 			} | ||||
| 		} | ||||
| 	} | ||||
|  | ||||
| 	return result; | ||||
| bool leftRule(Matrix m, int ColPos, int RowPos){ | ||||
| 	return ErrorToFalse(GetCellValue(m, ColPos + 1, RowPos)); | ||||
| } | ||||
|  | ||||
| Matrix downRule(Matrix m){ | ||||
| 	Matrix result = CreateMatrix(); | ||||
| bool rightRule(Matrix m, int ColPos, int RowPos){ | ||||
| 	return ErrorToFalse(GetCellValue(m, ColPos - 1, RowPos)); | ||||
| } | ||||
|  | ||||
| bool topRule(Matrix m, int ColPos, int RowPos){ | ||||
| 	return ErrorToFalse(GetCellValue(m, ColPos, RowPos -1)); | ||||
| } | ||||
|  | ||||
| bool bottomRule(Matrix m, int ColPos, int RowPos){ | ||||
| 	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 top_rightRule(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 bottom_rightRule(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 * bools = (bool *)malloc(sizeof(bool) * n); | ||||
| 	int i; | ||||
| 	int j; | ||||
|  | ||||
| 	result.colCount = m.colCount; | ||||
| 	result.rowCount = m.rowCount; | ||||
|  | ||||
| 	for (i=0;i<m.rowCount - 1;i++){ | ||||
| 		for (j=0;j<m.colCount;j++){ | ||||
| 			if (GetCellValue(m, j, i)){ | ||||
| 				SetCellValue(result, j, i + 1, true); | ||||
| 	if (bools != NULL){ | ||||
| 		for (i=0;i<n;i++){ | ||||
| 			switch (rules[i]){ | ||||
| 				case 8: | ||||
| 					bools[i] = topRule(m, ColPos, RowPos); | ||||
| 					break; | ||||
| 				case 128: | ||||
| 					bools[i] = bottomRule(m, ColPos, RowPos); | ||||
| 					break; | ||||
| 				case 2: | ||||
| 					bools[i] = leftRule(m, ColPos, RowPos); | ||||
| 					break; | ||||
| 				case 32: | ||||
| 					bools[i] = rightRule(m, ColPos, RowPos); | ||||
| 					break; | ||||
| 				case 4: | ||||
| 					bools[i] = top_leftRule(m, ColPos, RowPos); | ||||
| 					break; | ||||
| 				case 16: | ||||
| 					bools[i] = top_rightRule(m, ColPos, RowPos); | ||||
| 					break; | ||||
| 				case 256: | ||||
| 					bools[i] = bottom_leftRule(m, ColPos, RowPos); | ||||
| 					break; | ||||
| 				case 34: | ||||
| 					bools[i] = bottom_rightRule(m, ColPos, RowPos); | ||||
| 					break; | ||||
| 				case 1: | ||||
| 					bools[i] = firstRule(m, ColPos, RowPos); | ||||
| 			} | ||||
| 		} | ||||
| 	} | ||||
|  | ||||
| 	return result; | ||||
| 	return bools; | ||||
|  | ||||
| } | ||||
|  | ||||
| /* todos : | ||||
|   | ||||
| @@ -232,40 +232,113 @@ Matrix andRowSequenceOnMatrix(Matrix m); | ||||
| Matrix orRowSequenceOnMatrix(Matrix m); | ||||
|  | ||||
| /** | ||||
| * Apply XOR on a whole matrix | ||||
| * Apply a given set of rules | ||||
| * @param m a matrix | ||||
| * @param incrh the horizontal increment | ||||
| * @param incrv the vertical increment | ||||
| * @param n the number of rules | ||||
| * @param rules an array of rules | ||||
| * @return matrix a new modified matrix | ||||
| */ | ||||
| Matrix basicRule(Matrix m, int incrh, int incrv); | ||||
| Matrix matrixFromRules(Matrix m, int n, int rules[]); | ||||
|  | ||||
| /** | ||||
| * Apply right rule on a matrix | ||||
| * @param m a matrix | ||||
| * @return matrix a new matrix | ||||
| * 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 | ||||
| */ | ||||
| Matrix rightRule(Matrix m); | ||||
| bool MXOR(int n, bool bools[]); | ||||
|  | ||||
| /** | ||||
| * Apply left rule on a matrix | ||||
| * Get a cell with first rule | ||||
| * @param m a matrix | ||||
| * @return matrix a new 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 | ||||
| */ | ||||
| Matrix leftRule(Matrix m); | ||||
| /** | ||||
| * Apply top rule on a matrix | ||||
| * @param m a matrix | ||||
| * @return matrix a new matrix | ||||
| */ | ||||
| Matrix topRule(Matrix m); | ||||
| bool firstRule(Matrix m, int ColPos, int RowPos); | ||||
|  | ||||
| /** | ||||
| * Apply down rule on a matrix | ||||
| * Get a cell with right rule | ||||
| * @param m a matrix | ||||
| * @return matrix a new 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 | ||||
| */ | ||||
| Matrix downRule(Matrix m); | ||||
| 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); | ||||
|  | ||||
|   | ||||
		Reference in New Issue
	
	Block a user