public char[,] AddRootWord() { var dictList = WordList.Table; Dictionary <string, int> bestWordDict = new Dictionary <string, int>(); Dictionary <char, int> points = new Dictionary <char, int>(); //int scoreWords = 0; CordsLetterTable cl = new CordsLetterTable(); char keyindic = 'A'; int x = 0; int y = 0; int startX = 0; int startY = 0; string highestWord = ""; char[] wordCharArray = new char[0]; //put the points table into a dictionary foreach (var val in Config.IntersectingPointsPerLetter) { points.Add(keyindic, val); keyindic++; } //get random name from wordlist foreach (var n in dictList) { NamesList.Add(n.Key); } bool OK = false; while (OK == false) { int r = rnd.Next(NamesList.Count); highestWord = NamesList[r]; int lengthOfWord = highestWord.Length; //set the cords of the grid so the word is placed in the centre int row = Convert.ToInt16(RowsAndColumns.Rows); int col = Convert.ToInt16(RowsAndColumns.Columns); x = rnd.Next(2, row); y = rnd.Next(2, col); startX = x; startY = y; //create a char arrayu of the name wordCharArray = highestWord.ToCharArray(); for (int a = 0; a < wordCharArray.Length; a++) //foreach(var l in wordCharArray) { if (Grid[x, y] == '*') { OK = false; break; } else { OK = true; y = y + 1; continue; } } } //add the word to the grid foreach (var letter in wordCharArray) { Grid[startX, startY] = letter; Coordinate c = new Coordinate(startX, startY); cl.Add(c, letter); startY = startY + 1; } //add the name, letters and coords of each letter to the table //add properties to the object LetterCordsForWordsInGrid.Add(highestWord, cl); Score = LetterCordsForWordsInGrid.Keys.Count * Config.PointsPerWord; var objKey = WordList.Table[highestWord]; Dictionary <char, List <string> > objDict = new Dictionary <char, List <string> >(); foreach (var key in objKey) { objDict.Add(key.Key, key.Value); } var cor = LetterCordsForWordsInGrid[highestWord]; Dictionary <Coordinate, char> objCor = new Dictionary <Coordinate, char>(); foreach (var res in cor) { objCor.Add(res.Key, res.Value); } LastWordEntered wordObj = new LastWordEntered(highestWord, objDict, objCor); WordsInserted.Add(wordObj); WordList.Table.Remove(highestWord); RootWord = highestWord; WordsInGrid.Add(highestWord); Counter++; return(Grid); }
public char[,] AddWordToGrid() { List <LastWordEntered> copyWordsInserted = WordsInserted.ToList(); List <string> namesInserted = new List <string>(); foreach (var n in copyWordsInserted) { namesInserted.Add(n.Name); } foreach (var entry in copyWordsInserted) { string nameEntered = entry.Name; Counter = 0; Dictionary <char, int> points = new Dictionary <char, int>(); IndexedDictionary <char, List <string> > intersectingWords = new IndexedDictionary <char, List <string> >(); List <string> wordsThatIntersectOnAChar = new List <string>(); char keyindic = 'A'; char[,] grid = Grid; IndexOutOfRangeException outOfBounds = new IndexOutOfRangeException(); //put the points table into a dictionary foreach (var val in Config.IntersectingPointsPerLetter) { points.Add(keyindic, val); keyindic++; } Dictionary <Coordinate, char> allCoordsInGridWords = entry.LetterCords; Dictionary <char, List <string> > inwords = entry.IntersectingWords; Dictionary <char, Coordinate> coordsinExistingLetter = entry.LetterCoordsForIntersectingWords; int i; for (i = 0; i < allCoordsInGridWords.Count; i++) { var testName = entry.Name; var letterInExistingWord = allCoordsInGridWords.ElementAt(i).Value; var cords = allCoordsInGridWords.ElementAt(i).Key; wordsThatIntersectOnAChar = inwords[letterInExistingWord]; CheckNames(wordsThatIntersectOnAChar, letterInExistingWord, points, entry, testName, namesInserted, cords); if (lett.Added == false) { continue; } else { //add the name, letters and coords of each letter to the table //add properties to the object var objKey = WordList.Table[lett.Name]; Dictionary <char, List <string> > objDict = new Dictionary <char, List <string> >(); foreach (var key in objKey) { objDict.Add(key.Key, key.Value); } var cor = lett.AllCoordinatesOfLettersInName; Dictionary <Coordinate, char> objCor = new Dictionary <Coordinate, char>(); foreach (var res in cor) { objCor.Add(res.Key, res.Value); } LastWordEntered nameWord = new LastWordEntered(lett.Name, objDict, objCor); WordsInserted.Add(nameWord); WordList.Table.Remove(lett.Name); WordsInGrid.Add(lett.Name); wordsThatIntersectOnAChar.Remove(lett.Name); Counter++; } } WordsInserted.Remove(entry); continue; } return(Grid); }