%-------------------------------------------------------------------------------
% Jaroslav Klima
% Mastermind
%
% Neproceduralni programovani
% Zimni semestr 2005/2006
%-------------------------------------------------------------------------------
 

The functions of all clauses are described by comments within the code itself.

How does the computer guess the color code? The algorithm used is actually very simple. It takes advantage of the following two facts:

1) The set of all possible guesses can be ordered, and we can easily find the successor to a given color sequence.

2) For every possible combination (Guess,Target), it is true that Score(Guess,Target) is equal to Score(Target,Guess).

Given these two facts, we can construct a guessing algorithm, using mathematical induction:

The first guess will be the lowest member in the ordered set of possible guesses, typically [1,1,.....,1].

The (N+1)st guess will be the lowest member in the ordered set of possible guesses, such that Score(Guess(N+1),Guess(K)) is equal to Score(Guess(K),Secret), for K = <1..N>.

If we ever come to a state where there is no valid (N+1)st guess, the codemaker must have made a mistake. Otherwise, the algorithm is always finite, because there is a limited amount of possible guesses.


This algorithm is not the fastest in terms of execution time, nor the best player in terms of the number of incorrect guesses, but it performs well enough for our purpose. It beats Advanced Mastermind every time, and only ocassionaly loses in the Original Mastermind. Namely, our algorithm performs poorly in cases when the secret sequence consists of a large number of different colors ordered opposite to the guessing order.
