-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathBuffalo.java
128 lines (113 loc) · 3.34 KB
/
Buffalo.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
127
128
import java.util.Random;
/**
* A simple model of a buffalo.
* Buffalo age, move, breed, eat, and die.
*
* @author Aymen Berbache and Aleks
* @version 2022.02
*/
public class Buffalo extends Prey
{
// Characteristics shared by all buffalo (class variables).
// The age at which a buffalo can start to breed.
private static final int BREEDING_AGE = 15;
// The age to which a buffalo can live.
private static final int MAX_AGE = 70;
// The likelihood of a buffalo breeding.
private static final double BREEDING_PROBABILITY = 0.45;
// The maximum number of births.
private static final int MAX_LITTER_SIZE = 2;
// The value that is worth a buffalo when it is eaten by another animal
private static final int FOOD_VALUE = 25;
//The maximum food level of the buffalo.
private static final int MAX_FOOD_LEVEL = 30;
//A list of entities that are part of the buffalo'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.01;
/**
* Create a new buffalo. A buffalo may be created with age
* zero (a newborn) or with a random age.
*
* @param randomAge If true, the buffalo will have a random age.
* @param field The field currently occupied.
* @param location The location within the field.
*/
public Buffalo(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 = 14; //Initial food level of a newborn
}
}
/**
* Creates a new buffalo
* @param field The simulation field.
* @param location Location to create the new buffalo.
* @return The new buffalo
*/
protected Animal newAnimalObject(Field field, Location location) {
return new Buffalo(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 buffalo's food value when eaten
*/
protected int getFOOD_VALUE()
{
return FOOD_VALUE;
}
/**
* @return The list of species that the buffalo 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;
}
}