Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon. Entire thread

★【Challenge!】【Easy】 Hangman Solver

Name: !WIZardrY9E!UhEWzHM7+1tYUG2 2012-05-14 13:16

⚫ The Game of Hangman

A player guesses letters that are part of a word!
If he has not guessed the complete word before making six (6) mistakes, he has lost!

      _______
     |/      |
     |      (_)
     |      \|/   It is a game over!
     |       |
     |      / \
     |
  ___|___


⚫ Your Challenge

In a language of your choice, write a program that takes as its input (in some way) the target word (with blanks) and the letters that have been guessed already. It should then output the next letter to be guessed.
For example:

$ echo -n "p...s\npds" | ./guesser
e

You may assume the word to be guessed is an English word and contains only lowercase ASCII letters.
Provide code and instructions if usage is not obvious. Consider using a tripcode to ease conversation about your entry.

Entries will be judged on GOODITUDE (defined as its win/loss ratio over twenty random games), on SPEED, and on CLEVERNESS.

Your deadline is 23:59:59 on Sunday, May 20th. Results will be posted the following day.

 |∧_∧
 |´・ω・) < Good luck!♫
 ||と ノ

Name: Anonymous 2012-05-15 21:07


>>39
sorryyyyyyyyy

import sys
import random
#two arguments needed
if(len(sys.argv) != 2):
    print "Usage: n"
    print "n - word to finish guessing"
else:
    #get the guess
    guess = sys.argv[1]
    #to match the word
    def match(word):
        #get rid of extra whitespace!
        word = word.strip()
        #if the guess and the word have equal length
        if(len(word) == len(guess)):
            #for every character in both the guess and the word
            for i in range(len(guess)):
                #if the guess was made and the guess was incorrect
                if(guess[i] != '.' and guess[i] != word[i]):
                    #no match
                    return False
            #all guesses ok or not made - matches
            return True
        else:
            #no length match - no match
            return False
    #get all matching words from the word list
    l = filter(match, open("words.txt", "r"))
    #if we have matching words
    if(len(l) != 0):
        #get a list of all the un-made guess characters
        a = []
        for i in range(len(guess)):
            if(guess[i] == '.'):
                a.append(i)
        #pick a random word out of the word list, and then pick one of its random letters that corresponds to a un-made guess - BAD
        random.seed()
        print l[random.randint(0, len(l) - 1)][a[random.randint(0, len(a) - 1)]]

Newer Posts
Don't change these.
Name: Email:
Entire Thread Thread List