public void Undo() { if (ivHistory.Count > 0) { ivSudoku = ivHistory.Pop(); Invalidate(); } }
public SuDoKu_Field(SuDoKu_Field other) { ivDimension = other.ivDimension; ivGroupSize = other.ivGroupSize; ivCells = new SuDoKu_Cell[ivGroupSize, ivGroupSize]; for (int row = 0; row < ivGroupSize; row++) { for (int column = 0; column < ivGroupSize; column++) { ivCells[row, column] = new SuDoKu_Cell(other.ivCells[row, column]); } } }
//------------------------------------------------------------ // Try to find the correct value for all cell that have // only 2 options left // return true if the state is still valid public bool Solve_Twos() { for (int row = 0; row < ivGroupSize; ++row) { for (int column = 0; column < ivGroupSize; column++) { SuDoKu_Cell c = ivCells[row, column]; if (!c.isSet && c.Options_Count == 2) { SuDoKu_Field old = new SuDoKu_Field(this); int v = c.Options_First; set(row, column, v); // if (! Solve_Ones() ) } } } return(true); }
//************************************************************ // the constructor public SuDoKu() { InitializeComponent(); SetStyle(ControlStyles.UserPaint, true); SetStyle(ControlStyles.AllPaintingInWmPaint, true); SetStyle(ControlStyles.DoubleBuffer, true); ivBrush = new SolidBrush(this.ForeColor); ivLine_Normal = new Pen(_GridColor, 2); ivLine_Thick = new Pen(_GridColor, 4); ivFormat = new StringFormat(StringFormatFlags.NoClip); ivFormat.Alignment = StringAlignment.Center; ivFormat.LineAlignment = StringAlignment.Center; ivSudoku = new SuDoKu_Field(3); ivHistory = new Stack <SuDoKu_Field>(); UpdateDimensions(); }