Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Pleeasee solve in Pyhon, using Classes code from Hint: # _Part 4: Implement this Constructor._ # Given a guess and the secret word, provide a

image text in transcribedimage text in transcribedimage text in transcribedimage text in transcribed

Pleeasee solve in Pyhon, using Classes

code from Hint:

# _Part 4: Implement this Constructor._

# Given a guess and the secret word, provide a hint.

# The Hint should follow these guidelines:

# - the Hint should not store any knowledge of the secret word itself.

# - correctlyPlaced should have a length equal to the length of the secret word

# - incorrectlyPlaced should have a length equal to the length of the secret word

# - notInPuzzle should have a length less than or equal to the length of the secret word/guess.

# A character in the guess that is both the correct letter, and in the correct location in the word

# will appear in that location in the correctlyPlaced String. Characters in the guess that are not

# correctly placed will appear as the char '-' in the correctlyPlaced String.

# Thus, for a guess "skate" and a secret word "score", the correctlyPlaced will be: "s---e"

# A character in the guess that is the correct letter, but not in the correct location in the word

# will appear in the same location as the guess when placed in the incorrectedPlaced String.

# Note that duplicate characters are a bit tricky, they must be examined for correctly placed characters

# before incorrectly placed ones.

# Thus, for a guess "scoop" and a secret word "poofs", the correctlyPlaced String is: "--o--" and

# incorrectlyPlaced String is: "s--op"

# Note that the first 'o' is correctly placed, thus it must be the second 'o' that is incorrectly placed.

# It is incorrect to say that the first 'o' is incorrectly placed, as it is incorrect to say that

# both 'o's are incorrectly placed.

# Characters that are in the guess and are neither correctly placed nor incorrectly placed should be

# added to the notInPuzzle String. Thus, the length of the notInPuzzle String will never be greater

# than the length of the secret word, or the guess.

# @param guess

# @param secretWord

class Hint(object):

"""docstring for Hint"""

def __init__(self, guess, secretWord):

pass

def isWin(self):

pass

# Display a hint

# Given a secret word: 'state', and a guess 'scope' display:

# ---- Hint (scope) ----

# Correctly placed : s---e

# Incorrectly placed: -----

# Not in the puzzle : [cop]

# Given a secret word: 'state', and a guess 'state' display:

# ---- Hint (scope) ----

# Correctly placed : st--e

# Incorrectly placed: --ta-

# Not in the puzzle : []

def __repr__(self):

pass

COde from WORDLE:

# The puzzle game 'Wordle'!

# Basic idea:

# the game loads in a set of 'known words' from a file or an array.

# All 'known words' must have the same length (e.g., 5 characters)

# When the game starts, a secret word is chosen from the list of known words.

# The player can then issue guesses.

# Each guess returns a Hint object instance that tells:

# - which characters in the guess are correct, and correctly located.

# - which characters in the guess are in the secret word, but not at the location guessed

# - which characters in the guess are not in the secret word

# If all characters in the guess are correctly located, the game is won ;)

import random

from Hint import Hint

class Wordle(object):

"""docstring for Wordle"""

def __init__(self, file=None, wordList=[], length=0, minFreq=-1, maxFreq=-1):

pass

def numberOfKnownWords(self):

pass

# _Part 2: Implement this method._

# Load words from a file. Each line of the file contains a word followed by one or more spaces followed

# by a number whose value is higher for words that are more 'frequently occurring' than others.

# Loaded words should have a frequency value in the range [minfreq, maxfreq]. However, at times, these

# limits should be ignored (see comments below). Note that the words in the file may be many lengths

# (e.g., 3-10 characters). Only words of the specified length should be loaded.

# Hint: use a Scanner instance to read in the file and look for the next String or Long value.

# the following pattern will be useful ;)

# Scanner scan = new Scanner(new File(filenm));

# The line above creates a Scanner from a File with the filename stored in the variable filenm

# Use the scanner's .hasNext() method to test if there are more lines to read.

# Use the scanner's .next() method to grab the next String token (word).

# The scanner's .nextLong() method will grab the next token as a number (use this to read the frequency).

# For each line, you will want to call scan.next() and scan.nextLong() to read the data

# identifying a word and its relative frequency.

# Words of the specified length should be added into the knownWords list if their frequencies

# are the in the range specified.

# Hint: somewhere around 10-20 lines is probably appropriate here unless you have a lot of comments

# @param filenm - the file name to load from

# @param length - the length of words we want to load (e.g., 5 to load 5 character words)

# @param minfreq - the minimum allowable frequency for a loaded word

# @param maxfreq - the maximum allowable frequenct for a loaded word; 0 indicates no maximum

