예제 #1
0
        public SquigglyGrid RandomlyBlank(SquigglyGrid tempGrid, int sym, ref int blankCount)
        {
            //blank one or two squares(depending on if on center line) randomly
            Random rnd    = new Random();           //allow random number generation
            int    row    = rnd.Next(0, 8);         //choose randomly the row
            int    column = rnd.Next(0, 8);         //and column of cell to blank

            while (tempGrid.Grid[row, column] == 0) //don't blank a blank cell
            {
                row    = rnd.Next(0, 8);
                column = rnd.Next(0, 8);
            }
            tempGrid.InitSetCell(row, column, 0); //clear chosen cell
            blankCount++;                         //increment the count of blanks
            switch (sym)
            {
            //based on symmetry, blank a second cell
            case 0:                                       //vertical symmetry
                if (tempGrid.Grid[row, 8 - column] != 0)  //if not already blanked
                {
                    blankCount++;                         //increment blank counter
                }
                tempGrid.InitSetCell(row, 8 - column, 0); //blank opposite cell
                break;

            case 1:     //horizontal symmetry
                if (tempGrid.Grid[8 - row, column] != 0)
                {
                    blankCount++;
                }
                tempGrid.InitSetCell(8 - row, column, 0);
                break;

            case 2:     //diagonal symmetry
                if (tempGrid.Grid[column, row] != 0)
                {
                    blankCount++;
                }
                tempGrid.InitSetCell(column, row, 0);
                break;

            default:     //diagonal symmetry
                if (tempGrid.Grid[row, 8 - column] != 0)
                {
                    blankCount++;
                }
                tempGrid.InitSetCell(column, row, 0);
                break;
            }
            return(tempGrid);
        }
예제 #2
0
        public SquigglyGrid InitGrid()
        {
            //Randomly fill in the first row and column of squigglygrid
            SquigglyGrid tempGrid = new SquigglyGrid {
            };                                                            //temporary grid to assign values into
            int row = 0;                                                  //variable for navigating 'rows'
            int col = 0;                                                  //variable for navigating 'columns'
            int newVal;                                                   //value to place into grid
            //bool solved;
            List <int> valueSet = new List <int>(Enumerable.Range(1, 9)); //range of numbers that can be added to the grid

            List <int> valueSet2 = new List <int>();                      //placeholder values in column 0
            Random     rnd       = new Random();                          //random variable for choosing random number
            int        randIndex = 0;                                     //index in valueSet/valueSet2 that is accessed

            randIndex = rnd.Next(0, 8);                                   //get a random number and place in grid(0,0)
            newVal    = valueSet[randIndex];
            tempGrid.InitSetCell(row, col, newVal);
            valueSet.Remove(newVal);                        //remove paced value from options

            for (row = 1; row < 9; row++)
            {                                                           //fills in column 0 with remaining possible values, storing in place-
                //holder as it goes so as to preserve when placing in row 0 later
                randIndex = rnd.Next(0, valueSet.Count);
                newVal    = valueSet[randIndex];
                valueSet2.Add(newVal);
                valueSet.Remove(newVal);
                tempGrid.InitSetCell(row, col, newVal);
            }

            //row = 0;                                               //reset row to 0

            for (int i = 8; i >= 0; i--)
            {
                tempGrid.InitSetCell(0, 9 - i, tempGrid.Grid[i, 0]);
            }

            do
            {
                squigglySolver = new SquigglySolver(scheme);
                squigglySolver.SolveGrid((SquigglyGrid)tempGrid.Clone(), false); //Slv to fill remainder of grid
                SolutionGrid = squigglySolver.SolutionGrid;
            } while (SolutionGrid == null || SolutionGrid.IsBlank());

            PermaGrid = Blanker(SolutionGrid); //call Blanker to carry out the
            return(PermaGrid);                 //blanking of fileds,then return the grid to user to solve
        }
예제 #3
0
 /// <summary>
 /// This clones the object.
 /// </summary>
 /// <returns>A clone of itself.</returns>
 public object Clone()
 {
     //enable cloning for safe copying of the object
     SquigglyGrid p = new SquigglyGrid();
     for (int i = 0; i < Max; i++)
     {
         for (int j = 0; j < Max; j++)
         {
             p.InitSetCell(i, j, Grid[i, j]);
         }
     }
     return p;
 }
