A game of Absurdle Suppose the Absurdle manager only knows the…

Question A game of Absurdle Suppose the Absurdle manager only knows the… A game of AbsurdleSuppose the Absurdle manager only knows the following 4-letter words.ally, beta, cool, deal, else, flew, good, hope, ibexIn Absurdle, instead of beginning by choosing a word, the manager narrows down its set of possible answers as the player makes guesses. If the player guesses “argh” as the first word, the Absurdle manager considers all the possible patterns corresponding to the guess.???? — cool, else, flew, ibex????? — hope????? — good????? — beta, deal????? — allyThe manager picks the pattern that contains the largest number of target words. In this case, it would pick the pattern ???? corresponding to the target words cool, else, flew, ibex. If the player then guesses “beta”, the manager chooses between the following possible patterns.???? — cool????? — else, flew?????? — ibexThe manager would pick ????? corresponding to the target words else, flew. If the player then guesses “flew”, the manager chooses between the following possible patterns.?????? — else???????? — flewIn this case, there’s a tie between the possible patterns because both patterns include only 1 target word. The manager chooses the pattern ?????? not because it would prolong the game, but because ?????? appears before ???????? when considering the patterns in sorted order.After this, there’s only a single target word, else. The game ends when the player guesses the target word and the manager is left with no other option but to return the pattern ????????.Constructorpublic AbsurdleManager(Collection dictionary, int length)Given a dictionary of words and the target word length, initializes a new game of Absurdle. The set of words should initially contain all words from the dictionary of the given length, eliminating any duplicates. Throws an IllegalArgumentException if the given length is less than 1. Assume the given dictionary contains only non-empty strings composed entirely of lowercase letters.Methodspublic Set words()The client calls this method to get access to the current set of words considered by the manager.public static String patternFor(String word, String guess)This static method is used to generate the pattern for a given target word and guess. This would typically be a private method, but it is public to enable us to test your implementation. Assume the target word has the same length as the guess, and that both strings include only lowercase letters. The algorithm for generating a pattern should abide by Wordle’s rules for ?? yellow square tiles when a letter appears more than once.patternFor(“abbey”, “bebop”) — ????????. Notice how the middle letter ‘b’ in the guess “bebop” is green, while the first letter ‘b’ is yellow. Green tiles are assigned before yellow tiles.patternFor(“abbey”, “keeps”) — ??????. Notice how only the first letter ‘e’ in the guess “keeps” is yellow, while the second letter ‘e’ is gray. If there are multiple places for a yellow tile, choose the leftmost places.public String record(String guess)The client calls this method to record a guess. Using the given guess, this method determines the next set of words under consideration and returns the pattern for the guess. Throws an IllegalStateException if the set of words is empty, and throws an IllegalArgumentException if the guess does not have the correct length. Assume the guess contains all lowercase letters.Implementation guidelinesUse TreeSet and TreeMap implementations for all sets and maps in this assignment. When working with strings in this assignment, use the length and charAt methods; don’t call toCharArray.patternFor(String word, String guess)To implement this method, keep track of the number of times each letter appears in the target word, decrement the count when assigning green tiles, and decrement the count when assigning yellow tiles. Tiles not assigned green or yellow are gray. For example, to compute patternFor(“abbey”, “bebop”):?????? — assign green tiles first.???????? — assign yellow tiles next.???????? — assign gray tiles last.Use the following data structures in this method.Map counts to keep track of the count for each letter in the target word. We could also use your Letter Inventory, but in this assignment we ask that you use a Map instead.String[] pattern = new String[word.length()] to store the assigned green, yellow, and gray tiles. Each index in pattern stores one of the three types of tiles: “??”, “??”, or “?”. Construct the final string result from this pattern by appending all the tiles.We can’t use a char[] pattern because of limitations in the char type for tiles. Your tiles must be stored as strings!If you want to run the code in jGRASP for debugging purposes, the tiles may or may not display correctly. In this case, you may want to temporarily change the strings to other characters so that it’s easier to read.record(String guess)For each call to record, construct a Map to associate patterns with target word sets and use it to find all pick the pattern associated with the largest number of target words. When there are multiple patterns that have the same largest number of target words, pick the pattern that appears first in the sorted order, i.e. the pattern that appears earliest when iterating over the TreeMap. The associated target words becomes the dictionary for the next call to record. Computer Science Engineering & Technology Java Programming CS MISC Share QuestionEmailCopy link Comments (0)