www.pudn.com > sudoku.rar > GeneratorOptions.cs


//-------------------------------------------------------------------------- 
//  
//  Copyright (c) Microsoft Corporation.  All rights reserved.  
//  
//  File: GeneratorOptions.cs 
// 
//  Description: Configuration options for the puzzle generator. 
//  
//-------------------------------------------------------------------------- 
 
using System; 
using Microsoft.Sudoku.Nullables; 
using Microsoft.Sudoku.Techniques; 
using Microsoft.Sudoku.Collections; 
 
namespace Microsoft.Sudoku 
{ 
	/// Options used for generating puzzles. 
	public sealed class GeneratorOptions 
	{ 
		/// Perceived difficulty of the puzzle. 
		private PuzzleDifficulty _difficulty; 
		/// The minimum number of filled cells in the generated puzzle. 
		private int _minimumFilledCells; 
		/// The size of the puzzle to be generated. 
		private byte _size; 
		/// The maximum number of times brute-force techniques can be used in solving the puzzle. 
		private NullableInt _maximumNumberOfDecisionPoints; 
		/// The number of puzzles to generate in order to pick the best of the lot. 
		private int _numberOfPuzzles; 
		/// Techniques allowed to be used in the generation of puzzles. 
		private TechniqueCollection _eliminationTechniques; 
		/// Whether only symmetrical puzzles should be generated. 
		private bool _ensureSymmetry; 
 
		/// Creates generator options that will create a puzzle of the specified difficulty level. 
		/// The difficulty level. 
		/// Generator options appropriate for this level. 
		public static GeneratorOptions Create(PuzzleDifficulty difficultyLevel) 
		{ 
			switch(difficultyLevel) 
			{ 
				case PuzzleDifficulty.Easy: 
					return new GeneratorOptions(3, PuzzleDifficulty.Easy, 32, 0, 3,  
						new EliminationTechnique[]{ 
													  new BeginnerTechnique() 
												  }, true); 
 
				case PuzzleDifficulty.Medium: 
					return new GeneratorOptions(3, PuzzleDifficulty.Medium, 0, 0, 10, 
						new EliminationTechnique[]{ 
													  new BeginnerTechnique(), 
													  new NakedSingleTechnique(),  
													  new HiddenSingleTechnique(),  
													  new BlockAndColumnRowInteractionTechnique(), 
													  new NakedPairTechnique(), 
													  new HiddenPairTechnique(), 
													  new NakedTripletTechnique() 
												  }, true); 
 
				case PuzzleDifficulty.Hard: 
					return new GeneratorOptions(3, PuzzleDifficulty.Hard, 0, null, 20,  
						new EliminationTechnique[]{ 
													  new BeginnerTechnique(), 
													  new NakedSingleTechnique(),  
													  new HiddenSingleTechnique(),  
													  new BlockAndColumnRowInteractionTechnique(), 
													  new NakedPairTechnique(), 
													  new HiddenPairTechnique(), 
													  new NakedTripletTechnique(),  
													  new HiddenTripletTechnique(), 
													  new NakedQuadTechnique(),  
													  new HiddenQuadTechnique(),  
													  new XwingTechnique() 
												  }, true); 
				default: 
					throw new ArgumentOutOfRangeException("difficultyLevel"); 
			} 
		} 
 
		/// Initialize the GeneratorOptions 
		/// The size of the puzzle to be generated. 
		/// The difficulty of the puzzle to generate. 
		/// The minimum number of filled cells in the generated puzzle. 
		/// The maximum number of times brute-force techniques can be used in solving the puzzle. 
		/// The number of puzzles to generate in order to pick the best of the lot. 
		/// The techniques to use while generating the puzzle. 
		/// Whether all puzzles generated should be symmetrical. 
		private GeneratorOptions( 
			byte size, PuzzleDifficulty difficulty, int minimumFilledCells, NullableInt maximumNumberOfDecisionPoints, int numberOfPuzzles, 
			EliminationTechnique [] techniques, bool ensureSymmetry) 
		{ 
			if (size != 3) throw new ArgumentOutOfRangeException("size"); 
			if (difficulty != PuzzleDifficulty.Easy && 
				difficulty != PuzzleDifficulty.Medium && 
				difficulty != PuzzleDifficulty.Hard) throw new ArgumentOutOfRangeException("difficulty"); 
			if (minimumFilledCells < 0) throw new ArgumentOutOfRangeException("minimumFilledCells"); 
			if (numberOfPuzzles < 1) throw new ArgumentOutOfRangeException("numberOfPuzzles"); 
			if (techniques == null) throw new ArgumentNullException("techniques"); 
 
			_difficulty = difficulty; 
			_size = size; 
			_minimumFilledCells = minimumFilledCells; 
			_maximumNumberOfDecisionPoints = maximumNumberOfDecisionPoints; 
			_numberOfPuzzles = numberOfPuzzles; 
			_ensureSymmetry = ensureSymmetry; 
			_eliminationTechniques = new TechniqueCollection(techniques); 
		} 
 
		/// Gets the minimum number of filled cells in the generated puzzle. 
		public int MinimumFilledCells { get { return _minimumFilledCells; } } 
 
		/// Gets the size of the puzzle to be generated. 
		public byte Size { get { return _size; } } 
 
		/// Gets the maximum number of times brute-force techniques can be used in solving the puzzle. 
		public NullableInt MaximumNumberOfDecisionPoints { get { return _maximumNumberOfDecisionPoints; } } 
 
		/// Gets the number of puzzles to generate in order to pick the best of the lot. 
		public int NumberOfPuzzles { get { return _numberOfPuzzles; } } 
 
		/// Gets the elimination techniques to be used. 
		public TechniqueCollection Techniques { get { return _eliminationTechniques; } } 
 
		/// Gets whether all puzzles generated should be symmetrical. 
		public bool EnsureSymmetry { get { return _ensureSymmetry; } set { _ensureSymmetry = value; } } 
 
		/// Gets the perceived difficulty of the puzzle to create. 
		public PuzzleDifficulty Difficulty { get { return _difficulty; } } 
	} 
}