private ISudokuPuzzle ParsePuzzle2(string source)
        {
            ISudokuPuzzle puzzle;
            ISudokuPosition currentPosition = new SudokuPosition();

            string[] rows = source.Split(DELIMITER_ROW);
            string[] cols;

            puzzle = new SudokuPuzzle((int)Math.Sqrt(rows.Length));

            for (int i = 0; i < rows.Length; i++)
            {
                currentPosition.RowNumber = i;
                cols = rows[i].Split(DELIMITER_COL);

                for (int j = 0; j < cols.Length; j++)
                {
                    currentPosition.ColumnNumber = j;

                    puzzle.SetValue(currentPosition, Int32.Parse(cols[j].ToString()));
                }
            }

            return puzzle;
        }
        public ISudokuPuzzle Import(XmlNode source)
        {
            int size = Int32.Parse(source.Attributes[XML_ATT_SIZE].Value);
            ISudokuPuzzle puzzle = new SudokuPuzzle(size);

            ParsePuzzleXml(source, puzzle);

            return puzzle;
        }
Exemplo n.º 3
0
    private ISudokuPuzzle ParseInputPuzzleFromForm()
    {
        ISudokuPuzzle puzzle = new SudokuPuzzle(PUZZLE_SIZE);
        ISudokuPosition currentPosition = new SudokuPosition();

        foreach (string key in Request.Form.AllKeys)
        {
            int trash; // Dummy variable
            if(Int32.TryParse(key.Substring(0, 1), out trash))
            {
                string[] row_col = key.Split('_');
                currentPosition.RowNumber = Int32.Parse(row_col[0]);
                currentPosition.ColumnNumber = Int32.Parse(row_col[1]);
                int value = Int32.Parse(Request.Form[key]);

                puzzle.SetValue(currentPosition, value);
            }
        }

        return puzzle;
    }