This final problem was to create a python version of the game Ghost.  Ghost is a two player game.  Each player simply enters a letter until a word is created.  Once a word is created, the player who did so has lost the game.  There are few rules to this game.  First rule is that a vowel must be present in the first three letters entered.  Due to that rule a word can be (and often is found) present within the first three letters.  Creating a word within the first three letters is the only acceptable way to create a word without losing.  Once beyond the three letter mark, if a word is created that player loses the game.  

I rewrote this code so many times.  I might have finished this problem earlier in the week, but I had to create most of the functions on my own.  Please note that it wasn’t just creating the functions itself that was difficult, but mostly it was understanding what kinds of functions to create and how to organize them.  I was only provided with two functions with which to make my game.  This was the first time I attempted something this complicated without more help from the MIT course information provided.  In order to better explain my organization and final code I’m going to split this game up into a couple of blog entries, specifically as there were several function mishaps I want to discuss in detail.

To create this game I separated it into four different functions.  Three of those functions were supportive to the final function, which processed the game.  In this post I’ll just talk about my first function, the play function.
 

 

def play(word):
   print word
   player = raw_input("Please enter a letter:")
   for p in player:
       if p in alpha:
           word = word + player
   return word

 

This function was created to separate the play aspect and word creation out from the main processing function.  Here I have the word printed for the player, then I ask the player to enter a letter.  Then I verify that the player has submitted an alphabetic letter by comparing it against list of the alphabet.  Once that’s confirmed, I make sure to add the letter to a list that is being created.  Therefore I keep all the data entered by the two players in the game.