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;
        }
Пример #2
0
        public ISudokuRegion GetRegionByValuePosition(ISudokuPosition position)
        {
            int regionRow = position.RowNumber / Size;
            int regionCol = position.ColumnNumber / Size;
            ISudokuPosition regionPosition = new SudokuPosition(regionRow, regionCol);

            return GetRegion(regionPosition);
        }
Пример #3
0
        private void InitializeRegion(ISudokuPuzzle puzzle, ISudokuPosition position)
        {
            ISudokuPosition currentPosition = new SudokuPosition();
            board = new SimpleSudokuBoard(puzzle.Size);

            for (int i = 0; i < puzzle.Size; i++)
            {
                for (int j = 0; j < puzzle.Size; j++)
                {
                    currentPosition.RowNumber = puzzle.Size * position.RowNumber + i;
                    currentPosition.ColumnNumber = puzzle.Size * position.ColumnNumber + j;
                    board.SetValue(i, j, puzzle.GetValue(currentPosition));
                }
            }
        }
        private void ParsePuzzle(string source, ISudokuPuzzle puzzle)
        {
            ISudokuPosition currentPosition = new SudokuPosition();

            for (int i = 0; i < source.Length; i++)
            {
                if (source[i] == DELIMITER_COL)
                {
                    currentPosition.ColumnNumber++;
                }
                else if (source[i] == DELIMITER_ROW)
                {
                    currentPosition.RowNumber++;
                }
                else
                {
                    puzzle.SetValue(currentPosition, Int32.Parse(source[i].ToString()));
                }
            }
        }
Пример #5
0
        private bool ValidatePositionRegion(ISudokuPosition position, int value)
        {
            ISudokuRegion region = GetRegionByValuePosition(position);
            ISudokuPosition currentPosition = new SudokuPosition();

            for (int i = 0; i < region.Size; i++)
            {
                currentPosition.RowNumber = i;

                for (int j = 0; j < region.Size; j++)
                {
                    currentPosition.ColumnNumber = j;

                    if (region.GetValue(currentPosition) == value)
                    {
                        return false;
                    }
                }
            }

            return true;
        }
        private void ParsePuzzleXml(XmlNode source, ISudokuPuzzle puzzle)
        {
            int squareSize = puzzle.Size * puzzle.Size;
            ISudokuPosition currentPosition = new SudokuPosition();
            XmlElement elmBoard = source[XML_ELM_BOARD];
            XmlElement elmRow;
            XmlElement elmCell;
            XmlAttribute attRow;
            XmlAttribute attCol;

            foreach (XmlNode row in elmBoard.ChildNodes)
            {
                elmRow = (XmlElement)row;

                foreach (XmlNode cell in elmRow.ChildNodes)
                {
                    elmCell = (XmlElement)cell;
                    attRow = elmCell.Attributes[XML_ATT_ROW];
                    attCol = elmCell.Attributes[XML_ATT_COL];

                    currentPosition.RowNumber = Int32.Parse(attRow.Value);
                    currentPosition.ColumnNumber = Int32.Parse(attCol.Value);

                    puzzle.SetValue(currentPosition, Int32.Parse(elmCell.InnerText));
                }
            }

            //for (int i = 0; i < squareSize; i++)
            //{
            //    currentPosition.RowNumber = i;
            //    elmRow = (XmlElement)elmBoard.ChildNodes[i];

            //    for (int j = 0; j < squareSize; j++)
            //    {
            //        currentPosition.ColumnNumber = j;
            //        elmCell = (XmlElement)elmRow.ChildNodes[j];

            //        puzzle.SetValue(currentPosition, Int32.Parse(elmCell.InnerText));
            //    }
            //}
        }
Пример #7
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;
    }