generateDict specs

generateDict function Project description:

It returns a trie containing all words from the dictionary. Each line in the provided file contains exactly one word. The last line might not be terminated using a newline character. You may assume that you only encounter words of length exactly k. Additionally, an initialized pointer is provided as an argument. A randomly selected word should be written into this pointer. The behavior of the function is undefined if the dictionary is empty. The signature should be as follows:
Trie *generateDict(char *filename, int k, /*@out@*/ char *selected) <

  1. To be clear, our generateDict function should not be capable of processing english_words_full.txt because it has words of multiple lengths.

  2. What does /@out@/ mean?

  3. When we select the random word, is it ok to select it before loading the words into the trie or do we have to load everything into the trie and then create/implement an algorithm to fairly select words?

Hey,

  1. Yes, because “You may assume that you only encounter words of length exactly k.”

  2. It is there to indicate that selected is used as output of the function as well. Because you have to write the selected word at the location of the pointer.

  3. You can choose the word whenever you want, as long as it is chosen uniformly over all the input words.

Best,
Tim

2 Likes

as it stands in the wordle.h
Trie *generateDict(char *filename, int k, /*@out@*/ char *selected1, /*@out@*/ char *selected2 )
should we just ignore one of the char* selected pointer and write this function in an new created wordle.c in src with
Trie *generateDict(char *filename, int k, char *selected){ } ???

  1. It is there to indicate that selected is used as output of the function as well. Because you have to write the selected word at the location of the pointer.
    how can we implement the char pointer selected as output? cuz’ generateDict is supposed to have an Trie* as output…any hint?

  2. should we use “stdlib.h” in order to use the function drand48()?

To implement the interface, you have to write a function that takes all four arguments.

A pointer points to a memory block. One can read from the memory at that location or write into it. See the lecture (notes) about pointers and arrays.

Yes, drand48 is declared in stdlib.h.

Sorry, I guess I misunderstood it…it should use two char* selected…because we are supposed to implement the Quantum Wordle, not the classic one where we only pick one word for the player…so every time we should randomly select two words and store it to our Trie structure.

“A pointer points to a memory block. One can read from the memory at that location or write into it. See the lecture (notes) about pointers and arrays.”
Yes, I know it. Do I have the right intuition?
after we randomly selected two words from the file
→ we should first create a new Trie* by using the create() function
→ then we should use the insert () function to add the two words in our Trie
→ finally, we can just return the Trie*

No, not every time. Note that the project description says

(and a second secret word / nullpointer for qwordle)

So if you are playing normal wordle and not quantum wordle, the pointer is NULL. This way, you know which kind of game is being played.

so, it means, we should first check the second char* selected2, if it is a NULL pointer, then we only need to randomly selected a word for char* selected1 and store it to our Trie…otherwise, randomly choose two words from the file for both char* selected1 and char* selected2?

Every word in the dictionary is stored in the Trie. Storing things in the Trie and selecting words for the game are orthogonal. The secret word for the game is chosen by writing it into the slab of memory pointed to by selected1 (similarly for selected2, if needed).

Keep in mind that the dictionary is used to check whether the user’s guess is valid.

1 Like

okay, I see , thanks for your help :+1: