File tree Expand file tree Collapse file tree 3 files changed +14
-9
lines changed
Expand file tree Collapse file tree 3 files changed +14
-9
lines changed Original file line number Diff line number Diff 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 () {
Original file line number Diff line number Diff line change 11package wargame ;
22
3+ import java .util .*;
4+
35class 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
Original file line number Diff line number Diff line change 11package wargame ;
22
3+ import java .util .*;
4+
35class 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
You can’t perform that action at this time.
0 commit comments