Example #1
0
        public static void GenerateCrozzle(CrozzlePartial cp)
        {
            if (!Crozzle.aTimer.Enabled)
            {
                return;
            }
            List <Word> wordsToInsert = CanInsertWords(cp);
            int         length        = wordsToInsert.Count();

            if (length == 0)
            {
                // one crozzle is found
                if (cp.GetScore() > highScore)
                {
                    highScore = cp.GetScore();
                }
                else
                {
                    return;// return if the new crozzle's score is not high enough
                }
                if (PublicInfo.GetMinGroups() > 1)
                {
                    cp = SeperateGroups(cp);
                }
                if (cp.GetScore() > HighScoreCrozzle.GetScore())
                {
                    HighScoreCrozzle = cp;

                    // print score of crozzle
                    Console.WriteLine("===============================================================");
                    Console.WriteLine("New Highest Score: " + cp.GetScore());
                    Console.WriteLine("===============================================================");
                }
                return;
            }
            if (cp.GetUsedWord().Count >= PublicInfo.GetRows() && cp.GetUsedWord().Count <= PublicInfo.GetRows() + PublicInfo.GetColumns() && cp.GetScore() <= cp.GetUsedWord().Count *averageScorePerWord * 5 / 6)
            {
                return;
            }
            for (int i = 0; i < length; i++)
            {
                if (wordsToInsert[i].GetAddScore() < 0)
                {
                    continue;
                }
                CrozzlePartial c = InsertWord(cp, wordsToInsert[i], wordsToInsert[i].GetAddScore());
                GenerateCrozzle(c);
            }
        }
Example #2
0
        /// <summary>
        /// Seperate a one-group crozzle into multi-group crozzle
        /// </summary>
        /// <param name="cp">One-group crozzle</param>
        /// <returns>One multi-group crozzle</returns>
        public static CrozzlePartial SeperateGroups(CrozzlePartial cp)
        {
            int         bestScore     = 0;
            List <Word> bestUsedWords = new List <Word>();

            for (int i = 0; i < cp.GetUsedWord().Count; i++)
            {
                List <Word> usedWords = new List <Word>();
                for (int j = 0; j < cp.GetUsedWord().Count; j++)
                {
                    usedWords.Add(cp.GetUsedWord()[j]);
                }
                Word deleteWord = cp.GetUsedWord()[i];
                usedWords.Remove(cp.GetUsedWord()[i]);
                int groups;
                try
                {
                    WordGroupServiceClient ws;
                    string endpoint = "BasicHttpBinding_IWordGroupService";
                    ws = new WordGroupServiceClient(endpoint);
                    Grid     grid       = new Grid(PublicInfo.GetFullRows(), PublicInfo.GetFullColumns(), usedWords);
                    string[] stringGrid = ConvertToString(grid.GetGrid(), PublicInfo.GetFullRows(), PublicInfo.GetFullColumns());
                    groups = ws.Count(stringGrid);
                }
                catch
                {
                    // use local group calculation method if online method fail
                    groups = CalculateGroup(usedWords);
                }
                int score = CalculateScoreAfterRemovingAWord(cp, cp.GetUsedWord()[i]);
                if (groups >= PublicInfo.GetMinGroups() && groups <= PublicInfo.GetMaxGroups() && score > bestScore && CheckAllIntersections(usedWords))
                {
                    bestScore     = score;
                    bestUsedWords = usedWords;
                }
            }
            // generate a multi-groups crozzle with used words
            cp.SetUsedWord(bestUsedWords);
            cp.SetScore(bestScore);
            cp.SetGrid(new Grid(PublicInfo.GetFullRows(), PublicInfo.GetFullColumns(), bestUsedWords));
            return(cp);
        }