How to solve the "Mastermind" guessing game? (2009)
stackoverflow.com
stackoverflow.com
I've seen a lot of algorithms for how to play this, Donal Knuth has one that can win in 5 moves, but none that are really usable by humans. The method I use, which seems to always win is:
Guess 1111
Depending how many 1's were right, Guess 1222, 1122, 1112, 2222
Continue in this manor until the solution is found.
I just played this game ID: https://www.chiark.greenend.org.uk/~sgtatham/puzzles/js/gues...
where it worked perfectly:
RRRR -> (1, 0) One red, somewhere.
RYYY -> (0, 1) No yellows, red is not first
GRGG -> (0, 2) One green in the 2nd position, red is 3 or 4.
BGRB -> (1, 1) No blues, red must be last.
OGOR -> (4, 0) Success.
Have been meaning to simulate this and see if there are any games where this method would not work. Sometimes it takes all the moves but I've never lost.
It's not foolproof (it can get tricky if you're unlucky finding the location of pegs) but it's a very easy algorithm to remember and implement.
I was certain he wrote the article about MOO and/or bulls and cows, but it seems like I remember wrong.
It minimizes the worst-case, not the expected number of moves. I think Knuth’s algorithm can be beaten in that respect.
https://github.com/coding-horror/basic-computer-games/blob/m...
I hope I have explained my motivation, and why I responded about the particular aspect of the game in the way that I did. My apologies for coming off retarded and shit.
Start with a text file of every combination separated by lines.
RRRRR RRRRG RRRGG
Then use cat to output it to grep and use grep for all the constraints.
One for colors that aren't there. One for colors you know are in the right place. Then after that one grep for every color you know is there somewhere and one for each color you know isn't in a certain spot.
cat combinations.txt | grep -v [colors that aren't there] | grep ..R.G | grep B | grep -v .Y...
That's it. All you need is a command line. Generate guesses from the filtered list then add to the filters.
Are any solutions more likely than any others?
How are you getting an "optimal play algorithm" when the entire game is about using what you know to filter the solutions that are still possible?
https://en.wikipedia.org/wiki/Mastermind_(board_game)#Algori... https://en.wikipedia.org/wiki/Minimax#In_zero-sum_games
One of the early solutions to mastermind was by Donald Knuth. paper: https://www.cs.uni.edu/~wallingf/teaching/cs3530/resources/k... an implementation: https://github.com/johnathanlouie/mastermind
further development: https://arxiv.org/abs/1908.06183
Are there libraries that will allow for full multicore utilization in Python from the numeric analysis stuff? Am I wrong that Python isn't a great language for a computational experiment like this?