Ejemplo n.º 1
0
 public static SudokuBoard LoadFromFile(string a_fileName)
 {
     if (Path.GetExtension(a_fileName) == FileExtensions.ZipExt)
     {
         try
         {
             using (FileStream file_stream = new FileStream(a_fileName, FileMode.Open, FileAccess.Read))
             {
                 using (GZipStream gzip_stream = new GZipStream(file_stream, CompressionMode.Decompress))
                 {
                     using (StreamReader stream_reader = new StreamReader(gzip_stream, Encoding.ASCII))
                     {
                         return(SudokuBoard.LoadFromXML(XElement.Load(stream_reader)));
                     }
                 }
             }
         }
         catch
         {
             return(null);
         }
     }
     else if (Path.GetExtension(a_fileName) == FileExtensions.XmlExt)
     {
         return(SudokuBoard.LoadFromXML(XElement.Load(a_fileName)));
     }
     else if (Path.GetExtension(a_fileName) == FileExtensions.TxtExt)
     {
         return(SudokuBoard.LoadFromTextFile(a_fileName));
     }
     else
     {
         return(null);
     }
 }
Ejemplo n.º 2
0
        private static void LoadNodesFromXML(XElement a_element, SudokuSolutionNode a_parent)
        {
            a_element.Element("solution_nodes").Elements().ForEach(child_element =>
            {
                SudokuBoard board             = SudokuBoard.LoadFromXML(child_element.Element("board"));
                SudokuSolutionNode child_node = a_parent.AddNode(
                    board,
                    (SudokuSolutionNodeState)Enum.Parse(typeof(SudokuSolutionNodeState), child_element.Attribute("state").Value),
                    SudokuSolution.LoadFromXML(child_element.Element("solution"), board)
                    );

                LoadNodesFromXML(child_element, child_node);
            });
        }
        private static SudokuIntermediateSolution LoadFromXML(XElement a_element)
        {
            try
            {
                SudokuBoard    before   = SudokuBoard.LoadFromXML(a_element.Element("board_before"));
                SudokuBoard    after    = SudokuBoard.LoadFromXML(a_element.Element("board_after"));
                SudokuSolution solution = SudokuSolution.LoadFromXML(a_element.Element("solution"), before);

                SudokuIntermediateSolution intermediate_solution = new SudokuIntermediateSolution(before, after, solution);

                return(intermediate_solution);
            }
            catch
            {
                return(null);
            }
        }
Ejemplo n.º 4
0
        private static SudokuSolutionNode LoadFromXML(XElement a_element)
        {
            try
            {
                SudokuSolutionNode node = SudokuSolutionNode.CreateRoot(SudokuBoard.LoadFromXML(a_element.Element("board")));

                Debug.Assert(a_element.Element("solution").IsEmpty);

                LoadNodesFromXML(a_element, node);

                return(node);
            }
            catch
            {
                return(null);
            }
        }