Evolution doesn’t “know” anything. It is just a mindless, unintelligent process. It doesn’t know where it is going nor cares. Starting a time T, accumulate mutations, favorable mutants live, unfavorable die, neutral mutations stay in genome for another day. After an extinction event, resumes with just the survivors and carries on the mindless unintelligent process in the changed environment.