Although I will be keeping this blog for a (long) while up, I will not be adding any other posts or pages in the future.
After much deliberation, I decided to do the migration to a new platform, hosted for free in my github. It involves a great deal of hacking, but in spite of all the extra work, the move is totally worthwhile.
Please, redirect your browser to blancosilva.github.io for my new professional blog.
I would like to show how to code the NAO robot to beat us at Jotto (5-letter Mastermind) with
Choregraphe. I will employ a brute force technique that does not require any knowledge of the English language, the frequency of its letters, or smart combinations of vowels and consonants to try to minimize the number of attempts. It goes like this:
- Gather all 5-letter words with no repeated letters in a list.
- Choose a random word from that list—your guess—, and ask it to be scored ala Mastermind.
- Filter through the list all words that share the same score with your guess; discard the rest.
- Go back to step 2 and repeat until the target word is found.
Coding this strategy in
python requires only four variables:
whole_dict: the list with all the words
step = [x for x in whole_dict]: A copy of
whole_dict, which is going to be shortened on each step (hence the name). Note that stating
step = whole_dictwill change the contents of
whole_dictwhen we change the contents of
step— not a good idea.
guess = random.choice(step): A random choice from the list
score: A string containing the two digits we obtain after scoring the guess. The first digit indicates the number of correct letters in the same position as the target word; the second digit indicates the number of correct letters in the wrong position.
attempts: optional. The number of attempts at guessing words. For quality control purposes.
At this point, I urge the reader to stop reading the post and try to implement this strategy as a simple script. When done, come back to see how it can be coded in the NAO robot.