-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathDefector.java
More file actions
46 lines (37 loc) · 843 Bytes
/
Defector.java
File metadata and controls
46 lines (37 loc) · 843 Bytes
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
import java.util.Random;
import java.security.SecureRandom;
/**
* A subclass of Organism that never
* cooperates.
* Methods are modified to suit.
*/
public class Defector extends Organism {
//fields-----------------------------------
private Random rand;
//Constructor-------------------------------
public Defector() {
super();
this.rand = new SecureRandom();
}
//Methods-----------------------------------
@Override
public String getType() {
return "Defector";
}
@Override
public Organism reproduce() {
//Can mutate to PartialCooperator
if (rand.nextInt(100) == 0) {
return new PartialCooperator();
}
return new Defector();
}
@Override
public double getCooperationProbability() {
return 0;
}
@Override
public boolean cooperates() {
return false;
}
}