public void LookUpWords_9x9_AFewWords() { var grid = new WordGrid(9, 9); var words = new[] { "MATTHEW", "JOE", "MARY", "SARAH", "SALLLY" }; var domains = words.ToDictionary(w => w, w => (IReadOnlyCollection <List <WordGrid.GridLocation> >)grid.GenerateDomain(w)); var csp = new ConstraintSatisfactoryProblem <string, List <WordGrid.GridLocation> >(words, domains); csp.AddConstraint(new WordGrid.WordSearchConstraint(words)); var solution = csp.BacktrackingSearch(); foreach (var pair in solution) { _output.WriteLine($"{pair.Key} {string.Join(", ", pair.Value.Select(v => (v.Row, v.Column).ToString()))}"); } _output.WriteLine(grid.ToString()); foreach (var pair in solution) { grid.InitializeWithWord(pair.Key, pair.Value); } _output.WriteLine(grid.ToString()); }
public void ReadTexts() { string directory = isSwapLettersMode ? "swap" : "spell"; creditsText = Toolkit.Read(directory + "/word_credits.txt"); wordsText = Toolkit.Read(directory + "/word_list_moby_crossword.flat.txt"); if (isSwapLettersMode) { wordGrid = new WordGrid(); wordGrid.SetDictionary(wordsText + "\n" + creditsText); } messagesText = Toolkit.Read(directory + "/tutorial_messages.txt"); gridNames = new string[]{ "tutorial_grids.txt", "love_grids.txt", "health_grids.txt", "money_grids.txt", "charm_grids.txt", "success_grids.txt", "skill_grids.txt", "healing_grids.txt", "relaxation_grids.txt", "grief_grids.txt", "banishing_grids.txt", "credits_grids.txt" }; gridTexts = new string[gridNames.Length]; for (int index = 0; index < gridNames.Length; index++) { gridTexts[index] = Toolkit.Read(directory + "/" + gridNames[index]); } }
public ActionResult WordSearchReroll(string SessionKey) { db = Session[SessionKey] as WordGrid; db.ReInitWordGrid(); Session[SessionKey] = db; return(PartialView("_Grid", db)); }
public void AllDirectionsSmall() { var grid = new WordGrid(3, 3, new string[] { "BAC", "EOO", "CKB" }); var finder = new WordFinder(new List <string> { "BAC", "BOB", "BEC", "COC" }, grid); Assert.AreEqual("OK", finder.Find()); }
public void RightAligned_SET_FindsExpectedWord() { WordGrid grid = new WordGrid(6); grid.Lines[5] = " SET"; Assert.IsTrue(grid.FindHorizontalWords()); Assert.AreEqual(1, grid.FoundWords.Count); }
public void CreatesExpectedObject() { WordGrid grid = new WordGrid(6); Assert.AreEqual(6, grid.Lines.Length); foreach (string line in grid.Lines) { Assert.AreEqual(" ", line); } }
public void VerticalWords() { var grid = new WordGrid(4, 4, new string[] { "GTRI", "LMAL", "UAGO", "ECML" }); var finder = new WordFinder(new List <string> { "GLUE", "RAG", "LOL", "MAC" }, grid); Assert.AreEqual("TIM", finder.Find()); }
public void AND_SET_FindsExpectedWord() { WordGrid grid = new WordGrid(6); grid.Lines[4] = " AND"; grid.Lines[5] = " SET"; Assert.IsTrue(grid.FindHorizontalWords()); Assert.AreEqual(2, grid.FoundWords.Count); }
public void SET_FindsExpectedWord() { WordGrid grid = new WordGrid(6); grid.Lines[3] = "S "; grid.Lines[4] = "E "; grid.Lines[5] = "T "; Assert.IsTrue(grid.FindVerticalWords()); Assert.AreEqual(1, grid.FoundWords.Count); }
public void SET_Returns3() { WordGrid grid = new WordGrid(6); grid.Lines[3] = "S "; grid.Lines[4] = "E "; grid.Lines[5] = "T "; Assert.IsTrue(grid.FindVerticalWords()); Assert.AreEqual(3, grid.CalculateScore()); }
public void HorizontalWords() { var grid = new WordGrid(3, 3, new string[] { "BAC", "BOB", "RED" }); var finder = new WordFinder(new List <string> { "BAC", "BOB" }, grid); Assert.AreEqual("RED", finder.Find()); }
public void SET_And_TEST_Returns8() { WordGrid grid = new WordGrid(6); grid.Lines[3] = "S "; grid.Lines[4] = "E "; grid.Lines[5] = "TEST "; Assert.IsTrue(grid.FindVerticalWords()); Assert.IsTrue(grid.FindHorizontalWords()); Assert.AreEqual(8, grid.CalculateScore()); }
public void EmptyGrid_PlacesLetterAsExpected() { WordGrid grid = new WordGrid(6); var ableToDropLetter = grid.DropLetter('A', 0); Assert.AreEqual(true, ableToDropLetter); Assert.AreEqual(" ", grid.Lines[0]); Assert.AreEqual(" ", grid.Lines[1]); Assert.AreEqual(" ", grid.Lines[2]); Assert.AreEqual(" ", grid.Lines[3]); Assert.AreEqual(" ", grid.Lines[4]); Assert.AreEqual("A ", grid.Lines[5]); }
public void ClearsAsExpected() { WordGrid grid = new WordGrid(6); grid.Lines[5] = "setx "; Assert.IsTrue(grid.FindHorizontalWords()); grid.DeleteFoundWords(); Assert.AreEqual(0, grid.FoundWords.Count); Assert.AreEqual(" x ", grid.Lines[5]); }
public void Repeated_DoesNotAddAdditionalWords() { WordGrid grid = new WordGrid(6); grid.Lines[5] = "SET "; Assert.IsTrue(grid.FindHorizontalWords()); Assert.AreEqual(1, grid.FoundWords.Count); Assert.IsTrue(grid.FindHorizontalWords()); Assert.AreEqual(1, grid.FoundWords.Count); }
public void AllDirectionsBig() { var grid = new WordGrid(12, 12, new string[] { "VCENJUGUENTO", "OCORCSEERRAN", "SOCHASSIGNET", "SDRAHCUAFDND", "AENMALMENEES", "BSETINMUIDEM", "VOLLEYBALLTG", "COLATURESAUM", "ISEMAEGROGER", "SSURSITESERE", "TEGNITRIFIAT", "ENILECOUSAIS" }); var finder = new WordFinder(new List <string> { "BASSOV", "CELINE", "CHASSIGNET", "CISTE", "COLATURES", "COUSAIS", "EAMES", "ENJUGUENT", "ERES", "ESCROC", "FAUCHARDS", "GRAUBUNDEN", "INSERAIENT", "MALMENEES", "MEDIUMNITES", "NARREES", "NITRIFIAT", "ODES", "REGORGEA", "SURSITES", "TUERA", "VOLLEYBALL" }, grid); Assert.AreEqual("CODNGAME", finder.Find()); }
public void SingleDiagonalLine_DropsSuspendedLetters() { WordGrid gridWithSuspendedLetters = new WordGrid(6); gridWithSuspendedLetters.Lines[0] = "a "; gridWithSuspendedLetters.Lines[1] = " b "; gridWithSuspendedLetters.Lines[2] = " c "; gridWithSuspendedLetters.Lines[3] = " d "; gridWithSuspendedLetters.Lines[4] = " e "; gridWithSuspendedLetters.Lines[5] = " f"; gridWithSuspendedLetters.DropAllLetters(); for (int emptyIndex = 0; emptyIndex < 5; emptyIndex++) { Assert.AreEqual(" ", gridWithSuspendedLetters.Lines[emptyIndex]); } Assert.AreEqual("abcdef", gridWithSuspendedLetters.Lines[5]); }
public void TwoDiagonalLines_DropsSuspendedLetters() { WordGrid gridWithSuspendedLetters = new WordGrid(6); gridWithSuspendedLetters.Lines[0] = "a l"; gridWithSuspendedLetters.Lines[1] = " b k "; gridWithSuspendedLetters.Lines[2] = " cj "; gridWithSuspendedLetters.Lines[3] = " id "; gridWithSuspendedLetters.Lines[4] = " h e "; gridWithSuspendedLetters.Lines[5] = "g f"; gridWithSuspendedLetters.DropAllLetters(); for (int emptyIndex = 0; emptyIndex < 4; emptyIndex++) { Assert.AreEqual(" ", gridWithSuspendedLetters.Lines[emptyIndex]); } Assert.AreEqual("abcjkl", gridWithSuspendedLetters.Lines[4]); Assert.AreEqual("ghidef", gridWithSuspendedLetters.Lines[5]); }
public void FillColumn_PlacesLetterAsExpected() { WordGrid grid = new WordGrid(6); var ableToDropLetter = grid.DropLetter('A', 0); Assert.AreEqual(true, ableToDropLetter); Assert.AreEqual(" ", grid.Lines[0]); Assert.AreEqual(" ", grid.Lines[1]); Assert.AreEqual(" ", grid.Lines[2]); Assert.AreEqual(" ", grid.Lines[3]); Assert.AreEqual(" ", grid.Lines[4]); Assert.AreEqual("A ", grid.Lines[5]); ableToDropLetter = grid.DropLetter('B', 0); Assert.AreEqual(true, ableToDropLetter); Assert.AreEqual(" ", grid.Lines[0]); Assert.AreEqual(" ", grid.Lines[1]); Assert.AreEqual(" ", grid.Lines[2]); Assert.AreEqual(" ", grid.Lines[3]); Assert.AreEqual("B ", grid.Lines[4]); Assert.AreEqual("A ", grid.Lines[5]); ableToDropLetter = grid.DropLetter('C', 0); Assert.AreEqual(true, ableToDropLetter); Assert.AreEqual(" ", grid.Lines[0]); Assert.AreEqual(" ", grid.Lines[1]); Assert.AreEqual(" ", grid.Lines[2]); Assert.AreEqual("C ", grid.Lines[3]); Assert.AreEqual("B ", grid.Lines[4]); Assert.AreEqual("A ", grid.Lines[5]); ableToDropLetter = grid.DropLetter('D', 0); Assert.AreEqual(true, ableToDropLetter); Assert.AreEqual(" ", grid.Lines[0]); Assert.AreEqual(" ", grid.Lines[1]); Assert.AreEqual("D ", grid.Lines[2]); Assert.AreEqual("C ", grid.Lines[3]); Assert.AreEqual("B ", grid.Lines[4]); Assert.AreEqual("A ", grid.Lines[5]); ableToDropLetter = grid.DropLetter('E', 0); Assert.AreEqual(true, ableToDropLetter); Assert.AreEqual(" ", grid.Lines[0]); Assert.AreEqual("E ", grid.Lines[1]); Assert.AreEqual("D ", grid.Lines[2]); Assert.AreEqual("C ", grid.Lines[3]); Assert.AreEqual("B ", grid.Lines[4]); Assert.AreEqual("A ", grid.Lines[5]); ableToDropLetter = grid.DropLetter('F', 0); Assert.AreEqual(true, ableToDropLetter); Assert.AreEqual("F ", grid.Lines[0]); Assert.AreEqual("E ", grid.Lines[1]); Assert.AreEqual("D ", grid.Lines[2]); Assert.AreEqual("C ", grid.Lines[3]); Assert.AreEqual("B ", grid.Lines[4]); Assert.AreEqual("A ", grid.Lines[5]); ableToDropLetter = grid.DropLetter('G', 0); Assert.AreEqual(false, ableToDropLetter); Assert.AreEqual("F ", grid.Lines[0]); Assert.AreEqual("E ", grid.Lines[1]); Assert.AreEqual("D ", grid.Lines[2]); Assert.AreEqual("C ", grid.Lines[3]); Assert.AreEqual("B ", grid.Lines[4]); Assert.AreEqual("A ", grid.Lines[5]); }
public ActionResult GridLoad(string SessionKey) { db = Session[SessionKey] as WordGrid; return(PartialView("_Grid", db)); }
protected override void OnStart() { Load(); App.wordGrid = new WordGrid(); }
public void CanBuildWordGrid() { var grid = new WordGrid(1, 1, new string[] { "A" }); Assert.AreEqual(1, grid.Size); }
public void EmptyGrid_Returns0() { WordGrid grid = new WordGrid(6); Assert.AreEqual(0, grid.CalculateScore()); }
public ActionResult WordSearchUserFind(string input, string key) { db = Session[key] as WordGrid; return(db.ValidWord(input) ? Json(new { success = true }) : Json(new { success = false })); }