internal Sequence Update(IEnumerable <Tuple <Sector.ID, Sequence> > otherParents, ref int depth, ref int errors, int numGenerations, bool optimize) { List <State> newStates = new List <State>(); int consistentTo = 0; //bool consistent = true; List <Tuple <Sector.IDDelta, State?> > influence = new List <Tuple <Sector.IDDelta, State?> >(); for (int stateI = 0; stateI < numGenerations; stateI++) { int g = stateI + GenerationOffset; if (stateI == 0 || (optimize && stateI < ConsistentRange)) { Debug.Assert(States[stateI].InconsistentCells == 0); newStates.Add(States[stateI]); consistentTo++; } else { State b = newStates[newStates.Count() - 1]; if (stateI == ConsistentRange) { b = new State(); } foreach (var c in AtGeneration(otherParents, g - 1)) { if (MyID.RelevantToEvolution(c.Item1, g)) { influence.Add(new Tuple <Sector.IDDelta, State?>(c.Item1 - MyID, c.Item2)); } } var reference = stateI < States.Length ? new State?(States[stateI]) : null; State st = b.Evolve(influence); newStates.Add(st); influence.Clear(); if (g < depth && reference.HasValue && st != reference.Value) { //if (stateI == 1) //errors++; depth = g; } bool consistent = st.InconsistentCells == 0; if (consistent) { consistentTo++; } else if (st.InconsistentCells == State.MaxInconsistency) { stateI++; for (; stateI < numGenerations; stateI++) { newStates.Add(new State(State.MaxInconsistency)); } break; } } } return(new Sequence(newStates, GenerationOffset, consistentTo, MyID)); }