//------------------------------------------------------------ // explicit copy public void CopyFrom(SuDoKu_Cell other) { ivValue = other.ivValue; ivCalculated = other.ivCalculated; ivSet = other.ivSet; ivOptions_Count = other.ivOptions_Count; }
public void Options_OR(SuDoKu_Cell other) { uint old = ivValue; ivValue |= other.ivValue; if (old != ivValue) { ivOptions_Count = -1; } }
public void Options_REMOVE(SuDoKu_Cell other) { uint old = ivValue; ivValue &= (~other.ivValue); if (old != ivValue) { ivOptions_Count = -1; } }
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]); } } }
protected int ivGroupSize; // the number of fields in a row/column/square //************************************************************ public SuDoKu_Field(int MyDimension) { ivDimension = MyDimension; ivGroupSize = ivDimension * ivDimension; 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(ivGroupSize); } } }
//------------------------------------------------------------ // 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); }
//------------------------------------------------------------ public void FromString(string Data) { string[] Fields = Data.Split('\n'); ivDimension = int.Parse(Fields[0]); ivGroupSize = ivDimension * ivDimension; ivCells = new SuDoKu_Cell[ivGroupSize, ivGroupSize]; int i = 0; for (int row = 0; row < ivGroupSize; ++row) { for (int column = 0; column < ivGroupSize; ++column) { ivCells[row, column] = new SuDoKu_Cell(Fields[i]); ++i; } } }
//------------------------------------------------------------ // Set the value for all cells that have only one option less // return true if the state is still valid public bool Solve_Ones() { for (int row = 0; row < ivGroupSize; ++row) { for (int column = 0; column < ivGroupSize; column++) { SuDoKu_Cell c = ivCells[row, column]; if (!c.isSet) { int v = c.Value; if (v < 0) { return(false); } if (v > 0) { set(row, column, v); return(Solve_Ones()); } } } } return(true); }
//------------------------------------------------------------ // copy constructor public SuDoKu_Cell(SuDoKu_Cell other) { CopyFrom(other); }