Example #1
0
 /// <summary>
 /// Finds the Region that contains the specified coordinates
 /// </summary>
 /// <param name="Row"></param>
 /// <param name="Col"></param>
 /// <returns></returns>
 private SudokuRegion.RegionTemplate FindRegionAt(int Row, int Col)
 {
     SudokuRegion.RegionTemplate RegionOut = null;
     foreach (SudokuRegion.RegionTemplate Region in Regions)
     {
         if (Region.ContainsCoord(Row, Col))
         {
             RegionOut = Region;
             break;
         }
     }
     return(RegionOut);
 }
Example #2
0
        public void StartSolver(Sudoku pBoard, int threadNum)
        {
            Board = pBoard;
            int[,] BoardTemplate = new int[Board.Dimension, Board.Dimension];
            Regions = new SudokuRegion.RegionTemplate[Board.Dimension];
            for (int i = 0; i < Board.Dimension; i++)
            {
                Regions[i] = new SudokuRegion.RegionTemplate(Board.Regions[i]);
                for (int j = 0; j < Board.Dimension; j++)
                {
                    BoardTemplate[i, j] = 0;
                }
            }

            Tetros = new Tetromino.TetroTemplate[Board.Tetrominos.Count];
            for (int t = 0; t < Board.Tetrominos.Count; t++)
            {
                Tetros[t] = new Tetromino.TetroTemplate(Board.Tetrominos[t]);
            }

            PartialSolve(BoardTemplate);
        }
Example #3
0
        /// <summary>
        /// Checks if a number value is unique for a row, column, tetro and region on the partial solution
        /// </summary>
        /// <param name="Row"></param>
        /// <param name="Col"></param>
        /// <param name="newValue"></param>
        /// <returns></returns>
        private bool CheckValueTemplate(int newValue, int Row, int Col, int[,] BoardTemplate)
        {
            //Console.Write(">> Testing... ");
            bool aptValue = true;

            SudokuRegion.RegionTemplate Region = FindRegionAt(Row, Col);
            Tetromino.TetroTemplate     Tetro  = FindTetroAt(Row, Col);
            if ((Region != null && Region.CheckNumber(newValue, Row, Col, BoardTemplate)) || (Tetro != null && Tetro.CheckNumber(newValue, Row, Col, BoardTemplate)))
            {
                aptValue = false;
            }
            else
            {
                int RowCell, ColCell;
                for (int i = 0; i < Board.Dimension && aptValue; i++)
                {
                    RowCell = BoardTemplate[Row, i];
                    ColCell = BoardTemplate[i, Col];
                    if (RowCell == newValue && i != Col)
                    {
                        aptValue = false;
                        //Console.WriteLine("Found number on same row");
                    }

                    else if (ColCell == newValue && i != Row)
                    {
                        aptValue = false;
                        //Console.WriteLine("Found number on same column");
                    }
                }
            }

            /*
             * if (aptValue)
             *  Console.WriteLine(" Passed!");
             * //*/
            return(aptValue);
        }