Like this presentation? Why not share!

# An Algorithm for solving the game of Mastermind

## by Juan Julián Merelo Guervós, University Professor at Universidad de Granada on Apr 03, 2010

• 13,246 views

Presentation of our paper on an algorithm for cracking the code in a Mastermind Game. You can understand a bit more about the game in this blog post ...

Presentation of our paper on an algorithm for cracking the code in a Mastermind Game. You can understand a bit more about the game in this blog post http://geneura.wordpress.com/2012/07/06/why-mastermind/ Please post your questions and/or feedback wherever.

### Views

Total Views
13,246
Views on SlideShare
12,811
Embed Views
435

Likes
0
46
0

### Report content

• http://www.flickr.com/photos/96dpi/3045941013/ With a creative commons licence
• How would you play mastermind? It&apos;s not easy to do, since possible branches are many more than for Sudoku or even chess. In fact, this is the kind of game that can be played more easily by a machine than by a person. CC picture from http://www.flickr.com/photos/unloveable/2399932549/
• One of the possible ways to find solutions. Could be others, of course, but this is a good one.
• Creative Commons picture from http://www.flickr.com/photos/mayaevening/138372058/

## An Algorithm for solving the game of MastermindPresentation Transcript

• J. J. Merelo , T. P. Runarsson U. Granada (Spain) & U. Iceland Finding better solutions to the Mastermind puzzle using evolutionary algorithms
• Game of MasterMind
• Why should I care? I want to frag!
• 7 reasons why you should
• Donald Knuth
• NP-Complete
• Differential cryptanalisis
• Circuit and program test
• Genetic profiling
• Minimize guesses
• Minimize evaluations
• Let's play, then
• Consistent combinations
• Naïve Algorithm
• Repeat
• Find a consistent combination and play it.
• Looking for consistent solutions
• Optimization algorithm based on distance to consistency (for all combinations played)
D = 2
• Not all consistent combinations are born the same
• There's at least one better than the others (the solution)
• Some will reduce the remaining search space more.
• But scoring them is an open issue
• Score consistent set
• Enter partitions Most parts. Score = 5 Best worst case. Score = -3 Entropy. Score = 1.67 1.31 0.96 0.96 1.58 1.52 1.67 1.42 1.52 1.67
• Less Naïve Algorithm
• Play initial combination
• Repeat until end
• Eliminate non-consistent combinations
• Score them using partitions
• Play best score
• And the winner is...
• Entropy & Most parts obtains the best results ~ 4.408 combinations played
• Naïve algorithms obtain ~ 4.6
• Problem : exhaustive search needed
• We want to do better than exhaustive search
• Berghman et al.'s used only a subset of the set of consistent combinations with an evolutionary algorithm : non-exhaustive
• Better scaling
• Runarsson/Merelo computed the size of the set which obtains the same result as exhaustive search.
That's us!
• What we do in this paper Evolutionary algorithm Fitness = Distance-to-consistency Gather a set of consistent combinations Score using most-parts Play the best score
• Canonical GAs and EDA to the rescue
• Rank-based GA did not yield good results
• Population = ¼ of search space
• Reset after stagnation
• Run until 20 consistent combinations are found or 3 generations without change
• 10 * 1296 runs (10 for each combination AAAA .. FFFF)
• Results
• EDA and CGA obtain results better than (seudo) exhaustive search.
• It is also comparable with the rest
• And with less effort!
• The gritty details
• 2-3 combinations drawn from initial population
• Evolutionary algorithm acting on final stages
• Mostly exploratory regime.
• 2-3 combinations drawn from initial population
• Evolutionary algorithm acting on final stages
• Mostly exploratory regime.
• Exhaustive search can be defeated
• Running time similar to naïve evolutionary algorithm
• Conclusions in exhaustive search can be translated to EAs.
• Exhaustive search can be defeated
• Running time similar to naïve evolutionary algorithm
• Conclusions in exhaustive search can be translated to EAs.
Concluding...
• That's all Thanks for your attention