Ejemplo n.º 1
0
        /// <summary>
        /// A pretty simple method to check if there are certain cells that must be filled in regardless of clue position
        /// </summary>
        /// <remarks>
        /// If the clues are positioned as far left as they can go and then as far right as they can go there may be
        /// certain cells that will always be covered.
        /// For example, in an element of 15 cells a clue of length 10 will always cover cells 5 to 9
        /// </remarks>

        private static int Overlap(Grid grid, Clues clues, Blocks blocks, Spaces spaces, int element, int elementLength, bool isRow)
        {
            int filled    = 0;
            int firstFree = grid.GetFirstFreeCell(element, isRow);
            int lastFree  = grid.GetLastFreeCell(element, isRow);
            int rowToUpdate;
            int colToUpdate;

            //For a given space, find the clues that HAVE to be in that space and check limits
            for (int spaceNo = 0; spaceNo < spaces.getSpaceCount(); spaceNo++)
            {
                Clues cluesToTest = FindFewestClues(spaces, clues, spaceNo);
            }

            for (int clueNo = 0; clueNo < clues.GetClueCount(); clueNo++)
            {
                //this needs adapted to take account of filled cells
                int endClueLeft    = firstFree - 1 + clues.GetClueLength(0, clueNo);
                int startClueRight = lastFree + 1 - clues.GetClueLength(clueNo, clues.GetClueCount() - 1);
                if (startClueRight <= endClueLeft)
                {
                    for (int cellNo = startClueRight; cellNo <= endClueLeft; cellNo++)
                    {
                        rowToUpdate = (isRow) ? element : cellNo;
                        colToUpdate = (isRow) ? cellNo : element;
                        if (Update(grid, colToUpdate, rowToUpdate, clues.getClue(clueNo).Colour))
                        {
                            filled += 1;
                        }
                    }
                }
            }
            return(filled);
        }