Hangman

From UBC Wiki

Hangman

Authors: Brendan, Leann

What is the problem?

This project will be based on recreating the traditional Hangman game. First, the player must decide whether the computer or themself is doing the guessing.

  1. If the player is doing the guessing, the computer must come up with a word for the player to guess. If the player cannot get the correct answer within a certain number of tries, the player loses. Alternatively, if the player manages to guess the word or suggest all the letters in the word, the player wins. The score is updated.
  2. If the computer is doing the guessing, the player can enter a word, and have the computer guess the word within a certain number of tries. For each try the computer can either guess the word or suggest a letter in the word. If the letter guessed is not in the player's word or the computer gives an incorrect guess, the hangman state updates showing the number of guesses left until and the computer runs out of guesses and loses. Also, if the computer fails to guess the word, they lose. The score is updated.

A link for more details: https://www.hangmanwords.com/how-to

What is the something extra?

There are two ways we could add something extra to this project.

  1. The computer uses a word bank to get words for the user to guess and it can find the words to guess for the player's word. It can sort through the word bank to determine the word given by the player with the highest probability. The letters for the computer to guess are ranked according to how commonly they are used and based on the possible words it can form from its word bank.
  2. Provide an ASCII drawing of the hangman that updates along with the state of the game.

What did we learn from doing this?

  • The ASCII drawing of the hangman was much easier to implement than implementing the computer player. If we were able to rewrite the answers above, the computer player would have been the "something extra" instead. We threaded the drawing through the game the same way as we threaded the number of guesses left for the player, since those are are inherently connected.
  • The implementation for the Hangman game itself was relatively intuitive. We used the template given for a game from class (MagicSum.hs and Play.hs) and modified it for our own game. After a couple of changes to what InternalState and State would contain, the implementation of the game itself was relatively straightforward, albeit time-consuming.
  • The abstracted user interface was harder to implement. The graphical aspect of Hangman is a lot different to MagicSum. Consequently, many changes were made to Play.hs to better suit our needs.
  • The Decision Algorithm for determining the Computer Player's move was suitable for implementation in functional programming for the most part. It involved creating functions that recursively searched through a given Word Bank, determined the best letter to guess and narrowed down all possible words in the Word Bank until a possible match was found. With functional programming, it was easier to trace through the outputs of each function, easily debug if the output type and value were correct and validate the correctness of the output.
  • The difficult part was creating an algorithm for when the word to be guessed was not found in the Word Bank because now the algorithm involves more guess work and requires supporting a lot of conditional cases to check for certain conditions for making a smart guess by the Computer Player. This was harder to implement since these conditions are based on the common patterns we find in the language and it would require a larger database that can be stored in a mutable data type and updated based on collected data patterns. Functional Programming may not be suitable for implementing this feature because of this.

Links to code etc

https://github.com/learese/CPSC-312--Project-1-Hangman-.git