# Master Mind Rule ambiguity

A recent question about Programming a Prolog solver for a Master Mind type problem generated a question about a scoring rule ambiguity for Master Mind, which is not solved by the Wikipedia page entry for "Master Mind"

Suppose you have this situation, with letters a stand-in for color:

If you have a code:   ABCD
And the guess is:     EEAA


... Does the codemaker indicate:

1. 0 black pegs and 2 white pegs because there are no entries in the guess with the correct color at the correct place, and the two As are correct guesses but on the wrong place.
2. 0 black pegs and 1 white peg because there are no entries in the guess with the correct color at the correct place, and the only one of the A in the guess can be paired with the A in the code.

Case 2 is equivalent to drawing lines between the code pegs and the guess pegs, going for the vertical lines first (pair any pegs with same color at same position) and following up with any remaining diagonal lines (pair any pegs with same color at different positions).

Is (2) the right way of scoring?

# Formal

In the paper Mastermind is NP-Complete by Jeff Stuckman and Guo-Qiang Zhang give the following definition of b (the number of black pegs) and w-b (the number of white pegs). To make things short, they go for scoring method (2):

So, to make the labeling clear:

                      1234 <--- Position indicators
If you have a code:   ABCD <--- The array x[i] of code colors, 1 ≤ i ≤ 4
And the guess is:     EEAA <--- The array y[i] of guess colors, 1 ≤ i ≤ 4


Evidently in the above b = 0 because there is no i in [1,2,3,4] where x[i] = y[i]

w is a bit trickier, it is a sum over the colors, where j ranges over the colors:

      +--j
|
|    +--Number of occurrences of color j in array x
|    |
|    |    +--Number of occurrences of color j in array y
|    |    |
|    |    |    +--Minimum of both values (== number of possible pairings for that color)
|    |    |    |
Color A    1    2    1
Color B    1    0    0
Color C    1    0    0
Color D    1    0    0
Color E    0    2    0
-----
Sum: 1 = w = number of possible pairings in the (code,guess) pair


So, number of black pegs: b = 0 So, number of white pegs: w-b = 1-0 = 1

I don't know why you have concluded that the scoring ambiguity is not resolved by the Wikipedia page. There is text on that page which, to me, clearly addresses and resolves this issue:

If there are duplicate colours in the guess, they cannot all be awarded a key peg unless they correspond to the same number of duplicate colours in the hidden code. For example, if the hidden code is white-white-black-black and the player guesses white-white-white-black, the codemaker will award two colored key pegs for the two correct whites, nothing for the third white as there is not a third white in the code, and a colored key peg for the black. No indication is given of the fact that the code also includes a second black.

This text supports your option 2.

Furthermore, the original game box bottom also specifies rules, and those rules clearly address this question as well, also in support of your option 2. The image of the game box is here: https://i.stack.imgur.com/N1XDS.jpg. The relevant text is here:

A White Key Peg is placed ... for each hidden Code Peg which is matched in colour but not position by a peg placed by the Codebreaker. For example, one white Key Peg is placed if one red Code Peg is hidden, and the Codebreaker has placed two or more red Code Pegs in the wrong position.

• Thanks. On third reading the phrase "If there are duplicate colours in the guess, they cannot all be awarded a key peg unless they correspond to the same number of duplicate colours in the hidden code." indeed supports option 2, although the example does not. As for the text of the game (I didn't look for it), it makes no sense to me. "two or more" should really be "one or more" here. – David Tonhofer Apr 18 at 12:22
• @DavidTonhofer - I should have included the previous sentence from the box rules, as well. It is clearer when the two sentences are read together. I have revised my answer to include that sentence. But, yes, you are right that it could be written slightly better, and changing "two or more" to "one or more" would be a little better. As for the Wikipedia page, to me, the example given precisely supports option 2. It is not clear to me why you think otherwise. – Lanny Strack Apr 18 at 12:34
• Because the example pairs off the two whites and 1 black on the correct position leaving just a W in the guess and a B in the code. Simples, no ambiguity. It's a bad example for what it wants to illustrate. The box should still say "one or more" instead of "two or more". – David Tonhofer Apr 18 at 12:43
• I'm not sure what you mean by "leaving just a W in the guess and a B in the code", but at any rate, it's Wikipedia, so you can edit it and make it better! – Lanny Strack Apr 18 at 12:49