-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathEcoSim.java
More file actions
106 lines (83 loc) · 3.23 KB
/
EcoSim.java
File metadata and controls
106 lines (83 loc) · 3.23 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
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
import java.util.Scanner;
import java.lang.Math;
/**
* EcoSim.java
* @version 1.0
* @author Jesse Liu
* @since April 24, 2019
* Master program to simulate ecosystem
*
* CHANGES:
*
* Added Genders to entities. Sheep breeding, Wolf breeding + attacking is
* based genders in addition to health (additional criteria)
*
* Added preferential movement based on health of entity. If health is above threshold,
* the entity prioritizes movement to breed. If under the threshold, it must move to food.
*
* OPTIMAL NUMBERS:
* Grid Size: 50
* Frequency of Grass Spawn: 0.2
* Initial grass HP: 5
* Initial Number of Sheep: 100
* Initial Sheep HP: 25
* Initial Number of Wolves: 20
* Initial Wolf HP: 40
*
*/
class EcoSim {
static int plantHealth;
public static void main(String[] args) {
// Scanner
Scanner input = new Scanner(System.in);
// Get necessary info
System.out.println("Grid Size: ");
int mapSize = input.nextInt();
// Spawnrate
System.out.println("Frequency of grass spawning: ");
double grassRate = input.nextDouble();
// Grass Health
System.out.println("Initial health points of grass (integer value):");
int grassHP = input.nextInt();
// Initial number of sheep
System.out.println("Initial number of sheep (integer value): ");
int initialSheep = input.nextInt();
// Sheep Health
System.out.println("Initial sheep HP (integer value): ");
int sheepHP = input.nextInt();
// Initial number of Wolves
System.out.println("Initial number of wolves (integer value): ");
int initialWolves = input.nextInt();
// Wolf Health
System.out.println("Initial wolf HP (integer value): ");
int wolfHP = input.nextInt();
// Create the master map controller, pass all rates and stats into the controller
EntMaster master = new EntMaster(mapSize, grassRate, grassHP, initialSheep, sheepHP, initialWolves, wolfHP);
//
System.out.println("_______________________________________________\nSimulation Started.")
// Simulation boolean on
boolean simOn = true;
// Initialize display, spawn the initial grass in environment
master.displayMap();
master.spawnGrass();
// Compensate for an apparent delay on MAC - DELETE ON WINDOWS IF NO DELAY APPARENT
try{Thread.sleep(3000); }catch(Exception e) {};
while (simOn) {
master.updateInfo();
master.spawnGrass();
master.resetMoveConditions();
master.moveEntities();
master.displayMap();
try { Thread.sleep(100); }catch(Exception e) {};
// Check for extinction, turn simulation off
if (master.checkExtinction() == true) {
simOn = false;
}
}
System.out.println("_______________________________________________\nSimulation complete");
System.out.println("The simulation lasted " + master.getTurn() + " turns.");
System.out.println(master.getMasterGrass() + " total grass were spawned throughout the simulation.");
System.out.println(master.getMasterSheep() + " total sheep were spawned throughout the simulation.");
System.out.println(master.getMasterWolves() + " total wolves were spawned throughout the simulation.");
}
}