Exemple #1
0
        /// <summary>
        /// spaces mast be
        /// </summary>
        /// <param name="cells">cells</param>
        /// <param name="startPosition">start cell of word</param>
        /// <param name="endPosition">end cell of word</param>
        /// <param name="orientationIndex">index of orientation, to determine cell correctly</param>
        /// <param name="orientation">word orientation <see cref="WordOrientation"/></param>
        /// <returns>true - spaces exists, otherwise - not</returns>
        public static bool DelimetedBySpaces(this List <Cell> cells, int startPosition, int endPosition, int orientationIndex, WordOrientation orientation)
        {
            Cell first, last;
            bool firstIsValid = false, lastIsValid = false, enoughSpace = true;

            foreach (var cell in cells)
            {
                if (cell.CharacterIsEmpty() || !cell.EnoughSpace)
                {
                    continue;
                }

                var neighbors = cells.Where(c => (c.ColumnIndex == cell.GetNeighborColumn(NeighborOrientation.Horizontal) && c.RowIndex == cell.GetNeighborRow(NeighborOrientation.Horizontal)) ||
                                            (c.ColumnIndex == cell.GetNeighborColumn(NeighborOrientation.Vertical) && c.RowIndex == cell.GetNeighborRow(NeighborOrientation.Vertical)) ||
                                            (c.ColumnIndex == cell.GetNeighborColumn(NeighborOrientation.Diagonal) && c.RowIndex == cell.GetNeighborRow(NeighborOrientation.Diagonal)))
                                .ToList();

                if (AllFilled(neighbors))
                {
                    enoughSpace = cell.EnoughSpace = false;
                }
            }

            if (orientation == WordOrientation.Horizontal)
            {
                first = cells.FirstOrDefault(cell => cell.ColumnIndex == startPosition - 1 && cell.RowIndex == orientationIndex);
                last  = cells.FirstOrDefault(cell => cell.ColumnIndex == endPosition && cell.RowIndex == orientationIndex);

                if (first == null && last == null)
                {
                    return(enoughSpace);
                }

                firstIsValid = first?.CharacterIsEmpty() ?? true;

                lastIsValid = last?.CharacterIsEmpty() ?? true;
            }

            if (orientation == WordOrientation.Vertical)
            {
                first = cells.FirstOrDefault(cell => cell.RowIndex == startPosition - 1 && cell.ColumnIndex == orientationIndex);
                last  = cells.FirstOrDefault(cell => cell.RowIndex == endPosition && cell.ColumnIndex == orientationIndex);

                if (first == null && last == null)
                {
                    return(enoughSpace);
                }

                firstIsValid = first?.CharacterIsEmpty() ?? true;

                lastIsValid = last?.CharacterIsEmpty() ?? true;
            }

            return(enoughSpace && firstIsValid && lastIsValid);
        }
Exemple #2
0
 public WordSet(WordOrientation orientation)
 {
     mIncidentalWords = new HashSet<WordLocation>();
     mOrientation = orientation;
 }