def loadWords(self, file, length, minFreq, maxFreq):

pass

# _Part 3: Implement this method._

# Obtain a list of known words. This method creates a new copy of the known words list.

# Here, you simply need to copy the knownWords list and return that copy.

# @return a new copy of list of known words.

def getKnownWords(self):

pass

# Prepare the game for playing by choosing a new secret word.

def initGame(self):

pass

# Supply a guess and get a hint!

# Note that this implementation DOES NOT require that the guess be selected

# from the known words. Rather, this implementation allows one to guess arbitrary

# characters, so long as the guess is the same length as the secret word.

# @param g - the guess (a string which is the same length as the secret word)

# @return a hint indicating the letters guessed correctly/incorrectly

# @returns None if the guess is not the same length as the secret word

def guess(self, g):

pass

In this assignment you'll work on implementing the game 'Wordle'. If you haven't played it, I suggest you try it out (a google search will help you find it!) so you know what to aim for. Playing a game of wordle can be broken down into these steps: 1. The computer obtains a list of possible words 2. The computer selects one word as the "secret" which the player will try to guess 3. The player guesses a word 4. The computer generates a hint about which letters are correct/incorrect. 5. The hint is communicated to the player. 6. Guessing continues until the player is out of turns or wins the game. The game is implemented in three classes: Wordle, Hint, and WordleGame. The Wordle class is responsible for items (1) and (2) above. Both the Wordle class and the Hint class are responsible for item (4). The Wordle class must be part of providing a hint to the player since the Wordle class knows what the secret word is. However, the logic for how to construct the hint itself. and the data associated with the details of the hint are encapsulated by the Hint class. so the 6. Guessing continues until the player is out of turns or wins the game. The game is implemented in three classes: Wordle, Hint, and WordleGame. The Wordle class is responsible for items (1) and (2) above. Both the Wordle class and the Hint class are responsible for item (4). The Wordle class must be part of providing a hint to the player since the Wordle class knows what the secret word is. However, the logic for how to construct the hint itself, and the data associated with the details of the hint are encapsulated by the Hint class, so the Wordle class acts mainly as a middle-man. The WordleGame class contains the logic for interacting between the computer and the player. That is, it is a user of the Wordle and Hint classes. Specifically, the WordleGame starts steps (1) and (2) off by creating the Wordle object instance. The WordleGame allows a player to guess a word (step 3) by reading input from the keyboard, and then sends that to the computer (i.e., the Wordle object instance) to obtain a hint, which is then printed for the user (step 5). This "game loop" continues until no more guesses remain, or the game is won (step 6). Getting Started All coding takes place in the file Wordle.py. You should look through all the code and generally I've tried to order the parts so that easier items are implemented first. Without a doubt, the most complex code live in the Hint constructor. Here, you'll be constructing a Hint to the puzzle. Of course constructing a Hint requires knowing what the secret word is as well as what the guess was. Then you'll need to figure out what letters are correctly placed, what letters are in the secret word, but incorrectly placed, and what letters aren't in the secret word at all. Read the comments for the constructor for more details. I suggest you implement this with a series of stages. First determining which characters are correctly placed then All coding takes place in the file Wordle.py. You should look through all the code and generally I've tried to order the parts so that easier items are implemented first. Without a doubt, the most complex code live in the Hint constructor. Here, you'll be constructing a Hint to the puzzle. Of course constructing a Hint requires knowing what the secret word is as well as what the guess was. Then you'll need to figure out what letters are correctly placed, what letters are in the secret word, but incorrectly placed, and what letters aren't in the secret word at all. Read the comments for the constructor for more details. I suggest you implement this with a series of stages. First determining which characters are correctly placed then checking which are incorrectly placed, and finally determining which are not in the puzzle. Each stage will require some looping. At the top of the Hint constructor, you should provide a comment that provides reasoning/justification for the method you've used to build the Strings each Hint instance uses. is as well as what the guess was. Then you'll need to figure out what letters are correctly placed, what letters are in the secret word, but incorrectly placed, and what letters aren't in the secret word at all. Read the comments for the constructor for more details. I suggest you implement this with a series of stages. First determining which characters are correctly placed then checking which are incorrectly placed, and finally determining which are not in the puzzle. Each stage will require some looping. At the top of the Hint constructor, you should provide a comment that provides reasoning/justification for the method you've used to build the Strings each Hint instance uses. Rubric 50% General performance of code 30% General style/approach of code 20% Reasoning and justification for Hint constructor What to turn in: - Hint.py - Wordle.py - Note: I will use the methods as in WordleGame.py to test your code

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Students also viewed these Databases questions