Esempio n. 1
0
 /// <summary>
 /// Finds the Tetro that contains the specified coordinates
 /// </summary>
 /// <param name="Row"></param>
 /// <param name="Col"></param>
 /// <returns></returns>
 private Tetromino.TetroTemplate FindTetroAt(int Row, int Col)
 {
     Tetromino.TetroTemplate TetroOut = null;
     foreach (Tetromino.TetroTemplate Tetro in Tetros)
     {
         if (Tetro.ContainsCoord(Row, Col))
         {
             TetroOut = Tetro;
             break;
         }
     }
     return(TetroOut);
 }
Esempio n. 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);
        }
Esempio n. 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);
        }