Is there any specific way to solve Mastermind?
Apart from the first step that is pure chance, is there any way to continue based on the colors that you think are correct?
Wikipedia has the nice section on optimal Mastermind strategies:
MathWorld's page on Mastermind also gives a nice synopsis and mention a few more strategies:
In summary, there is a trade-off to make between the average length and the maximum length of the game. (length is expressed in the number of code guesses)
I play Mastermind with numbers instead of colours, because I first learned it in the second grade as Bagel Pico Fermi which uses numbers. For the rest of my answer, I will refer to red pegs as "bagels", and white pegs as "picos" (and holes without pegs as "fermis").
The system I tend to use is suboptimal but very easy to follow. It goes as follows:
An example of this algorithm at work might be as follows:
This isn't as good as the algorithm that a computer would use, but it's very simple and systematic, and very easy to get the hang of once you understand what you're doing.
A simple strategy which is good and computationally much faster than Knuth's is the following (I have programmed both)
Create the list 1111,...,6666 of all candidate secret codes
Start with 0011.
Repeat the following 2 steps:
1) After you got the answer (number of red and number of white pegs) eliminate from the list of candidates all codes that would not have produced the same answer if they were the secret code.
2) Pick the first element in the list and use it as new guess.
This requires in general no more than 5 guesses.
This is the Swaszek (1999-2000) strategy that was mentioned in another answer.
It may not be the fastest technique, but I generally take the trivial solution of starting with a row with all one color. This tells me how many of that color exist in the solution.
If none, I simply move on to another color. If one or more match, I leave that many of the color and move on to the next color for the remaining spaces. Using this technique it will determine the exact set of colors within 6 moves, but not the order.
While I am working on that technique, I also start working on determining position by swapping positions to rule out possible positions for each color. This is where the technique I use gets a bit more complicated.
I look carefully at the previous combinations and select combinations that will eliminate positions for certain colors based on whatever output I get, for example, placing colors I know are not present (or already know the position of) to blank portions of the board. For each color I lock in, the number of possible guesses is reduced on future guesses.
If possible, I will also try solving more than one peg simultaneously by leaving one in place and moving the other. If I don't lose a black peg, then I know that the one I didn't move was correct, if I gain a black peg, I know that both are correct. If I lose a black peg, I know that the one I moved was correct.
Using this technique, I can reliably win pretty much any mastermind game, though I do sometimes use most of my guesses, so it isn't the most efficient solution out there.