Spring Semester 2007

Lecture Two: Simple Program Development

The lab tomorrow will be very tutorial in nature, as will be all the other labs.

Today we try to develop a program along the following specifications:

• the program helps play a game
• the computer chooses a four digit string
• the user enters four digit guesses
• the computer provides feedback for each entry (see below)
• the user tries to use this feedback to guess the string as fast as possible
• the game ends when the user submits the secret string
• when the game ends the computer reports the number of submitted guesses

A sample session with the program is presented below.

Before we go into that let's describe the feedback provided by the program:

• if a digit appears in the correct place a plus (+) is reported
• if a digit belongs to the secret string but is misplaced a minus (-) is reported
• if a digit does not belong to the secret string nothing is reported
• in the feedback the pluses must precede the minuses

Some examples. If 0677 is the secret string. Then:

• 6500 produces a feedback of ---
• 7670 produces ++-- as feedback
• 6666 produces a feedback string of +---
• 1234 produces an empty string for the feedback

Here's how my program works:

```IDLE 1.1.3      ==== No Subprocess ====
>>>
8442
Nope, keep trying.  --
Nope, keep trying.  -
Nope, keep trying.
Nope, keep trying.
Nope, keep trying.  +---
Nope, keep trying.  +---
Nope, keep trying.
Nope, keep trying.
Nope, keep trying.  ----
Nope, keep trying.  +---
Great, you guessed the secret word in  11 tries.
Thanks for using this program.
>>>```

I believe a version of this program is called Mastermind.

In the example above it's not very clear how I have chosen my guesses.

I have added a feature to my program whereby it reveals the secret string to me.

That's just for debugging, of course; in real life we'd suppress that.

In class we'll discuss the development, from design to implementation.

Updated by Adrian German for A202/A598