public SudokuGenerator(ISudokuSolver sudokuSolver, ISudokuTransformer sudokuTransformer) { if (sudokuSolver == null || sudokuTransformer == null) { throw new ArgumentNullException("SudokuSolver 이나/또는 sudokuTransformer 가 null 입니다!"); } this.sudokuSolver = sudokuSolver; this.sudokuTransformer = sudokuTransformer; generatedSudokuBoard = new byte[9][]; for (int i = 0; i < 9; i++) { generatedSudokuBoard[i] = new byte[9]; } // 이곳에서는 스도쿠 보드를 생성하되, 빈칸은 0으로 채워져 있습니다. // sudokuBoard[행][열]로 저장하여 나중에 저장된 이 byte[][] 배열을 참조하여 다른 스도쿠 보드를 생성합니다. // 또한 새롭게 생성된 스도쿠 보드를 또다시 섞어 다른 스도쿠 보드를 만듭니다. this.sudokuSolver.SolveSudoku(generatedSudokuBoard); sudokuBoardForPlayer = new byte[9][]; for (int i = 0; i < 9; i++) { sudokuBoardForPlayer[i] = new byte[9]; } }
public HomeController(IOptions <BoardConfiguration> options, ISudokuGenerator sudokuGenerator, ISudokuValidator sudokuValidator, ISudokuSolver sudokuSolver) { _options = options; _sudokuGenerator = sudokuGenerator; _sudokuValidator = sudokuValidator; _sudokuSolver = sudokuSolver; }
private void Window_Loaded(object sender, RoutedEventArgs e) { Solver = LoadSolver("SampleSolver.dll"); var workingArea = System.Windows.SystemParameters.WorkArea; this.Left = workingArea.Left; this.Top = workingArea.Top - this.Height; }
static void Main(string[] args) { var container = Bootstrap.start(); ISudokuSolver solver = (ISudokuSolver)container.Resolve(typeof(ISudokuSolver)); var fileName = ConfigurationManager.AppSettings["defaultFileName"]; var filesToSolve = new List <string>(); if (args.Length > 0) { if (args[0] == "-p") { solveProectEuler(args[1], solver); } else { for (var i = 0; i < args.Length; i++) { filesToSolve.Add(args[i]); } } } else { filesToSolve.Add(fileName); } foreach (var fileToSolve in filesToSolve) { var grid = solver.SolvePuzzle(fileToSolve); foreach (var row in grid) { foreach (var col in row) { if (col.Count == 1) { Console.Write(col.Single()); } else { Console.Write('X'); } } Console.WriteLine(); } Console.WriteLine(); } #if DEBUG Console.ReadLine(); #endif }
public SudokuUserControl(ISudokuGenerator sudokuGenerator, ISudokuSolver sudokuSolver) { if (sudokuGenerator == null || sudokuSolver == null) { throw new ArgumentNullException("SudokuGenerator 과/또는 sudokuSolver 가 null 입니다!"); } this.sudokuGenerator = sudokuGenerator; this.sudokuSolver = sudokuSolver; }
public static SudokuBoard NewSudoku(SudokuDifficulty difficulty, ISudokuSolver solverGenerator = null) { _solverGenerator = solverGenerator ?? new DeepFirstSearchSolver(); var blankboard = new SudokuBoard(difficulty); return(_solverGenerator .Solve(blankboard) .CreateBlankCells()); }
public void GenerateGameUsingSolver(ISudokuSolver s, int givens) { int size = Rows.Count * Rows.Count; if (givens < 0 || givens > size * size) { throw new ArgumentOutOfRangeException("givens", givens, "Invalid number of givens"); } for (int r = 0; r < size; r++) { for (int c = 0; c < size; c++) { Cell cell = this[r, c]; cell.ReadOnly = false; cell.Value = null; } } Random rnd = new Random(); int row = rnd.Next(size); int col = rnd.Next(size); this[row, col].Value = rnd.Next(size) + 1; int?[,] a = this.ToArray(); s.Solve(ref a); this.FromArray(a); for (int i = 0; i < (size * size) - givens; i++) { for (; ;) { int r = rnd.Next(size); int c = rnd.Next(size); Cell cell = this[r, c]; if (!cell.Value.HasValue) { continue; } cell.Value = null; cell.ReadOnly = false; break; } } for (int r = 0; r < size; r++) { for (int c = 0; c < size; c++) { Cell cell = this[r, c]; if (cell.Value.HasValue) { cell.ReadOnly = true; } } } }
void WindowLoaded(object sender, RoutedEventArgs e) { TitleReflect.Fill = new VisualBrush(TitleText); Solver = LoadSolver("SampleSolver.dll"); TimerControls.IsEnabled = false; TimerControls.Opacity = 0.25; //NewGameClicked(null, null); //DoubleAnimation da = new DoubleAnimation(0, 1, new Duration(TimeSpan.FromSeconds(5))); //da.RepeatBehavior = RepeatBehavior.Forever; //StopwatchControl.BeginAnimation(Stopwatch.CurrentTimeProperty, da); }
public Sudoku(List <SudokuCell> cells) { if (cells == null) { throw new ArgumentNullException("cells can't be equal to null"); } _cells = cells; _sudokuSolver = ServiceLocator.Current.GetInstance <ISudokuSolver>(); _sudokuComplexityEstimator = ServiceLocator.Current.GetInstance <ISudokuComplexityEstimator>(); _sudokuDifficultyLevel = _sudokuComplexityEstimator.EstimateComplexityLevel(this); }
public Sudoku(ISudokuSolver solver, int[] table) { if (table.Length != 81) { throw new ArgumentException("table size must be 81", "table"); } if (table.Any(x => x < 0 || x > 9)) { throw new ArgumentException("Each value in table must be between 0 and 9"); } _table = table.Copy(); _solver = solver; }
public SudokuGenerator(IOptions <BoardConfiguration> options, ISudokuSolver sudokuSolver) { _sudokuSolver = sudokuSolver; _boardSize = options.Value.BoardSize; _blockSize = options.Value.BlockSize; _mixStrategies = new List <Func <byte?[, ], byte, byte, byte, byte?[, ]> > { BoardExtensions.Transpose, BoardExtensions.SwapRow, BoardExtensions.SwapRowBlock, BoardExtensions.SwapColumn, BoardExtensions.SwapColumnBlock }; _random = new Random(); }
public SudokuViewModel(IWpfThread thread, ISudokuSolver solver) { SolveAnimatedCommand = new RelayCommand(StartSolvingAnimated); SolveCommand = new RelayCommand(Solve); ResetCommand = new RelayCommand(Reset); _backingArray = new SudokuViewModelItem[81]; for (int i = 0; i < _backingArray.Length; i++) { Cells.Add(_backingArray[i] = new SudokuViewModelItem()); } _thread = thread; _solver = solver; }
public static float testSolution(ISudokuSolver solver, String sudoku) { var watch = Stopwatch.StartNew(); float elapsedMs; solver.Sudoku.newSudoku(sudoku); watch = Stopwatch.StartNew(); solver.Solve(); watch.Stop(); elapsedMs = watch.ElapsedMilliseconds; if (!solver.Sudoku.validationSudoku()) { solver.Sudoku.showTwoSudoku(); return(-1); } //solver.Sudoku.showTwoSudoku(); return(elapsedMs); }
private static void solveProectEuler(string projectEulerFileName, ISudokuSolver solver) { var file = new StreamReader(projectEulerFileName); var line = ""; while ((line = file.ReadLine()) != null) { Console.WriteLine(line); var grid = new List <List <HashSet <int> > >(); for (var i = 0; i < 9; i++) { var row = new List <HashSet <int> >(); line = file.ReadLine(); foreach (var box in line) { if (box == 'X' || box == '0') { row.Add(new HashSet <int>() { 1, 2, 3, 4, 5, 6, 7, 8, 9 }); } else { row.Add(new HashSet <int> { int.Parse(box.ToString()) }); } } grid.Add(row); } var result = solver.SolvePuzzle(grid); printGrid(result); Console.WriteLine(isValid(result)); } }
void SolveClicked(object sender, RoutedEventArgs e) { ISudokuSolver sol = SolverList.SelectedItem as ISudokuSolver; Board.IsEnabled = true; Storyboard sb = this.Resources["TimerAnimation"] as Storyboard; sb.Stop(this); MinNumber.Tag = 59; SecNumber.Tag = 59; SubSecNumber.Tag = 59; TimerControls.Opacity = 0.25; TimerControls.IsEnabled = false; StopwatchControl.IsChecked = false; ShowWait(); int?[,] a = Board.GameBoard.ToArray(); bool solved = false; solverWorker = new BackgroundWorker(); solverWorker.DoWork += new DoWorkEventHandler(delegate(object dwsender, DoWorkEventArgs dwe) { solved = sol.Solve(ref a); }); solverWorker.RunWorkerCompleted += new RunWorkerCompletedEventHandler(delegate(object rwcsender, RunWorkerCompletedEventArgs rwce) { MessageLayer.IsEnabled = false; if (!solved) { ShowMessage("No Solution!"); } else { Board.GameBoard.FromArray(a); } }); solverWorker.RunWorkerAsync(); }
static void Main(string[] args) { var types = AppDomain.CurrentDomain.GetAssemblies() .SelectMany(s => s.GetTypes()) .Where(p => typeof(SudokuLib.ISudokuSolver).IsAssignableFrom(p)); foreach (Type item in types) { Sudoku sud = new Sudoku(); ISudokuSolver localSolver = (ISudokuSolver)Activator.CreateInstance(item); var sud_one = sud.ParseFile(@"C:\Users\K\Documents\Work\CSharp\Sudoku_General\Benchmark\sudoku_files\Easy.txt")[0]; var watch = System.Diagnostics.Stopwatch.StartNew(); localSolver.Solve(sud_one); watch.Stop(); var elapsedMs = watch.ElapsedMilliseconds; Console.WriteLine(item.Name); Console.WriteLine(elapsedMs); Console.ReadKey(); } }
public SudokuController(ISudokuSolver sudokuSolver, ISudokuGenerator sudokuGenerator) { SudokuGenerator = sudokuGenerator; SudokuSolver = sudokuSolver; }
public void Init(Type t) { solver = Activator.CreateInstance(t) as ISudokuSolver; }
//使用解题器的随机生成方法 /// <summary> /// 通过解题器生成游戏 /// </summary> public void GenerateGameUsingSolver(ISudokuSolver s, int givens) { int size = Rows.Count * Rows.Count; if (givens < 0 || givens > size * size) { throw new ArgumentOutOfRangeException("givens", givens, "给定的生成已知数数目数目不合法"); } for (int r = 0; r < size; r++) { for (int c = 0; c < size; c++) { Cell cell = this[r, c]; cell.ReadOnly = false; cell.Value = null; } } Random rnd = new Random(); int row = rnd.Next(size); int col = rnd.Next(size); this[row, col].Value = rnd.Next(size) + 1; int?[,] a = this.ToArray();//将谜题放入数组 s.Solve(ref a); //判断能否求得谜题答案 this.FromArray(a); for (int i = 0; i < (size * size) - givens; i++) //挖掉数字 { for (; ; ) { int r = rnd.Next(size); int c = rnd.Next(size); Cell cell = this[r, c]; if (!cell.Value.HasValue)//判断是否为空值 continue; cell.Value = null; cell.ReadOnly = false; break; } } for (int r = 0; r < size; r++) { for (int c = 0; c < size; c++) { Cell cell = this[r, c]; if (cell.Value.HasValue) cell.ReadOnly = true; } } }
public SudokuSolverService(ISudokuSolver sudokuSolver) { this.sudokuSolver = sudokuSolver; }
private Sudoku(ISudokuSolver solver, ISudokuGenerator generator) { _solver = solver; _generator = generator; _loadFactory = new DataLoadFactory(); }
public Sudoku(ISudokuSolver solver) { _table = generateNewSudoku(); _solver = solver; }
public SudokuService() { sudokuFieldBuilder = new SudokuFieldBuilder(); sudokuValidator = new SudokuValidator(); sudokuSolver = new SudokuSolver(); }
void NewGameClicked(object sender, RoutedEventArgs e) { Board.GameBoard = new Board((int)BoardSize.SelectedItem); Storyboard s = this.Resources["TimerAnimation"] as Storyboard; if (FastGenRadio.IsChecked == true) { Board.GameBoard.GenerateGame((int)BoardSize.SelectedItem * 2); Board.GameBoard.PropertyChanged += new System.ComponentModel.PropertyChangedEventHandler(GameBoard_PropertyChanged); } else { Board b = Board.GameBoard; int givens = (int)BoardSize.SelectedItem * 2; ISudokuSolver sol = SolverList.SelectedItem as ISudokuSolver; solverWorker = new BackgroundWorker(); ShowWait(); solverWorker.DoWork += new DoWorkEventHandler(delegate(object dwsender, DoWorkEventArgs dwe) { b.GenerateGameUsingSolver(sol, givens); }); solverWorker.RunWorkerCompleted += new RunWorkerCompletedEventHandler(delegate(object rwcsender, RunWorkerCompletedEventArgs rwce) { MessageLayer.IsEnabled = false; s.Begin(this, true); Board.GameBoard.PropertyChanged += new System.ComponentModel.PropertyChangedEventHandler(GameBoard_PropertyChanged); }); solverWorker.RunWorkerAsync(); } s.Stop(this); if (NoTimerRadio.IsChecked == true) { MinNumber.Tag = 59; SecNumber.Tag = 59; SubSecNumber.Tag = 59; TimerControls.Opacity = 0.25; TimerControls.IsEnabled = false; StopwatchControl.IsChecked = false; } else { Int32 length; if (EasyTimerRadio.IsChecked == true) { length = 15; } else if (MediumTimerRadio.IsChecked == true) { length = 10; } else { length = 5; } //s.CutoffTime = TimeSpan.FromMinutes(length); s.Children[0].Duration = new Duration(TimeSpan.FromMinutes(length)); s.Children[1].Duration = new Duration(TimeSpan.FromMinutes(length)); s.Children[2].RepeatBehavior = new RepeatBehavior(TimeSpan.FromMinutes(length)); s.Children[3].RepeatBehavior = new RepeatBehavior(TimeSpan.FromMinutes(length)); ((Int32Animation)s.Children[1]).From = length - 1; StopwatchControl.IsChecked = true; MinNumber.Tag = length - 1; TimerControls.Opacity = 1; TimerControls.IsEnabled = true; if (FastGenRadio.IsChecked == true) { s.Begin(this, true); } } Board.IsEnabled = true; }
public void Setup() { SudokuSolver = new SudokuSolver(); }
public void Setup() { SudokuSolver = new SudokuSolver(); SudokuGenerator = new SudokuGenerator(SudokuSolver); }
public ConcurrentSudokuGame(ISudokuGenerator generator, ISudokuSolver solver, ISessionMapper <Guid> sessionMapper) : base(generator, solver, sessionMapper) { }
public SolvingManager(string input) { var sudoku = new Sudoku(input); solver = new SudokuSolver(sudoku); }
protected AbstractSudokuGame(ISudokuGenerator generator, ISudokuSolver solver, ISessionMapper <Guid> sessionMapper) { Generator = generator; Solver = solver; this.SessionMapper = sessionMapper; }
public SudokuGenerator(ISudokuSolver sudokuSolver) { SudokuSolver = sudokuSolver; }