The objective of the exercise is to develop a game strategy for the game "Mastermind".
In Mastermind, a player (the 'decoder'), has to guess a secret code. The secret code has N distinct decimal digits (NO REPETITIONS, only 10 possible symbols for each position).
The decoder tries to guess the code by submitting various attemps. Strategically in your guess you can use repeated digits, despite knowing that in the code there are no repetitions.
As a help, you will recieve a response for each guess, and you will be provided with a couple of numbers a,b:
- 'a' being the number of digits of your guess that are in the right position
- 'b' being the number of digits of your guess that are present in the code but in the wrong position
For example, in the case of the code being 34670915 and the guess being 93375948, the answer will be the couple (2,3).
The 2 represents the digits 7 and 9 of the code in the 4th and 6th position, while the 3 represents the digits 3,4,5 which are present in the code but never in the right position.
In this version of mastermind, N (the lenght of the code) can be 6, 7 or 8, and in the couple given as a response of each guess, 'a' and 'b' may be reversed so that you can't know for sure what 'a' and 'b' represent.
For example, if the code was 34670915 and the guess was 93375948, the anwsers (2,3) and (3,2) are both possible.
A configuration of the game is represented as a list of lists (L).
The first element of 'L' is a digit N representing the length of the code.
Any of the other elements of L represent a guess submitted by the decoder and its relative response.
More precisely, L[i] with i>0, if present, will contain a tuple made of two elements:
- The list whose lenght is N digits with the guess submitted by the decoder in a previous step
- The tuple of numbers (a,b) recieved as a response.
The program you have to realize contains the following function:
which is the AI that plays the game. The function must recieve as an input the actual configuration of the game and it has to produce a guess (list of characters from 0 to 9).
I hope I got everything right, please correct me if I made mistakes, I hope I have time to translate the other one!