Exemple #1
0
        // c'tor
        public Board()
        {
            // create the groups
            for (int i = 0; i < 9; i++)
            {
                rows[i] = new Group();
                cols[i] = new Group();
                squares[i] = new Group();
            }

            // create the boxes
            for (int j = 0; j < 9; j++)
            {
                for (int i = 0; i < 9; i++)
                {
                    Box newBox = new Box(this);
                    boxes[i, j] = newBox;
                    cols[i].AddBox(newBox);
                    newBox.AssignToGroup(cols[i]);
                    rows[j].AddBox(newBox);
                    newBox.AssignToGroup(rows[j]);

                    int iSquare = ((j / 3) * 3) + (i / 3);

                    squares[iSquare].AddBox(newBox);
                    newBox.AssignToGroup(squares[iSquare]);
                }
            }

            // Keep making picks until board is filled
            do
            {
                int iRow = iPick / 9;
                int iCol = iPick - (iRow * 9);

                if (boxes[iRow, iCol].MakePick())
                {
                    iPick++;
                }
                else
                {
                    iPick--;
                }
            } while (iPick < 81);
        }
Exemple #2
0
        /// <summary>
        /// A group is notifying this box that a value previously in use is now available to the group.  Consider it
        /// to be available this box if it does not conflict with one of this box's other groups.
        /// </summary>
        /// <param name="fromGroup"></param>
        /// <param name="val"></param>
        public void AddAvailableVal(Group fromGroup, int val)
        {
            bool fOK = true;

            foreach (Group g in groups)
            {
                if (g != fromGroup && g.IsValueInUse(val))
                {
                    fOK = false;
                    break;
                }
            }

            if (fOK && !availableVals.Contains(val))
            {
                availableVals.Add(val);
            }
        }
Exemple #3
0
 /// <summary>
 /// Let this box know it is in the group.
 /// </summary>
 /// <param name="g"></param>
 public void AssignToGroup(Group g)
 {
     groups.Add(g);
 }