private void makeMoves(object sender, DoWorkEventArgs args) { bool hasMoves = true; bool parseFailed = false; Stopwatch stopwatch = new Stopwatch(); while (hasMoves) { stopwatch.Start(); clearAllGuesses(); parseFailed = !parseScreenAfterAnimation(); if (parseFailed) { passComplete((BackgroundWorker)sender, stopwatch); break; } hasMoves = false; foreach (IAlgorithm alg in algorithms) { var moves = alg.FindMoves(this); if (moves.Any()) { foreach (var move in moves) { hasMoves = true; move.Execute(parser); Stats.AddMove(alg.Name); } // After a move was found, restart the entire process. // Re-parsing the screen and then doing the faster algorithms is the best step break; } } // Must make a guess at this point if (!hasMoves) { var guesses = guesser.FindMoves(this); if (guesses.Any()) { if (AutoGuess) { hasMoves = true; guesses.First().Execute(parser); } else { guesses.First().MoveMouseToBlock(parser); } Stats.AddMove(guesser.Name); worker.ReportProgress(0, "Make Guess: " + guesses.First().ToString()); } } passComplete((BackgroundWorker)sender, stopwatch); } }