Description:
Some refactoring.
Commit status:
[Not Reviewed]
References:
Diff options:
Comments:
0 Commit comments
0 Inline Comments
Unresolved TODOs:
There are no unresolved TODOs
@@ -124,7 +124,7 | |||||
|
124 | { |
|
124 | { |
|
125 | if (this.random_generator.NextDouble() > 0.75) |
|
125 | if (this.random_generator.NextDouble() > 0.75) |
|
126 | { |
|
126 | { |
|
127 |
int random_year = (int)MathHelper.Clamp((float)MathUtils.NextNormal(random_generator, 2010.0f, 40.0f), 1800, |
|
127 | int random_year = (int)MathHelper.Clamp((float)MathUtils.NextNormal(random_generator, 2010.0f, 40.0f), 1800, Simulation.START_YEAR); |
|
128 | int random_month = random_generator.Next(1, 12); |
|
128 | int random_month = random_generator.Next(1, 12); |
|
129 | DateTime random_date = new DateTime(random_year, random_month, 1); |
|
129 | DateTime random_date = new DateTime(random_year, random_month, 1); |
|
130 |
|
130 | ||
@@ -145,9 +145,6 | |||||
|
145 |
|
145 | ||
|
146 | currentNode = DialogTrees.introTree; |
|
146 | currentNode = DialogTrees.introTree; |
|
147 |
|
147 | ||
|
148 |
|
|||
|
149 |
|
|||
|
150 |
|
|||
|
151 | } |
|
148 | } |
|
152 |
|
149 | ||
|
153 | protected override void Initialize() |
|
150 | protected override void Initialize() |
@@ -37,6 +37,11 | |||||
|
37 | public const int START_MONTH = 1; |
|
37 | public const int START_MONTH = 1; |
|
38 | public const int START_DAY = 1; |
|
38 | public const int START_DAY = 1; |
|
39 |
|
39 | ||
|
|
40 | public DateTime START_DATETIME{ | ||
|
|
41 | get { | ||
|
|
42 | return new DateTime(START_YEAR, START_MONTH, START_DAY); | ||
|
|
43 | }} | ||
|
|
44 | |||
|
40 |
|
45 | ||
|
41 | private const float SPONTANEOUS_NEW_TREE_CHANCE = 0.9995f; |
|
46 | private const float SPONTANEOUS_NEW_TREE_CHANCE = 0.9995f; |
|
42 | private const float NEIGHBOR_NEW_TREE_CHANCE = 0.995f; |
|
47 | private const float NEIGHBOR_NEW_TREE_CHANCE = 0.995f; |
@@ -45,6 +50,9 | |||||
|
45 | public const int TREE_PLANT_COST = 750; |
|
50 | public const int TREE_PLANT_COST = 750; |
|
46 | public const int TREE_CLEAR_COST = 500; |
|
51 | public const int TREE_CLEAR_COST = 500; |
|
47 |
|
52 | ||
|
|
53 | public const int MAX_TREES_TO_PLANT = 25; | ||
|
|
54 | public const int MAX_TREES_TO_CLEAR = 25; | ||
|
|
55 | |||
|
48 | public int Tick |
|
56 | public int Tick |
|
49 | { |
|
57 | { |
|
50 | get; |
|
58 | get; |
@@ -139,7 +147,7 | |||||
|
139 | return _tree_planting; |
|
147 | return _tree_planting; |
|
140 | } |
|
148 | } |
|
141 | set { |
|
149 | set { |
|
142 |
_tree_planting = MathUtils.Clamp(value, 0, |
|
150 | _tree_planting = MathUtils.Clamp(value, 0, MAX_TREES_TO_PLANT); |
|
143 | } |
|
151 | } |
|
144 | } |
|
152 | } |
|
145 | private int _tree_clearing = 0; |
|
153 | private int _tree_clearing = 0; |
@@ -149,7 +157,7 | |||||
|
149 | return _tree_clearing; |
|
157 | return _tree_clearing; |
|
150 | } |
|
158 | } |
|
151 | set { |
|
159 | set { |
|
152 |
_tree_clearing = MathUtils.Clamp(value, 0, |
|
160 | _tree_clearing = MathUtils.Clamp(value, 0, MAX_TREES_TO_CLEAR); |
|
153 | } |
|
161 | } |
|
154 | } |
|
162 | } |
|
155 |
|
163 |
@@ -34,11 +34,11 | |||||
|
34 |
|
34 | ||
|
35 |
|
35 | ||
|
36 | int new_tree_planting = sim.tree_planting; |
|
36 | int new_tree_planting = sim.tree_planting; |
|
37 |
ImGui.SliderInt("Tree Planting ", ref new_tree_planting, 0, |
|
37 | ImGui.SliderInt("Tree Planting ", ref new_tree_planting, 0, Simulation.MAX_TREES_TO_PLANT, string.Format("%d (${0})", new_tree_planting*Simulation.TREE_PLANT_COST)); |
|
38 | sim.tree_planting = new_tree_planting; |
|
38 | sim.tree_planting = new_tree_planting; |
|
39 |
|
39 | ||
|
40 | int new_tree_clearing = sim.tree_clearing; |
|
40 | int new_tree_clearing = sim.tree_clearing; |
|
41 |
ImGui.SliderInt("Tree Clearing", ref new_tree_clearing, 0, |
|
41 | ImGui.SliderInt("Tree Clearing", ref new_tree_clearing, 0, Simulation.MAX_TREES_TO_CLEAR, string.Format("%d (${0})", new_tree_clearing*Simulation.TREE_CLEAR_COST)); |
|
42 | sim.tree_clearing = new_tree_clearing; |
|
42 | sim.tree_clearing = new_tree_clearing; |
|
43 |
|
43 | ||
|
44 | ImGui.Text(string.Format("Crowded Trees: {0}", sim.crowded_trees )); |
|
44 | ImGui.Text(string.Format("Crowded Trees: {0}", sim.crowded_trees )); |
@@ -60,7 +60,7 | |||||
|
60 | } |
|
60 | } |
|
61 |
|
61 | ||
|
62 |
|
62 | ||
|
63 | public static System.Collections.Generic.IEnumerable<Double> NextNormalEnumerator(Random random, float mean) |
|
63 | public static System.Collections.Generic.IEnumerable<Double> NextNormalEnumerator(Random random, float mean, float variation) |
|
64 | { |
|
64 | { |
|
65 |
|
65 | ||
|
66 | while (true) { |
|
66 | while (true) { |
@@ -70,13 +70,14 | |||||
|
70 | double z1 = Math.Sqrt(-2 * Math.Log(u1)) * Math.Cos(2 * Math.PI * u2); |
|
70 | double z1 = Math.Sqrt(-2 * Math.Log(u1)) * Math.Cos(2 * Math.PI * u2); |
|
71 | double z2 = Math.Sqrt(-2 * Math.Log(u1)) * Math.Sin(2 * Math.PI * u2); |
|
71 | double z2 = Math.Sqrt(-2 * Math.Log(u1)) * Math.Sin(2 * Math.PI * u2); |
|
72 |
|
72 | ||
|
73 | yield return z1; |
|
73 | yield return (variation * z1) + mean; |
|
74 | yield return z2; |
|
74 | yield return (variation * z2) + mean; |
|
75 | } |
|
75 | } |
|
76 | } |
|
76 | } |
|
77 |
|
77 | ||
|
78 | public static Double NextNormal(Random random, float mean, float variation) |
|
78 | public static Double NextNormal(Random random, float mean, float variation) |
|
79 | { |
|
79 | { |
|
|
80 | //Uses Box-Muller to scale the default uniform distribution | ||
|
80 | double u1 = random.NextDouble(); |
|
81 | double u1 = random.NextDouble(); |
|
81 | double u2 = random.NextDouble(); |
|
82 | double u2 = random.NextDouble(); |
|
82 |
|
83 |
You need to be logged in to leave comments.
Login now