CSC207 - Project 2
Ghost in the Machine

Assigned Oct 15th 4 p.m.
Due October 31st 4 p.m.


Overview

For this project, we will explore more complex interactions with the user by implementing control statements and loops. We will create a program for two users to play the game Ghost.

In particular, this project will cover the following concepts we have discussed in class:

Description

Two sides of intelligence that we have studied are inductive and deductive logic. An interesting side-effect of intelligence as we know it is our propensity for puzzles and games. With logical rules guiding our interactions and a fixed sense of the end goal, games give us a controlled setting for testing our intelligence skills. Games and puzzles have been found as artifacts of many ancient civilizations, and it is reasonable to expect that any intelligence we find elsewhere in the universe will have a similar need and fascination with games.

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.

Coding

For this assignment we will be writing a Python program to let two users play the word game Ghost and its three variants listed above.

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.

Extra

Your current implementation for this assignment allows two players to compete in a game of Ghost. As an extra extension, (Note, this is not a required part of the assignment) create a computer opponent for Ghost. First, try to have the computer make a random valid move. If this is successful, then think of how to have the computer automatically make the best possible move in any situation.

What to Hand In

Log in to 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:

and any other files necessary to run your code.
© Mark Goadrich 2008, Centenary College of Louisiana