Ants are pretty smart indeed, as the Bible points out also.
They seem only to be attracted to foods in the open, which probably means that they have a highly-developed olfactory system. Maybe they're too cautious to go into boxes/closed containers; roaches aren't cautious.
Ants also, after having observed where constantly-open food area is, just move there. Ants move the closest to their food source. And since they're tiny, they can live in between small cracks; their babies are the size of a small tick. They're indetectable to average eyes.
Want to get rid of ants ? Don't leave food in the open. Ants seem to even detect un-smelling foods.
WISE ANTS