Ejemplo n.º 1
0
        public void LoadSudokuDialog(object sender, RoutedEventArgs e)
        {
            OpenFileDialog dlg = new OpenFileDialog();

            //filter to only accept .txt
            dlg.DefaultExt = ".txt";
            dlg.Filter     = "Text documents (.txt)|*.txt";

            Nullable <bool> result = dlg.ShowDialog();

            if (result == true)
            {
                //Fails if the selected file is not a correct sudoku format
                try {
                    string sudokuString = ConvertDotToZero(LoadSudoku(dlg.FileName));
                    //Initialize the attributes we need
                    sudokuArray = CreateArrayFromString(sudokuString);
                    sudo        = SudokuFactory.CreateSudoku(sudokuString);
                    //Initialize the sudoku based on the loaded sudoku
                    InitializeSudoku(sudokuArray);
                } catch {
                    MessageBox.Show("Den valgte fil kan ikke læses", "error");
                }
            }
        }
Ejemplo n.º 2
0
        public void ButtonPressed(byte input)
        {
            int row    = int.Parse(selectedButton.Name[3] + "");
            int column = int.Parse(selectedButton.Name[4] + "");

            if (input == 0)
            {
                Stat.Text = "N***a, you cannot put 0 in a sudoku";
                return;
            }

            ISudoku tmpSudo = sudo.Clone();

            tmpSudo.SetNumberAt(column, row, input);

            if (tmpSudo.IsSolvable())
            {
                sudokuArray[column, row] = (int)input;
                selectedButton.Content   = input;
                selectedButton.IsEnabled = false;
                sudo.SetNumberAt(column, row, input);
                Stat.Text = "GJ N***A";
                if (sudo.IsSolved())
                {
                    Stat.Text = "YOU DONE DID N***A, FRIED CHICKEN FOR EVERYONE!";
                }
                return;
            }
            else
            {
                Stat.Text = "N***A YOU STUPID AS HELL";
                return;
            }
        }
Ejemplo n.º 3
0
        /// <summary>
        /// C'tor
        /// </summary>
        /// <param name="sudoku"></param>
        public MatrixSolver(ISudoku sudoku)
        {
            this.Sudoku = sudoku;
            matrix      = new LinkedList <uint> [sudoku.Size, sudoku.Size];

            ReCalculateMatrix();
        }
Ejemplo n.º 4
0
        /// <summary>
        /// Check if a sudoku is completed.
        /// This means that all it's blocks and rows/columns must be completed.
        /// </summary>
        /// <returns> True if the sudoku is completed </returns>
        public static bool IsCompleted(this ISudoku sudoku)
        {
            //check lines (rows and columns)
            for (int line = 0; line < sudoku.Size; line++)
            {
                if (!sudoku.Rows[line].IsCompleted() || !sudoku.Columns[line].IsCompleted())
                {
                    return(false);
                }
            }

            //check blocks
            for (int row = 0; row < sudoku.BlockSize; row++)
            {
                for (int column = 0; column < sudoku.BlockSize; column++)
                {
                    if (!sudoku.Blocks[row, column].IsCompleted())
                    {
                        return(false);
                    }
                }
            }

            return(true);
        }
Ejemplo n.º 5
0
        static void Main()
        {
            /* Code for console app */
            Loader  loader = new Loader();
            ISudoku game   = loader.LoadDefault();

            new SudokuGameController(new ConsoleView(), game).Go();
        }
Ejemplo n.º 6
0
 public void SolveSudokuDialog(object sender, RoutedEventArgs e)
 {
     try {
         sudo = sudo.Solve();
         string solvedString = Regex.Replace(sudo.ToString(), @"\t|\n|\r|\s", "");
         InitializeSudoku(CreateArrayFromString(solvedString));
     } catch {
         Stat.Text = "YOU NEED TO START A SUDOKU FIRST, MY N***A!";
     }
 }
        public static ISudoku[] FromArray(string[] strArr)
        {
            ISudoku[] result = new ISudoku[strArr.Length];
            for (int i = 0; i < strArr.Length; i++)
            {
                result[i] = FromString(strArr[i]);
            }

            return(result);
        }
