Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
56 changes: 53 additions & 3 deletions csharp-scrabble-challenge.Main/Scrabble.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,65 @@ namespace csharp_scrabble_challenge.Main
{
public class Scrabble
{
private string _word;
public Scrabble(string word)
{
//TODO: do something with the word variable
_word = word.ToUpper();

}

public int LetterValue(char letter)
{
int value = letter switch
{
'A' or 'E' or 'I' or 'O' or 'U' or 'L' or 'N' or 'R' or 'S' or 'T' => 1,
'D' or 'G' => 2,
'B' or 'C' or 'M' or 'P' => 3,
'F' or 'H' or 'V' or 'W' or 'Y' => 4,
'K' => 5,
'J' or 'X' => 8,
'Q' or 'Z' => 10,
'{' or '}' or '[' or ']' => 0,
_ => 0
};
return value;
}

public int score()
{
//TODO: score calculation code goes here
throw new NotImplementedException(); //TODO: Remove this line when the code has been written

bool doublePoint = false;
bool triplePoint = false;

int score = 0;
if (_word.Length == 0 || !IsValid(_word))
{
return score;
}

foreach (char c in _word)
{

if (c == '{')
{
doublePoint = true;
}
else if (c == '[')
{
triplePoint = true;
}

score += LetterValue(c);
}
if (doublePoint) { score = score * 2; }
else if (triplePoint) { score = score * 3; }

return score;
}

public bool IsValid(string word)
{
return System.Text.RegularExpressions.Regex.IsMatch(word, @"^[a-zA-Z\[\]{}]+$");
}
}
}