Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

i asked this qusiton befor bu was not given a satisfactory answer. Please solve in Pyhon, using the template functions from each file. code from

i asked this qusiton befor bu was not given a satisfactory answer.

Please solve in Pyhon, using the template functions from each file.

code from Hint:.py

# _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.py:

# 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

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

Recommended Textbook for

Students also viewed these Databases questions