Download as pdf or txt
Download as pdf or txt
You are on page 1of 3

CMPT 120,

Fall 2008, SFU Burnaby


Instructor: Diana Cukierman
“Starting to work on Project #1”: this document includes the description of the
game to be implemented for Project #1 and some suggested exercises to be done to
start. Details about what to submit and a sample run will be provided in a
subsequent document.

This is a 2 team people work (you can also work individually if you prefer so).
While you can discuss generalities with colleagues from other teams about this
exercise, you cannot develop the same code, nor share code among teams, nor
obtain code from other sources.

Being a team exercise it places a big responsibility on each individual. You


want to respect your partner and yourself: DO YOUR SHARE, and BE KNOWLEADGEABLE
OF THE WHOLE PROJECT. The project will give you a percentage of your course, but
the main purpose of the project is that you learn! (both about the topic and
about team work). In particular, the project is meant to help you get prepared
for the midterm and final exams, which together constitute 64% worth of the
whole course. It goes without saying as well that you are learning for your own
future!

Submission deadline: The exercises described in this (“starting to work”)


document should NOT be submitted independently. All the submission will be done
in one package together as part of the whole project solution. It is highly
encouraged that you work on the exercises suggested in this document as a first
stage.

Submission deadline of the whole project: Tuesday October 28, at 5 pm. It will
only be an electronic submission. You are encouraged to start working on this
right away. Examples related to this project may be discussed during lectures.

1. The project consists of implementing a variation of the Mastermind game,


which we will refer to as “Mastermind 120” game: the program will choose a
codeword formed by a certain number of (lowercase) letters and the user
will need to guess it based on clues that the computer will provide.

2. Description of the “MasterMind 120” that we will implement:

a. The game will be implemented so that the user is first asked to


provide certain general parameters (such as length of codewords,
number of (lowercase) letters that are available to use, maximum
number of trials allowed, and so on).

b. As an extra feature (providing you bonus points) the program can offer
the user two options: level 1 – no repeated letters in the codeword
allowed, level 2 – repetitions allowed. (As a first version (or
perhaps your only version) you are recommended to not control this –
which makes it harder to the user but easier to the program.)

c. Then one game starts: the program randomly chooses a restricted


alphabet (that is, it determines the letters to use, as many letters
as indicated by the user at the beginning) and a codeword (using
letters from the chosen alphabet and not longer than the maximum
codeword length indicated by the user).
d. Then the program should inform the user what the alphabet is (which
letters can be used) and the number of letters that the chosen
codeword has.

e. Then the user will try to guess the secret codeword with several
trials (not more that the established maximum), by guessing a whole
tentative codeword at a time.

f. After each guess, the user will be shown how many letters from his/her
guess there are in the right position and how many letters from
his/her guess there are in the wrong position. The program will also
show the user all the guesses and the outcomes played so far
(associated to this codeword). (See example below)

g. If the user discovers the codeword before exhausting all his/her


guesses, the user wins, otherwise the user loses (in the latter case
the program shows the secret codeword). The user can play more games
(with potentially different alphabets and codewords).

h. At the end of all the games (when the user does not want to play any
more) the program will inform to the user how many games the user
played, how many the user won and how many the user lost.

Example of one “MasterMind 120” game:

™ Assume the program chooses the alphabet {a,e,i,x,y,z} and codeword ‘axey’.
™ As a first step the program will show to the user the alphabet {a,e,i,x,y,z}
and it will inform that the codeword has 4 letters.
™ Assume the user proposes the codeword as his/her first guess: ‘aeix’.
™ Then the program should inform that there is/are:
¾ 1 correct letter and position [that’s the “a”] and
¾ 2 correct letters in wrong position [that’s the “e” and the “x”].
™ As well, the program should show the state of the game so far including
information displayed somehow like the following:

codeword correct letter/pos correct letter


aeix 1 2

™ Then the user tries again proposing a new codeword. Let’s assume the user
provides the codeword: “axyz”
™ Then the program should inform that there is/are:
¾ 2 correct letters and position [that’s the “a” and the “x”] and
¾ 1 correct letter in wrong position [that’s the “y”].
™ At this point, the state of the game so far to be displayed should be:

codeword correct letter/pos correct letter


aeix 1 2
axyz 2 1

™ and so on…
™ if the user wins or the number of guesses are over, the game is over and the
user can play new games.
3. Exercises/activities to do in preparation for the project: (you will have
to submit parts of these exercises only when submitting the whole project)

a. Play the game (paper/pencil) to realize how it works and/or if you


have any questions

b. Think about how you would implement this game. Think about a top level
description of the solution. Think about which information you need to
be able to run this game: which variables you need to control the
execution of the game and which variables you need to do calculations.
If some information is not provided in this description, think which
could be reasonable assumptions. Think of questions you may have about
the game.

c. Design a top level flow chart diagram describing an algorithm to play


only the guessing of one codeword in the “Mastermind 120” game.

d. Design another top level flow chart diagram describing the same game
as in part (3c), but additionally allowing that the user can play many
games (i.e. guessing different codewords)

e. In preparation for implementing some subroutines and functions for


your program, design flow charts and write Python functions which:

i. Given a variable which we can call sizeAlphabet create a list (or


a string) with random lowercase letters, as many as indicated by
sizeAlphabet. Hint: consider using the built-in function “chr()”;
chr(97) returns the character “a”, if k = 122, chr(k) returns “z”.

ii. Given a variable which we can call length and a list (or a string)
of characters, it generates a random codeword containing randomly,
as many characters from that list (or string) as the value in
length, in any order.

iii. Given two codewords (one is the “program” or “secret” codeword,


the other the “user” codeword) determines how many letters from
the user word are in the same position as in the secret word.

f. To test these functions (described in part 3e), you can initialize


directly the variables that need to be provided.

g. You may want to test some software to do flowchart diagrams, such as


MS visio (available at CSIL). (You will also be able to submit
flowcharts which you write by hand and then scan)

h. Keep track (a log) in a text file of what you do/work on to help you
keep control of the project and distribute tasks in case of working as
a team. You will be asked to submit some report about how you
organized your work and this log will provide you that information.

4. Details about what to submit and sample runs will be provided in a


subsequent document.

End of description of “starting to work on Project #1”.

You might also like