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
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
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.
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.
365 Puzzlers Calendar 2017
365 Puzzlers Calendar 2018
(Hint: If you can
wait, current year calendars are usually on sale in January.)
e-mail with your comments about this program (or anything else).
#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
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
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
Non-programmers, click here to jump to
Notes for programmers:
|We 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
procedure so that users can easily change the word list by edit the
text file. |
|The 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.|
|The GetWordDlg dialog has an example of
setting ModalResult return code to prevent exiting until
problems (word too long or not in dictionary) are resolved. |
|I 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.|
| 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
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
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
Suggestions for Further Explorations
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.
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
July 29, 2017