/// <summary> /// Randomize/reset all crosses /// </summary> public void Shuffle() { Items.Clear(); HorizontalSequences.Clear(); VerticalSequences.Clear(); int probability = settings.GetCrossProbability(); for (int i = 0; i < settings.Rows; i++) { IList <Item> row = new List <Item>(); for (int j = 0; j < settings.Columns; j++) { bool crossed = random.Next(101) < probability; row.Add(new Item(i, j, crossed)); } Items.Add(row); HorizontalSequences.Add(new Sequence(row)); } for (int i = 0; i < settings.Columns; i++) { VerticalSequences.Add(new Sequence(Items.Column(i))); } }
private void AddHorizontalSequences(List <String[]> crozzleRows) { int rowNumber = 0; int columnIndex; String row; foreach (String[] crozzleRow in crozzleRows) { rowNumber++; columnIndex = 0; // Place all letters into one string, so that we can split it later. row = ""; foreach (String letter in crozzleRow) { row = row + letter; } // Use split to collect all sequences of letters. String[] letterSequences = row.Split(new char[] { ' ' }, StringSplitOptions.RemoveEmptyEntries); // Collect and store data about each letter sequence of length > 1, as a sequence of one letter is not a word. foreach (String sequence in letterSequences) { if (sequence.Length > 1) { // Set column values. int columnNumber = row.IndexOf(sequence, columnIndex) + 1; //////// check for duplicate word //////WordData duplicate = Sequences.Find(x => x.Letters.Equals(sequence)); //////if (duplicate != null) ////// ErrorMessages.Add("\"" + sequence + "\" at (" + rowNumber + ", " + columnNumber + ") already exists in the crozzle at (" + duplicate.Location.Row + ", " + duplicate.Location.Column + ")"); //////// Check that duplicate words are within limits. //////List<WordData> duplicates = Sequences.FindAll(x => x.Letters.Equals(sequence)); //////if (duplicates.Count < Configuration.MinimumNumberOfTheSameWord) ////// ErrorMessages.Add("\"" + sequence + "\" at (" + rowNumber + ", " + columnNumber + ") exists in the crozzle " + duplicates.Count + ////// " times, which is more than the limit of " + Configuration.MinimumNumberOfTheSameWord); //////if (duplicates.Count > Configuration.MaximumNumberOfTheSameWord) ////// ErrorMessages.Add("\"" + sequence + "\" at (" + rowNumber + ", " + columnNumber + ") exists in the crozzle " + duplicates.Count + ////// " times, which is more than the limit of " + Configuration.MaximumNumberOfTheSameWord); // Collect data about the word, and // update the index for the next substring search. WordData word = new WordData(WordData.OrientationRow, rowNumber, row.IndexOf(sequence, columnIndex) + 1, sequence); columnIndex = word.Location.Column - 1 + sequence.Length; // Store data about the word. Sequences.Add(word); HorizontalSequences.Add(word); } } } }
private void AddHorizontalSequences(List <String[]> crozzleRows) { int rowNumber = 0; int columnIndex; String row; foreach (String[] crozzleRow in crozzleRows) { rowNumber++; columnIndex = 0; // Place all letters into one string, so that we can split it later. row = ""; foreach (String letter in crozzleRow) { row = row + letter; } // Use split to collect all sequences of letters. String[] letterSequences = row.Split(new char[] { ' ' }, StringSplitOptions.RemoveEmptyEntries); // Collect and store data about each letter sequence of length > 1, as a sequence of one letter is not a word. foreach (String sequence in letterSequences) { if (sequence.Length > 1) { // Set column values. int columnNumber = row.IndexOf(sequence, columnIndex) + 1; // Collect data about the word, and // update the index for the next substring search. WordData word = new WordData(WordData.OrientationRow, rowNumber, row.IndexOf(sequence, columnIndex) + 1, sequence); columnIndex = word.Location.Column - 1 + sequence.Length; // Store data about the word. Sequences.Add(word); HorizontalSequences.Add(word); } } } }