Ejemplo n.º 1
0
        /// <summary>
        /// Attempts to generate results for a specific column
        /// </summary>
        /// <param name="column">column index</param>
        /// <returns>False if an error was found. Else true</returns>
        private bool InitColumn(int column)
        {
            int[] colArr = _ng.GetColumnArray(column);
            if (_ng.Height - (colArr.Sum() + colArr.Length - 1) == 0)
            {
                return(FullColumn(column, colArr));
            }
            int[] colInts = new int[_ng.Height];
            int   idx     = 0;

            for (int i = 0; i < colArr.Length; i++)
            {
                for (int j = 0; j < colArr[i]; j++)
                {
                    colInts[idx] = i + 1;
                    idx++;
                }
                idx++;
            }
            idx = _ng.Height - 1;
            for (int i = colArr.Length - 1; i >= 0; i--)
            {
                for (int j = 0; j < colArr[i]; j++)
                {
                    if (colInts[idx] == i + 1 && !_marked[idx][column].HasValue)
                    {
                        _results.Add(new Result(idx, column, true));
                    }
                    else if (_marked[idx][column].HasValue && !_marked[idx][column].Value)
                    {
                        return(false);
                    }
                    idx--;
                }
                idx--;
            }
            return(true);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Evaluates the specified column
        /// </summary>
        /// <param name="index">column index</param>
        /// <returns>False if a contradiction is encountered</returns>
        private bool FillColumn(int index)
        {
            bool solved = true;

            for (int i = 0; i < _ng.Height; i++)
            {
                if (!_ng.Resolved(i, index))
                {
                    solved = false;
                    break;
                }
            }
            if (solved)
            {
                return(true);
            }
            int[] leftInts = new int[_ng.Height];
            if (!ColLeft(index, leftInts, 0, 0))
            {
                return(false);
            }
            int[] rightInts = new int[_ng.Height];
            ColRight(index, rightInts, _ng.GetColumnArray(index).Length - 1, _ng.Height - 1);
            for (int i = 0; i < leftInts.Length; i++)
            {
                if (leftInts[i] == rightInts[i] && !_ng.Resolved(i, index))
                {
                    bool state = leftInts[i] % 2 == 0;
                    _rowChanged[i]     = true;
                    _colChanged[index] = true;
                    _resultList.Add(new Result(i, index, state));
                    _ng.Set(i, index, state);
                }
            }
            return(true);
        }