To see how far your skills have come, we are going to give you a mission to update our super important Scrabble Scorer program. Did you think you were going to work on Mars rover code already?
The current Scrabble Scorer program takes in a word and returns its point value. The program needs to be rewritten for two reasons:
Your updates will make the program more efficient and user friendly.
Starter Code can be found here. Fork the code then clone it to your machine and work on it in Visual Studio.
Note
The requirements below are what your END assignment will look like. This assignment is broken down so you can complete small pieces as you go. You need to move sequentially starting at part A below. Please read the WHOLE assignment page before starting.
InitialPrompt
method that asks the user which scoring
algorithm to use.Transform
method that takes in the oldPointStructure
dictionary and returns a newPointStructure
dictionary.ScoringAlgorithms
method to invoke one of the three scoring methods.RunProgram
method to serve as the starting point for your
program.Note
As you create your methods, think about where the output is best utilized. Will it be something a user only needs to read? Will it become a parameter for another method? Revisit the Methods chapter if you feel unsure.
The starter code is currently set up to use only one scoring algorithm. For
the new version, we want to let the user pick between three algorithms. Define
an InitialPrompt
method that introduces the program and asks the user
which scoring algorithm to use.
Your prompt could look something like:
Welcome to the Scrabble score calculator!
Which scoring algorithm would you like to use?
1 - Scrabble: The traditional scoring algorithm.
2 - Simple Score: Each letter is worth 1 point.
3 - Bonus Vowels: Vowels are worth 3 pts, and consonants are 1 pt.
Enter 1, 2 or 3:
Currently, the software uses the oldPointStructure
dictionary for the traditional
Scrabble scoring algorithm. Take a few moments to review the code below to see how oldPointStructure
relates a point value to a letter.
Be sure to notice the data types of this dictionary.
1 2 3 4 5 6 7 8 9 10 | public static Dictionary<int, string> oldPointStructure = new Dictionary<int, string>()
{
{1, "A, E, I, O, U, L, N, R, S, T"},
{2, "D, G"},
{3, "B, C, M, P" },
{4, "F, H, V, W, Y" },
{5, "K" },
{8, "J, X" },
{10, "Q, Z" }
};
|
The keys of oldPointStructure
are the Scrabble points stored as ints, and the
values a string of letters. All letters in the string have the Scrabble
point value equal to the key. For example, "A"
and "R"
are worth 1,
"K"
is worth 5, and "J"
is worth 8.
To find the point value for a letter with the old format, the program must
iterate over each key in oldPointStructure
and then check if the letter is
inside the string paired with that key. This search within a search is
inefficient.
Try it yourself, find "L"
and "M"
.
Unless you have the scrabble scores memorized, you had to search each string.
Tedious, right? You can improve this.
It would be better to create a newPointStructure
dictionary that has 26 keys,
one for each letter. The value of each key will be the Scrabble point value.
Examples of the new key storage:
a
is worth 1
b
is worth 3
c
is worth 3
j
is worth 8
In newPointStructure
, the letters themselves are keys, so a single search
will identify a point value. This is much more efficient than the old method.
Example
Example of newPointStructure
dictionary usage.
Console.WriteLine("Scrabble scoring values for");
Console.WriteLine("letter a: {0}", newPointStructure['a']);
Console.WriteLine("letter j: {0}", newPointStructure['j']);
Console.WriteLine("letter z: {0}", newPointStructure['z']);
Console Output
Scrabble scoring values for
letter a: 1
letter j: 8
letter z: 10
Do not panic! Instead of tediously hard-coding newPointStructure
, use your
clever coding skills to create the new object.
Transform
method that returns a dictionary and has no parameters. Calling
Transform()
will return a dictionary with lowercase
letters as keys. The value for each key will be the points assigned to that
letter.newPointStructure
dictionary by setting it equal to
Transform()
.Transform()
:foreach
loops
iterate over the key/value pairs within a dictionary.oldPointStructure
, use bracket
notation (oldPointStructure[key]
).We are going to create the individual scoring methods first. Be sure to test them as you build them. Once all three are working, we are going to create a different method to invoke them. Read through this section before coding anything.
Create a separate method for each of the following scoring algorithms.
newPointStructure
.Each method should have a way to display the original word and the total value of points.
Examples
ScrabbleScorer("taxi");
//Output: Your word: taxi is worth 11
SimpleScorer("taxi");
//Output: Your word: taxi is worth 4
BonusVowels("taxi");
//Output: Your word: taxi is worth 8
ScoringAlgorithms
method¶1
or an invalid option, use the Scrabble Scorer method.2
, use the Simple Score method.3
, use the Bonus Vowels method.Good! Your ScoringAlgorithms
method now invokes all of the scoring
options and passes the user’s word to the selected method. Looks like we have a good start on this Scrabble program.
To access a scoring method via ScoringAlgorithms
, call it and pass the score option and a test word.
In our example, we will be using “taxi” as our test word.
Examples
// Scrabble scoring
ScoringAlgorithms(1, "taxi");
//Output: Your score for "taxi": 11
// Simple scoring
ScoringAlgorithms(2, "taxi");
//Output: Your score for "taxi": 4
// Bonus Vowel scoring
ScoringAlgorithms(3, "taxi");
//Output: Your score for "taxi": 8
Define a RunProgram
method that will do the following when called:
InitialPrompt
to pick the algorithm.ScoringAlgorithms
method chosen by the user with the correct parameters."Stop"
.
(This should also be case-insensitive.)Here are some words you can use to test your code:
CSharp
= 13 points using Scrabble, 6 using Simple Score, and 8
using Bonus Vowels.Scrabble
= 14 points using Scrabble, 8 using Simple Score, and 12 using
Bonus Vowels.Zox
= 19 points using Scrabble, 3 using Simple Score, and 5 using Bonus
Vowels.Welcome to the Scrabble score calculator!
Which scoring algorithm would you like to use?
1 - Scrabble: The traditional scoring algorithm.
2 - Simple Score: Each letter is worth 1 point.
3 - Bonus Vowels: Vowels are worth 3 pts, and consonants are 1 pt.
Enter 1, 2, or 3:
Enter a word to be scored, or "Stop" to quit: LaunchCode
Your score for "LaunchCode": 18
Enter a word to be scored, or "Stop" to quit: Rocket
Your score for "Rocket": 12
Enter a word to be scored, or "Stop" to quit: stop
' '
to the
newPointStructure
object. The point value for a blank tile is 0
.commit
and push
your work to the repository on your GitHub profile.