GeneralGuesser

The GeneralGuesser class also has to implement the constructor and setFirstGuess, but generally, that is it. It does not need to do anything else:

package packt.java189fundamentals.example.mastermind;

public class GeneralGuesser extends Guesser {

    public GeneralGuesser(Table table) {
        super(table);
    }

    @Override
    protected void setFirstGuess() {
        int i = 0;
        for (Color color = table.manager.firstColor();
             i < lastGuess.length;
            ) {
            lastGuess[i++] = color;
        }
    }
}

The algorithm is extremely simple. It just puts the first color into each column of the lastGuess array. Guess could not be simpler. Everything else is inherited from the abstract class Guesser.

Get Java Projects - Second Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.