示例#1
0
        /// <summary>
        /// Converts the given <see cref="SudokuPuzzle"/> into a list of strings
        /// </summary>
        /// <param name="puzzle">The <see cref="SudokuPuzzle"/> being converted into a list of strings</param>
        /// <returns>A list of strings containing the <see cref="SudokuPuzzle"/></returns>
        public List <string> ConvertToStrings(SudokuPuzzle puzzle)
        {
            List <string> stringEquivalent = new List <string>();

            stringEquivalent.Add((puzzle.Dimension * puzzle.Dimension).ToString());
            StringBuilder symbolLineBuilder = new StringBuilder();

            for (int i = puzzle.CellMin; i <= puzzle.CellMax; ++i)
            {
                if (symbolLineBuilder.Length > 0)
                {
                    symbolLineBuilder.Append(' ');
                }

                symbolLineBuilder.Append(this.intToSymbolMap[i]);
            }

            stringEquivalent.Add(symbolLineBuilder.ToString());

            symbolLineBuilder.Clear();
            foreach (var row in puzzle.Rows)
            {
                foreach (Cell cell in row)
                {
                    if (symbolLineBuilder.Length > 0)
                    {
                        symbolLineBuilder.Append(' ');
                    }

                    int cellValue = 0;
                    if (cell.Count == 1)
                    {
                        cellValue = cell.AllowedValue;
                    }

                    symbolLineBuilder.Append(this.intToSymbolMap[cellValue]);
                }

                stringEquivalent.Add(symbolLineBuilder.ToString());
                symbolLineBuilder.Clear();
            }

            return(stringEquivalent);
        }
示例#2
0
        /// <summary>
        /// Creates a copy of the <see cref="SudokuPuzzle"/>
        /// </summary>
        /// <returns>A copy of the <see cref="SudokuPuzzle"/></returns>
        public SudokuPuzzle Clone()
        {
            List <int> cellValues = new List <int>();

            for (int i = 0; i < this.Dimension * this.Dimension * this.Dimension * this.Dimension; ++i)
            {
                cellValues.Add(0);
            }

            SudokuPuzzle newPuzzle = new SudokuPuzzle(this.Dimension, cellValues);

            for (int i = 0; i < this.Dimension * this.Dimension; ++i)
            {
                for (int k = 0; k < this.Dimension * this.Dimension; ++k)
                {
                    this.SetCellAllowedValues(this.rows[i][k], newPuzzle.rows[i][k]);
                }
            }

            return(newPuzzle);
        }