matlab代写-ML3
时间:2022-05-05
ML3 - Wordle
Summary:
There is a popular new game called Wordle in which the player attempts to guess a five
letter word using deduction and hints. Here, we will make a version of it using arrays and
functions using our MATLAB knowledge. I recommend starting early, as this game will take
some time to get the logic worked out correctly. For this assignment, each function needs to
be a separate file. https://www.nytimes.com/games/wordle/index.html
Skills to be Obtained:
● Implement looping, branching, arrays, and functions in Matlab
● Use functions that are separate files from the main script
● Read csv files
● Install a plugin from the Mathworks website (cprintf)
Details:
The game will require the player to determine a Northeastern-themed five letter word. To
crack the code, enter a five-letter word (all capital letters). Players get up to six (6) guesses to
match the five letter word before they lose. If the five letters entered are correct and in the
correct order, then the player has won. But they must meet both conditions (letters and order).
The starting word is chosen randomly from the list below and imported from a .csv file
that you will make. To make a .csv file, put the words into a spreadsheet program (excel, google
sheets, etc.) and put each word in its own cell. Then, use save as to make a .csv (comma
delimited) file. Import it into Matlab and double click on the array to see if it imported correctly.
Word list - please use all UPPERCASE letters:
● CABOT
● LIGHT
● SMITH
● LASER
● DRAFT
● SKILL
● ARRAY
● SMILE
● HAPPY
● HUSKY
● NORTH
● CIVIL
● DAVIS
● BREAK
● GREEN
● RYDER
● SNELL
● SPARK
● CURRY
● DODGE
Bring the .csv file into Matlab. Choose one of the words randomly and this word is the code
word the player will need to guess to win the game. I recommend outputting the word to the
user while troubleshooting, but in the final version, do not give the word to the player!
Once the code word is chosen, ask the player for their first five-letter guess. After each
guess, have the program send the player’s guess and the code word to a function that will
determine what information to give the player. In the function, print the guessed word with the
following conditions for each letter
1.) The letter is not in the code word at all = black text color
2.) The letter is in the word but not in the right spot (right letter + wrong place) = magenta text
color
3.) The letter is in the word in the correct location (right letter + right place) = green text color.
An example for the code word LEAVE is seen below. This function does not need to return
anything to the main script. We will use the ‘cprintf’ plugin to print colors other than black in the
output. This will need to be downloaded as a toolbox and installed. Please see the Appendix
for full details.
Print: Please enter your guesses as a sequence of five capital letters.
Guess 1. L A S E R
L A S E R
Guess 2. L L A M A
L L A M A
Guess 3. L E E D S
L E E D S
Guess 4. L E A V E
L E A V E
Print: You guessed the word. You win!
The most difficult thing about programming this game will be coding the logic that
determines which letters are correct. When a guess is entered, the function should determine if
letters are in the 1) correct location or 2) wrong location 3) not in the word at all. This logic is
complicated to get correct because there can be repeated letters in the guess and/or code word.
For example, in the game shown above, the 2nd guess contains two L’s. The first L is the match
for right letter/right loc. The second L does not get counted as a match because the L in the
secret word has already been accounted for. I highly recommend writing pseudocode for the
logic before you start coding!
In this project, you will develop a script that allows a user to play this game. Specific
functionality expected from your code is:
- Create the code word as a string/character array and fill it with a random word from the
list in the .csv file (each index should hold one letter)
- Ask the player to enter a five-letter word and store each guess in a new row of a
character array
- Send the code word and guess to a function and have the function print the letters of the
appropriate colors based on the logic above. Check the right letter + location logic for
each letter for the entire word first. Then, check the right letter + wrong location logic.
- Repeat the previous two steps to give the player up to 6 tries. If the correct word is
guessed on any of those tries, the player is congratulated, and the game stops. If an
incorrect guess is made on the 6th try, then the player is told of their loss, and the correct
word is revealed. After the end condition is met, end the program.
Milestones Towards Completion:
First write a script that imports a randomly selected word from your .csv word-bank file.
Next store the code-word array in a 1D array and make a 2D guess array that is 5 letters long
and 6 rows. Finally, create the dialogue for win/lose conditions. Each guess will occupy one row
of the 2D guess array.
Next, create a function for the logic where you will compare the code word to the player
guess and determine which colors to return to the main and send to the player (GMB). Writing
this in a separate script will make debugging the logic easier.
NOTE: Be careful not to double count! As you write the logic, one great way to make sure
you don’t double count repeated values in the code or guess array is to use a 5-element number
array that stores whether each spot in the code has already been found as a match to one of
the numbers in the guess. Make 2 number arrays, one for the code and one for the guess that
have all 0s in their 5 slots. Each time you match a guess and code, change the 0 to a 1 or 2 in
the number array. Use a 1 for ‘right letter, right place’ and a 2 for ‘right letter, wrong place’. Right
letter means that the letter is somewhere in the word - right/wrong place refers to whether a
correct letter is also in the correct location in the word. When checking if the letters match, also
check that the corresponding spot in the number array is a 0. If it is not a 0, that letter has
already been accounted for. This means, you will need to check if the guess and code letter
matches, the guess number array is a 0, AND the code number array is 0 for each letter
comparison. I recommend checking every ‘right letter, right location’ first then every ‘right letter,
wrong location’.
If you set the number array up for both the guess array and the secret code array, then you
can avoid measuring double counting and other errors. (ex. word:PHONE guess:BOOKS print
to screen:BOOKS where one “O” matches perfectly and the other “O” isn’t magenta since the
code-“O” in PHONE has already been assigned.)
If you use this method, you may choose to have these number arrays only exist in your
function or be passed from the main script to the function - your choice!
An example:
Guess: Larva
Code: Leave
Number for Array Guess starts 00000
Number Array for Guess after ‘right letter, right place’ 10010
Number Array for Guess after ‘right letter, wrong place’ 12010
Number Array for Code starts 00000
Number Array for Code after ‘right letter, right place’ 10010
Number Array for Code after ‘right letter, wrong place’ 10210
After the ‘right letter, right place’ measurement, if both number arrays are 11111, the guess
should perfectly match the code! When outputting, the number array 0s will correspond to
black, 1s will correspond to green, and 2s will correspond to magenta.
Extended Work:
Though not required, you may perform one of the following extended work options:
- Hard Mode: Ask the user at the beginning if they want to play on hard mode. If
they agree, whenever they input a guess, make sure that they used all previously
correct letters (use characters that were green or magenta in the previous guess)
- In addition to importing the group of 20 words for the code word, import a dictionary
and compare each guessed word to the dictionary to see if the player inserted a real
word. If the player did not input a real word, ask them again to give you a word and
do not count the not-a-word as a guess!
- Any other findings or extensions to the method that you found particularly
useful, curious, and/or interesting. You may wish to run your ideas by Prof. Davis
before pursuing this option, just to make sure it is of sufficient complexity to count as
extended analysis.
Submission Requirements:
Please submit your work by the due date listed on Canvas. Please submit both your report
(.pdf), the code(s) as separate .m/.mlx file(s), and the .csv file you created. The report should be
1-2 pages (with an appendix for the code and screenshots). Included in the report should be:
● Introduction
● Description of your work including text description of what the code does
● Pseudocode description of how the code works
● Results showing that your code is fully functional (screen shots)
● Conclusion
● Appendix
Transcribe the commented code in a neatly formatted manner in the appendix. The entire report
should have text that neatly flows from beginning to end. Do not assume that the person reading
the report remembers anything about what you have been tasked to perform. In other words,
the report should be readable on its own, without someone having read this document.
Plugins: cprintf
Sample - fprintf('This is a ') ; cprintf('_magenta', 'colorful ') ; fprintf('example!\n') ;
https://www.mathworks.com/matlabcentral/fileexchange/24093-cprintf-display-formatted-colored
-text-in-command-window
Go to the website and click the arrow next to Download. Select ‘Toolbox’ and download/install it.
Careful to click the right thing. You should need to sign into Matlab if you are not already signed
in. The file you download should be called “cprintf.mltbx”. If it is not called that, do not download
or install the file.
essay、essay代写