Esempio n. 1
0
 public static void deSerialise(matrix m)
 {
     for (int y = 0; y < height; y++)
     {
         for (int x = 0; x < width; x++)
         {
             var TB = baseform.grid.GetControlByName(getname(x, y));
             if (m.grid[y][x] != 0)
                 TB.Text = m.grid[y][x].ToString();
             else
                 TB.Text = "";
         }
     }
 }
Esempio n. 2
0
        public static void generateRandom(int widthIN, int heightIN, int random)
        {
            matrix m = new matrix(widthIN, heightIN);
            m.solveHead();

            int rcount = 0;
            Random RN = new Random();

            while (rcount < random)
            {
                int x = RN.Next() % width;
                int y = RN.Next() % height;
                if (m.grid[y][x] == 0)
                    continue;
                m.grid[y][x] = 0;
                rcount++;
            }

            init(widthIN, heightIN);
            deSerialise(m);
            doCheck();
        }
Esempio n. 3
0
 public void copyFrom(matrix m)
 {
     width = m.width;
     height = m.height;
     grid = null;
     grid = MatrixOps.CloneMatrix(m.grid, width, height);
     max = getMaxNumber();
     square = getSquareSize();
 }
Esempio n. 4
0
 public matrix clone()
 {
     var m = new matrix(width, height);
     m.grid = MatrixOps.CloneMatrix(grid, width, height);
     return m;
 }
Esempio n. 5
0
 public static void doCheck()
 {
     matrix m = new matrix(width, height, matrixgrid.serialise());
     var check = m.checkGrid();
     applyCheck(check.Item1);
 }
Esempio n. 6
0
        static void TB_MouseHover(object sender, EventArgs e)
        {
            if (baseform.showPossibleMovesOnHoverToolStripMenuItem.Checked == false)
                return;

            TextBox TB = sender as TextBox;
            if (TB == null)
                return;

            var a = getLocationFromName(TB.Name);
            int x = a.Item2;
            int y = a.Item1;
            matrix m = new matrix(width, height, serialise());
            var b = m.getPossibilities(x, y);

            String TT = ListExtras.Serialise(b.Cast<object>().ToList());
            if (TT.Length == 0)
                TT = "No Options";
            ObjectExtras.AddToolTip(TB, TT);
        }
Esempio n. 7
0
        private static void applyCheck(matrix.celltype[][] matrix)
        {
            bool whiteout = !baseform.showInvalidMovesToolStripMenuItem.Checked;

            for (int y = 0; y < height; y++)
            {
                for (int x = 0; x < width; x++)
                {
                    var TB = baseform.grid.GetControlByName(getname(x, y));
                    if (whiteout)
                    {
                        TB.BackColor = Color.White;
                        continue;
                    }

                    SudokuSolver.matrix.celltype CT = matrix[y][x];
                    switch (CT)
                    {
                        case SudokuSolver.matrix.celltype.bad:
                            TB.BackColor = Color.Tomato;
                            break;
                        case SudokuSolver.matrix.celltype.empty:
                            TB.BackColor = Color.LightGoldenrodYellow;
                            break;

                        case SudokuSolver.matrix.celltype.good:
                            TB.BackColor = Color.GreenYellow;
                            break;
                    }
                }
            }
        }
Esempio n. 8
0
        public static void solve()
        {
            matrix m = new matrix(width, height, matrixgrid.serialise());

            //check its possible to start with
            var test = m.checkGrid(true, true);
            if (test.Item2 == false)
            {
                MessageBox.Show("There are errors in the puzzle to start with, impossible to solve");
                return;
            }

            bool possible = m.solveHead();

            if (possible == false)
            {
                MessageBox.Show("No solutions found");
                return;
            }
            deSerialise(m);
            var check = m.checkGrid();
            applyCheck(check.Item1);
        }