Mastermind or finding a needle in a haystack algorithmmical ly
J. J. Merelo University of Granada @jjmerelo
GAME-ON 2012, Mรกlaga
Set combinat ion
Mastermind
2
player makes guess
Mastermind
3
Response: white and black pins
Mastermind
4
Making another guess and response
Mastermind
5
Could this be it?
Mastermind
6
Yes! ďžş
Mastermind
7
In the beginning were the bulls and the cows
Mastermind
8
But then came Mordechai Meirowitz
Mastermind
9
This computer wants to play too!
Mastermind
10
C'mon, really, why????
Mastermind
11
1. Donald Knuth
Mastermind
12
II. NPComplet e
Mastermind
13
III Genetic profiling/selec tive phenotyping
Mastermind
14
IV. ATM cracking
Mastermind
15
V. No optimal solution in the general case
Mastermind
16
OK, I'm in. How? I need a strategy!
Mastermind
17
How would you do it? Usually first colors, then positions
Mastermind
18
Enter eligible combinatio ns
Mastermind
19
● ●
easy Play a random combination. algorith While ( combination != secret ) Find and play an eligible combination. m ●
Mastermind
20
● ●
Random.
How do you find it?
Exhaustive search. ●
Just as long as you have memory.
Mastermind
21
Evolutionary algorithms
Mastermind
22
Eligibility is not enough
Mastermind
23
Create partitions in the set of eligible combinations AAA BBB CCC ABC CBA AAB AAC AAD BCA
AAA 3b-0w 0b-0w 0b-0w 1b-0w 1b-0w 2b-0w 2b-0w 2b-0w 1b-0w
BBB 0b-0w 3b-0w 0b-0w 1b-0w 1b-0w 1b-0w 0b-0w 0b-0w 1b-0w
CCC 0b-0w 0b-0w 3b-0w 1b-0w 1b-0w 0b-0w 1b-0w 0b-0w 1b-0w
ABC 1b-0w 1b-0w 1b-0w 3b-0w 1b-2w 1b-1w 2b-0w 1b-0w 0b-3w
CBA 1b-0w 1b-0w 1b-0w 1b-2w 3b-0w 0b-2w 0b-2w 0b-1w 1b-2w
Evolutionary Mastermind - Merelo/Runarsson
AAB 2b-0w 1b-0w 0b-0w 1b-1w 0b-2w 3b-0w 2b-0w 2b-0w 0b-2w
AAC 2b-0w 0b-0w 1b-0w 2b-0w 0b-2w 2b-0w 3b-0w 2b-0w 0b-2w
AAD 2b-0w 0b-0w 0b-0w 1b-0w 0b-1w 2b-0w 2b-0w 3b-0w 0b-1w
BCA 1b-0w 1b-0w 1b-0w 0b-3w 1b-2w 0b-2w 0b-2w 0b-1w 3b-0w
24
And score them Most parts. Score = 5
Best worst case. Score = 3
Entropy. Score = 1.67
0b-0w 0b-1w 0b-2w 0b-3w 1b-0w 1b-1w 1b-2w 2b-0w AAA 2 0 0 0 3 0 0 3 BBB 4 0 0 0 4 0 0 0 CCC 4 0 0 0 4 0 0 0 ABC 0 0 0 1 4 1 1 1 CBA 0 1 2 0 3 0 2 0 AAB 1 0 2 0 1 1 0 3 AAC 1 0 2 0 1 0 0 4 AAD 2 2 0 0 1 0 0 3 BCA 0 1 2 1 3 0 1 0
Evolutionary Mastermind - Merelo/Runarsson
1.31 0.96 0.96 1.58 1.52 1.67 1.42 1.52 1.67
25
Not all eligible combinations are the same
But we don't know which score is the best! Mastermind
26
Two mechanisms at work ●
●
Reduction of eligible combinations to a single one. Playing by chance the secret code. ●
●
Entropy (black) vs. Most parts (red)
Expected size and worst case → not so good
Mastermind
27
●
What happens if you can't use all eligible codes
●
Behavior changes
●
Chaos ensues ●
●
100
You pick a sample
40 30
Not really
Sample size must increase with problem size.
Mastermind
20
28
●
12 colors, length=8 (Berghman) ●
●
A few seconds
10 colors, length=7 ●
Several minutes
How far can we go? Mastermind
29
Where do we go from here? ●
●
Where no mastermind pin has gone before. Improve evolutionary algorithm.
●
Optimize speed.
●
Paralellize
●
Sub-optimal strategy?
Mastermind
30
Open source your science!
Fine tuning Evolutionary Mastermind - Merelo/Mora/Cotta/Runรกrsson
31
Thanks a lot!
Happy gaming! http://geneura.wordpress.com Mastermind
32