Skip to content

Commit b01d791

Browse files
committed
Menu working
1 parent 4f0eb30 commit b01d791

File tree

6 files changed

+95
-15
lines changed

6 files changed

+95
-15
lines changed

EcoSim/Assets/Controller/Controller.cs

Lines changed: 55 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,14 @@ public class Controller : MonoBehaviour
3939
public GameObject grRate;
4040
public GameObject trhold;
4141

42+
//Strategy
43+
private int strategy;
44+
private int iterations;
45+
private int agents;
46+
public GameObject stratMenu;
47+
public GameObject itMenu;
48+
public GameObject agentsMenu;
49+
4250
//PARAMETERS OF SIMULATION
4351
private int NUMBER_OF_SIMULATIONS = 1;
4452
private int ITERATIONS_PER_SIMULATION = 200;
@@ -75,21 +83,26 @@ void Start()
7583
{
7684
this.ready = false;
7785
this.firstTime = true;
78-
86+
//Predators
7987
this.reproductionPredator = 0.3;
8088
this.maxSpeedPredator = 0.6;
81-
this.visionRadiusPredator = 15;
82-
this.initialPopulationPredator = 12;
83-
89+
this.visionRadiusPredator = 30;
90+
this.initialPopulationPredator = 8;
91+
//Preys
8492
this.reproductionPrey = 0.9;
8593
this.maxSpeedPrey = 0.55;
8694
this.visionRadiusPrey = 8;
87-
this.initialPopulationPrey = 500;
88-
95+
this.initialPopulationPrey = 200;
96+
//Plants
8997
this.initialPlants = 1200;
9098
this.growthRate = 1.7;
9199
this.threshold = 200;
92-
}
100+
//Strategy
101+
this.strategy = 0;
102+
this.iterations = 200;
103+
this.agents = 4;
104+
}
105+
93106
// Update is called once per frame
94107
void Update()
95108
{
@@ -106,7 +119,7 @@ void Update()
106119
Resource plants = new Resource(initialPlants, growthRate, threshold);
107120
Debug.Log(initialPlants);
108121
Debug.Log(threshold);
109-
this._ecosystem = new Ecosystem(this._preyParameters, this._predatorParameters, plants);
122+
this._ecosystem = new Ecosystem(this._preyParameters, this._predatorParameters, plants, iterations, agents, strategy);
110123

111124
//Initialize the view
112125
this._myView = Instantiate(MyView);
@@ -149,7 +162,7 @@ void Update()
149162

150163
//Initialize the ecosystem
151164
Resource plants = new Resource(initialPlants, growthRate, threshold);
152-
this._ecosystem = new Ecosystem(this._preyParameters, this._predatorParameters, plants);
165+
this._ecosystem = new Ecosystem(this._preyParameters, this._predatorParameters, plants, iterations, agents, strategy);
153166
//Reset the view
154167
this.ResetView();
155168
//Create a new file to save the data of the simulation
@@ -318,6 +331,39 @@ public void InitiateParameters() {
318331
}
319332

320333
//Strategy
334+
string strStrategy = stratMenu.GetComponent<Text>().text;
335+
if (!string.IsNullOrEmpty(strStrategy))
336+
{
337+
switch (strStrategy)
338+
{
339+
case "Estrategia simple":
340+
this.strategy = 0;
341+
break;
342+
case "Particle Swarm Optimization":
343+
this.strategy = 1;
344+
break;
345+
case "Grey Wolf Optimizer":
346+
this.strategy = 2;
347+
break;
348+
case "Whale Optimization Algorithm":
349+
this.strategy = 3;
350+
break;
351+
default:
352+
this.strategy = 0;
353+
break;
354+
}
355+
}
356+
string strIterations = itMenu.GetComponent<Text>().text;
357+
if (!string.IsNullOrEmpty(strIterations))
358+
{
359+
this.iterations = Convert.ToInt32(strIterations);
360+
}
361+
string strAgents = agentsMenu.GetComponent<Text>().text;
362+
if (!string.IsNullOrEmpty(strAgents))
363+
{
364+
this.agents = Convert.ToInt32(strAgents);
365+
}
366+
321367
Destroy(menu);
322368
}
323369
}

EcoSim/Assets/Model/AnimalGroup/Builder/PredatorBuilder.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,13 @@
44

