Ejemplo n.º 1
0
        private int height = 500; //הגובה של הלוח מבחינה גרפית

        /// <summary>
        /// מייצר את הלוח
        /// </summary>
        public SudukuBoard()
        {
            this.ColumnCount = 3;
            this.ColumnStyles.Add(new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Percent, 33.33333F));
            this.ColumnStyles.Add(new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Percent, 33.33333F));
            this.ColumnStyles.Add(new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Percent, 33.33333F));

            this.RowCount = 3;
            this.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Percent, 33.33333F));
            this.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Percent, 33.33333F));
            this.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Percent, 33.33333F));


            this.Location = new System.Drawing.Point(0, 40);
            this.Name     = "Board";

            this.Size = new System.Drawing.Size(this.width, this.height);

            for (int i = 0; i < 3; i++)
            {
                for (int k = 0; k < 3; k++)
                {
                    SudukuCellGroup tmp_group = new SudukuCellGroup(i, k, this.width / 3, this.height / 3);
                    this.Controls.Add(tmp_group, i, k);
                }
            }
        }
Ejemplo n.º 2
0
 /// <summary>
 /// פונקציה שמחזירה מערך דו מממדי של כל ערכי הלוח
 /// </summary>
 /// <returns></returns>
 public int[][] GetValues()
 {
     int[][] tmp = new int[9][];
     for (int i = 0; i < 9; i++)
     {
         SudukuCellGroup tmpGroup = (SudukuCellGroup)this.Controls[i];
         tmp[i] = tmpGroup.GetValues();
     }
     return(tmp);
 }
Ejemplo n.º 3
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());
        }
Ejemplo n.º 4
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);
        }