The applet on this page will let you play the game of MasterMind. The aim of
this game is guessing the code of the opponent. Unlike most MasterMind
implementations, this applet will not only let you guess a code, it will
also try to guess your code (and it is good at it too!!).
The applet has two alternating playing modes.
It starts by trying to guess your code.
Then it lets you guess a code and after that the cycle starts again.
Switching to the next mode happens after pushing the New game button,
which appears after the current mode has finished.
When the applet tries to guess your code
When the applet tries to guess your code, you should enter the number of
black and white result pegs in the box right of the applets guess and then
press the Enter result button. Entering result pegs can be done by
clicking on the hole where you want to place the peg. Clicking cycles through
the possibilities: white peg, black peg, no peg. The position of the result
pegs is not important.
When you try to guess the applets code
When you try to guess the applets code, you should enter your guess in the
(lowest available) left box and then press the Enter guess button.
Entering a guess can be done by dragging a colored peg to the desired hole.
Pegs can be dragged from either the peg store at the right or from already
placed pegs on the left.
To save a few people some frustration, the applet shows its code in the
Java console after the round has finished. It shows the code as numbers
which give the order in the peg store (i.e. 0=blue, 1=green, etc.).
Rules of the game
MasterMind is a game played by two persons. The object of the game is to
guess the opponents code. A code is a row of five colored pegs, each of
which can have any of nine colors. The game proceeds as follows:
- Person A picks a code (the code to be guessed).
- Person B places a code (the guess) in the first (lowest) free box on the
left of the playing board.
- Person A compares the two codes and places result pegs in the box right
of the guess:
- One black peg for each color of the guess that appears in the same
position in the code to be guessed.
- One white peg for each color of the guess that appears in the code to
be guessed but is not in the correct position.
- If the code is not guessed and there are still free boxes on the left,
then go back to step 2, otherwise this game has finished and person A and B
should switch sides and start another game.
When the applet is guessing your code, it can come to the conclusion there is
no code possible that agrees with the result of the previous guesses. If so,
it will print a message in the Java console and in the status bar of your
browser and start a new game.
Note that this applet uses a several (about 30) different colors with some
subtle shades. When you use a screen that allows only 256 simultaneous colors,
not all of these colors might be presented correctly.
In general it is still possible to use the applet on such systems (i.e. the
different peg colors are still recognizable), but the applet will not look
as good as it should. If your system allows more (e.g. 65536) simultaneous
colors, you should see the applet as intended.
The source of this applet consists of three classes:
- mastermind.java is the applet class and handles all I/O.
- mm.java contains the logic of the MasterMind game.
- mm_result.java is just a small utility class.
You can download the code at the Sourceforge project pages.