public void Scenario8Case3() { Configuration config; WordList wordlist; Crozzle crozzle; String[] expectedStrings = { "Configuration file is invalid", "Crozzle file is invalid", "Word list file is invalid" }; Configuration.TryParse(@"..\..\..\..\Test Files\UnitTest3.cfg", out config); WordList.TryParse(@"..\..\..\..\Test Files\UnitTest3.seq", config, out wordlist); Crozzle.TryParse(@"..\..\..\..\Test Files\UnitTest1.czl", config, wordlist, out crozzle); var htmlString = crozzle.ToStringHTML(); foreach (String eString in expectedStrings) { if (!htmlString.Contains(eString)) { Assert.Fail(); } } }
public void TestMethod7() { // Arrange. string myCrozzleFile = @"C:\temp\Old Program and Old Files\Assessment Task 1 Files\Test1.czl"; string myWordlistFile = @"C:\temp\Old Program and Old Files\Assessment Task 1 Files\Test1.seq"; string myConfigFile = @"C:\temp\Old Program and Old Files\Assessment Task 1 Files\Test1.cfg"; string myConfigFile2 = @"C:\temp\Old Program and Old Files\Test Files\unitTest9\Test1 Configuration_groupCount2.cfg"; string myConfigFile3 = @"C:\temp\Old Program and Old Files\Test Files\unitTest9\Test1 Configuration_groupCount4.cfg"; string myCrozzleFile2 = @"C:\temp\Old Program and Old Files\Test Files\unitTest9\Test1 Crozzle_groupCount2.czl"; string myCrozzleFile3 = @"C:\temp\Old Program and Old Files\Test Files\unitTest9\Test1 Crozzle_groupCount4.czl"; //test 1 - Original files Configuration config; Configuration.TryParse(myConfigFile, out config); WordList wordlist; WordList.TryParse(myWordlistFile, config, out wordlist); Crozzle crozzle; Crozzle.TryParse(myCrozzleFile, config, wordlist, out crozzle); CrozzleMap crozzleMap = new CrozzleMap(crozzle.CrozzleRows, crozzle.CrozzleColumns); //Test 2 - Files edited into two groups of connected words. Words removed are Mark and Jack Configuration config2; Configuration.TryParse(myConfigFile2, out config2); WordList wordlist2; WordList.TryParse(myWordlistFile, config2, out wordlist2); Crozzle crozzle2; Crozzle.TryParse(myCrozzleFile2, config2, wordlist2, out crozzle2); CrozzleMap crozzleMap2 = new CrozzleMap(crozzle2.CrozzleRows, crozzle2.CrozzleColumns); //test 3 - Files edited into four groups. Configuration config3; Configuration.TryParse(myConfigFile3, out config3); WordList wordlist3; WordList.TryParse(myWordlistFile, config3, out wordlist3); Crozzle crozzle3; Crozzle.TryParse(myCrozzleFile3, config3, wordlist3, out crozzle3); CrozzleMap crozzleMap3 = new CrozzleMap(crozzle3.CrozzleRows, crozzle3.CrozzleColumns); int expectedGroupCount = 1; int expectedNewGroupCount1 = 2; int expectedNewGroupCount2 = 4; // Act. int ActualGroupCount = crozzleMap.GroupCount(); int ActualNewGroupCount1 = crozzleMap2.GroupCount(); int ActualNewGroupCount2 = crozzleMap3.GroupCount(); // Assert. Assert.AreEqual(expectedGroupCount, ActualGroupCount, "failed ..."); Assert.AreEqual(expectedNewGroupCount1, ActualNewGroupCount1, "failed ..."); Assert.AreEqual(expectedNewGroupCount2, ActualNewGroupCount2, "failed ..."); }
public void TestMethod12() { // Arrange. string myCrozzleFile = @"C:\SIT323_Assignment1\Old Program and Old Files\Test 1 Crozzle.txt"; string myWordlistFile = @"C:\SIT323_Assignment1\Old Program and Old Files\Test 1 Wordlist.txt"; string myConfigFile = @"C:\SIT323_Assignment1\Old Program and Old Files\Test 1 Configuration.txt"; Configuration config; Configuration.TryParse(myConfigFile, out config); WordList wordlist; WordList.TryParse(myWordlistFile, config, out wordlist); Crozzle crozzle; Crozzle.TryParse(myCrozzleFile, config, wordlist, out crozzle); int expectedReturnRows = 10; int expectedReturnColumns = 15; string expectedWordListPath = "C:\\SIT323_Assignment1\\Old Program and Old Files\\Test 1 Wordlist.txt"; // Act. int actualReturnRows = crozzle.Rows; int actualReturnColumns = crozzle.Columns; string actualWordlistPath = crozzle.WordListPath; // Assert. Assert.AreEqual(expectedReturnRows, actualReturnRows, "failed ..."); Assert.AreEqual(expectedReturnColumns, actualReturnColumns, "failed ..."); Assert.AreEqual(expectedWordListPath, actualWordlistPath, "failed ..."); }
public void TestMethod5() { // Arrange. string myCrozzleFile = @"C:\SIT323_Assignment1\Old Program and Old Files\Test 1 Crozzle.txt"; string myCrozzleFile2 = @"C:\SIT323_Assignment1\Old Program and Old Files\unitTest5\Test 1 Crozzle_invalidScore.txt"; string myWordlistFile = @"C:\SIT323_Assignment1\Old Program and Old Files\Test 1 Wordlist.txt"; string myConfigFile = @"C:\SIT323_Assignment1\Old Program and Old Files\Test 1 Configuration.txt"; string myCrozzleFile3 = @"C:\SIT323_Assignment1\Old Program and Old Files\unitTest5\Test 1 Crozzle_scoreNewWords.txt"; string myWordlistFile3 = @"C:\SIT323_Assignment1\Old Program and Old Files\unitTest5\Test 1 Wordlist_scoreNewWords.txt"; //CASE 1 Configuration config; Configuration.TryParse(myConfigFile, out config); WordList wordlist; WordList.TryParse(myWordlistFile, config, out wordlist); Crozzle crozzle; Crozzle.TryParse(myCrozzleFile, config, wordlist, out crozzle); //CASE 2 Removed a row from crozzle file Crozzle crozzle2; Crozzle.TryParse(myCrozzleFile2, config, wordlist, out crozzle2); //CASE 3 Adding two new words to crozzle files WordList wordlist3; WordList.TryParse(myWordlistFile3, config, out wordlist3); Crozzle crozzle3; Crozzle.TryParse(myCrozzleFile3, config, wordlist3, out crozzle3); //the expected output should be 303 string expectedOriginalScore = "303"; //the expected output of the edited crozzle file should be "INVALID CROZZLE" as row is missing string expectedInvalidScore = "INVALID CROZZLE"; //the expected output should be 336 with the new words of JACKIE and TOMORY string expectedNewWordsScore = "336"; // Act. crozzle.Validate(); crozzle2.Validate(); crozzle3.Validate(); string actualOriginalScore = crozzle.Score(); string actualInvalidScore = crozzle2.Score(); string actualNewWordsScore = crozzle3.Score(); // Assert. Assert.AreEqual(expectedOriginalScore, actualOriginalScore, "failed ..."); Assert.AreEqual(expectedInvalidScore, actualInvalidScore, "failed ..."); Assert.AreEqual(expectedNewWordsScore, actualNewWordsScore, "failed ..."); }
private bool CheckAndAdd(CrozzleArray crozzleArray) { bool added = false; if (crozzleArray != null) { CrozzleArray tempCA = new CrozzleArray(crozzleArray.Height, crozzleArray.Width); tempCA.DeepCopy(crozzleArray); Crozzle croz = new Crozzle(tempCA._crozzleGrid); GeneratedList.Add(croz); added = true; } return added; }
// Event handler from Open file menu private void OpenFile_Click(object sender, RoutedEventArgs e) { openFile.Filter = "Text file (*.txt) | *.txt"; if (openFile.ShowDialog() == true) { string file = openFile.FileName; fileName.Text = file; Crozzle crozzle = new Crozzle(file); } else { fileName.Text = "Felipe"; } }
public void CrozzleTest_BestWordList() { int[] nonIntersectingLetterPoints = new int[] { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }; int[] intersectingLetterPoints = new int[] { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26 }; List <String> WordStrList = new List <String>() { "AADEN", "AANYA", "AARON", "AL", "ALAN", "ALEX", "ALEXANDER", "ALEXANDRA", "ALEXIA", "ALI", "ALLA", "ALLAN", "ALLY", "AMY", "ANDREW", "ANN", "ANNE", "ANTHONY", "ARJUN", "ARLA", "ARLO", "ARLY", "ARMANI", "ARMIDA", "ARNOLD", "ARTHUR", "ARVIL", "ARYANA", "ASH", "ASHELY", "ASHLEA", "ASHLEE", "ASHLEIGH", "ASHLEY", "ASHLIE", "ASHLYN", "ASHTON", "ASHTYN", "ASTRID", "ATHENA", "AUBREE", "AUBREY", "AUBRIE", "AUDREY", "AURORA", "AURORE", "AUSTIN", "AXL", "AYDEN", "AYLA" }; List <String> retWords = Crozzle.CreateCrozzelByGreedyAlgorithm(10, 8, WordStrList, intersectingLetterPoints, nonIntersectingLetterPoints); foreach (String word in retWords) { Console.WriteLine(word); } }
public void TestMethod7() { // Arrange. string myCrozzleFile = @"C:\SIT323_Assignment1\Old Program and Old Files\Test 1 Crozzle.txt"; string myWordlistFile = @"C:\SIT323_Assignment1\Old Program and Old Files\Test 1 Wordlist.txt"; string myCrozzleFile2 = @"C:\SIT323_Assignment1\Old Program and Old Files\unitTest7\Test 1 Crozzle_validateFalse.txt"; string myWordlistFile2 = @"C:\SIT323_Assignment1\Old Program and Old Files\unitTest7\Test 1 Wordlist_validateFalse.txt"; string myConfigFile = @"C:\SIT323_Assignment1\Old Program and Old Files\Test 1 Configuration.txt"; Configuration config; Configuration.TryParse(myConfigFile, out config); WordList wordlist; WordList.TryParse(myWordlistFile, config, out wordlist); Crozzle crozzle; Crozzle.TryParse(myCrozzleFile, config, wordlist, out crozzle); //Unit test 2 and 3 - Word AL is removed from Crozzle file. Errors are RONALD is removed and group counts exceed config limits WordList wordlist2; WordList.TryParse(myWordlistFile2, config, out wordlist2); Crozzle crozzle2; Crozzle.TryParse(myCrozzleFile2, config, wordlist2, out crozzle2); bool expectedTrueValidityOriginal = true; bool expectedFalseValidityNew = false; string expectedErrorMessageNew = "code 11002: the number of horizontal words intersecting AL is 0, but this is not within [1, 100]"; // Act. crozzle.Validate(); crozzle2.Validate(); bool actualTrueValidityOriginal = crozzle.CrozzleValid; bool actualFalseValidityNew = crozzle2.CrozzleValid; string actualErrorMessageNew = crozzle2.CrozzleGridErrors[0]; // Assert. Assert.AreEqual(expectedTrueValidityOriginal, actualTrueValidityOriginal, "failed ..."); Assert.AreEqual(expectedFalseValidityNew, actualFalseValidityNew, "failed ..."); Assert.AreEqual(expectedErrorMessageNew, actualErrorMessageNew, "failed ..."); }
public void GenerateCrozzleXmlTest() { var d = new XmlDocument(); var setted = true; var crozzle = new Crozzle(); for (int i = 0; i < 10; i++) { var row = new Row(); for (int j = 0; j < 10; j++) { var column = new Cell(); column.Character = setted ? "A" : "<![CDATA[ ]]> "; row.Cells.Add(column); setted = !setted; } crozzle.Rows.Add(row); } var xmlSerizlizer = new XmlSerializer(typeof(Crozzle)); xmlSerizlizer.Serialize(Console.Out, crozzle); }
// Import files for testing public void setAttributes() { String wordListPath1 = ".\\UploadedFiles\\.\\Test1.seq"; String wordListPath2 = ".\\UploadedFiles\\.\\Test2.seq"; String wordListPath3 = ".\\UploadedFiles\\.\\Test3.seq"; String configurationPath1 = ".\\UploadedFiles\\.\\Test1.cfg"; String configurationPath2 = ".\\UploadedFiles\\.\\Test2.cfg"; String configurationPath3 = ".\\UploadedFiles\\.\\Test3.cfg"; String crozzlePath1 = ".\\UploadedFiles\\Test1.czl"; String crozzlePath2 = ".\\UploadedFiles\\Test2.czl"; String crozzlePath3 = ".\\UploadedFiles\\Test3.czl"; Configuration.TryParse(configurationPath1, out aConfiguration1); Configuration.TryParse(configurationPath2, out aConfiguration2); Configuration.TryParse(configurationPath3, out aConfiguration3); WordList.TryParse(wordListPath1, aConfiguration1, out aWordList1); WordList.TryParse(wordListPath2, aConfiguration2, out aWordList2); WordList.TryParse(wordListPath3, aConfiguration3, out aWordList3); Crozzle.TryParse(crozzlePath1, aConfiguration1, aWordList1, out aCrozzle1); Crozzle.TryParse(crozzlePath2, aConfiguration2, aWordList2, out aCrozzle2); Crozzle.TryParse(crozzlePath3, aConfiguration3, aWordList3, out aCrozzle3); }
private void Reset() { _headerIsSet = _wordsDictionaryIsSet = false; _crozzle = new Crozzle(); }
public void TestMethod8() { // Arrange. string myCrozzleFile = @"C:\SIT323_Assignment1\Old Program and Old Files\Test 1 Crozzle.txt"; string myWordlistFile = @"C:\SIT323_Assignment1\Old Program and Old Files\Test 1 Wordlist.txt"; string myConfigFile = @"C:\SIT323_Assignment1\Old Program and Old Files\Test 1 Configuration.txt"; string myCrozzleFile2 = @"C:\SIT323_Assignment1\Old Program and Old Files\unitTest8\Test 1 Crozzle_scoreNewWords.txt"; string myWordlistFile2 = @"C:\SIT323_Assignment1\Old Program and Old Files\unitTest8\Test 1 Wordlist_scoreNewWords.txt"; string myConfigFile2 = @"C:\SIT323_Assignment1\Old Program and Old Files\unitTest8\Test 1 Configuration.txt"; //TEST 1 - Saving files after the validate method Configuration config; Configuration.TryParse(myConfigFile, out config); WordList wordlist; WordList.TryParse(myWordlistFile, config, out wordlist); Crozzle crozzle; Crozzle.TryParse(myCrozzleFile, config, wordlist, out crozzle); crozzle.Validate(); //Save toStringHTML() result to text file StreamWriter writer = new StreamWriter(@"C:\SIT323_Assignment1\Old Program and Old Files\unitTest8\html.txt"); writer.Write(crozzle.ToStringHTML()); writer.Close(); //Load the HTML file to a string StreamReader reader = new StreamReader(@"C:\SIT323_Assignment1\Old Program and Old Files\unitTest8\html.txt"); string expectedAfterValidate = reader.ReadToEnd(); reader.Close(); //TEST 2 - Saving files before the validate method Crozzle crozzle2; Crozzle.TryParse(myCrozzleFile, config, wordlist, out crozzle2); StreamWriter writer2 = new StreamWriter(@"C:\SIT323_Assignment1\Old Program and Old Files\unitTest8\html2.txt"); writer2.Write(crozzle2.ToStringHTML()); writer2.Close(); StreamReader reader2 = new StreamReader(@"C:\SIT323_Assignment1\Old Program and Old Files\unitTest8\html2.txt"); string expectedBeforeValidate = reader2.ReadToEnd(); reader2.Close(); //TEST 3 - Files with new Score and seeing that the expected HTML score matches that of the actual new HTML score Configuration config3; Configuration.TryParse(myConfigFile2, out config3); WordList wordlist3; WordList.TryParse(myWordlistFile2, config3, out wordlist3); Crozzle crozzle3; Crozzle.TryParse(myCrozzleFile2, config3, wordlist3, out crozzle3); crozzle3.Validate(); StreamWriter writer3 = new StreamWriter(@"C:\SIT323_Assignment1\Old Program and Old Files\unitTest8\html3.txt"); writer3.Write(crozzle3.ToStringHTML()); writer3.Close(); StreamReader reader3 = new StreamReader(@"C:\SIT323_Assignment1\Old Program and Old Files\unitTest8\html3.txt"); string expectedNewHTML = reader3.ReadToEnd(); reader3.Close(); // Act. string actualAfterValidate = crozzle.ToStringHTML(); string actualBeforeValidate = crozzle2.ToStringHTML(); string actualNewHTML = crozzle3.ToStringHTML(); crozzle2.Validate(); // Assert. Assert.AreEqual(expectedAfterValidate, actualAfterValidate, "failed ..."); Assert.AreEqual(expectedBeforeValidate, actualBeforeValidate, "failed ..."); Assert.AreEqual(expectedNewHTML, actualNewHTML, "failed ..."); }
public void TestMethod6() { // Arrange. string myCrozzleFile = @"C:\SIT323_Assignment1\Old Program and Old Files\Test 1 Crozzle.txt"; string myWordlistFile = @"C:\SIT323_Assignment1\Old Program and Old Files\Test 1 Wordlist.txt"; string myConfigFile = @"C:\SIT323_Assignment1\Old Program and Old Files\Test 1 Configuration.txt"; Configuration config; Configuration.TryParse(myConfigFile, out config); WordList wordlist; WordList.TryParse(myWordlistFile, config, out wordlist); Crozzle crozzle; Crozzle.TryParse(myCrozzleFile, config, wordlist, out crozzle); CrozzleSequences crozzleSequences = new CrozzleSequences(crozzle.CrozzleRows, crozzle.CrozzleColumns, config); //SECOND FILES - Files changed so that there are two "RON" with valid config file max duplcates capped a 2. string myCrozzleFile2 = @"C:\SIT323_Assignment1\Old Program and Old Files\unitTest6\Test 1 Crozzle_checkDuplicates.txt"; string myWordlistFile2 = @"C:\SIT323_Assignment1\Old Program and Old Files\unitTest6\Test 1 Wordlist_checkDuplicates.txt"; string myConfigFile2 = @"C:\SIT323_Assignment1\Old Program and Old Files\unitTest6\Test 1 Configuration_checkDuplicates.txt"; Configuration config2; Configuration.TryParse(myConfigFile2, out config2); WordList wordlist2; WordList.TryParse(myWordlistFile2, config2, out wordlist2); Crozzle crozzle2; Crozzle.TryParse(myCrozzleFile2, config2, wordlist2, out crozzle2); CrozzleSequences crozzleSequences2 = new CrozzleSequences(crozzle2.CrozzleRows, crozzle2.CrozzleColumns, config2); //Third Test - Files changed so that there are two "RON" but with config max duplicates capped at 1. string myCrozzleFile3 = @"C:\SIT323_Assignment1\Old Program and Old Files\unitTest6\Test 1 Crozzle_checkDuplicates.txt"; string myWordlistFile3 = @"C:\SIT323_Assignment1\Old Program and Old Files\unitTest6\Test 1 Wordlist_checkDuplicates.txt"; string myConfigFile3 = @"C:\SIT323_Assignment1\Old Program and Old Files\Test 1 Configuration.txt"; Configuration config3; Configuration.TryParse(myConfigFile3, out config3); WordList wordlist3; WordList.TryParse(myWordlistFile3, config3, out wordlist3); Crozzle crozzle3; Crozzle.TryParse(myCrozzleFile3, config3, wordlist3, out crozzle3); CrozzleSequences crozzleSequences3 = new CrozzleSequences(crozzle3.CrozzleRows, crozzle3.CrozzleColumns, config3); bool expectedFalseErrors = false; bool expectedFalseErrorsNew = false; bool expectedTrueErrorsNew = true; // Act. crozzleSequences.CheckDuplicateWords(1, 1); crozzleSequences2.CheckDuplicateWords(1, 2); crozzleSequences3.CheckDuplicateWords(1, 1); bool actualFalseErrors = crozzleSequences.ErrorsDetected; bool actualFalseErrorsNew = crozzleSequences2.ErrorsDetected; bool actualTrueErrorsNew = crozzleSequences3.ErrorsDetected; // Assert. Assert.AreEqual(expectedFalseErrors, actualFalseErrors, "failed ..."); Assert.AreEqual(expectedFalseErrorsNew, actualFalseErrorsNew, "failed ..."); Assert.AreEqual(expectedTrueErrorsNew, actualTrueErrorsNew, "failed ..."); }
private void btnSelectCrozzle_Click(object sender, EventArgs e) { CrozzleFound = false; OpenFileDialog openFileDialog = new OpenFileDialog(); openFileDialog.InitialDirectory = "."; openFileDialog.FilterIndex = 2; openFileDialog.RestoreDirectory = true; openFileDialog.Title = "Select the Crozzle file to Load..."; openFileDialog.Filter = "txt files (*.txt)|*.txt"; if (openFileDialog.ShowDialog() == DialogResult.OK) { string tempName = openFileDialog.FileName; if (File.Exists(tempName)) { try { crozzle = new Crozzle(tempName); if (crozzle.ValidFile) { validCrozzleUpdateUI(); } else { gridCrozzle.Rows.Clear(); MessageBox.Show("Invalid crozzle file! Check the log for details."); } } catch (Exception ex) { LogFile.WriteLine(ex.Message); return; } } } }
private void btnValidate_Click(object sender, EventArgs e) { if ((CrozzleFound && WordlistFound)) { if (crozzle.ValidFile && wordlist.ValidFile) { if (wordlist.Height == crozzle.Height && wordlist.Width == crozzle.Width) { try { Crozzle ValidatedCrozzle = CrozzleValidation.Validate(crozzle, wordlist); if (ValidatedCrozzle != null) { crozzle = ValidatedCrozzle; string score = CrozzleValidation.GetScore(crozzle, wordlist).ToString(); lblScore.Text = score; #if DEBUG LogFile.WriteLine("\t[INFO] Crozzle is Valid! Score: {0}", score); #endif } else { LogFile.WriteLine("\t[!ERROR!] Crozzle is Invalid!"); lblScore.Text = "-1"; } } catch (Exception ex) { LogFile.WriteLine(ex.Message); lblScore.Text = "-1"; return; } } else { LogFile.WriteLine("\t[!ERROR!] Word list Dimensions do not match Crozzle Dimensions ([{0},{1}] != [{2},{3}])", wordlist.Width, crozzle.Width, wordlist.Height, crozzle.Height ); lblScore.Text = "-1"; } } else { MessageBox.Show("One or more of your files did not pass validation!"); lblScore.Text = "-1"; } } else { MessageBox.Show("You must select both a crozzle and a word list to perform validation!"); lblScore.Text = "-1"; } }
public CrozzleGUI() { InitializeComponent(); crozzle = new Crozzle(); }
private void GetBest() { Crozzle BestCrozzle = null; int BestScore = 0; List<Crozzle> HoriCrozzleList = HoriGenerator.Finalise(); List<Crozzle> VertCrozzleList = VertGenerator.Finalise(); List<Crozzle> MasterList = HoriCrozzleList.Concat(VertCrozzleList).ToList(); this.Invoke((MethodInvoker)delegate { lblTimer.Text = "Finding best score... 0/" + MasterList.Count.ToString(); progTimer.Maximum = MasterList.Count; progTimer.Step = 1; progTimer.Value = 0; }); int counter = 0; foreach (Crozzle crozz in MasterList) { counter++; ////////////////////////// crozzle = crozz; this.Invoke((MethodInvoker)delegate { lblTimer.Text = "Finding best score... " + counter + "/" + MasterList.Count.ToString(); lblScore.Text = BestScore.ToString(); validCrozzleUpdateUI(); progTimer.PerformStep(); this.Refresh(); }); ////////////////////////// Crozzle scoredCrozzle = CrozzleValidation.Validate(crozz, wordlist); if (scoredCrozzle != null) { int CurrentScore = CrozzleValidation.GetScore(scoredCrozzle, wordlist); if (CurrentScore > BestScore) { CrozzleArray temp = crozz.ToCrozzleArray(); BestCrozzle = new Crozzle(temp._crozzleGrid); BestScore = CurrentScore; } } } this.Invoke((MethodInvoker)delegate { crozzle = BestCrozzle; lblScore.Text = BestScore.ToString(); progTimer.Visible = false; progTimer.Maximum = FIVEMINUTES; progTimer.Step = 1; progTimer.Value = 0; lblTimer.Visible = false; lblTimer.Text = "5:00"; this.UseWaitCursor = false; validCrozzleUpdateUI(); }); }
public static Crozzle Validate(Crozzle crozzle, Wordlist wordlist) { CrozzleToValidate = crozzle; WordlistToValidate = wordlist; CrozzleToValidate.Words = new Dictionary<string, WordLocation>(); CrozzleToValidate.HorizontalWords = new List<string>(); CrozzleToValidate.VerticalWords = new List<string>(); #if DEBUG Stopwatch sw = new Stopwatch(); sw.Start(); #endif bool Valid = true; for (int y = 0; y < CrozzleToValidate.Height; y++) { for (int x = 0; x < CrozzleToValidate.Width; x++) { if (isLetter(CrozzleToValidate[x, y])) // Current Cell is letter { if (x + 1 < CrozzleToValidate.Width && isLetter(CrozzleToValidate[x + 1, y])) // Not far right column AND next cell is a Letter { if (x == 0 || isNotLetter(CrozzleToValidate[x - 1, y])) // Is far Left column OR previous cell is not a Letter (Prevents checking end of completed words) { string wordIn = traverseHori(x, y); if (wordIn != null) { CrozzleToValidate.Words.Add(wordIn, new WordLocation(x, y)); CrozzleToValidate.HorizontalWords.Add(wordIn); } else { Valid = Valid & false; } } } if (y + 1 < CrozzleToValidate.Height && isLetter(CrozzleToValidate[x, y + 1])) // Not bottom row AND cell below is a Letter { if (y == 0 || isNotLetter(CrozzleToValidate[x, y - 1])) // Is top row OR previous cell is not a Letter (Prevents checking end of completed words) { string wordIn = traverseVert(x, y); if (wordIn != null) { CrozzleToValidate.Words.Add(wordIn, new WordLocation(x, y)); CrozzleToValidate.VerticalWords.Add(wordIn); } else { Valid = Valid & false; } } } } } } Valid = Valid & checkIntersections(); if (wordlist.Difficulty == "EXTREME") { Valid = Valid & contigiousCheck(); } #if DEBUG sw.Stop(); LogFile.WriteLine("\t[INFO] Validation Complete in {0}ms!", sw.ElapsedMilliseconds); #endif if (Valid) return CrozzleToValidate; else return null; }
public static int GetScore(Crozzle crozz, Wordlist wordl) { CrozzleToValidate = crozz; WordlistToValidate = wordl; int runningTotal = 0; if (WordlistToValidate.Difficulty != "EXTREME") { for (int y = 0; y < CrozzleToValidate.Height; y++) { for (int x = 0; x < CrozzleToValidate.Width; x++) { char currentChar = CrozzleToValidate[x, y]; if (isLetter(currentChar)) runningTotal += getLetterScore(currentChar); } } if (WordlistToValidate.Difficulty == "HARD") { runningTotal += (CrozzleToValidate.Words.Count * 10); } } else { foreach (string wordH in CrozzleToValidate.HorizontalWords) { CrozzleWord cwH = new CrozzleWord(wordH, CrozzleToValidate.Words[wordH]); foreach (CrozzleWord cwV in CrozzleToValidate.IntersectedWords[wordH]) { int foundX = -1; for (int i = cwH.X; i < cwH.X + cwH.Length; i++) { if (i == cwV.X) { foundX = i; break; } } int foundY = -1; for (int j = cwV.Y; j < cwV.Y + cwV.Length; j++) { if (j == cwH.Y) { foundY = j; break; } } if (foundX >= 0 && foundY >= 0) { runningTotal += getLetterScore(CrozzleToValidate[foundX, foundY]); } } } runningTotal += (CrozzleToValidate.Words.Count * 10); } return runningTotal; }