public override bool Equals(object a_obj) { if (a_obj == null) { return(false); } if (ReferenceEquals(this, a_obj)) { return(true); } SudokuBoard board = a_obj as SudokuBoard; if (board == null) { return(false); } return(Cells().SequenceEqual(board.Cells())); }
private static SudokuBoard LoadFromText(string a_str) { a_str = a_str.Replace(System.Environment.NewLine, System.Environment.NewLine.Substring(0, 1)); List <string> lines = a_str.Split(System.Environment.NewLine[0]).ToList(); for (int i = lines.Count - 1; i >= 0; i--) { lines[i] = lines[i].Replace(" ", ""); if (lines[i].IndexOfAny(new char[] { ']', '[', '-', '+', '*' }) != -1) { lines.RemoveAt(i); } else if (lines[i].Length == 0) { lines.RemoveAt(i); } } if (lines.Count == 1) { string str = lines[0]; if (str.Length == 9 * 9) { lines.Clear(); for (int i = 0; i < 9; i++) { lines.Add(str.Substring(i * 9, 9)); } } } for (int i = lines.Count - 1; i >= 0; i--) { lines[i] = lines[i].Replace(" |", ""); lines[i] = lines[i].Replace("|", ""); lines[i] = lines[i].Replace(" ", "."); } for (int i = lines.Count - 1; i >= 0; i--) { if (lines[i].Length != SIZE) { lines.RemoveAt(i); } } if (lines.Count != SIZE) { return(null); } SudokuBoard board = new SudokuBoard(); (from cell in board.Cells() where lines[cell.Row][cell.Col] != '.' select cell).ForEach(cell => cell[Int32.Parse(new string(new char[] { lines[cell.Row][cell.Col] })) - 1].State = SudokuNumberState.sudokucellstateManualEntered); if (!board.Check()) { return(null); } return(board); }