Exemplo n.º 1
0
        private static void RunOptionsAndReturnExitCode(Options opts)
        {
            if (opts.DoLog)
            {
                ConfigureLog4Net();
            }

            try
            {
                using (FileStream fs = new FileStream(opts.JsonPath, FileMode.Open))
                {
                    using (StreamReader sr = new StreamReader(fs))
                    {
                        string json = sr.ReadToEnd();
                        Puzzle = JsonConvert.DeserializeObject <PicrossPuzzle>(json);
                        Console.WriteLine($"Loaded puzzle from {fs.Name}");
                    }
                }
            }
            catch (Exception)
            {
                Console.WriteLine("Error while opening json");
            }

            Board = new PicrossBoard(Puzzle);
            Console.WriteLine("Board loaded, next is solving...");
            Board.Solve(verboseLevel: opts.Verbose);
            Console.WriteLine("Solving complete, result:");
            Console.Write(Board.Print());

            if (!opts.NoWait)
            {
                PressEnterToContinue();
            }
        }
Exemplo n.º 2
0
 public void LoadFromJson_Solve(string puzzlePath)
 {
     using (FileStream fs = new FileStream(puzzlePath, FileMode.Open))
     {
         using (StreamReader sr = new StreamReader(fs))
         {
             string        json   = sr.ReadToEnd();
             PicrossPuzzle puzzle = JsonConvert.DeserializeObject <PicrossPuzzle>(json);
             PicrossBoard  board  = new PicrossBoard(puzzle);
             board.Solve();
             Assert.True(board.IsSolved);
         }
     }
 }