jottoModel
, can be used with both user interfaces!
See snarfing help for information on how to use the Ambient/Snarf functionality in Eclipse. Note that the snarf URL for this semester is http://www.cs.duke.edu/courses/cps006/spring11/snarf
jottoMain.py
for the command-line version or
jottoGui.py
for the GUI version. All code is in the code directory
linked here.
jottoModel.py
module you will need to add global state and implement the functions
whose comments and signatures are provided. A function signature is
its name, parameters, and return type. Read these descriptions
carefully, but be prepared to fix mistakes as they arise since sometimes
it is tricky to find errors when global variables are used.
Some of the functions will need to access (read) and sometimes alter
(write) the different global state kept in the module. For example
the load_words
function is written for you and fills the
global list _wordlist
. This list will be used in
start_game
and possibly in other functions.
start_game
needs to initialize the global state so
that the first guess can be made. This will include creating a list of
words that the secret word picked by the player could be, you should
call this list _possiblewords
. Initially
_possiblewords
contains the same words that
are in _wordlist
. You can't use _wordlist
itself for the list of possible words because _possiblewords
will change each time the user reports how many letters in common the
guess has with the user's secret word. Be sure that start_game
initializes all the state for a new game.
get_guess
will return a randomly chosen word that
could be the secret word, i.e., the word
is chosen from _possiblewords
. It will alter global state to
keep track of what the word guessed is for the next function ---
you'll need to determine what this state is, but please read the
documentation for process_common_last
carefully.
process_common_lst
will use the number of letters in common
that's passed to it as a parameter and the global state that
represents the last word guessed by the computer to eliminate
all words from the global list of possible secret words that
don't have the same number of letters in common with the last
guess.
For example, if the last guess is "ghost" (stored in global state) and
the user chooses 3 as the number of letters in common which is then
passed to process_common_last
then the function removes all words
from _possiblewords
that do not have 3 letters in common
with "ghost". You'll likely want to call commonCount
in
implementing process_common_last
.
guess_count
returns the number of guesses made by the
computer in trying to guess the user's word. Ideally this will
simply be returning the value stored in a global variable or the
length of a global list or dictionary. Your code should not
make signficant calculations in determining the number of guesses made.
There are many algorithms for removing words that can no longer be guessed from the total available words. The one given above is perhaps the simplest to implement, but it has no intelligence about the problem it is solving. You will receive extra credit for developing a "smarter" algorithm than the one above, i.e., one that takes fewer steps to guess your secret word. After every one has submitted a solution, we will play them against eachother in a tournament to see whose is the best guesser.