Skip to content

Commit 4b4ff62

Browse files
committed
cleaned up the code's aesthetic
1 parent 466ee7a commit 4b4ff62

File tree

1 file changed

+5
-27
lines changed

1 file changed

+5
-27
lines changed

simulation/Simulation.java

Lines changed: 5 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -363,42 +363,20 @@ void run_hand(ArrayList<Deck_Card> hand) {
363363
if (this.equation.evaluate(hand)) {
364364
this.count.incrementAndGet();
365365
}
366+
reset_hand(hand);
366367
}
367368
}
368369

369370
final List<ScenarioCount> forestCount = FOREST.stream().map(ScenarioCount::new).collect(Collectors.toList());
370-
371-
/*
372-
Minimalist Strategy
373-
Only create a single thread for each drawn hand, and have each hand test all scenarios
374-
*/
375-
class HandGenerator implements Supplier<ArrayList<Deck_Card>> {
376-
@Override
377-
public ArrayList<Deck_Card> get() {
378-
synchronized (DECK) {
379-
return Deck_Card.deep_copy(draw_hand(HAND_SIZE, DECK));
380-
}
381-
}
382-
}
383-
384-
class HandTester implements Consumer<ArrayList<Deck_Card>> {
385-
@Override
386-
public void accept(ArrayList<Deck_Card> hand) {
387-
for(ScenarioCount sc : forestCount) {
388-
sc.run_hand(hand);
389-
reset_hand(hand);
390-
}
391-
}
392-
}
393-
394-
395371
final long START_TIME; //simulation start time in milliseconds
396372

397373
synchronized (Simulation.PARALLEL_SIMULATION_LOCK) {
398374
START_TIME = System.currentTimeMillis();
399375

400-
Stream<ArrayList<Deck_Card>> random_hands = Stream.generate(new HandGenerator());
401-
random_hands.parallel().limit(TEST_HAND_COUNT).forEach(new HandTester());
376+
Stream.generate(() -> Deck_Card.deep_copy(draw_hand(HAND_SIZE, DECK)))
377+
.parallel()
378+
.limit(TEST_HAND_COUNT)
379+
.forEach(hand -> forestCount.forEach(fc -> fc.run_hand(hand)));
402380

403381
AtomicInteger[] HITS = forestCount.stream().map(a -> a.count).toArray(AtomicInteger[]::new);
404382

0 commit comments

Comments
 (0)