/// <summary> /// Generate the list of across word spaces. /// </summary> private void GenerateAcrossWordSpaces() { _wordSpaces = new List <WordSpace>(); for (int row = 0; row < _puzzleGrid[0].Length; ++row) { int endColumn; var startColumn = endColumn = 0; do { if (_puzzleGrid[endColumn][row] != BLOCK) { // Read word space. while (endColumn < _puzzleGrid.Length && _puzzleGrid[endColumn][row] != BLOCK) { ++endColumn; } int length = endColumn - startColumn; if (!_lengthGroups.ContainsKey(length)) { continue; } // We have an across word space. var word = new WordSpace() { Direction = Direction.Across, EndPoint = new Cell(endColumn - 1, row), Filled = false, Length = length, PossibleWords = _lengthGroups.ContainsKey(length) ? new List <string>(_lengthGroups[length]) : new List <string>(), StartPoint = new Cell(startColumn, row) }; _wordSpaces.Add(word); } else { // Skip over block sequence. while (endColumn < _puzzleGrid.Length && _puzzleGrid[endColumn][row] == BLOCK) { ++endColumn; } startColumn = endColumn; } } while (endColumn < _puzzleGrid.Length); } }
/// <summary> /// Generate the list of down word spaces. /// </summary> private void GenerateDownWordSpaces() { for (int column = 0; column < _puzzleGrid.Length; ++column) { int endRow; var startRow = endRow = 0; do { if (_puzzleGrid[column][endRow] == SPACE) { // Read word space. while (endRow < _puzzleGrid[0].Length && _puzzleGrid[column][endRow] != BLOCK) { ++endRow; } int length = endRow - startRow; if (!_lengthGroups.ContainsKey(length)) { continue; } // We have an across word space. var wordSpace = new WordSpace() { Direction = Direction.Down, EndPoint = new Cell(column, endRow - 1), Filled = false, Length = length, PossibleWords = _lengthGroups.ContainsKey(length) ? new List <string>(_lengthGroups[length]) : new List <string>(), StartPoint = new Cell(column, startRow) }; _wordSpaces.Add(wordSpace); } else // (puzzleGrid[column][endRow] == BLOCK) { // Skip over block sequence. while (endRow < _puzzleGrid[0].Length && _puzzleGrid[column][endRow] == BLOCK) { ++endRow; } startRow = endRow; } } while (endRow < _puzzleGrid[0].Length); } }
private void InvalidOperation(WordSpace wordSpace, string methodName) { throw new InvalidOperationException(methodName + " | All possible words were eliminated for word space at (" + wordSpace.StartPoint.Column + "," + wordSpace.StartPoint.Row + ") to (" + wordSpace.EndPoint.Column + "," + wordSpace.EndPoint.Row + ")."); }