Learning enables adaptation in cooperation for multi-player stochastic games