public void CellsTest() { int index = 0; // TODO: Initialize to an appropriate value Column target = new Column(index); // TODO: Initialize to an appropriate value Cell[] expected = new Cell[9]; Cell[] actual; actual = target.Cells; CollectionAssert.AreEqual(expected, actual); }
/// <summary> /// Check wether the given cell is the only place for /// the given digit in the house. /// </summary> /// <param name="cell">Cell.</param> /// <param name="digit">Digit.</param> /// <returns>True, if the cell is the only place for /// the given digit in the house, false otherwise.</returns> public bool HasOnlyOnePlaceFor(Cell cell, int digit) { foreach (Cell c in this.GetCells()) { if (c != null && !c.Equals(cell)) { if (c.Digit.HasValue && c.Digit.Value == digit) return false; else if (c.HasACandidateFor(digit)) return false; } } return true; }
public CellControl(Cell cell) { this.Cell = cell; this.AutoSize = true; this.BackColor = System.Drawing.SystemColors.Control; this.BorderStyle = System.Windows.Forms.BorderStyle.None; this.Cursor = System.Windows.Forms.Cursors.Default; this.Dock = System.Windows.Forms.DockStyle.Fill; this.Font = new System.Drawing.Font("Trebuchet MS", 14.25F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(0))); this.ForeColor = System.Drawing.SystemColors.ControlText; this.Margin = new System.Windows.Forms.Padding(0); this.ReadOnly = true; this.TextAlign = System.Drawing.ContentAlignment.MiddleCenter; this.Enter += new EventHandler(CellControl_Enter); this.Leave += new EventHandler(CellControl_Leave); this.Name = cell.ToString(); this.TabIndex = ((cell.Row.Index - 1) * 9) + cell.Column.Index; }
private void InitGrid() { // Boxes : this._Boxes = new Box[3, 3]; for (int row = 0; row < 3; row++) for (int col = 0; col < 3; col++) this._Boxes[row, col] = new Box(row, col); // Columns : this._Columns = new Column[9]; for (int col = 0; col < 9; col++) this._Columns[col] = new Column(col); // Rows : this._Rows = new Row[9]; for (int row = 0; row < 9; row++) this._Rows[row] = new Row(row); // Cells : int boxCol = 0; int boxRow = 0; this._Cells = new Cell[9, 9]; for (int row = 0; row < 9; row++) { for (int col = 0; col < 9; col++) { Cell cell = new Cell(); cell.Grid = this; cell.Box = this._Boxes[this.BoxIndex(row), this.BoxIndex(col)]; cell.Column = this._Columns[col]; cell.Row = this._Rows[row]; cell.Grid.Cells[row, col] = cell; cell.Box.Cells[boxRow, boxCol] = cell; cell.Column.Cells[cell.Row.Index] = cell; cell.Row.Cells[cell.Column.Index] = cell; boxCol = (boxCol < 2) ? boxCol + 1 : 0; } boxRow = (boxRow < 2) ? boxRow + 1 : 0; } }