-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrules.txt
More file actions
75 lines (61 loc) · 3.04 KB
/
rules.txt
File metadata and controls
75 lines (61 loc) · 3.04 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
We need the following matrices
1) Nutrient matrix
2) Sunlight matrix
3) Water matrix
4) Age matrix
Values of each element of the matrices range between 0 and 1
Normalization will be done by linear interpolation or sigmoid curve
This function has to be decided experimentally, whichever gives better results
In age matrix 1 means there is no tree in that cell
In age matrix >.8 means the tree is decaying
All matrices will update every iteration
Number of trees we consider "adjacent" has to be set before simulation
- Nutrient Matrix -
--Soil nutrient will decrease if there are more trees in the vicinity competing for resources
--The further the competitor, the lesser the competition
--Decaying trees increase soil nutrient over time
nutrientConsumption = 0
nutrientSupply = 0
for each tree in adjacent trees:
distanceFactor = distance from i,j
// Dead trees don't consume, middle aged trees consume most
nutrientConsumption += if age of an adjacent tree > .8 0. else gaussian(tree.age * 10/8)/distanceFactor
// Nutrients supplied by dead trees decrease over time
nutrientSupply += (if age of an adjacent tree > .8 then 1-(age-.8 * 5) else 0)/distanceFactor
nutrient[i][j] = normalize(nutrientSupply - nutrientConsumption) // Limit between 0 and 1
- Sunlight matrix -
-- Sunlight depends on number of adjacent trees, their age and distance
cumulativeFactor = 0
for each tree in adjacent trees
ageFactor = normalizedGaussian(tree.age)
// If the gaussian distribution does not work as expected we can try a linear function
//ageFactor = if tree.age > .8 then (1-tree.age*5) else tree.age * 10/8
distanceFactor = 1/distance of it from i,j
cumulativeFactor += ageFactor + distanceFactor
sunlight[i][j] = 1 - normalize(cumulativeFactor)
- Water matrix -
--The further the competitor, the lesser the competition
--Older trees consume more water
cumulativeFactor = 0
for each tree in adjacent trees
distanceFactor = 1/distance of it from i,j
// Older trees consume more water but dead trees do not consume water
ageFactor = if tree.age > .8 then 0 else sigmoid(tree.age*10/8)
cumulativeFactor += distanceFactor + ageFactor
water[i][j] = 1 - normalize(cumulativeFactor)
- Age matrix -
--Every iteration increment age by a random value in a range
--If the tree is unhealthy, have a shorter life
health = nutrient[i][j] * water[i][j] * sunlight[i][j]
if age[i][j] is not 1 then age[i][j] += (1/heath) + value between .001 and .005 or something IDK
- Chance of birth -
--If there are no trees in the forest, age[i][j] for all i,j is 1 (totally decayed)
--If a tree is born, we say age[i][j] = 0
--chance depends on reproductive capability of adjacent tree and their distance
cumulativeChance = 0
for each tree in adjacent trees
// Assuming middle aged trees are more reproductive
ageFactor = if tree.age > .8 then 0 else gaussian(tree.age * 10/8)
distanceFactor = 1/(distance of tree from i,j)
cumulativeChance += ageFactor + distanceFactor
if Math.random() < normalize(cumulativeChance) then age[i][j] = 0