mirror of
https://gitlab.com/klmp200/LO27.git
synced 2024-11-22 16:03:19 +00:00
Rule 34 + algo
This commit is contained in:
parent
1c08a861d8
commit
cc955328c6
@ -579,11 +579,12 @@ bool * getFromRules(Matrix m, int ColPos, int RowPos, int n, int rules[]){
|
||||
case 256:
|
||||
bools[i] = bottomLeftRule(m, ColPos, RowPos);
|
||||
break;
|
||||
case 34:
|
||||
case 64:
|
||||
bools[i] = bottomRightRule(m, ColPos, RowPos);
|
||||
break;
|
||||
case 1:
|
||||
bools[i] = firstRule(m, ColPos, RowPos);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
74
report.md
74
report.md
@ -336,6 +336,80 @@ BEGIN
|
||||
applyRules <- tempMatrix1
|
||||
|
||||
END
|
||||
|
||||
matrixFromRules(m:Matrix, n:integer, rules:integer[0...n-1]):Matrix
|
||||
BEGIN
|
||||
i:integer
|
||||
j:integer
|
||||
|
||||
bools:bool[n-1]
|
||||
result:Matrix <- createMatrix()
|
||||
|
||||
if (isEmpty(rules)){
|
||||
colCount(result) <- 0
|
||||
rowCount(result) <- 0
|
||||
matrixFromRules <- result
|
||||
}
|
||||
|
||||
colCount(result) <- value(colCount(m))
|
||||
rowCount(result) <- value(rowCount(m))
|
||||
|
||||
for i from 0 to value(rowCount(m)) - 1 do
|
||||
for j from 0 to value(colCount(m)) do
|
||||
bools <- getFromRules(m, j, i, n, rules)
|
||||
if not isEmpty(bools) then
|
||||
if MXOR(n, bools) then
|
||||
setCellValue(result, j, i, true)
|
||||
endif
|
||||
endif
|
||||
endfor
|
||||
endfor
|
||||
matrixFromRules <- result
|
||||
END
|
||||
|
||||
getFromRules(m:Matrix, ColPos:integer, RowPos:integer, n:integer, int rules: integer[0...n-1]):bool[0...n-1]
|
||||
BEGIN
|
||||
bools:bool[0...n-1]
|
||||
i:integer
|
||||
|
||||
for i from 0 to n-1 then
|
||||
switch rules[i]
|
||||
case 8
|
||||
bools[i] <- topRule(m, ColPos, RowPos)
|
||||
case 128
|
||||
bools[i] <- bottomRule(m, ColPos, RowPos)
|
||||
case 2
|
||||
bools[i] <- leftRule(m, ColPos, RowPos)
|
||||
case 32
|
||||
bools[i] <- rightRule(m, ColPos, RowPos)
|
||||
case 4
|
||||
bools[i] <- topLeftRule(m, ColPos, RowPos)
|
||||
case 16
|
||||
bools[i] <- topRightRule(m, ColPos, RowPos)
|
||||
case 256
|
||||
bools[i] <- bottomLeftRule(m, ColPos, RowPos)
|
||||
case 64
|
||||
bools[i] <- bottomRightRule(m, ColPos, RowPos)
|
||||
case 1
|
||||
bools[i] <- firstRule(m, ColPos, RowPos)
|
||||
endswitch
|
||||
endfor
|
||||
|
||||
getFromRules <- bools
|
||||
```
|
||||
|
||||
# Conclusion
|
||||
|
||||
As we said before, we decided to not store false values in our matrix. So, by default, all values are set to false and every time we created a new matrix, we only used setCellValue for true values.
|
||||
|
||||
To easily handle errors, we added ERROR to the bool enum. It was handy to detect out of bounds values and could be treated as false values on applyRules with the errorToFalse function.
|
||||
|
||||
We created OR, AND and XOR function. OR and AND were created for colSequenceOnMatrix and rowSequenceOnMatrix to be passed as pointers. The XOR function was created for readability. We also added MXOR function to apply XOR on a given array of boolean.
|
||||
|
||||
On applyRules, we decided to create an array with a static size of 9 integers. We agreed on this value because it was the maximum possible number of rules that could be applied at the same time and because it was the most balanced choice between performances and memory. Actually, 9 integers doesn't take so much memory and avoided to use malloc and realloc that relied on systems calls and on the operating system will that could slow down the process of factorization.
|
||||
|
||||
For boolean matrix, we created a structure to easily handle the size inside all our function and to respect the given prototype where we should have guessed the size.
|
||||
|
||||
Our program is fully functional but encounter, as we predicted, some performance issues on big matrix. We tested for our SDL GUI (that should only used on big matrix) a 1900x1080 sized matrix and it was long to process (more than 5 seconds). It was due to the original design we had to follow and would have been a lot faster with only a simple array-based allocated matrix keeping all false values.
|
||||
|
||||
We also had troubles with the freeMatrix function that is not really optimized. Our first attempt without slow setCellValue and getCellValue functions was a nightmare to understand and caused memory loss. It was unreadable and we both decided to prioritize readability over performances. Memory loss was unacceptable since the main goal was to sacrifice computational power to save memory.
|
Loading…
Reference in New Issue
Block a user