Reference no: EM133699530
1.Please, provide the solution based on the "def" blocks of the assignment and according to the specified instructions, otherwise I will not be able to use the solution.
2. Could you please comment on basic actions of the code you are implementing
3. All the comments and explanations provided in the code below came with the assignment
4. We are given a dictionary.txt as input, that has a list of words in lines (one word per line) which corresponds to the words_file of the first def function below
5. My main request is if you could please stick to the instructions and implement based on these instructions. I have received another two solutions but I was not able to use them.
6. Also, I would like to ask if you could minimize the use of compact commands (e.g. i for i, ....), if applicable, or, if you need to use them, if you could comment on what exactly they do.
My goal is to mainly learn the topic and work on it by myself, but it is complicated and I am new, so I really count on comments and explanations.
Thank you very much for your time and help :)
class WordMakerAI():
def __init__(self, words_file, debug):
# read in the words into any data structures you see fit
# input format is a file of words separated by newlines
# use open() to open the file, and remember to split up words by word length!
# DO NOT print anything unless debug is set to true
# You can optionally save and use the `debug` parameter to control your own print statements within the game loop.
# Use this code if you like.
"""
with open(words_file) as file_obj:
for line in file_obj:
word = line.strip()
# Use word
"""
pass # TODO: implement this
def reset(self, word_length):
# start a new game with a word length of `word_length`. This will always be called before guess() or getValidWord() are called.
# this function should be O(1). That is, you shouldn't have to process over the entire dictionary here (find somewhere else to preprocess it)
# DO NOT print anything unless debug is set to true on object initialization
pass # TODO: implement this
def getValidWord(self):
# get a valid word in the active dictionary, to return when you lose
# can return any word, as long as it satisfies the previous guesses
# DO NOT print anything unless debug is set to true on object initialization
pass # TODO: implement this
def getAmountOfValidWords(self):
# get the total amount of words that satisfy all the guesses since self.reset was called
# should be O(1)
# Note: Make sure this works! Here's an example input to verify:
# With a word length of 5, after guessing "a, e, i, o, u", you should see 301 remaining words.
# You can see this number by running with the debug flag, i.e. `python3 evil_hangman.py --debug`
# DO NOT print anything unless debug is set to true on object initialization
pass # TODO: implement this
def get_letter_positions_in_word(self, word: str, guess_letter: str) -> tuple[int, ...]:
# This function should return the positions of guess_letter in word. For instance:
# get_letter_positions_in_word("hello", "l") should return (2, 3). The list should
# be sorted ascending and 0-indexed.
# You can assume that word is lowercase with at least length 1 and guess_letter has exactly length 1 and is a lowercase a-z letter.
# Note: to convert from a list to a tuple, call tuple() on the list. For instance:
result = []
#pass TODO:add letter positions to result
return tuple(result)
def guess(self, guess_letter):
# update your data structures and find the longest set of words with the given guess
# should return the list of positions in which the letter was found
# That is, if the guess is "a" and the words left are ["ah", "ai", "bo"], then we should return [0], because
# we are picking the family of words with an "a" in the 0th position. If this function decides that the biggest family
# has no a's, then we'd return [].
# in the case of a tie (multiple families have the same amount of words), should pick the set of words with fewer guess_letter's
# That is, if the guess is "a" and the words left are ["ah", "hi"], we should return [] (picking the set ["hi"]),
# since ["hi"] and ["ah"] are equal length and "hi" has fewer a's than "ah".
# if both sets have an equal number of guess_letter's, then it is ok to pick either.
# For example, if the guess is "a" and the words left are ["aha", "haa"], you can return either [0, 2] or [1, 2].
# The order of the returned list does not matter. You can assume that 'guess_letter' has not been seen yet since the last call to self.reset(),
# and that guess_letter has len of 1 and is a lowercase a-z letter.
# DO NOT print anything unless debug is set to true on object initialization
pass # TODO: implement this