-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathPartialCooperator.java
More file actions
50 lines (41 loc) · 1.04 KB
/
PartialCooperator.java
File metadata and controls
50 lines (41 loc) · 1.04 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
import java.util.Random;
import java.security.SecureRandom;
/**
* A subclass of organism that cooperates
* half of the time.
* A random field has been added.
* The methods are changed to suit.
*/
public class PartialCooperator extends Organism {
//fields--------------------------------------------
private Random rand;
//Constructor---------------------------------------
public PartialCooperator() {
super();
rand = new SecureRandom();
}
//Methods-------------------------------------------
@Override
public String getType() {
return "PartialCooperator";
}
@Override
public Organism reproduce() {
//Check to see whether mutation to Cooperator or Defector occurs
int mut = rand.nextInt(100);
if (mut == 0) {
return new Cooperator();
} else if (mut == 999) {
return new Defector();
}
return new PartialCooperator();
}
@Override
public double getCooperationProbability() {
return .5;
}
@Override
public boolean cooperates() {
return rand.nextBoolean();
}
}