19
7
I could only find code-golf challenges for Mastermind, so here's a code-challenge version that I would have liked to take on myself.
An optimal strategy for the normal Mastermind game, MM(4,6), was found by Koyama and Lai in 1993, having an average # of guesses = 5625/1296 ~ 4.34. MM(5,8) is still unsolved, but is estimated to have an average # of guesses ~ 5.5.
Your task is to create an MM(5,8) strategy, that is for 5 holes and 8 colors, covering all pow(8,5) = 32768
possible distinct solutions. Obviously, it doesn't have to be an optimal one. You have two choices:
- Post a deterministic program that generates the strategy. The program must be compileable/runnable on Windows 7, Mac OS X or Linux without any extra non-free software.
- Publish your strategy (along with your StackExchange name) somewhere on the Internet and post the URL here.
In both cases, state the score (see below) in the answer's header.
The strategy must be encoded according to the following grammar:
strategy : guessing-strategy | known-solution-strategy
guessing-strategy : '{' guess ':' branches '}'
known-solution-strategy : guess
guess : color color color color color
color : 'A'..'H'
branches : '{' branch (',' branch)* '}'
branch : reply ':' strategy
reply : number-of-blacks number-of-whites
number-of-blacks : number-of-key-pegs
number-of-whites : number-of-key-pegs
number-of-key-pegs : '0'..'5'
The algorithm used to decide the number of black/white key pegs is described in http://en.wikipedia.org/wiki/Mastermind_(board_game)
Note that the reply "50" (i.e. correct guess) is implied and not part of the grammar.
Scoring: N = the sum of the number of guesses for each of the 32768 paths/solutions. The strategy with the lowest N wins. First tie-break: The lowest maximum number of guesses. Second tie-break: The first posted answer. The competition ends August 1, 2014 0:00 GMT.
An example of a strategy for MM(2,3) with score = 21:
{AB:{10:{AC:{10:AA,01:CB,00:BB}},02:BA,01:{BC:{01:CA}},00:CC}}
Using this strategy, the 9 possible games will go like this:
- AB 20
- AB 10, AC 20
- AB 10, AC 10, AA 20
- AB 10, AC 01, CB 20
- AB 10, AC 00, BB 20
- AB 02, BA 20
- AB 01, BC 20
- AB 01, BC 01, CA 20
- AB 00, CC 20
I will soon post a Java-based MM(5,8) strategy verifier for your convenience.
For information, a MM(5,8) strategy was implemented scoring 179929 with a maximum depth of 8 as detailed here (github site): Optimal MM(5,8) strategy This strategy is "mathematically optimal" with the restriction of only making possible guesses (not impossible ones) and takes a few days to complete.
– Aurélien – 2019-05-12T16:01:35.040I'm having a difficult time understanding how the example strategy of MM(2,3) is applied. Can you post a sample game explaining the strategy? – None – 2014-06-18T22:15:17.820
@tolos I added all 9 :) – MrBackend – 2014-06-18T22:58:12.160
It would be great if your verifier could output a score, too! – Not that Charles – 2014-06-24T11:06:06.617
@Charles Will do! – MrBackend – 2014-06-24T12:01:23.500
How is the verifier going? :) – Martin Ender – 2014-07-19T10:49:05.173
2Would you be willing to change your grammar to allow the same response to multiple key peg combinations? Like
{AB:{10|01:BB}}
? I do have an answer, but it's pretty naive and due to the tree-structure of the grammar it doesn't scale well at all (4 holes, 3 colours, generates a 147MB strategy, which I could cut down significantly by combining parts of the tree). – Martin Ender – 2014-07-19T14:44:14.877