Esempio n. 1
0
        public ActionResult Index(int k = 0)
        {
            int?[,] numbers = new int?[9, 9];

            for (int i = 0; i < 9; i++)
            {
                for (int j = 0; j < 9; j++)
                {
                    string key = string.Format("f{0}{1}", i, j);
                    int number;
                    if (int.TryParse(Request[key], out number))
                        numbers[i, j] = number;
                }
            }

            Game game = new Game(numbers);
            Solver solver = new Solver();

            try
            {
                DateTime start = DateTime.Now;
                solver.Solve(game);
                DateTime end = DateTime.Now;

                ViewBag.Interval = string.Format("Solved in {0} ms.", end.Subtract(start).Milliseconds);
            }
            catch (InvalidGameException)
            {
                ViewBag.Message = "Invalid entry.  There is no solution for the game!";
            }

            ViewBag.Numbers = game.Numbers;
            return View();
        }
Esempio n. 2
0
        private void TrySolveOneCell()
        {
            var solver = new Solver.Solver(_mainGrid);

            if (solver.TrySolveOneCell())
            {
                RefreshAll();
            }
            else
            {
                MessageBox.Show("No obvious cell :(");
            }
        }
Esempio n. 3
0
 private void SolveGrid()
 {
     try
     {
         var solver = new Solver.Solver(_mainGrid);
         if (solver.TrySolveGrid())
         {
             RefreshAll();
         }
         else
         {
             MessageBox.Show("Can not solve this grid :(");
         }
     }
     catch (Exception ex)
     {
         MessageBox.Show(ex.Message);
     }
 }
Esempio n. 4
0
        public void TestExpert()
        {
            int?[,] setup = new int?[,]
            {
                { 5, null, 6, null, null, 4, null, null, null },
                { 4, null, null, null, null, null, null, 2, null },
                { null, 2, null, null, null, null, 5, null, 7 },
                { null, null, null, 7, null, 8, null, null, null },
                { null, null, null, null, 3, null, 2, null, 1 },
                { null, null, null, null, null, null, 3, null, null },
                { 1, null, null, 4, null, 2, null, null, 5 },
                { null, null, 4, null, null, 5, 8, null, null },
                { null, null, 3, 6, 8, null, null, null, 2 }
            };

            Game game = new Game(setup);
            Solver solver = new Solver();
            solver.Solve(game);

            Console.Out.Write(game);
            Assert.IsTrue(game.IsSolved);
        }
Esempio n. 5
0
        public void TestEasy()
        {
            int?[,] setup = new int?[,]
            {
                { null, null, 9, 1, null, null, null, null, 3 },
                { null, 5, 6, 2, 8, 9, 7, 1, 4 },
                { null, 7, 8, 6, 4, 3, 2, null, null },
                { null, null, 2, null, null, null, 1, null, 9 },
                { null, 3, 7, 5, null, null, 8, null, null },
                { null, 1, 4, 9, null, null, null, 6, null },
                { 8, null, 5, null, null, null, null, null, 1 },
                { 4, 6, 3, null, null, null, null, 2, null },
                { 7, 9, null, null, 5, null, null, null, null }
            };

            Game game = new Game(setup);
            Solver solver = new Solver();
            solver.Solve(game);

            Console.Out.Write(game);
            Assert.IsTrue(game.IsSolved);
        }