This code is not meant to be a "final product":
1. No input validation;
2. User is supposed to enter the word to guess and then to guess the word;
3. Italian language;
4. No GUI.
Although, a few adjustments are enough to make it a playable game; it is a good starting point to easily implement a game such as Wordle achieving high performance.
A word is a string of
The system will read information and instructions from stdin, as follows:
1. The value
2. A sequence of words, which compose the dictionary of allowed words (HP: no duplicates);
3. The instruction "+nuova_partita".
When that happens, the game starts. The system will now read:
1. A reference word (it must be an allowed word);
2. The value
3. A sequence of words to compare to the reference, or instructions to execute.
For each read word, the system prints a string of
1. If the
2. If the
3. If the
If the system reads the instruction "+stampa_filtrate", the system prints, in lexicographic order, the set of allowed words in the dictionary which are still suitable.
If the system reads the instruction "+inserisci_inizio", it will start reading a new sequence of words to add to the allowed words in the dictionary, until it will read "+inserisci_fine" (HP: no duplicates).
In the sequence of words to compare, if the system reads an attempted word which is not allowed, it prints "not_exists". If the system reads the reference word, it prints "ok". If the system reads
When the game ends, it can only read "+nuova_partita" to start a new game or "+inserisci_inizio" to insert more words into the dictionary.
I used a Patricia Trie to implement the dictionary of allowed words. Due to this choice:
1. The time required to find a word in the dictionary (to check if it's allowed) is
2. The time required to insert a word in the dictionary is
3. If a wrong character is detected in the current word, or if, while visiting the trie, the number of occurrences of a character is higher than the number of occurrences of such character in the reference word, it is no more needed to visit the nodes below such word, so a whole sub-trie gets cut off, which makes the filtering function much faster.