예제 #1
0
        public CrozzleCreation(Wordlist wordlist, bool direction)
        {
            currentWordlist = wordlist;
            FirstDirection = direction;

            currentCrozzle = new CrozzleArray(wordlist.Height, wordlist.Width);
            GeneratedList = new List<Crozzle>();

            ScoredWordlist tempScoredList = new ScoredWordlist(wordlist);
            WordsByScoreAll = new List<string>(wordlist.WordCount);
            WordsByScoreCurrent = new List<string>(wordlist.WordCount);
            foreach (CrozzleWord cw in tempScoredList)
            {
                WordsByScoreAll.Add(cw.Word);
                WordsByScoreCurrent.Add(cw.Word);
            }
        }
예제 #2
0
        private List<CrozzleWord> sortScoreList(Wordlist currentWordlist)
        {
            string Difficulty = currentWordlist.Difficulty;
            if (Difficulty != "EXTREME") Difficulty = "HARD";
            List<CrozzleWord> wordScores = new List<CrozzleWord>(currentWordlist.WordCount);
            foreach (string word in currentWordlist)
            {
                wordScores.Add(new CrozzleWord(word, CrozzleValidation.GetWordScore(Difficulty, word)));
            }

            List<CrozzleWord> result = wordScores.OrderByDescending(s => s.Score).ThenBy(s => s.Score).ToList();

            if (result.Count > 1)
            {
                CrozzleWord ts = result[0];
                result[0] = result[1];
                result[1] = ts;
            }

            return result;
        }
예제 #3
0
 public ScoredWordlist(Wordlist wl)
 {
     sortedByScore = sortScoreList(wl);
 }
예제 #4
0
        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;
        }
예제 #5
0
        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;
        }
예제 #6
0
        private void btnSelectWordlist_Click(object sender, EventArgs e)
        {
            WordlistFound = false;
            OpenFileDialog openFileDialog = new OpenFileDialog();
            openFileDialog.InitialDirectory = ".";
            openFileDialog.FilterIndex = 2;
            openFileDialog.RestoreDirectory = true;

            openFileDialog.Title = "Select the Word list file to load...";
            openFileDialog.Filter = "csv files (*.csv)|*.csv";
            if (openFileDialog.ShowDialog() == DialogResult.OK)
            {
                string tempName = openFileDialog.FileName;
                if (File.Exists(tempName))
                {
                    try
                    {
                        wordlist = new Wordlist(tempName);

                        if (wordlist.ValidFile)
                        {
                            listCrozzle_LoadData();
                        }
                        else
                        {
                            listCrozzle.Items.Clear();
                            MessageBox.Show("Invalid Word list file! Check the log for details.");
                        }

                        WordlistFound = true;
                    }
                    catch (Exception ex)
                    {
                        LogFile.WriteLine(ex.Message);
                        return;
                    }
                }
            }
        }