bluering.nl contact sieuwert_at_bluering.nl

On the left you see an applet, in which you can play the famous game mastermind. The computer has in mind a sequence of colours. For example {red,blue,white,white}. You if you enter the sequence the computer had in mind. The colours that are used are: Red , Green , Yellow , Blue , White and Dark . You can input a guess in the textfield. Use he first letter of every colour. Examples of input are: rrgg ybdy wdwb . (This is why the colour black is named dark.) If your guess was correct, the computer will decloak his code. If it wasn't, the computer will give you an evaluation or score: Right beside your guess some black and white pins will appear. A black pin means that one of your colours was at the right position. A white pin means that one of you colours was indeed in the computer's code, but not at that place.

The position of the black and white pins does not tell you for which colour you got that pin. You may guess ten times.

Sourcecode

In addition to the comments in the sourcecode, I have the following remarks:

A code, or a guess, is in the listing a array of four ints. The values of these ints are 0,1,2,3,4,5. Which colour is which number is defined in the color table of screen. Which letter is used for which number is defined in charToInt.

An evaluation,( or a score, that's the same), is also an array of 4 ints. These ints can be 0 (no pin), 1 (a white pin), or 2 (a black pin). Usually, first black pins are given, then white pins.

The least readable method is the paint of the screen. Some explanation: By using magfactor I can make the applet bigger and smaller if I want to (I don't want to, but it's nice I can do it). In every call to graphics, I must multiply the coordinates with magfactor.

I for myself have made a sketch of the screen division: There are eleven code positions(The last one is used for the code that has to be guessed. The first ten are for your guesses): A code gets 40 by 10 pixels (if magfactor were 1). Besides every code position, there is room for an evaluation. This measures 10 by 10. (The real life bord game uses the same division.)

To evaluate the code, I had to make sure no colours were doublely rewarded. For instance a colour can be at the exact position, and can cause a black pin, and have the same color to something at a different position. To tackle this problem, I copy both the code and the guess, so I can write in it. I first check for black pins. If you have a match, you overwrite the colors in both the code and the guess with some different nonsense number. Now they will not match anything else, so they can't be rewarded double.

I hope this helped you read this, I must admit, not so structured program. If you still can't read it, maybe you should mail me.

Another good mastermind version by Rehman Mackwani can be found  here (based on  this ).
[click here if you see no menu]