77
88namespace PiCross
99{
10- public class AmbiguousConstraintsException : PiCrossException
10+ public class InvalidConstraintsException : PiCrossException
1111 {
12- public AmbiguousConstraintsException ( )
13- : base ( "Ambiguous constraints" )
12+ public InvalidConstraintsException ( )
13+ : base ( "Invalid constraints" )
1414 {
1515 // NOP
1616 }
@@ -23,13 +23,15 @@ public AmbiguousConstraintsException()
2323 public sealed class Puzzle
2424 {
2525 /// <summary>
26- /// Creates a Puzzle from the constraints. Since a Puzzle
27- /// contains the solution, this method solves the given puzzle.
26+ /// Creates a Puzzle from the constraints.
27+ /// Internally, the puzzle is automatically solved.
28+ /// If the constraints are ambiguous or contradictory,
29+ /// an exception is thrown.
2830 /// </summary>
2931 /// <param name="columnConstraints">Column constraints.</param>
3032 /// <param name="rowConstraints">Row constraints.</param>
3133 /// <returns>A Puzzle with the given constraints.</returns>
32- /// <exception cref="AmbiguousConstraintsException ">Thrown when the constraints
34+ /// <exception cref="InvalidConstraintsException ">Thrown when the constraints
3335 /// don't lead to a single solution.</exception>
3436 public static Puzzle FromConstraints ( ISequence < Constraints > columnConstraints , ISequence < Constraints > rowConstraints )
3537 {
@@ -38,7 +40,7 @@ public static Puzzle FromConstraints( ISequence<Constraints> columnConstraints,
3840
3941 if ( ! solverGrid . IsSolved )
4042 {
41- throw new ArgumentException ( "Ambiguous constraints" ) ;
43+ throw new InvalidConstraintsException ( ) ;
4244 }
4345 else
4446 {
@@ -48,6 +50,25 @@ public static Puzzle FromConstraints( ISequence<Constraints> columnConstraints,
4850 }
4951 }
5052
53+ /// <summary>
54+ /// Creates a Puzzle from the constraints.
55+ /// Internally, the puzzle is automatically solved.
56+ /// If the constraints are ambiguous or contradictory,
57+ /// an exception is thrown.
58+ /// </summary>
59+ /// <param name="columnConstraints">Column constraints.</param>
60+ /// <param name="rowConstraints">Row constraints.</param>
61+ /// <returns>A Puzzle with the given constraints.</returns>
62+ /// <exception cref="InvalidConstraintsException">Thrown when the constraints
63+ /// don't lead to a single solution.</exception>
64+ public static Puzzle FromConstraints ( int [ ] [ ] columnConstraints , int [ ] [ ] rowConstraints )
65+ {
66+ var columnConstraintsAsSequence = Sequence . FromItems ( columnConstraints . Select ( Constraints . FromValues ) . ToArray ( ) ) ;
67+ var rowConstraintsAsSequence = Sequence . FromItems ( rowConstraints . Select ( Constraints . FromValues ) . ToArray ( ) ) ;
68+
69+ return FromConstraints ( columnConstraints : columnConstraintsAsSequence , rowConstraints : rowConstraintsAsSequence ) ;
70+ }
71+
5172 /// <summary>
5273 /// Creates a Puzzle from a solution. The constraints
5374 /// will be inferred.
0 commit comments