Ejemplo n.º 8
0
        private void LoadSudoku(ISudoku sudokuToLoad, string name = "a Sudoku.")
        {
            sudokuGrid.Children.RemoveRange(0, sudokuGrid.Children.Count);

            for (int i = 0; i < 9; i++)
            {
                for (int j = 0; j < 9; j++)
                {
                    int cell = sudokuToLoad[i, j];

                    Label cellLabel = new Label
                    {
                        Content = cell != 0 ? cell.ToString() : " ",
                        HorizontalContentAlignment = HorizontalAlignment.Center,
                        VerticalContentAlignment   = VerticalAlignment.Center,
                        FontSize  = 32,
                        MinWidth  = 50,
                        MinHeight = 50,
                        Tag       = Tuple.Create(i, j)
                    };

                    // Alternate 3-cell group coloring.
                    Console.WriteLine(cell);
                    if (ShouldColorCellAt(i, j))
                    {
                        cellLabel.Background = Brushes.LightGray;
                    }

                    // "Click" handler.
                    cellLabel.MouseLeftButtonUp += OnCellLeftClick;

                    Border cellBorder = new Border
                    {
                        BorderBrush     = Brushes.Black,
                        BorderThickness = new Thickness(1),
                        Child           = cellLabel
                    };

                    // Add our border, containing our label (i.e. cell)
                    sudokuGrid.Children.Add(cellBorder);
                }
            }

            sudoku   = sudokuToLoad;
            solution = sudokuToLoad.Clone().Solve();

            statusLeft.Content = "Loaded " + name;

            UpdateStatistics();
        }
        protected override void Arrange()
        {
            var row1 = new Row(1);

            _cell11 = row1.Cell(1);
            _cell11.RememberValueCanNotBe(Solver.CellValue.One);
            _cell11.RememberValueCanNotBe(Solver.CellValue.Two);
            _cell11.RememberValueCanNotBe(Solver.CellValue.Three);
            _cell11.RememberValueCanNotBe(Solver.CellValue.Four);
            _cell11.RememberValueCanNotBe(Solver.CellValue.Five);
            _cell11.RememberValueCanNotBe(Solver.CellValue.Six);
            _cell11.RememberValueCanNotBe(Solver.CellValue.Seven);

            Assert.That(_cell11.Value, Is.EqualTo(Solver.CellValue.Unknown));

            _sudokuStub = MockRepository.GenerateStub <ISudoku>();
            foreach (var cell in row1.Cells)
            {
                Link.A((ICellUnderConstruction)cell).To(_sudokuStub);
            }
        }
Ejemplo n.º 10
0
        public bool IsSolved(int[,] sudokuBoard)
        {
            List <ISudoku> algorithms = new List <ISudoku>()
            {
                new BruteForce(_sudokuBlock),
                //additional algorithms can be submitted here. (Demonstrates the interface.)
            };

            var startState  = _sudokuState.State(sudokuBoard);                                       //Once file is loaded generate state
            var finishState = _sudokuState.State(algorithms.FirstOrDefault().IsSolved(sudokuBoard)); //Next state is when the algorithm runs and the ending board is shown.

            //If Sudoku board is not solved the loop will keep running otherwise print out the ending State.
            while (!_sudokuState.SudokuSolved(sudokuBoard) && startState != finishState)
            {
                startState = finishState;
                for (int i = 0; i < algorithms.Count; i++)
                {
                    ISudoku a = algorithms[i];
                    finishState = _sudokuState.State(a.IsSolved(sudokuBoard));
                }
            }

            return(_sudokuState.SudokuSolved(sudokuBoard));
        }
Ejemplo n.º 11
0
 public void To(ISudoku sudoku)
 {
     _cell.Sudoku = sudoku;
 }
Ejemplo n.º 12
0
 public SudokuGameController(IView theView, ISudoku theGame)
 {
     view = theView;
     game = theGame;
 }
Ejemplo n.º 13
0
 public SudokuPresenter(IView view, ISudoku sudoku)
 {
     puzzleView   = view;
     sudokuSolver = sudoku;
     Initialize();
 }
Ejemplo n.º 14
0
 internal SolveCommand(IGameContext gameContext, ISudoku sudoku)
 {
     _sudoku      = sudoku;
     _gameContext = gameContext;
 }
Ejemplo n.º 15
0
 public HomeController(ISudoku game)
 {
     this.game = game;
 }
Ejemplo n.º 16
0
 internal GenerateCommand(IGameContext gameContext, ISudoku sudoku)
 {
     _sudoku      = sudoku;
     _gameContext = gameContext;
 }
Ejemplo n.º 17
0
 public HomeController(ILogger <HomeController> logger, ISudoku sudoku)
 {
     _logger = logger;
     _sudoku = sudoku;
 }
Ejemplo n.º 18
0
 protected override void Arrange()
 {
     _sudoku = SudokuMother.Create1StarSudoku();
 }
Ejemplo n.º 19
0
 public static string ToHumanString(this ISudoku sudoku)
 {
     return(sudoku.ToString().Replace('0', '.')); // ☐
 }
Ejemplo n.º 20
0
 internal LoadFromFileCommand(IGameContext gameContext, ISudoku sudoku)
 {
     _sudoku      = sudoku;
     _gameContext = gameContext;
 }
Ejemplo n.º 21
0
        private SmartBruteForceSolver variation; //allows this

        public SmartBruteForceSolver(ISudoku sudoku) : base(sudoku)
        {
        }
Ejemplo n.º 22
0
 public Sudoku(ISudoku sudokuSolver)
 {
     this._sudokuSolver = sudokuSolver;
 }
Ejemplo n.º 23
0
 public SudokuSolver(ISudoku data)
 {
     sudoku = data;
 }