/// <summary> /// A box in this group is notifying the group that it is relinquishing its value. All other members /// of this group may now use the value provided it does not conflict with their groups. /// </summary> /// <param name="val"></param> public void ValueIsAvailable(Box fromBox, int val) { foreach (Box b in boxes) { if (b != fromBox) { b.AddAvailableVal(this, val); } } }
/// <summary> /// A box in this group is notifying the group that it is using a new value. All other members /// of this group must remove it from their set of available groups. /// </summary> /// <param name="fromBox"></param> /// <param name="val"></param> public void ValueIsUnavailable( Box fromBox, int val) { foreach (Box b in boxes) { if (b != fromBox) { b.RemoveAvailableVal(val); } } }
// 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); }
public void AddBox(Box box) { boxes.Add(box); }