public void ScrabbleWord_ReturnErrorStatementIfInputContainsNotLetters_PleaseUseOnlyLetters() { ScrabbleWord newWord = new ScrabbleWord("tomato!"); string checkedWord = newWord.LettersOnly(); Assert.AreEqual("Please input only letters", checkedWord); }
public void WordScore_ReturnWordScore_Int() { ScrabbleWord newWord = new ScrabbleWord("Hello"); int checkScore = newWord.WordScore(newWord); Assert.AreEqual(7, checkScore); }
public ActionResult Result() { string userWord = Request.Form["userWord"]; ScrabbleWord newScrabbleWord = new ScrabbleWord(userWord); return(View("Index", newScrabbleWord)); }
public HomeModule() { Get["/"] = _ => { Dictionary <string, string> model = new Dictionary <string, string>(); model["HasResponse"] = "false"; return(View["index.cshtml", model]); }; Post["/"] = _ => { Dictionary <string, string> model = new Dictionary <string, string>(); model["HasResponse"] = "true"; model["value"] = ScrabbleWord.GetWordValue(Request.Form["userInput"]).ToString(); return(View["index.cshtml", model]); }; }
static void Main(string[] args) { List <ScrabbleWord> gameDictionary = new List <ScrabbleWord>(); ScrabbleRuleset ruleset = new ScrabbleRuleset(); ruleset.AddCharScores("eaionrtlsu", 1); ruleset.AddCharScores("dg", 2); ruleset.AddCharScores("bcmp", 3); ruleset.AddCharScores("fhvwy", 4); ruleset.AddCharScores("k", 5); ruleset.AddCharScores("jx", 8); ruleset.AddCharScores("qz", 10); int N = int.Parse(Console.ReadLine()); for (int i = 0; i < N; i++) { string W = Console.ReadLine(); gameDictionary.Add(new ScrabbleWord(W, ruleset)); } ScrabbleWord bestWord = null; string gameLetters = Console.ReadLine(); foreach (ScrabbleWord gameWord in gameDictionary) { if (gameWord.Usable(gameLetters) && bestWord == null) { bestWord = gameWord; } else if (gameWord.Usable(gameLetters) && gameWord.Score > bestWord.Score) { bestWord = gameWord; } } if (bestWord == null) { Console.WriteLine("Empty list"); } else { Console.WriteLine(bestWord.Word); } }
public void AddDictWord(string s) { if (s.Length > 7) return; ScrabbleWord word = new ScrabbleWord(s); if (!word.CanBeBuiltFrom(Seed)) { Console.Error.WriteLine(s + " cannot be built from " + Seed); return; } if (!WordList.Keys.Contains(word.SortedWord)) WordList.Add(s, word); else { if (WordList[word.SortedWord].Value < word.Value) WordList[word.SortedWord] = word; } if (word.Value > BestScore) { BestScore = word.Value; BestWord = s; } }
/// <summary> /// Searches for a valid scrabble word. /// </summary> /// <param name="word">The word</param> /// <returns>The scrabble word if valid, null if no match found.</returns> public IScrabbleWord Search(string word) { var sWord = default(IScrabbleWord); if (!string.IsNullOrWhiteSpace(word)) { if (_roots.ContainsKey(word[0])) { var path = SearchForScrabblePath(_roots[word[0]], word); if (path.Count == word.Length && path[path.Count - 1].IsEnd) { // check we matched the whole provided word AND that we completed a word. var scrabbleWord = new ScrabbleWord(); foreach (var node in path) { scrabbleWord.Add(ScrabbleTileFactory.Get(node.Value)); } sWord = scrabbleWord; } } } return(sWord); }
public void WordConstructor_CreatesInstanceOfItem_Word() { ScrabbleWord newWord = new ScrabbleWord("tomato"); Assert.AreEqual(typeof(ScrabbleWord), newWord.GetType()); }
public ActionResult Index() { ScrabbleWord newScrabbleWord = new ScrabbleWord(""); return(View(newScrabbleWord)); }