55
public class PredatorBuilder : AnimalBuilder
66
{
7-
private double X_UPPER = 100;
7+
private double X_UPPER = 20;
88
private double X_LOWER = 0;
99

1010
private double Y_UPPER = 0;
1111
private double Y_LOWER = 0;
1212

13-
private double Z_UPPER = 100;
13+
private double Z_UPPER = 50;
1414
private double Z_LOWER = 0;
1515

1616
private int iterations;

EcoSim/Assets/Model/AnimalGroup/Builder/PreyBuilder.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@
44

55
public class PreyBuilder : AnimalBuilder
66
{
7-
private double X_UPPER = 100;
8-
private double X_LOWER = 0;
7+
private double X_UPPER = 40;
8+
private double X_LOWER = 10;
99

1010
private double Y_UPPER = 0;
1111
private double Y_LOWER = 0;

EcoSim/Assets/Model/SimulationCore/Ecosystem.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ public class Ecosystem
2525

2626

2727
//SECTION: Constructor and main methods
28-
public Ecosystem(GroupParameters preyParameters, GroupParameters predatorParameters, Resource plants)
28+
public Ecosystem(GroupParameters preyParameters, GroupParameters predatorParameters, Resource plants, int iterations, int agents, int strategy)
2929
{
3030
this.TransitionTo(new SimulationSurviveState());
3131
this._iteration = 0;
@@ -36,7 +36,7 @@ public Ecosystem(GroupParameters preyParameters, GroupParameters predatorParamet
3636

3737
Resource meat = new Resource(0, 0, 0);
3838
AnimalMediator predatorMediator = new AnimalMediator(meat);
39-
AnimalBuilder predatorBuilder = new PredatorBuilder(predatorParameters);
39+
AnimalBuilder predatorBuilder = new PredatorBuilder(predatorParameters, iterations, agents, strategy);
4040
this._predators = new AnimalGroup(predatorParameters, predatorBuilder, predatorMediator);
4141
}
4242

EcoSim/Assets/Scenes/Scene2.unity

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,12 @@ NavMeshSettings:
121121
debug:
122122
m_Flags: 0
123123
m_NavMeshData: {fileID: 0}
124+
--- !u!1 &148217658 stripped
125+
GameObject:
126+
m_CorrespondingSourceObject: {fileID: 1819000987019419942, guid: 9be69d7278b611041bf4a75e19c11b48,
127+
type: 3}
128+
m_PrefabInstance: {fileID: 604660364}
129+
m_PrefabAsset: {fileID: 0}
124130
--- !u!1 &158732703 stripped
125131
GameObject:
126132
m_CorrespondingSourceObject: {fileID: 1819000988066163790, guid: 9be69d7278b611041bf4a75e19c11b48,
@@ -461,6 +467,21 @@ PrefabInstance:
461467
propertyPath: trhold
462468
value:
463469
objectReference: {fileID: 1871423386}
470+
- target: {fileID: 5670853230243482470, guid: 67007c2f051f6fe4bb036819c2e190f5,
471+
type: 3}
472+
propertyPath: stratMenu
473+
value:
474+
objectReference: {fileID: 148217658}
475+
- target: {fileID: 5670853230243482470, guid: 67007c2f051f6fe4bb036819c2e190f5,
476+
type: 3}
477+
propertyPath: agentsMenu
478+
value:
479+
objectReference: {fileID: 1038250889}
480+
- target: {fileID: 5670853230243482470, guid: 67007c2f051f6fe4bb036819c2e190f5,
481+
type: 3}
482+
propertyPath: itMenu
483+
value:
484+
objectReference: {fileID: 1638413175}
464485
- target: {fileID: 8465234516850191603, guid: 67007c2f051f6fe4bb036819c2e190f5,
465486
type: 3}
466487
propertyPath: m_Name
@@ -572,6 +593,12 @@ Transform:
572593
m_Father: {fileID: 0}
573594
m_RootOrder: 1
574595
m_LocalEulerAnglesHint: {x: 50, y: -30, z: 0}
596+
--- !u!1 &1038250889 stripped
597+
GameObject:
598+
m_CorrespondingSourceObject: {fileID: 1819000987865868517, guid: 9be69d7278b611041bf4a75e19c11b48,
599+
type: 3}
600+
m_PrefabInstance: {fileID: 604660364}
601+
m_PrefabAsset: {fileID: 0}
575602
--- !u!1 &1098851179
576603
GameObject:
577604
m_ObjectHideFlags: 0
@@ -751,6 +778,12 @@ GameObject:
751778
type: 3}
752779
m_PrefabInstance: {fileID: 604660364}
753780
m_PrefabAsset: {fileID: 0}
781+
--- !u!1 &1638413175 stripped
782+
GameObject:
783+
m_CorrespondingSourceObject: {fileID: 1819000987924925063, guid: 9be69d7278b611041bf4a75e19c11b48,
784+
type: 3}
785+
m_PrefabInstance: {fileID: 604660364}
786+
m_PrefabAsset: {fileID: 0}
754787
--- !u!1 &1641573912 stripped
755788
GameObject:
756789
m_CorrespondingSourceObject: {fileID: 1819000987137233691, guid: 9be69d7278b611041bf4a75e19c11b48,

EcoSim/Assets/SimulationData/SimulationDataPhase2/Stage2-Simulation1.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,3 +2,4 @@
22
Parameters (in next line): Iterations|PreyReproductionRate|PreyMaxSpeed|PreyVisionRadius|PredatorReproductionRate|PredatorMaxSpeed|PredatorVisionRadius|InitialPlants|GrowthRate
33
200||0,9|0,55|8||0,3|0,6|15|600|5,6
44
Iteracion|InicialPresas|InicialPredadores|SupervivientesPresas|SupervivientesPredadores|Plantas|PlantasSupervivientes
5+
0|4|10|0|10|1200|1200

0 commit comments

Comments
 (0)