-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathZebra.java
126 lines (114 loc) · 3.32 KB
/
Zebra.java
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
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
import java.util.Random;
/**
* A simple model of a zebra.
* Zebras age, move, breed, eat, and die.
*
* @author Colin Billhardt and Thom Treebus
* @version 2022.02
*/
public class Zebra extends Prey
{
// Characteristics shared by all zebras (class variables).
// The age at which a zebra can start to breed.
private static final int BREEDING_AGE = 15;
// The likelihood of a zebra breeding.
private static final double BREEDING_PROBABILITY = 0.5;
// The age to which a zebra can live.
private static final int MAX_AGE = 70;
// The maximum number of births.
private static final int MAX_LITTER_SIZE = 1;
// The value that is worth a zebra when it is eaten by another animal
private static final int FOOD_VALUE = 25;
//The maximum food level of the zebra.
private static final int MAX_FOOD_LEVEL = 30;
//A list of species that are part of the zebra's diet.
private static final String[] preys = {"Grass"};
// A shared random number generator to control breeding.
private static final Random rand = Randomizer.getRandom();
// The infection probability of the animal.
private static final double DISEASE_INFECTION_RATE = 0.001;
/**
* Create a new zebra. A zebra may be created with age
* zero (a newborn) or with a random age.
*
* @param randomAge If true, the zebra will have a random age.
* @param field The field currently occupied.
* @param location The location within the field.
*/
public Zebra(boolean randomAge, Field field, Location location)
{
super(field, location);
if(randomAge) {
// We assume the simulation starts with a relatively young population
age = rand.nextInt(MAX_AGE/2);
// food level initialized by Animal constructor
}else{
// age = 0; Implied by Entity constructor
foodLevel = 15; //Initial food level of a newborn
}
}
/**
* Creates a new zebra
* @param field The simulation field.
* @param location Location to create the new zebra.
* @return The new zebra
*/
protected Animal newAnimalObject(Field field, Location location) {
return new Zebra(false, field, location);
}
/**
* @return The maximum age
*/
protected int getMAX_AGE()
{
return MAX_AGE;
}
/**
* @return The breeding age
*/
protected int getBREEDING_AGE()
{
return BREEDING_AGE;
}
/**
* @return The breeding probability
*/
protected double getBREEDING_PROBABILITY()
{
return BREEDING_PROBABILITY;
}
/**
* @return The maximum litter size
*/
protected int getMAX_LITTER_SIZE()
{
return MAX_LITTER_SIZE;
}
/**
*
* @return The max food value
*/
protected int getMAX_FOOD_LEVEL()
{
return MAX_FOOD_LEVEL;
}
/**
* @return The zebra's food value when eaten
*/
protected int getFOOD_VALUE()
{
return FOOD_VALUE;
}
/**
* @return The list of species that the zebra can eat.
*/
protected String[] getPreys() {
return preys;
}
/**
* @return the animal's chance to get infected randomly.
*/
protected double getDISEASE_INFECTION_RATE(){
return DISEASE_INFECTION_RATE;
}
}