Beispiel #1
0
        /// <summary>
        /// Sets up the game board and solution with the given puzzle.
        /// </summary>
        /// <param name="puzzle">The sudoku puzzle to be entered and solved.</param>
        /// <returns>The setup board along with the solution.</returns>
        private static GameBoardLogic FillNewPuzzle(string puzzle)
        {
            GameBoardLogic result = new GameBoardLogic();
            result.EmptyBoxes = 0;

            List<SquareViewLogic> squares = new List<SquareViewLogic>();
            foreach (char s in puzzle.ToCharArray())
            {
                SquareViewLogic square = new SquareViewLogic();
                if (s != '0' && s != '.')
                {
                    square.Value = int.Parse(s.ToString());
                    square.IsEditable = false;
                }
                else
                {
                    square.IsEditable = true;
                    result.EmptyBoxes++;
                }
                squares.Add(square);
            }

            result.GameArray = LoadFromSquareList(squares);

            RuleBasedSolver solv = new RuleBasedSolver(puzzle);
            solv.RunStep(10000);
            result.solution = solv.board.ToString();

            return result;
        }
Beispiel #2
0
 public SquareView(SquareViewLogic viewModel)
 {
     InitializeComponent();
     _viewLogic = viewModel;
     this.DataContext = _viewLogic;
     _viewLogic.PropertyChanged += new System.ComponentModel.PropertyChangedEventHandler(viewModel_PropertyChanged);
     SetColors();
     SetThickness();
 }
Beispiel #3
0
        private static SquareViewLogic[,] LoadFromSquareList(List<SquareViewLogic> list)
        {
            SquareViewLogic[,] result = new SquareViewLogic[9, 9];
            int counter = 0;
            for (int i = 0; i < 9; i++)
            {
                for (int j = 0; j < 9; j++)
                {
                    result[i, j] = list[counter];
                    result[i, j].Row = i;
                    result[i, j].Column = j;
                    counter += 1;
                }
            }

            return result;
        }