Question: Code to call your function: %Input arguments must be in the following order: target word, guess word x = wordle('query', 'chore') display_wordle('chore', x) figure y=wordle('query',

Wordle scoring The latest word game craze is Wordle, in which a

Code to call your function:

%Input arguments must be in the following order: target word, guess word

x = wordle('query', 'chore')

display_wordle('chore', x)

figure

y=wordle('query', 'quiet')

display_wordle('quiet', y)

figure

y = wordle('block', 'broom')

display_wordle('broom', y)

%************************************

% No need to modify this function

% It displays the result graphically

% with the color code:

% green = correct letter

% yellow = letter is in the word

% grey = letter is not in the word

%************************************

function display_wordle(guess, letter_vals)

%initialize to white

disp_array = ones(1,5,3);

for k = 1:5

switch letter_vals(k)

case 1

%letter matches - make it green

disp_array(1,k,:) = [0,1,0];

case 0

%letter is in the word - make it yellow

disp_array(1,k,:) = [0.75,0.75,0];

case -1

%letter is not in the word - make it grey

disp_array(1,k,:) = 0.5;

end

end

imshow(imresize(disp_array, 50, 'nearest'));

for k = 1:5

text(10+50*(k-1), 25, upper(guess(k)), 'fontsize', 36, 'color', 'w');

end

end

Wordle scoring The latest word game craze is Wordle, in which a player tries to guess a 5-letter word and, after each guess. is provided with feedback about which letters are correct. Write a function, named wordle, that takes two CHARACTER ARRAYS as inputs: the target word, and the player's guess. The function should compare the two and return a 1x5 numerical: For each letter in the guess, set the corresponding value in the numerical array as follows: If that letter matches the letter in the same position of the target word, +1 If that letter is in the target word, but not in the same position, 0 (Hint: a relational operator with the sum function is the easiest way to do this.) If that letter is not in the target word, -1 So, for example, if the target word is 'clump' and the user guess is 'chill', the function should return [1, -1, -1, 0, 0] Note: This is a simplified version of Wordle scoring that doesn't handle the case of multiple occurrences of a letter correctly. For example, if the target word = "block", and the guess = "broom", this function will return [1,-1, 1, 0, -1], whereas in the real game it would be [1, -1, 1, -1, -1]. For a challenge, you can try implementing the more complete scoring, but for the tests used in this problem, the result will be the same. Function Reset MATLAB Documentation

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!