Ejemplo n.º 1
0
        //recursive search for where to add the new node
        private void AddR(ref Node N, CrozzleGrid grid)
        {
            int value = grid.GetScore();

            //recusive search on where to add the new node
            if (N == null)
            {
                //Node doesnt exist add it here
                Node NewNode = new Node(grid);
                N = NewNode; //set the old node ref to the newly create node and attach to tree
                return;      //end the function call and fall back
            }

            if (value < N.Grid.GetScore())
            {
                AddR(ref N.Left, grid);
                return;
            }

            if (value >= N.Grid.GetScore())
            {
                AddR(ref N.Right, grid);
                return;
            }
        }
Ejemplo n.º 2
0
        private CrozzleGrid Recursive(CrozzleGrid aGrid, WordListTaskTwo wordList)
        {
            while (aTimer.Enabled == true)
            {
                if (aGrid.GetWordlistCount() == 0)
                {
                    return(aGrid);
                }
                if (aGrid.GetRootWord() == "")
                {
                    aGrid.AddRootWord();
                    aGrid.AddWordToGrid();
                }
                else
                {
                    aGrid.AddWordToGrid();
                }
                if (aGrid.GetCounter() == 0)
                {
                    ListOfGrids.Add(aGrid); //not copying the obj, everytime it adds a new grid it overides the reference in the list
                    WordListTaskTwo freshWordlist = new WordListTaskTwo(wordList);
                    CrozzleGrid     bGrid         = new CrozzleGrid(aGrid, freshWordlist);

                    return(Recursive(bGrid, freshWordlist));
                }

                return(Recursive(aGrid, wordList));
            }

            return(aGrid);
        }
Ejemplo n.º 3
0
        public string DisplayGrid(CrozzleGrid game)
        {
            char[,] grid = game.Grid;
            String crozzleHTML = "";
            String style       = Config.Style;

            style += @"<style>
                       .empty { background-color: " + Config.BGcolourEmptyTD + @"; }
                       .nonempty { background-color: " + Config.BGcolourNonEmptyTD + @"; }
                       .border { background-color: black; }
                       </style>";

            crozzleHTML += @"<!DOCTYPE html><html><head>";
            crozzleHTML += style;
            crozzleHTML += @"</head><body>";
            crozzleHTML += @"<table>";

            for (int i = 0; i < grid.GetLength(0); i++)
            {
                crozzleHTML += @"<tr>";

                for (int j = 0; j < grid.GetLength(1); j++)
                {
                    if (grid[i, j] == '*')
                    {
                        crozzleHTML += @"<td hidden class=""border""></td>";
                    }
                    else if (grid[i, j] == 0)
                    {
                        crozzleHTML += @"<td class=""empty""></td>";
                    }
                    else
                    {
                        crozzleHTML += @"<td class=""nonempty"">" + grid[i, j] + @"</td>";
                    }
                }
                crozzleHTML += @"</tr>";
            }
            crozzleHTML += @"</table>";

            crozzleHTML += @"<p>Score = " + game.Score + @"</p>";

            if (game.Counter == 0)
            {
                crozzleHTML += @"<p>Cannot add any more words.</p>";
            }

            crozzleHTML += @"</body></html>";

            return(crozzleHTML);
        }
Ejemplo n.º 4
0
        //non recursive
        public void Add(CrozzleGrid grid)
        {
            int value = grid.GetScore();

            if (Root == null)
            {
                Node NewNode = new Node(grid);
                Root = NewNode;
                return;
            }
            Node currentnode = Root;
            bool added       = false;

            do
            {
                //traverse tree
                if (value < currentnode.Grid.GetScore())
                {
                    //go left
                    if (currentnode.Left == null)
                    {
                        //add the item
                        Node NewNode = new Node(grid);
                        currentnode.Left = NewNode;
                        added            = true;
                    }
                    else
                    {
                        currentnode = currentnode.Left;
                    }
                }

                if (value >= currentnode.Grid.GetScore())
                {
                    if (currentnode.Right == null)
                    {
                        Node NewNode = new Node(grid);
                        currentnode.Right = NewNode;
                        added             = true;
                    }
                    else
                    {
                        currentnode = currentnode.Right;
                    }
                }
            } while (!added);
        }
Ejemplo n.º 5
0
 public CrozzleGrid(CrozzleGrid copy, WordListTaskTwo wordCopy)
 {
     this.Config                    = copy.Config;
     this.WordList                  = wordCopy; //this needs to be a fresh wordlist minus the rootword in the previous grids
     this.RowsAndColumns            = copy.RowsAndColumns;
     this.Grid                      = CreateGrid();
     this.Score                     = GetScore();
     this.LetterCordsForWordsInGrid = new CordsWordTable();
     this.RootWord                  = "";
     this.WordsInGrid               = new List <string>();
     this.WordsInserted             = new List <LastWordEntered>();
     this.WordsInsertedInGrid       = new List <Word>();
     this.index                     = 0;
     this.Counter                   = 0;
     this.WordListInUse             = WordList.Table;
     this.PreviousRootWords         = copy.PreviousRootWords;
     this.NamesList                 = new List <string>();
 }
Ejemplo n.º 6
0
 public Node(CrozzleGrid grid)
 {
     Grid  = grid;
     Left  = null;
     Right = null;
 }
Ejemplo n.º 7
0
        private void OpenCrozzleAss2()
        {
            aTimer.Enabled = true;



            CrozzleTaskTwo config = new CrozzleTaskTwo(URLs.Task2Crozzle);
            // string configurationFileName = GetConfigurationFileName(URLs.Task2Crozzle);

            //validate configuration file.
            Configuration aConfiguration = null;

            Configuration.TryParseTaskTwo(config.ConfigurationURL, out aConfiguration);

            // Parse wordlist file.
            WordListTaskTwo wordList = new WordListTaskTwo(config.WordlistURL);

            //WordList.TryParseTaskTwo(config.WordlistURL, aConfiguration, out wordList);

            //char[,] grid = new char[Convert.ToInt16(config.Rows), Convert.ToInt16(config.Columns)];

            CrozzleGrid aGrid = new CrozzleGrid(aConfiguration, wordList, config);

            aGrid.AddRootWord();
            //aGrid.AddFirstWord();

            //Tree aTree = new Tree(aGrid);
            //aGrid.AddNameToGrid();

            //while (aTimer.Enabled = true || aGrid.GetWordlistCount() > 0)
            //{

            //}

            Recursive(aGrid, wordList);


            //aGrid.AddWordToGrid();
            //aTree.Add(aGrid);
            //aGrid.AddWordToGrid();
            //aGrid.AddWordToGrid();
            //aGrid.AddWordToGrid();
            //aGrid.AddWordToGrid();



            //ListOfGrids.Sort((x, y) => x.Score.CompareTo(y.OrderDate));

            //ListOfGrids.Sort()


            var maxObject = ListOfGrids.OrderByDescending(item => item.Score).First();

            string res = aGrid.DisplayGrid(maxObject);

            //string res = aGrid.CreateGrid();

            crozzleWebBrowser.DocumentText = res;

            //string res = aGrid.DisplayGrid(aGrid);
            ////string res = aGrid.CreateGrid();

            //crozzleWebBrowser.DocumentText = res;
        }
Ejemplo n.º 8
0
 //recursive
 public void AddRecursive(CrozzleGrid grid)
 {
     AddR(ref Root, grid);
 }
Ejemplo n.º 9
0
 //constructor assign the node to the root of tree
 public Tree(CrozzleGrid grid)
 {
     Root = new Node(grid);
 }