// Better memory usage, does not creat an array of all nodes public void WriteTree(BinaryWriter bw, SolverNode root) { var count = root.CountRecursive(); WriteHeader(bw, root.MoveMap.Size, count); int cc = 0; foreach (var node in root.Recurse()) { Write(bw, node); cc++; } if (cc != count) { throw new Exception($"Invalid Counts: Count: {count} vs {cc} vs {root.Recurse().Count()}"); } }