예제 #4
0
        /// <summary>
        /// This clones the object.
        /// </summary>
        /// <returns>A clone of itself.</returns>
        public object Clone()
        {
            //enable cloning for safe copying of the object
            SquigglyGrid p = new SquigglyGrid();

            for (int i = 0; i < Max; i++)
            {
                for (int j = 0; j < Max; j++)
                {
                    p.InitSetCell(i, j, Grid[i, j]);
                }
            }
            return(p);
        }
예제 #5
0
        public SquigglyGrid InitGrid()
        {
            //Randomly fill in the first row and column of squigglygrid
            SquigglyGrid tempGrid = new SquigglyGrid { };       //temporary grid to assign values into
            int row = 0;                         		    //variable for navigating 'rows'
            int col = 0;                        			//variable for navigating 'columns'
            int newVal;                        	            //value to place into grid
            //bool solved;
            List<int> valueSet = new List<int>(Enumerable.Range(1, 9));   //range of numbers that can be added to the grid

            List<int> valueSet2 = new List<int>(); 			//placeholder values in column 0
            Random rnd = new Random(); 						//random variable for choosing random number
            int randIndex = 0;       						//index in valueSet/valueSet2 that is accessed
            randIndex = rnd.Next(0, 8); 						//get a random number and place in grid(0,0)
            newVal = valueSet[randIndex];
            tempGrid.InitSetCell(row, col, newVal);
            valueSet.Remove(newVal);                        //remove paced value from options

            for (row = 1; row < 9; row++)
            { 								//fills in column 0 with remaining possible values, storing in place-
                //holder as it goes so as to preserve when placing in row 0 later
                randIndex = rnd.Next(0, valueSet.Count);
                newVal = valueSet[randIndex];
                valueSet2.Add(newVal);
                valueSet.Remove(newVal);
                tempGrid.InitSetCell(row, col, newVal);
            }

            //row = 0;                                               //reset row to 0

            for (int i = 8; i >= 0; i--)
            {
                tempGrid.InitSetCell(0, 9 - i, tempGrid.Grid[i, 0]);
            }

            do
            {
                squigglySolver = new SquigglySolver(scheme);
                squigglySolver.SolveGrid((SquigglyGrid)tempGrid.Clone(), false); //Slv to fill remainder of grid
                SolutionGrid = squigglySolver.SolutionGrid;
            } while (SolutionGrid == null || SolutionGrid.IsBlank());

            PermaGrid = Blanker(SolutionGrid);       //call Blanker to carry out the
            return PermaGrid;         //blanking of fileds,then return the grid to user to solve
        }
예제 #6
0
 public SquigglyGrid RandomlyBlank(SquigglyGrid tempGrid, int sym, ref int blankCount)
 {
     //blank one or two squares(depending on if on center line) randomly
     Random rnd = new Random(); //allow random number generation
     int row = rnd.Next(0, 8); //choose randomly the row
     int column = rnd.Next(0, 8); //and column of cell to blank
     while (tempGrid.Grid[row, column] == 0) //don't blank a blank cell
     {
         row = rnd.Next(0, 8);
         column = rnd.Next(0, 8);
     }
     tempGrid.InitSetCell(row, column, 0); //clear chosen cell
     blankCount++; //increment the count of blanks
     switch (sym)
     {
         //based on symmetry, blank a second cell
         case 0: //vertical symmetry
             if (tempGrid.Grid[row, 8 - column] != 0) //if not already blanked
                 blankCount++; //increment blank counter
             tempGrid.InitSetCell(row, 8 - column, 0); //blank opposite cell
             break;
         case 1: //horizontal symmetry
             if (tempGrid.Grid[8 - row, column] != 0)
                 blankCount++;
             tempGrid.InitSetCell(8 - row, column, 0);
             break;
         case 2: //diagonal symmetry
             if (tempGrid.Grid[column, row] != 0)
                 blankCount++;
             tempGrid.InitSetCell(column, row, 0);
             break;
         default: //diagonal symmetry
             if (tempGrid.Grid[row, 8 - column] != 0)
                 blankCount++;
             tempGrid.InitSetCell(column, row, 0);
             break;
     }
     return tempGrid;
 }