Skip to content

Commit 876511a

Browse files
committed
Merge branch 'parity-rng' into parity-develop-edge
2 parents 274ad2d + 28ac513 commit 876511a

File tree

3 files changed

+14
-9
lines changed

3 files changed

+14
-9
lines changed

source/wargame/Deck.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,8 @@ class Deck {
1414
cards = new ArrayList<Card>();
1515
}
1616

17-
public void shuffle() {
18-
Collections.shuffle(this.cards);
17+
public void shuffle(Random rng) {
18+
Collections.shuffle(this.cards, rng);
1919
}
2020

2121
public int getSize() {

source/wargame/WarGame.java

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,13 @@
11
package wargame;
22

3+
import java.util.*;
4+
35
class WarGame {
46

5-
public void play() {
7+
public void play(Random rng) {
68

79
Deck deck = Deck.fresh();
8-
deck.shuffle();
10+
deck.shuffle(rng);
911

1012
Deck[] player = deck.split();
1113

@@ -40,10 +42,10 @@ public void play() {
4042
player[1].giveCard(winner);
4143

4244
if (c1.compareTo(c2) > 0) {
43-
winner.shuffle();
45+
winner.shuffle(rng);
4446
winner.giveCards(player[0]);
4547
} else if (c1.compareTo(c2) < 0) {
46-
winner.shuffle();
48+
winner.shuffle(rng);
4749
winner.giveCards(player[1]);
4850
} else {
4951
// another war
@@ -52,10 +54,10 @@ public void play() {
5254
} while (c1.compareTo(c2) == 0);
5355

5456
} else if (c1.compareTo(c2) > 0) {
55-
winner.shuffle();
57+
winner.shuffle(rng);
5658
winner.giveCards(player[0]);
5759
} else if (c1.compareTo(c2) < 0) {
58-
winner.shuffle();
60+
winner.shuffle(rng);
5961
winner.giveCards(player[1]);
6062
}
6163

source/wargame/WarGameThread.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
package wargame;
22

3+
import java.util.*;
4+
35
class WarGameThread extends Thread {
46

57
public static boolean isAlive(WarGameThread[] threads) {
@@ -55,8 +57,9 @@ public void terminate() {
5557

5658
public void run() {
5759
WarGame game = new WarGame();
60+
Random rng = new Random();
5861
while ( !this.terminate ) {
59-
game.play();
62+
game.play(rng);
6063
this.processed++;
6164
}
6265

0 commit comments

Comments
 (0)