IntervalGuesser
We discussed the different Java language elements and JDK classes that are all available to implement parallel algorithms. Now, we will see how to use these approaches to implement the parallel guesser for the Masterrmind game.
The class that performs the creation of the guesses is named IntervalGuesser
. It creates the guesses between a start and an end guess and sends them to a BlockingQueue
. The class implements Runnable
so it can run in a separate Thread
. The purist implementation will separate the Runnable
functionality from the interval guessing, but as the whole class is hardly more than 50 lines, it is forgivable sin implementing the two functionalities in a single class.
public class IntervalGuesser extends UniqueGuesser implements Runnable { private final Guess start; private final Guess end; private Guess lastGuess; private final BlockingQueue<Guess> guessQueue; public IntervalGuesser(Table table, Guess start, Guess end, BlockingQueue...