I wrote this little script a few years ago. As the holiday season comes upon us once again, I decided to spruce it up with some nice colors—and a voice—for another year of family mischief.
This is a program that plays Mastermind... and always wins! To play in interactive mode (i.e. for facing off against your friend), just run:
$ python masterminder.py
(Don't be alarmed—it talks!)
If you instead just want to see it play against itself by giving it a pattern to start with, just run
$ python masterminder.py ABCD
where ABCD is any string of four colors that represent the secret configuration (for example, WWOO for white-white-orange-orange).
This script essentially implements the minimax algorithm as demonstrated by Donald Knuth in 1977.
Feel free to adjust the variables at the top of the file to fit your version of the game.