Building a Mastermind AI
This is a work in progress. Remaining tasks:
- Add game logic to allow duplicate colours
- Improve UI
- Beautify settings section
- Possibly add drag and drop functionality for pegs
- Write article explaining the game and AI
- Explain the game
- Explain the various types of AI approaches
- Run experiments to compare AI performance
- Publish code and experimental results to GitHub
Remaining options: 360
NOTES
If the code size is , then the set of possible keys is
The total number of unique keys is then
For any given guess from the set of valid guesses, , we can partition the set of possible codes, , into upto nonempty mutually disjoint subsets, , where . This gives us the framework to consider some myopic strategies by using greedy algorithms, which optimise the current turn without considering future turns.
The first greedy algorthm would be to choose the guess that minimizes the maximum number of possible codes after the result is known, thereby mitigating the worst case scenario of the next turn.
Another greedy algorithm would be to choose the guess that minimises the expected number of possible codes after the key is known. This could result in a better average performance over multiple games. If all codes are equally likely then the probability of each key is the size of the corresponding subset divided by the total number of possible codes.
In practice the factor of can be omitted as it is constant for all guesses.
In many cases it can happen that multiple guesses are equally optimal according to these greedy metrics. Ties can be broken arbitrarily by choosing the first, last or a random guess from the set of equally greedily optimal guesses. Possibly a better approach would be to use another greedy metric to break the tie. This is lexicographic optimisation. In fact, these two greedy metrics are from the same class. Consider the metric which minimises the expected size of the next partition raised to the power of .