Sfoglia il codice sorgente

added stats

master
Robin Thoni 7 anni fa
parent
commit
68c310e66e

+ 6
- 0
.idea/.idea.uqac-ia-sudoku-csp/.idea/vcs.xml Vedi File

@@ -0,0 +1,6 @@
1
+<?xml version="1.0" encoding="UTF-8"?>
2
+<project version="4">
3
+  <component name="VcsDirectoryMappings">
4
+    <mapping directory="$PROJECT_DIR$" vcs="Git" />
5
+  </component>
6
+</project>

+ 4
- 2
uqac-ia-sudoku-csp/Interfaces/ISolver.cs Vedi File

@@ -1,7 +1,9 @@
1
-namespace uqac_ia_sudoku_csp.Interfaces
1
+using uqac_ia_sudoku_csp.Solver;
2
+
3
+namespace uqac_ia_sudoku_csp.Interfaces
2 4
 {
3 5
     public interface ISolver
4 6
     {
5
-        bool Resolve(Board board);
7
+        SolverResult Resolve(Board board);
6 8
     }
7 9
 }

+ 2
- 1
uqac-ia-sudoku-csp/Program.cs Vedi File

@@ -21,7 +21,7 @@ namespace uqac_ia_sudoku_csp
21 21
             var solver = new BacktrackSearch();
22 22
             var resolved = solver.Resolve(board);
23 23
 
24
-            if (resolved)
24
+            if (resolved.Success)
25 25
             {
26 26
                 Console.WriteLine("Resolved:");
27 27
                 board.Print(Console.Out);
@@ -30,6 +30,7 @@ namespace uqac_ia_sudoku_csp
30 30
             {
31 31
                 Console.WriteLine("Not resolved");
32 32
             }
33
+            Console.WriteLine($"{resolved.TryCount} tries");
33 34
         }
34 35
     }
35 36
 }

+ 7
- 4
uqac-ia-sudoku-csp/Solver/BacktrackSearch.cs Vedi File

@@ -20,12 +20,14 @@ namespace uqac_ia_sudoku_csp.Solver
20 20
             };
21 21
         }
22 22
 
23
-        public bool Resolve(Board board)
23
+        public SolverResult Resolve(Board board)
24 24
         {
25
-            return RecursiveResolve(board);
25
+            var result = new SolverResult();
26
+            result.Success = RecursiveResolve(board, result);
27
+            return result;
26 28
         }
27 29
 
28
-        protected bool RecursiveResolve(Board board)
30
+        protected bool RecursiveResolve(Board board, SolverResult result)
29 31
         {
30 32
             if (board.IsComplete())
31 33
             {
@@ -35,10 +37,11 @@ namespace uqac_ia_sudoku_csp.Solver
35 37
             SelectVariable(board, out x, out y);
36 38
             foreach (var value in GetDomainValues(board))
37 39
             {
40
+                ++result.TryCount;
38 41
                 board.SetNumber(x, y, value);
39 42
                 if (IsConsistent(board, x, y))
40 43
                 {
41
-                    if (RecursiveResolve(board))
44
+                    if (RecursiveResolve(board, result))
42 45
                     {
43 46
                         return true;
44 47
                     }

+ 9
- 0
uqac-ia-sudoku-csp/Solver/SolverResult.cs Vedi File

@@ -0,0 +1,9 @@
1
+namespace uqac_ia_sudoku_csp.Solver
2
+{
3
+    public class SolverResult
4
+    {
5
+        public int TryCount { get; set; }
6
+
7
+        public bool Success { get; set; }
8
+    }
9
+}

Loading…
Annulla
Salva