Evolution of collective behavior, communication, and cognition