Use foldLeft in AI module, tests still pass