Skip to content

Commit ee04cd2

Browse files
committed
modify code
1 parent ef4fdd3 commit ee04cd2

File tree

4 files changed

+10
-5
lines changed

4 files changed

+10
-5
lines changed
Binary file not shown.

src/class095/Code02_PrimePowerStones.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ public static void main(String[] args) throws IOException {
4141
}
4242

4343
public static String compute(int n) {
44-
return n % 6 == 0 ? "Roy wins!" : "October wins!";
44+
return n % 6 != 0 ? "October wins!" : "Roy wins!";
4545
}
4646

4747
}

src/class095/Code04_AntiNimGame.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ public static String compute() {
5555
if (sum == n) {
5656
return (n & 1) == 1 ? "Brother" : "John";
5757
} else {
58-
return eor == 0 ? "Brother" : "John";
58+
return eor != 0 ? "John" : "Brother";
5959
}
6060
}
6161

src/class095/Code06_WythoffGame.java

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121

2222
public class Code06_WythoffGame {
2323

24+
// 黄金分割比例
2425
public static double split = (Math.sqrt(5.0) + 1.0) / 2.0;
2526

2627
public static int a, b;
@@ -43,10 +44,14 @@ public static void main(String[] args) throws IOException {
4344
public static int compute() {
4445
int min = Math.min(a, b);
4546
int max = Math.max(a, b);
46-
if (min == (int) (split * (max - min))) {
47-
return 0;
48-
} else {
47+
// 威佐夫博弈
48+
// 小 != (大 - 小) * 黄金分割比例,先手赢
49+
// 小 == (大 - 小) * 黄金分割比例,后手赢
50+
// 要向下取整
51+
if (min != (int) (split * (max - min))) {
4952
return 1;
53+
} else {
54+
return 0;
5055
}
5156
}
5257

0 commit comments

Comments
 (0)