Esempio n. 1
0
        //Crozzle generation methods.
        private void getHighestScoringGrid()
        {
            //Create a WordData object we intend to place.
            WordData wordToPlace = null;

            //Checks both (HORIZONTAL_WORD = 0) and (VERTICAL_WORD = 1) word placement.
            for (int direction = 0; direction < 2; direction++)
            {
                //Start from the top left corner of the grix (x:0, y:0).
                for (int y = 0; y < crozzleGrid.RowSize; y++)
                {
                    for (int x = 0; x < crozzleGrid.ColumnSize; x++)
                    {
                        //Check if each word in the list fits the particular position.
                        foreach (WordData word in completeWordList)
                        {
                            //Create the first word placement.
                            wordToPlace = createFirstWordPlacement(word, x, y, direction);

                            //Add the first word to the grid.
                            crozzleGrid.addWordToGrid(wordToPlace);

                            //While a word can be found to connect to the previous word, add it to the grid.
                            while ((wordToPlace = createConnectingWordPlacement(wordToPlace)) != null)
                            {
                                crozzleGrid.addWordToGrid(wordToPlace);
                            }

                            //This solution can be further traversed and optimised here....


                            //Cache the highest scoring grid.
                            if (highScoreGrid == null || crozzleGrid.TotalScore > highScoreGrid.TotalScore)
                            {
                                highScoreGrid = crozzleGrid;
                            }

                            //Print each grid to the console (this significantly slows down the solution calculation).
                            //crozzleGrid.printGridToConsole();

                            //Create a new grid to use use for next grid generation
                            crozzleGrid = new CrozzleGrid(crozzleGrid.RowSize, crozzleGrid.ColumnSize, crozzleGrid.Difficulty);
                        }
                    }
                }
            }
        }
Esempio n. 2
0
        /// <summary>
        /// This method builts a new crozzle after reading the files from the given destination.
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void getCrozzleBTN_Click(object sender, EventArgs e)
        {
            crozzle = new CrozzleGrid(addressesCB.Text);
            try
            {
                crozzle.ReadCrozzle();
                MyTimer          = new System.Timers.Timer(crozzle.Config.RUNTIME_LIMIT * 1000);
                MyTimer.Elapsed += MyTimer_Elasped;
                MyTimer.Start();
                while (MyTimer.Enabled)
                {
                    crozzle.Fill();
                }

                string endpoint           = "BasicHttpBinding_IWordGroupService";
                WordGroupServiceClient ws = new WordGroupServiceClient(endpoint);
                int NumberOfGroups        = ws.Count(crozzle.GetGrid());
                if (NumberOfGroups >= crozzle.Config.MINIMUM_NUMBER_OF_GROUPS && NumberOfGroups <= crozzle.Config.MAXIMUM_NUMBER_OF_GROUPS)
                {
                    string result = crozzle.GetHtmlTable();
                    int    score  = crozzle.CalculateScore();
                    result += "<br/><div><p><b> Score = " + score + "</b></p></div>";
                    webBrowser1.Navigate("about:blank");
                    HtmlDocument doc = webBrowser1.Document;
                    doc.Write(String.Empty);
                    webBrowser1.DocumentText = result;
                }
                else
                {
                    MessageBox.Show("Crozzle cannot be formed because valid number of groups were not formed");
                    string result = crozzle.GetHtmlTable();
                    result += "<br/><div><p><b> Invalid Crozzle is Generated !</b></p></div>";
                    webBrowser1.Navigate("about:blank");
                    HtmlDocument doc = webBrowser1.Document;
                    doc.Write(String.Empty);
                    webBrowser1.DocumentText = result;
                }
            }
            catch (Exception)
            {
                MessageBox.Show("Network Failure: Cannot Read Crozzle Configurations from the given address!");
            }
        }
Esempio n. 3
0
 private void button2_Click(object sender, EventArgs e)
 {
     openFileDialog1.FileName   = "";
     openFileDialog1.DefaultExt = "txt";
     openFileDialog1.Filter     = "Crozzle Files (*.czl)|*.czl";
     if (openFileDialog1.ShowDialog() != DialogResult.Cancel)
     {
         crozzle      = new CrozzleGrid();
         crozzle.Path = openFileDialog1.FileName;
         crozzle.ReadFile();
         crozzle.Load();
         crozzle.ReadWordsFromLocalFile();
         string result = crozzle.GetHtmlTable();
         int    score  = crozzle.CalculateScore();
         result += "<br/><div><p><b> Score = " + score + "</b></p></div>";
         webBrowser1.Navigate("about:blank");
         HtmlDocument doc = webBrowser1.Document;
         doc.Write(String.Empty);
         webBrowser1.DocumentText = result;
     }
 }
Esempio n. 4
0
        //Any validation code would go here, this example assumes all input is valid.
        private void validateCSVFile(String filename)
        {
            int           difficulty   = Constants.UNASSIGNED_DIFFICULTY;
            List <string> tempWordList = new List <string>();

            try
            {
                StreamReader sr            = new StreamReader(filename);
                Char[]       separator     = { ',' };
                String[]     line          = sr.ReadLine().Split(separator);
                int          field         = 0;
                int          numberOfWords = 0;
                int          wordCount     = 0;

                int rowSize    = 0;
                int columnSize = 0;

                foreach (String value in line)
                {
                    if (field == 0)
                    {
                        int number = Convert.ToInt32(value);
                        numberOfWords = number;
                    }
                    else if (field == 1)
                    {
                        int number = Convert.ToInt32(value);
                        rowSize = number;
                    }
                    else if (field == 2)
                    {
                        int number = Convert.ToInt32(value);
                        columnSize = number;
                    }
                    else if (field == 3)
                    {
                        if (String.Equals(value.ToUpper(), "EASY") == true)
                        {
                            difficulty = Constants.EASY_DIFFICULTY;
                        }
                        else if (String.Equals(value.ToUpper(), "MEDIUM") == true)
                        {
                            difficulty = Constants.MEDIUM_DIFFICULTY;
                        }
                        else if (String.Equals(value.ToUpper(), "HARD") == true)
                        {
                            difficulty = Constants.HARD_DIFFICULTY;
                        }
                        else if (String.Equals(value.ToUpper(), "EXTREME") == true)
                        {
                            difficulty = Constants.EXTREME_DIFFICULTY;
                        }
                    }
                    else
                    {
                        wordCount++;
                        tempWordList.Add(value);
                    }
                    field++;
                }

                sr.Close();

                //Create a new grid.
                crozzleGrid = new CrozzleGrid(rowSize, columnSize, difficulty);
                buildWordData(tempWordList);

                //Enable generation button.
                btnSolveGame.Enabled = true;
            }
            catch (System.IO.IOException)
            {
                MessageBox.Show("Error: File open, please close the file and try re-opening.");
            }
        }