Beispiel #1
0
        internal static SudokuBoard LoadFromXML(XElement a_element)
        {
            try
            {
                SudokuBoard board = new SudokuBoard();

                a_element.Elements().ForEach(cell =>
                {
                    Point p = Converters.CoordToPoint(cell.Attribute("coord").Value);
                    int col = p.X;
                    int row = p.Y;

                    cell.Elements().ForEach(num =>
                    {
                        int num_index = Int32.Parse(num.Value) - 1;
                        board[p.X, p.Y][num_index].State = Converters.StringToSudokuNumberState(num.Attribute("state").Value);
                    });
                });

                if (!board.Check())
                {
                    return(null);
                }

                return(board);
            }
            catch
            {
                return(null);
            }
        }
Beispiel #2
0
        internal static SudokuSolution LoadFromXML(XElement a_node, SudokuBoard a_board)
        {
            try
            {
                if (a_node.IsEmpty)
                {
                    return(null);
                }

                return(new SudokuSolution(

                           (SudokuSolutionType)Enum.Parse(typeof(SudokuSolutionType), a_node.Attribute("type").Value),

                           from num in a_node.Element("removed").Elements()
                           select a_board[Converters.CoordToPoint(num.Attribute("coord").Value).X,
                                          Converters.CoordToPoint(num.Attribute("coord").Value).Y]
                           [Int32.Parse(num.Value) - 1],

                           from num in a_node.Element("stayed").Elements()
                           select a_board[Converters.CoordToPoint(num.Attribute("coord").Value).X,
                                          Converters.CoordToPoint(num.Attribute("coord").Value).Y]
                           [Int32.Parse(num.Value) - 1],

                           from num in a_node.Element("solved").Elements()
                           select a_board[Converters.CoordToPoint(num.Attribute("coord").Value).X,
                                          Converters.CoordToPoint(num.Attribute("coord").Value).Y]
                           [Int32.Parse(num.Value) - 1],

                           from unit in a_node.Element("cellcolors").Elements()
                           select(from cellcolor in unit.Elements()
                                  select a_board[Converters.CoordToPoint(cellcolor.Attribute("coord").Value).X,
                                                 Converters.CoordToPoint(cellcolor.Attribute("coord").Value).Y])
                           ));
            }
            catch
            {
                return(null);
            }
        }