public CellState[] DoSolveLine() { var len = cells.Length; var count = sections.Length; if (count == 0 || (count == 1 && sections[0] == 0)) { return(ArrayExtension.NewFill(len, CellState.Unknown)); } solveFlags = new CellSolve[len]; passResult = PassResultSolve; CheckLineRecursion(0, 0); var result = solveFlags .Select(s => s.CheckCellState) .ToArray(); return(result); }
public CellState[] DoSolveLine() { var len = cells.Length; var count = sections.Length; if (count == 0 || (count == 1 && sections[0] == 0)) { return ArrayExtension.NewFill(len, CellState.Unknown); } solveFlags = new CellSolve[len]; passResult = PassResultSolve; CheckLineRecursion(0, 0); var result = solveFlags .Select(s => s.CheckCellState) .ToArray(); return result; }
public SectionState[] DoCheckLine() { var count = sections.Length; var result = new SectionState[count]; if (count == 0 || (count == 1 && sections[0] == 0)) { var state = cells.Any(c => c == CellState.Fill) ? SectionState.Wrong : cells.All(c => c == CellState.Dot) ? SectionState.Right : SectionState.InProgress; result.Fill(state); return(result); } if (cells.All(c => c == CellState.Unknown)) { result.Fill(SectionState.InProgress); return(result); } posFlags = new bool[count, cells.Length]; passResult = PassResultPosition; CheckLineRecursion(0, 0); for (int i = 0; i < count; i++) { int trueCount = posFlags .AsEnumerableDimension1(i) .Count(f => f); switch (trueCount) { //not founded any position, answer is wrong case 0: result.Fill(SectionState.Wrong); return(result); //only one position, is good case 1: //check position of True value int pos = posFlags .AsEnumerableDimension1(i) .TakeWhile(f => !f) .Count(); //check all Fill from position bool allIsFill = cells .Skip(pos) .Take(sections[i]) .All(cs => cs == CellState.Fill); result[i] = allIsFill ? SectionState.Right : SectionState.InProgress; break; default: result[i] = SectionState.InProgress; break; } } return(result); }
public SectionState[] DoCheckLine() { var count = sections.Length; var result = new SectionState[count]; if (count == 0 || (count == 1 && sections[0] == 0)) { var state = cells.Any(c => c == CellState.Fill) ? SectionState.Wrong : cells.All(c => c == CellState.Dot) ? SectionState.Right : SectionState.InProgress; result.Fill(state); return result; } if (cells.All(c => c == CellState.Unknown)) { result.Fill(SectionState.InProgress); return result; } posFlags = new bool[count, cells.Length]; passResult = PassResultPosition; CheckLineRecursion(0, 0); for (int i = 0; i < count; i++) { int trueCount = posFlags .AsEnumerableDimension1(i) .Count(f => f); switch (trueCount) { //not founded any position, answer is wrong case 0: result.Fill(SectionState.Wrong); return result; //only one position, is good case 1: //check position of True value int pos = posFlags .AsEnumerableDimension1(i) .TakeWhile(f => !f) .Count(); //check all Fill from position bool allIsFill = cells .Skip(pos) .Take(sections[i]) .All(cs => cs == CellState.Fill); result[i] = allIsFill ? SectionState.Right : SectionState.InProgress; break; default: result[i] = SectionState.InProgress; break; } } return result; }