Anne
Dawson: CSCI120A_LAB6_SP05.htm
Last
updated: Monday 21st February 2005, 8:16 PT
This
document is subject to change without notice.
Please
report any errors or omissions in this document:
adawson@coquitlamcollege.com
Special instructions:
For this assignment you may work in teams of 2, or alone. This lab is due at the end of the lab
session.
Spring 2005
Lab Assignment 6
Step 1
Study the following web page:
http://www.coquitlamcollege.com/adawson/MasterMindRules.htm
Step 2
Play a sample game:
http://www.bfoit.org/Intro_to_Programming/mastermind.html
In your own version of the game,
you will use the six numbers: 1,2,3,4,5,6 instead of six colours, and the
combination of numbers to be guessed must not contain duplicates (you may
assume that the user of the game will not enter duplicate numbers in their guesses).
You must use a Python list to store the 4 number combination, and a Python list
to store the score. The user gets
a maximum of ten guesses to get the correct combination.
Example:
If the combination is:
1234
And the first guess is
2345
The score is 0,3 (Meaning 0 numbers in the correct
position, but 3 correct numbers).
An example game:
Hidden correct combination: 2461
(2461)
Guess
Score
1234 0 3
4321 1 2
3421 2 1
2431 3 0
2451 3 0
2461 4 0 You win in 6 guesses!
For Bonus points, enforce unique
number entry (no duplicates) and generate a random 4 number sequence to be
guessed at the start of each game. At the end of the game, ask if the user
wishes to play again, and repeat the game on request.
Step 3
Study the algorithm below.
Algorithm:
1. Create a list of any 4 unique numbers in the range 1 - 6.
2. Ask the user to input their guess: 4 unique numbers in the
range 1 - 6.
3. Check each inputted number against the hidden combination:
If the guessed number is in the correct position add 1 to a score
counter
If the guessed number is one of the correct numbers but is in an
incorrect
position add 1 to a second score counter.
4. After each guess add 1 to a guess counter
5. Display the guess number and score counters
6. If first score counter has a value of 4, player wins. Game
over. Go to step 9.
7. If the guess counter has a value of 10, player loses. Game
over. Go to step 9.
8. If player has not won or lost,
Set
score counters back to zero.
Go
back to step 2.
9. Output win or lose status and
end.
Create your own pseudocode from
the given algorithm.
Step 4
Using your pseudocode as a guide,
implement your program in the Python language. Use the IDLE GUI to edit and run
your program:
http://www.coquitlamcollege.com/adawson/Python_Editor_IDLE.htm
Your program should start with a
comment block that contains the following information:
# File: lab6.py
# Purpose: The Mastermind Game
# Programmer: [your name]
# Partner: [your partner's name]
# Course: CSCI120A
# Date: Monday 21st February 2005
Step 5
Test your program by supplying your own test data. You should test your
program with at least 3 sets of test data. Show your test data and results in
comments at the top of your program.
Step 6
At the end of the class, save your program file (lab6.py) to your folder
on the network in:
CSCI120A\Week08\Lab06
Program points will be based on the
following marking scheme:
Marking Scheme: CSCI120A - Lab 6
- Mastermind Game
Student name(s):
|
Category |
Points |
Description |
|
Pseudocode |
15 |
A formal description of the
steps that must be taken to solve the problem. |
|
Comments |
10 |
The program is commented appropriately. |
|
Style |
15 |
The source code should use meaningful variable
names (identifiers). |
|
Output |
15 |
Screen prompts and results should be
user-friendly. |
|
Correctness |
15 |
The program should output correct results. |
|
Completeness |
15 |
The program should be complete. |
|
Test |
15 |
Comments in the code explain how the code was
tested. |
|
Bonus Points |
5 |
For Bonus points, enforce unique
number entry (no duplicates) and generate a random 4 number sequence to be
guessed at the start of each game. At the end of the game, ask if the user
wishes to play again, and repeat the game on request. |
Assignment Presentations : In the next theory class, a random
selection of lab assignment programs will be presented to the CSCI120A
group.