Inheriting code
This chapter is a case study of legacy code that needs (what should be) a minor change. We will quickly find out that the change is not so minor. To begin, let's look at what the legacy application does.
Here is some sample output from a run of this code:
Take a guess: AAAA ---+ Take a guess: BBBA -+-+ Take a guess: CBCA ++ Take a guess: DBDA ++-+
Take a guess: DBEA ++++ Congratulations you guessed the password in 5 tries. Press any key to quit.
Looking at the interactions, this program doesn't look that bad. In speaking with the business analyst, the application was explained as a game.
The game
This particular game is called Mastermind and is a code-breaking puzzle. According to the business analyst, the code consists of the letters A through F and contains four of the letters chosen at random. It is the goal of the player to determine the passcode.
The player is given hints along the way. For a correctly placed letter, the player receives a plus symbol. For a correct letter in...