  Complex social behaviors lie at the heart of many of the challenges facing
evolutionary biology, sociology, economics, and beyond. For evolutionary
biologists in particular the question is often how such behaviors can arise
\textit{de novo} in a simple evolving system. How can group behaviors such as
collective action, or decision making that accounts for memories of past
experience, emerge and persist? Evolutionary game theory provides a framework
for formalizing these questions and admitting them to rigorous study. Here we
develop such a framework to study the evolution of sustained collective action
in multi-player public-goods games, in which players have arbitrarily long
memories of prior rounds of play and can react to their experience in an
arbitrary way. To study this problem we construct a coordinate system for
memory-$m$ strategies in iterated $n$-player games that permits us to
characterize all the cooperative strategies that resist invasion by any mutant
strategy, and thus stabilize cooperative behavior. We show that while larger
games inevitably make cooperation harder to evolve, there nevertheless always
exists a positive volume of strategies that stabilize cooperation provided the
population size is large enough. We also show that, when games are small,
longer-memory strategies make cooperation easier to evolve, by increasing the
number of ways to stabilize cooperation. Finally we explore the co-evolution of
behavior and memory capacity, and we find that longer-memory strategies tend to
evolve in small games, which in turn drives the evolution of cooperation even
when the benefits for cooperation are low.
