Counterfactual thinking in cooperation dynamics