Tricky Hangman

[Home]   [Puzzles & Projects]    [Delphi Techniques]   [Math topics]   [Library]   [Utilities]

 

 

Search

Search WWW

Search DelphiForFun.org

As of October, 2016, Embarcadero is offering a free release of Delphi (Delphi 10.1 Berlin Starter Edition ).     There are a few restrictions, but it is a welcome step toward making more programmers aware of the joys of Delphi.  They do say "Offer may be withdrawn at any time", so don't delay if you want to check it out.  Please use the feedback link to let me know if the link stops working.

 

Support DFF - Shop

 If you shop at Amazon anyway,  consider using this link. 

     

We receive a few cents from each purchase.  Thanks

 


Support DFF - Donate

 If you benefit from the website,  in terms of knowledge, entertainment value, or something otherwise useful, consider making a donation via PayPal  to help defray the costs.  (No PayPal account necessary to donate via credit card.)  Transaction is secure.

Mensa® Daily Puzzlers

For over 15 years Mensa Page-A-Day calendars have provided several puzzles a year for my programming pleasure.  Coding "solvers" is most fun, but many programs also allow user solving, convenient for "fill in the blanks" type.  Below are Amazon  links to the two most recent years.

Mensa® 365 Puzzlers  Calendar 2017

Mensa® 365 Puzzlers Calendar 2018

(Hint: If you can wait, current year calendars are usually on sale in January.)

Contact

Feedback:  Send an e-mail with your comments about this program (or anything else).

Search DelphiForFun.org only

 

 

 

Problem Description

Hangman #2 is an enhancement to Hangman #1.  In this version we add computer play, so either a human or the program can play either the Hangman or Convict role. 

The computer can also play the role of "Tricky Hangman" who really loves to hang convicts so he bends (without actually breaking),   the rules of the game.   

Background & Techniques

A couple of notes for players:

If you're not happy with the vocabulary, you can manually edit the HangmanWords.txt file to add or delete words.  The list does not have to be kept in alphabetical order, but it's probably a good idea just to simplify future changes.

If you want to take the hangman role against the computer, and don't trust the program  with your word, you can keep it secret.  In this case, your word cannot be verified against the dictionary so you can always win by selecting an unknown  word. 

If you play the Tricky Hangman against the Computer Convict, either may win - but the losing words selected will represent a limited vocabulary.  He may be tricky, but he's not very smart.

I claim that  the Computer Convict will always escape hanging when playing against a against the non-Tricky Computer Hangman or against a human who chooses a word in the hangman  dictionary.      

Non-programmers,  click here to  jump to download area.

Notes for programmers:

bulletWe use the dictionary component in a couple of ways.  The computer hangman uses the dictionary to randomly choose the secret word.  The computer convict also uses the dictionary to filter potential secret words based on letter frequencies and past correct guesses (which makes finding the word almost too successful to be fun).    I selected 1500 words to make a special "Hangman" dictionary, HangmanWords.txt.   I decided to use the LoadDicFromFile procedure  so that users can easily change the word list by edit the text file.  
bulletThe human hangman has the option of not revealing his  secret word  to the program, in which case  the human must do the scoring.  The HumanScoreDlg dialog that does this was an interesting programming exercise.  I ended up dynamically creating an array of TEdit components, one for each letter in the secret word.  We rebuild these for each move and allow to the hangman to click only on the underscore (unresolved) letters to indicate which positions are to be filled by the convict's current letter guess.
bulletThe GetWordDlg dialog has an example of setting ModalResult return code to  prevent exiting until problems (word too long or not in dictionary) are resolved. 
bulletI used a TTrackbar to allow players to set a difficulty level which affects the maximum  size of the secret word and also how many mistakes it takes to draw the gallows.
bullet And, of course, the "tricky hangman" part.  The tricky hangman makes a list of all dictionary words of the required length and after each guess, eliminates all of the words that contain that letter so long as at least one word remains.  He then selects the top word as the new secret word.   That's it.  But it's enough to make saving your neck considerably more difficult.   

Addendum December 9, 2003:  A viewer recently requested a simplified version that always has the program assume the role of Hangman and the human the Convict.  I posted that version, OnePlayerHangman, today.   The role choice box has been removed, the computer always does the scoring, and the hangman becomes "tricky" only when the highest play level is set.    

Running/Exploring the Program  

bulletBrowse source extract 
bulletDownload Hangan2 source 
bulletDownload  Hangman 2 executable
bulletDownload OnePlayerHangan source 
bulletDownload  OnePlayerHangman executable

Suggestions for Further Explorations

When the Computer Convict runs out of valid choices, he starts guessing letters alphabetically.  I guess it make more sense for the guesses to be made based on a table of letter frequencies in the English language.  Although I'm not sure that his chances of guessing an unknown word would be increased much by this.   
Human Hangmen can win by turning off computer assisted scoring and then selecting a word not in our dictionary.  Wouldn't it be nasty, and cool,  in this case to get revenge by making up a word the next time the program plays hangman against the human?      

 

Created: April 2, 2005

Modified: May 15, 2018

 

 

  [Feedback]   [Newsletters (subscribe/view)] [About me]
Copyright © 2000-2018, Gary Darby    All rights reserved.