In particular, this project will cover the following concepts we have discussed in class:
Ghost is a relatively recent word game (invented in the last 100 years) which is simple to play yet requires a large vocabulary to win. The rules for Ghost are as follows:
Choose a player to go first. Players will take turns building a word from letters until a complete word is formed. On your turn, you must add a letter to the end of the current word fragment; on the first turn of the game there is no prior word fragment, so you just choose a letter. Players will then alternate turns until one player has completed a valid English word at least 4 letters long. The player who completes the word loses the game.
At any point in the game, if you believe the current word fragment is not the prefix of any valid English word, you can declare a challenge. If you are correct, you immediately win the game, however if you are incorrect, you immediately lose.
A sample game of Ghost might go as follows:
1: H 2: HO 1: HOR 2: HORI 1: HORIZ 2: HORIZO 1: HORIZON
There are two variations of Ghost which use the same general structure to the game.
In this variant, players can add a letter to either the beginning or the end of the current word fragment.
For SuperDuperGhost, the chosen letter can be inserted anywhere in the current word fragment, including the beginning and end.
Download the text file english-words.txt
and the python module
dictionary.py
files.
You must create a python program
called ghost.py
. It will:
Your code should make good use of functions, as there are clear pieces of the game which
are common to all the above variants. Additional dictionary functions should be added
to dictionary.py
. Using functions will reduce the amount of code you need
to write as well as make your program easier to debug. However, do not write spaghetti code, where
functions call each other back and forth to continue execution of the program;
let your functions naturally return values and use loops to repeat the game turns.
Your code must check all user input for validitiy (such as ensuring they only enter one character, and enter a valid insertion index for SuperDuperGhost) and reprompt them for correct input if any mistakes are made. I recommend coding the basic version of Ghost first, then augmenting this program with SuperGhost and SuperDuperGhost next.
cs.centenary.edu
through either Secure FTP or WinSCP using your
cs login and password. Create a subdirectory from csc207
called project2
. Copy your ghost.py
project into this directory, along with any other files
you need to run your code. Make sure
you have followed the Python Style Guide, and
have run your project through the Automated Style Checker.You must hand in: