The emergence of cooperation by evolutionary generalization