Open pangiann opened 2 years ago
Computer chooses randomly a word from the loaded dictionary. Then, the first round starts:
The player has to choose a character for one of the word's positions.
For every position in the easy mode we provide possible characters sorted with their probabilities to be the right ones for the corresponding place.
How do we calculate this probability? It is the percentage of a character found in all the candidate words in the dictionary when the word:
Has the same length with the hidden selected word.
Has the same already opened characters in other positions with the hidden selected word.
Then, the player selects one character for a position. There are two possible outcomes: a. Player finds the hidden character:
5 points
if P > 0.610 points
if 0.4 < P <= 0.615 points
if 0.25 < P <= 0.430 points
if P <= 0.25b. Player doesn't find the hidden character:
The game ends: a. When the player guesses the word correct. b. When player has 6 wrong guesses.
This class represents an active round during the game. That is:
Computes the probability of a character to be the right one for the corresponding position by finding the percentage of words that have this character in the same position.
This function does the following:
Removes unlike words in regard to the one current playing. There are two possible cases when a user guesses a char c in a position x in the word:
Plays a new round in the game. The player guesses a character in a certain position in the word. Computes the points of the player considering if the guess was correct and updates the state of the game accordingly. More specifically:
Hangman game execution
Before the game starts a user has to options:
If the user wants to start playing, they have to choose a dictionary to load.
Eventually, the game is ready to start with a valid dictionary of words loaded. What happens next?