-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathComputer.java
76 lines (70 loc) · 2.2 KB
/
Computer.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
public class Computer {
private boolean active;
private String difficulty;
public Computer() {
}
public void computerActive(boolean isActive) {
active = isActive;
}
public boolean isActive() {
return active;
}
public void setDiff(String diff) {
difficulty = diff;
}
public void turn(int player, int sticks) {
if (difficulty == "easy") {
Game.runMove((int) Math.floor((Math.random() * ((sticks / 2) + 1)) + 1));
} else if (difficulty == "medium") {
if (7 < sticks && sticks < 14) {
Game.runMove(sticks - 7);
} else {
switch (sticks) {
case 6:
Game.runMove(3);
break;
case 5:
Game.runMove(2);
break;
case 7:
case 4:
case 3:
case 2:
Game.runMove(1);
break;
default:
Game.runMove((int) Math.floor((Math.random() * ((sticks / 2) + 1)) + 1));
break;
}
;
}
} else if (difficulty == "hard") {
if (31 < sticks) {
Game.runMove(sticks - 31);
} else if (15 < sticks && sticks < 31) {
Game.runMove(sticks - 15);
} else if (7 < sticks && sticks < 14) {
Game.runMove(sticks - 7);
} else {
switch (sticks) {
case 6:
Game.runMove(3);
break;
case 5:
Game.runMove(2);
break;
case 7:
case 4:
case 3:
case 2:
Game.runMove(1);
break;
default:
Game.runMove((int) Math.floor((Math.random() * ((sticks / 2) + 1)) + 1));
break;
}
;
}
}
}
}