Exemplo n.º 1
0
        /// <summary>
        /// מקבל אינדקסים של תא ומחזיר את כל המספרים האפשריים שאפשר להכניס בתא זה
        /// </summary>
        /// <param name="groupIndex"></param>
        /// <param name="cellIndex"></param>
        /// <returns></returns>
        public int[] GetPossibleNumbers(int groupIndex, int cellIndex)
        {
            int[] columeNumbers = SudukuCellGroup.GetValuesByCellsArray(Board.GetAllCellsFromColume(Board.GetGroupByIndex(groupIndex).colume, Board.GetGroupByIndex(groupIndex).GetCellByIndex(cellIndex).colume));
            int[] rowNumbers    = SudukuCellGroup.GetValuesByCellsArray(Board.GetAllCellsFromRow(Board.GetGroupByIndex(groupIndex).row, Board.GetGroupByIndex(groupIndex).GetCellByIndex(cellIndex).row));
            int[] groupNumbers  = SudukuCellGroup.CorrectNumberArray(Board.GetGroupByIndex(groupIndex).GetValues());
            int[] remaining     = new int[9] {
                0, 0, 0, 0, 0, 0, 0, 0, 0
            };
            for (int i = 0; i < columeNumbers.Length; i++)
            {
                if (columeNumbers[i] == 0)
                {
                    continue;
                }
                remaining[columeNumbers[i] - 1] = 1;
            }
            for (int i = 0; i < rowNumbers.Length; i++)
            {
                if (rowNumbers[i] == 0)
                {
                    continue;
                }
                remaining[rowNumbers[i] - 1] = 1;
            }
            for (int i = 0; i < groupNumbers.Length; i++)
            {
                if (groupNumbers[i] == 0)
                {
                    continue;
                }
                remaining[groupNumbers[i] - 1] = 1;
            }
            List <int> remainingNumbers = new List <int>();

            for (int i = 0; i < 9; i++)
            {
                if (remaining[i] == 0)
                {
                    remainingNumbers.Add(i + 1);
                }
            }
            return(remainingNumbers.ToArray());
        }
Exemplo n.º 2
0
        /// <summary>
        /// מקבל אינדקסים של תא ומערך של הלוח ובודק אם הערך בתא אפשרי
        /// </summary>
        /// <param name="results"></param>
        /// <param name="groupIndex"></param>
        /// <param name="cellIndex"></param>
        /// <returns></returns>
        public bool CheckIfPossible(int[][] results, int groupIndex, int cellIndex)
        {
            int cellNumber = results[groupIndex][cellIndex];

            int[] columeNumbers = SudukuCellGroup.GetValuesByCellsArray(Board.GetAllCellsFromColume(Board.GetGroupByIndex(groupIndex).colume, Board.GetGroupByIndex(groupIndex).GetCellByIndex(cellIndex).colume));
            int[] rowNumbers    = SudukuCellGroup.GetValuesByCellsArray(Board.GetAllCellsFromRow(Board.GetGroupByIndex(groupIndex).row, Board.GetGroupByIndex(groupIndex).GetCellByIndex(cellIndex).row));
            int[] groupNumbers  = SudukuCellGroup.CorrectNumberArray(Board.GetGroupByIndex(groupIndex).GetValues());
            int   columeCounter = 0;
            int   rowCounter    = 0;
            int   groupCounter  = 0;

            for (int i = 0; i < columeNumbers.Length; i++)
            {
                if (columeNumbers[i] == cellNumber)
                {
                    columeCounter++;
                }
            }
            for (int i = 0; i < rowNumbers.Length; i++)
            {
                if (rowNumbers[i] == cellNumber)
                {
                    rowCounter++;
                }
            }
            for (int i = 0; i < groupNumbers.Length; i++)
            {
                if (groupNumbers[i] == cellNumber)
                {
                    groupCounter++;
                }
            }
            if (columeCounter > 1 || rowCounter > 1 || groupCounter > 1)
            {
                return(false);
            }
            return(true);
        }