Giter Club home page Giter Club logo

evilhangman's Introduction

EvilHangman

CS240 Evil Hangman

EvilHangmanProject

ProgramDescription:​ Evil Hangman is a program that actively cheats at Hangman. Instead ofchoosing a single word that the player tries to guess, the program maintains a set of words thatit continuously pares down. It does the latter in such a way as to minimize the player’s chanceof winning.For this program we assume a word is a sequence of letters a-z. We also assume that lettercomparisons are case-insensitive. Thus, ‘a’ matches either ‘a’ or ‘A’, and ‘A’ matches either ‘a’or ‘A’.

HowtheProgramWorks:

1.​​Run your program using the following usage statement:Usage: java ​[your main class name]​ dictionary wordLength guessesdictionary ​is the path to a text file with whitespace separated words (no numbers,punctuation, etc.)wordLength​ is an integer ≥ 2.guesses​ is an integer ≥ 1.

2.​​Begin with a set of English words. In theory, the set contains all the words in theEnglish language, but your set will be initialized with contents from a dictionary file.

3.​​Run the game: a.​At the beginning of each turn, display the number of remaining guesses,an alphabetized list of letters guessed so far, and the partially constructedword. b.Prompt the user for his/her next letter guess. If the guess is not an upper-or lower-case letter then print “Invalid input” on the next line and reprompt.If the user has already guessed the letter print “You already used thatletter” on the next line and reprompt. c.Report the number of position(s) in which the letter appears. If the currentword list doesn't contain any word with that letter, decrement the numberof remaining guesses and print “​Sorry, there are no <​inputLetter>​’s​” on anew line (replace ​inputLetter​ with the actual letter input). If all words in thelist contain at least one word with that letter, print “​Yes, there is​​<​number>​” where ​letter​ is the letter guessed and ​numbers​ is the number oftimes ​letter​ appears in the word with the fewest number of those letters. d.If there are more turns left, repeat step 3 (this step). Remember, thenumber of turns only decrements when there is at least one word in the listthat does not contain the guessed letter.

4.​​When the user runs out of guesses, pick a word from the word list and display it asthe word that the computer initially “chose.” If the user correctly guesses the word,before he/she runs out of guesses, display “You Win!” and display the correct word.

The“Evil”Algorithm: 1.​​Begin with the set of English words, B, read in from the indicated input file. 2.​​Assuming the user inputs a length ​l​, Create a subset of words, L, such that everyword in B of length ​l​ is in L and L ⊆ S. 3.​​Each time the user guesses a letter:a.Partition the word list into "word groups" based on the positions of theguessed letter in the words.For example, let the current word list be [ALLY, BEST, COOL, DEAL, ECHO, ELSE,FLEW, GOOD, HEAL, HOPE, LAZY]. Assume the player guesses the letter “E.” Yourprogram should partition the word list into the following six word families:1.​​E---contains ​E​CHO.2.​​-E--contains B​E​ST, D​E​AL,​​H​E​AL.3.​​--E-contains FL​E​W.4.​​---Econtains HOP​E​.5.​​E--Econtains ​E​LS​E​.6.​​----contains ALLY, COOL, GOOD, LAZY.b.Choose ​​the largest of these word groups to replace L.In the example above, the largest word group is of the form ----​.If two or more of the groups are of the same size, choose the one to returnaccording to the following priorities: 1. Choose the group in which the letter does not appear at all. 2. If each group has the guessed letter, choose the one with thefewest letters. 3. If this still has not resolved the issue, choose the one with therightmost guessed letter. 4. If there is still more than one group, choose the one with the nextrightmost letter. Repeat this step (step 4) until a group ischosen.

Deliverables:
Build a class that correctly implements the ​IEvilHangmanGame ​interface according to thisspecification. This class should have a constructor that takes no arguments. The passoff driverwill call methods on this class to test your implementation. The ​IEvilHangmanGame​ interfaceis provided on the course web site in the files associated with this project.

Also create a class containing a main method for running your game from the command line.This main method should function as described previously. When the TA’s pass you off, theywill run your main method manually from the command line to make sure your game works.ErrorHandling:Errors that could occur include an empty dictionary file, bad command line parameters, and badcharacters in the dictionary file. You may handle these errors in any way you like as long as theIEvilHangmanGame​ interface is implemented correctly. ​We will not test for unexpected inputduring the first part of the passoff (viz. while we are checking that your “evil” algorithm is workingproperly), including the ​GuessAlreadyMadeException​. However, we will check to makesure you are handling ​EmptyDictionException ​correctly. This exception should occurwhen the dictionary passed to you is empty ​OR​ when no words in the dictionary file match thelength passed as the second argument. Also, when we call your ​main ​method to play yourversion of the game we will be checking for input error. You will want to consider all of thepossible inputs that a user could do and plan for them accordingly. ​(ie. Is the input a number? aspecial character [like ​$​ or ​#​ or ​!​, etc...]? a capital letter? a newline? a space? a string of morethan one characters? etc....)Hints&ThingstoConsider:1.​​Consider which data structure would best handle the operations you need toperform on the word set.2.​​Letter position matters just as much as letter frequency. For example, “DEER” and“HERE” are in two different families even though they both have two E’s in them.3.​​Don't explicitly enumerate word families. If you are working with a word of length n,then there are 2​n​ possible word families for each letter. However, most of thesefamilies don't actually appear in the English language. For example, no Englishwords contain three consecutive U’s, and no word matches the pattern E-EE-EE-E.There will be no words in the input file that cannot be found in English dictionaries.4.Be careful to consider which parts of your code you need to be stateless and which partsyou want to maintain state from one method call to another. (viz. You need to update yourcurrent dictionary of possible words after every call of ​makeGuess​)5.The function ​makeGuess​ should be case insensitive, able to take in upper and lower caseletters.6.Your class that instantiates ​IEvilHangmanGame ​MUST​ be named EvilHangmanGame andyour game loop ​MUST​ be called EvilHangman for us to properly identify your classesduring passoff

evilhangman's People

Contributors

jbeatty88 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.