Exemple #1
0
        /// <summary>
        /// Expects a nested array with the first dimension representing the rows/columns, and the second dimension representing the hints for each of those rows/columns.
        /// For example, [[1], [1,2], [3]] represents a HintCollection with 3 Rows or Columns, with "1" being the hint for the first, "1,2" for the second and "3" for the third.
        /// </summary>
        /// <param name="hints"></param>
        /// <returns></returns>
        public static HintCollection From2DArray(int[][] hints)
        {
            if (hints == null)
            {
                throw new ArgumentNullException(nameof(hints));
            }

            var coll = new HintCollection(hints.Length);

            for (int i = 0; i < hints.Length; i++)
            {
                var data = hints[i];
                if (data.Length == 0)
                {
                    data = new int[] { 0 };
                }

                coll[i] = new int[data.Length];
                for (int j = 0; j < data.Length; j++)
                {
                    coll.SetHintValue(i, j, data[j]);
                }
            }
            return(coll);
        }
Exemple #2
0
        /// <summary>
        /// Expects a string where each row/column is separated by space and each hint is separated by a comma.
        /// For example, "1 1,2 3" will result in 3 Rows or Columns, with "1", "1,2" and "3" being the hints for those.
        /// </summary>
        /// <param name="hintString"></param>
        /// <returns></returns>
        public static HintCollection FromString(string hintString)
        {
            if (hintString == null)
            {
                throw new ArgumentNullException(nameof(hintString));
            }

            var elems = hintString.Split(new char[] { ' ' }, StringSplitOptions.RemoveEmptyEntries);
            var coll  = new HintCollection(elems.Length);

            for (int i = 0; i < elems.Length; i++)
            {
                var data = elems[i].Split(',').Select(s => int.Parse(s)).ToArray();
                coll[i] = data;
            }
            return(coll);
        }
Exemple #3
0
        public Nonogram(string name, int rowCount, int colCount, HintCollection rowHints, HintCollection columnHints)
        {
            Name        = name ?? string.Empty;
            RowCount    = rowCount;
            ColumnCount = colCount;
            RowHints    = rowHints ?? throw new ArgumentNullException(nameof(rowHints));
            ColumnHints = columnHints ?? throw new ArgumentNullException(nameof(columnHints));

            if (RowHints.Count != RowCount)
            {
                throw new ArgumentException($"Expected hints for {RowCount} rows, but got {RowHints.Count} instead.");
            }

            if (ColumnHints.Count != ColumnCount)
            {
                throw new ArgumentException($"Expected hints for {ColumnCount} columns, but got {ColumnHints.Count} instead.");
            }
        }
Exemple #4
0
 public HintCollectionEnumerator(HintCollection hints)
 {
     _hints = hints;
     _index = -1;
 }
Exemple #5
0
 public Nonogram(string name, int rowCount, int colCount, string rowHintString, string colHintString) : this(name, rowCount, colCount, HintCollection.FromString(rowHintString), HintCollection.FromString(colHintString))
 {
 }
Exemple #6
0
 private static int MaxArrayLength(HintCollection hints) => hints.Count == 0 ? 0 : hints.Max(h => h.Length);