-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCPU.java
More file actions
32 lines (23 loc) · 745 Bytes
/
CPU.java
File metadata and controls
32 lines (23 loc) · 745 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
import java.lang.reflect.Array;
import java.util.ArrayList;
import java.util.List;
import javax.naming.ldap.StartTlsRequest;
public class CPU {
private Strategy strategy;
private List<Action> history = new ArrayList<>();
public CPU(Strategy strategy, List<Action> history) {
this.strategy = strategy;
this.history = history;
}
public void setStrategy(Strategy strategy) {
this.strategy = strategy;
}
public Action play(int consecutiveWins, List<Action> history) {
if (consecutiveWins == 3 && strategy instanceof CycleStrategy){
setStrategy(new LastStrategy(history));
} else if (consecutiveWins == 3 && strategy instanceof LastStrategy){
setStrategy(new RandomStrategy());
}
return strategy.getAction();
}
}