Adversity and cooperation in heterogeneous pairs

This paper provides a game-theoretic model of the effect of higher adversity on the evolution of cooperation. The focus lies on how this effect of higher adversity is impacted when there is transient, non-genetic heterogeneity in the form of differences in the players’ capabilities of contributing to the public good, in the benefits they obtain from the public good, or in their cooperation costs. A framework is provided that identifies the common mechanisms that are at work across two models of cooperation (jointly producing a public good, and jointly defending an existing public good), and across the mentioned types of heterogeneity. With relatively small heterogeneity, higher adversity generates a common-enemy effect for large cooperation costs and a deterrence effect for small cooperation costs. Yet, these results on the effect of higher adversity are completely reversed for relatively large heterogeneity.

Explaining the evolution of cooperation is one of the key themes in evolutionary biology [1][2][3][4][5][6][7] . Standard explanations for the evolution of cooperation include direct 8 and indirect reciprocity 9 , kin selection 10 , group selection 11 , and network reciprocity 12 . An alternative explanation is by-product mutualism, which argues that organisms cooperate whenever it is in their individual interests to do so 13,14 . Specifically, following an argument that dates back to Kropotkin 15 , the common-enemy hypothesis of by-product mutualism argues that cooperation arises when organisms face the "common enemy of a sufficiently adverse environment" [ 16 , p.273], where the common enemy may be biotic (e.g., a predator) or abiotic (e.g., climatic conditions). This hypothesis thus provides a rationale for the phenotypic plasticity of cooperative behaviour 17 , which would be triggered by harsh environments.
At the same time, explanations of the evolution of cooperation often only model homogeneous organisms, whereas cooperating organisms may typically be heterogeneous [18][19][20][21] . Part of the literature on reciprocity [22][23][24] , on group selection 18 , and on network reciprocity [25][26][27][28][29] has already shown that heterogeneity can fundamentally affect predictions on the evolution of cooperation. Also, part of the literature on kin selection can be interpreted as investigating how heterogeneity mediates the effect of relatedness on cooperation 30 . An analysis of heterogeneity in the context of the common-enemy hypothesis is so far missing, and this report attempts to fill this gap. As will be shown, analysing the effect of heterogeneity in this context is important, as sufficiently large heterogeneity is predicted to fundamentally change the incidence of the common-enemy effect.
We focus on transient, non-genetic heterogeneity, where because of random environmental conditions, players differ according to their ability to contribute to the public good, their costs of contributing to the public good, or the benefits they obtain from the public good (this form of heterogeneity has also been referred to as ecological asymmetry 31 ; a related concept is the one of social diversity 25 , defined as differences in the scaling factor relating payoffs to fitness). Such a focus is justified, first, simply because of the importance of transient heterogeneity (see 23 ); second, because even if heterogeneous traits are non-transient and subject to evolution, these traits may evolve for reasons unrelated to the cooperative situation considered ([ 32 , p.160]; third, because even if heterogeneous traits evolve directly as a result of the cooperative situation, then as a first step one still needs to know how cooperative behaviour evolves, once evolution has led to heterogeneous groups being formed.
The common-enemy hypothesis has been formulated in several disciplines [33][34][35][36][37] , including evolutionary biology 16,[38][39][40][41][42] . Most accounts in evolutionary biology combine the hypothesis with standard explanations of cooperation. For instance, when higher adversity takes the form of larger cooperation costs, these costs in the short run wipe out cooperators who are matched with defectors; yet, in case of positive assortment this short-run effect may actually promote cooperation in the long run 43 (several other treatments combine harsh environments with forms of network reciprocity 25,[44][45][46][47][48]. Another account proposes that higher adversity in the form of a higher risk of predation can give potentially cooperating prey more reasons to repeatedly interact, and may thus promote reciprocity 49 . Finally, the common-enemy has been modeled as taking the form of a competing group, in a theory that includes elements of group selection 50 .

Model
In both modelling variants, at any point of time, the population consists of a fraction of strong and weak players (where strong players benefit more from cooperating than weak players). These fractions do not vary across time, and players are randomly assigned to the strong and weak roles independently of the roles they had in the past. Also, players are randomly matched in pairs independently from their roles (see the Methods section for the exact details). The cases of interest are subgames where a strong and a weak player are matched. Such subgames can be represented by the asymmetric bimatrix game in Table 1. The row player is the strong player (s), and the column player is the weak player (w). Each of the players can either contribute to a public good (cooperate, C), or not contribute (defect, D), with corresponding benefits and costs as defined in the literature on public goods 58-61 (while the term public-goods game is usually used for games with more than two players, we here consider a simplified setting with two players). Alternatively, cooperating may mean producing a private good for oneself which happens to produce a by-product benefit for others, where benefits and costs are defined in a different manner 62,63 ; as shown in Section 5 of the Supplementary Information, the introduction of heterogeneity in such a private-good model does not qualitatively affect the predictions, which is why it is not considered here.
Specifically, b i (x, y) denotes the benefit that player i = s, w obtains from the public good when player s adopts strategy x = C, D and player w adopts strategy y = C, D. Furthermore in Table 1, c denotes cooperation costs, with c > 0. Define by ∆ x i (with ∆ > 0 x i ) the added benefit of cooperating rather than defecting (in short: added benefit) for focal player i = s, w, when the other player cooperates ( s s s 1 . These added benefits depend on both the degree of adversity (in short: adversity) and on the degree of heterogeneity (in short: heterogeneity), which we now define.
Adversity. Denoting in general adversity by a, in both modelling variants for minimal adversity it is the case , meaning that with minimal adversity, a player of a given type contributes the same to the public good, whether or not the other player contributes as well. Furthermore, in both modelling variants the effect of adversity on the added benefits is monotonic; specifically, it is the case that ∂∆ ∂ > a / 0 i 1 , and ∂∆ ∂ < a / 0 i 0 , so that as adversity is increased, a second cooperating player of a given type contributes more than a first cooperating player (this is with some abuse of notation, as in the defence variant the variable measuring adversity can only take on integer values). Put otherwise, as adversity is increased, a player who defects from joint cooperation becomes to a larger extent the victim of his own defection (referred to as the boomerang effect 16,38 ); at the same time a player who deviates from joint defection by cooperating benefits to a smaller extent.
As detailed in the Methods section, in the production variant, adversity is measured by the degree of complementarity between the players' efforts, which measures how much a second cooperating player in a pair contributes to the public good compared to a first cooperating player (and thus measures to what extent a player's contribution is pivotal). In the defence variant, the degree of complementarity between the players' contributions to the public good is instead fixed. Players in a pair face random attacks, and a player contributes to the public good when defending the public good (=cooperating), but also when not defending it (=defecting) but never Weak player (w)

Cooperate (C) Defect (D)
Strong player (s) Table 1. Asymmetric bimatrix game representing payoffs of the strong player (s) and the weak player (w), depending on whether each of the players cooperates (C) or defects (D). b i (x, y) denotes the benefit that player i = s, w obtains from the public good when player s adopts strategy x = C, D and player w adopts strategy y = C, D. The cooperation costs are denoted by c.
being attacked. Adversity is now measured by the number of random attacks facing the players. For a large number of attacks, defecting means not contributing to the public good with probability approaching 1, and the extent to which a second cooperating player contributes to the public good compared to the first cooperating player is reflected by the fixed degree of complementarity. For a lower number of random attacks, a second cooperating player contributes less to the public good, because a defecting player is targeted with a probability lower than 1.
The number of attacks therefore has a similar effect as the variable degree of complementarity in the production variant, in making each player's effort more pivotal.
Heterogeneity. The strong and the weak player differ in the sense that the strong player gains more from cooperating than defecting than the weak player, whatever the action taken by the other player; put otherwise, for As explained in detail in the Methods section, for both modelling variants we separately consider the case where the strong player contributes more to the public good than the weak player, where the strong player obtains a larger share of the public good than the weak player, and where the strong player has lower cooperation costs than the weak player (where the latter case is analytically equivalent to a case with heterogeneous benefits and homogeneous costs, and therefore can still be analysed within this framework of Table 1). In each of these cases, heterogeneity is caught by a single parameter h, where for vanishing heterogeneity we have ∆ = ∆ , such that all else equal larger heterogeneity increases (decreases) how much the strong (weak) player gains from cooperating rather than defecting.

Results
Strict equilibria. The question we seek to answer is: what actions do evolutionarily stable strategies (ESSs 64 ) prescribe for players in subgames as Table 1, when players face a particular level of cooperation costs, a particular degree of adversity, and a particular degree of heterogeneity. As shown in the Methods section, to answer this question, it suffices to look for strict equilibria of the subgames. It is straightforward to see that three strict equilibria are possible, as summarized in Table 2. Given that ∆ ≥ ∆ types of games played. From the previous it follows that the game in Table 1 , the only strict equilibrium is joint defection, and we have a Prisoner's Dilemma 67 . When ∆ < ∆ s w 0 1 and ∆ < < ∆ c s w 0 1 , both joint cooperation and joint defection are equilibria, and we have a Stag Hunt 68 . Heterogeneity means that the strong player benefits more from contributing to the public good than the weak player, adversity means that a second cooperating player in a pair contributes more than a first cooperating player; the necessary condition ∆ < ∆ for a Stag Hunt thus requires that adversity has more impact than heterogeneity, as a weak second cooperating player then benefits more than a strong first cooperating player. When ∆ < ∆ w s 1 0 and ∆ < < ∆ c w s 1 0 the game only has a strict equilibrium where the strong player cooperates and the weak player defects, and we refer to it as a Free-Rider game (referred to as exploitation of the great by the small in the classical analysis of collective action problems by Olson 69 ). A necessary condition for a Free-Rider game is that heterogeneity is sufficiently strong compared to adversity, such that a second weak cooperating player benefits less than a first strong cooperating player.
Comparison of vanishing and large heterogeneity. As a starting point to assess the effect of higher adversity (where the possible types of effects are summarised in Table 3), and how this effect is impacted by heterogeneity, we compare vanishing and large heterogeneity. Figure 1 considers as an example the defence variant of the model, with heterogeneity in the form of different shares of the public good obtained (for details, see the  Table 2. Depending on the relation between cooperation costs c on the one hand, and the added benefit of cooperating rather than defecting to the strong player when the other player defects (∆ s 0 ) and the added benefit of cooperating rather than defecting to the weak player when the other player cooperates (∆ w 1 ): strict equilibria obtained, and corresponding form of the game in Table 1. www.nature.com/scientificreports www.nature.com/scientificreports/ Methods section), and represents ∆ s 0 and ∆ w 1 as a function adversity in the form of the number of random attacks A (where for ease of representation, we present ∆ s 0 and ∆ w 1 as continuous functions, even though A can only take on integer values). Figure 1(a) represents the limit case where heterogeneity is vanishingly small, as analysed elsewhere 52 . In this case, for minimal adversity we have ∆ = ∆ w s 1 0 . Representing cooperation costs along the Y-axis and comparing them to ∆ s 0 and ∆ w 1 , one can now indicate in Fig. 1(a) whether the game is a Prisoner's Dilemma, a Stag Hunt, or a Harmony Game. Starting from low adversity, when cooperation costs are large no cooperation takes place (Prisoner's Dilemma). With higher adversity, a first cooperating player benefits even less from unilaterally cooperating (∂∆ ∂ < a / 0 s 0 ), but a second cooperating player has more and more to lose from unilaterally deviating from joint cooperation (∂∆ ∂ > a / 0 w 1 ). Because of this a common-enemy effect is obtained, as joint cooperation now also becomes a strict equilibrium (Stag Hunt). We refer to this as the symmetric common-enemy effect. Starting again from low adversity, when cooperation costs are instead small, joint cooperation takes place (Harmony Game). With higher adversity, a second cooperating player loses even more when failing to cooperate (∂∆ ∂ > a / 0 w 1 ) and joint cooperation continues to be a strict equilibrium, but a first cooperating player has less to gain from unilaterally cooperating (∂∆ ∂ < a / 0 s 0 ), so that joint defection also becomes a strict equilibrium (Stag Hunt). We refer to this as the symmetric deterrence effect.
Starting from Fig. 1(a), larger heterogeneity shifts ∆ s 0 upwards and ∆ w 1 downwards. Figure 1(d) represents the case where heterogeneity is large, and where shifting has taken place to such an extent that it is the case that ∆ > ∆ s w 0 1 for any degree of adversity. Start from small adversity and consider cooperation cost ranges ∆ < < ∆ c w s 1 0 , such that the game is a Free-Rider game. Consider first large cooperation costs. As we increase adversity, it now continues to be the case that a weak second cooperating player is better off defecting (∆ < c w 1 ), but it also becomes the case that a strong first cooperating player is also better off defecting (∆ < c s 0 ), so that the game becomes a Prisoner's Dilemma; we refer to this as the asymmetric deterrence effect. Next, consider small cooperation costs. For higher adversity, it is still the case that a strong first cooperating player is better off cooperating < ∆ c ( ) s 0 , but a weak second cooperating player also becomes better off cooperating < ∆ c ( ) w 1 , so that the game becomes a Harmony Game; we refer to this as the asymmetric common-enemy effect (this distinction between symmetric and asymmetric effects is similar to the effect of the degree of relatedness on the probability of cooperation in the treatment of Hamilton's rule 70 ). As comparison of Fig. 1(a,d) shows, compared to the case of vanishing heterogeneity, large heterogeneity completely reverses the incidence of the common-enemy and deterrence effects as a function of the cooperation costs.
Non-monotonic effects of adversity for small heterogeneity. Figure 1(b,c) represent scenarios where heterogeneity is not vanishing, but at the same time not as large as in Fig. 1(d), where we refer to these scenarios as small heterogeneity. In such scenarios, higher adversity can have a non-monotonic effect on the probability of cooperation. Figure 1(b) represents a scenario within the lower range of small heterogeneity. In this case, just as the case in Fig. 1(a) (vanishing heterogeneity), for the upper ranges of high cooperation costs, the symmetric common-enemy effect applies, and for the lower ranges of small cooperation costs the symmetric deterrence effect applies. Yet, for the lower ranges of large cooperation costs, as adversity is increased, first the asymmetric deterrence effect applies, and only then the symmetric common-enemy effect. For the upper ranges of low cooperation costs, as adversity is increased, first the asymmetric common-enemy effect applies, and only then the symmetric deterrence effect. Figure 1(c) represents a scenario within the upper range of smaller heterogeneity. In this case, just as in Fig. 1(d) (large heterogeneity), for the upper ranges of high cooperation costs, the asymmetric deterrence effect applies, and for the lower ranges of small cooperation costs the asymmetric common-enemy effect applies. Yet, for intermediate cost levels, the same non-monotonic effects as in Fig. 1(b) are obtained.
Intuition for non-monotonic effects. While Fig. 1(a,d) show that the incidence of the common-enemy and deterrence effect is reversed for large heterogeneity, the non-monotonic effects of adversity for small heterogeneity in Fig. 1(b,c) complicate the results. Yet, we now argue that the non-monotonic effects are part of the same mechanism where sufficiently large heterogeneity reverses the incidence of the common-enemy and deterrence effects. Indeed, as higher adversity make each player's contribution to the public good more pivotal, a weak second cooperating player may then still contribute more than a strong first cooperating player, thus undoing the effect of heterogeneity, explaining why in Fig. 1(b,c) the symmetric effects apply for high adversity. In contrast, low adversity means that heterogeneity will have a relatively large impact, and that the asymmetric effects  Table 3. Possible cases for the effect of higher adversity on the probability of cooperation identified across all modelling variants considered in the Methods section; definition of these effects in terms of changes in the form of the game (see Table 2).
www.nature.com/scientificreports www.nature.com/scientificreports/ are obtained (with the corresponding reversed incidence of the common-enemy and deterrence effects), even though heterogeneity may be small in absolute terms. The incidence of the common-enemy and deterrence effects therefore depends on how large the degree of heterogeneity is relative to the degree of adversity. In Fig. 1(d), heterogeneity is so large that high adversity can never undo it, and the asymmetric effects apply. In Fig. 1(b,c), heterogeneity is relatively large when adversity is low (asymmetric effects), but heterogeneity becomes relative small when adversity is high (symmetric effects).
Detailed results. Figure 1 represents the results for the defence variant, when heterogeneity takes the form that players obtain different shares from the public good. While the results of all modelling variants have common features, the precise details differ, as represented in Table 4. Common features are that as heterogeneity is increased, the asymmetric common-enemy and deterrence effects apply for a wider range of degrees of adversity; this follows naturally from the fact that heterogeneity shifts ∆ s 0 upwards, and ∆ w 1 downwards, as can be seen by comparing Fig. 1(b,c). The way in which the detailed results differ across the variants, is that in some variants for sufficiently large heterogeneity, the asymmetric common-enemy and deterrence effects become the only possible effects (as is the case in Fig. 1(d)), whereas in other variants even for a maximal heterogeneity, the symmetric effects continue to apply as long as adversity is sufficiently high.
These differences in results are explained as follows. First, the results differ between the production and defence variants for the following reason. In the production variant, where adversity is measured by the degree of complementarity, complementarity can become so large that a first cooperating player contributes vanishingly little compared to a second cooperating player; in this case, the effect of heterogeneity is undone, explaining why in the production variant symmetric effects continue to be obtained for high adversity. In the defence variant on the contrary, the fixed degree of complementarity between the players' contributions need not be maximal. For this reason, even with maximal adversity (=large number of random attacks), the extent to which players' contributions are pivotal is still not maximal. The consequence is that even high adversity does not undo the effect of heterogeneity, explaining why for large heterogeneity (cf. Fig. 1(d)) only the asymmetric effects may apply.
Second, heterogeneity modelled as a difference in capability of contributing to the public good leads to different effects than the other two types of heterogeneity considered. Even if players differ considerably in their capabilities to contribute to the public good, when a second cooperating player's effort becomes to a large extent  Table 1, as a function of adversity a, added benefit of cooperating rather than defecting for the weak player if the other player cooperates (∆ w 1 ), and for the strong player if the other player defects (∆ s 0 ). Depending on the relation between cooperation costs and these added benefits, the form of the game played is indicated (see Table 2). Depending on how adversity affects the form of the game played, it is indicated whether as a function of the cooperation costs the (a) symmetric common-enemy or (a) symmetric deterrence effect applies, as defined in Table 3. The particular case represented is the defence variant of the model (so that adversity a is measured by the number of random attacks A, which in the graphs range from 1 to 7 attacks) with heterogeneous shares obtained from the public good (see Methods section), where V = 1 and www.nature.com/scientificreports www.nature.com/scientificreports/ critical, this undoes the effect of heterogeneity and the symmetric effects are obtained. However, when heterogeneity takes the form of players obtaining different shares of the public good or incurring different cooperation costs, heterogeneity can always be so large that a first cooperating player who is strong is more inclined to contribute to the public good than a second cooperating player who is weak, whatever the degree of adversity (cf. Fig. 1(d)). This explains why in these cases, for large heterogeneity, only the asymmetric effects may apply.

Discussion
The game-theoretic model in this report allows not only for a common-enemy effect, but also for a deterrence effect of a harsher environment. Moreover, how the incidence of these two effects of a harsher environment changes as a function of the cooperation costs, depends on the degree to which the players are heterogeneous: if heterogeneity is relatively small, the common-enemy effect applies for large cooperation costs, and the deterrence effect applies for small cooperation costs; if heterogeneity is instead relatively large, it is the deterrence effect that applies for large cooperation costs, and the common-enemy effect for small cooperation costs. The model thus provides detailed predictions for how the phenotypic plasticity of cooperative behaviour may be influenced by the harshness of the environment, the cooperation costs, and the degree of heterogeneity between the players.
It should be stressed that the model for which these predictions are obtained is extremely stylised, with several simplifying assumptions. Costs of plasticity 71 , such as information-acquisition costs to determine the cooperation costs, the degree of adversity and the degree heterogeneity, were not considered (though experiments suggest that even simple organisms are able to overcome these costs 17 ). In the model, players cooperate in pairs, whereas in reality cooperating groups may have any size (an extension in the Supplementary Information (Section 6) suggests that the results extend to larger groups, even though these give rise to additional non-monotonic effects of adversity). Additionally, the formation of groups may itself be subject to evolution, rather than groups being given as in the model 72 . What players produce in the model is a pure public good; in reality, players who do not cooperate may obtain fewer benefits than players who defect (e.g., free-riding on the collective hunt of other predators in one's group may lead one to obtain a smaller share of the prey), and congestion may take place as the number of cooperators in a group increases (e.g., when more predators participate in a collective hunt, the prey needs to be shared among more predators) 73 . Finally, while in the model investment in the public good is an all-or-nothing one-dimensional decision, in reality cooperators' efforts may be continuous 58 . Though the expectation is that the stylised model in this report reveals mechanisms that are at work in much more complex reality, relaxing the mentioned simplifying assumptions deserves separate attention. Most of all, while in the model the focus is on the effect of harsher environments on the probability of cooperation, future research needs to investigate how this effect interacts with standard rationales for the evolution of cooperation, including crucially network reciprocity. Moreover, an avenue for future research is to explore the effect of harsher environments when players are able to collaborate, in being able to make coordinated moves towards strategies that are mutually beneficial 74,75 .  Table 4. Summary of the results for the effect of higher adversity on the probability of cooperation. The rows represent the different modelling variants in the Methodology section. Each column represents which of the effects of a higher adversity listed in Table 3 occurs, where these effects are ordered according to their incidence as a function of the cooperation costs (from large to small cooperation costs). The columns are ordered representing larger heterogeneity from left to right. Specifically for the defence variant of the model, the case with a large fixed degree of complementarity is represented. www.nature.com/scientificreports www.nature.com/scientificreports/ We end by exploring how the results of the model could be translated into testable hypotheses. While adversity may be quantified by predation risk in the defence variant, or by the size of a prey in the production variant (where a larger prey makes each predator's contribution to a collective hunt more pivotal) 16 , and while heterogeneity may also have a direct biological interpretation, cooperation costs may be difficult to quantify (a similar problem arises when deriving hypotheses from theories on the formation of coalitions and alliances 76 ). The level of the cooperation costs is moreover only defined relative to the benefits obtained from the public good, which also do not have a direct biological interpretation. Moreover, even if an appropriate proxy variable could be found to account for relative cooperation costs, such a variable need not relate in a linear way to fitness, and therefore to the payoffs in Table 1. For this reason, a large size of any such proxy variable need not translate into what corresponds to large cooperation costs in the model, so that it may not be possible to observe all the cases in the model by using a proxy variable for cooperation costs. Also, even if one can find a proxy variable that is not subject to this problem, one additionally needs to ensure that the different variables are not correlated. For instance, a larger prey may not only make each predator's contribution to a cooperative hunt more pivotal and may thus not only measure adversity, but may also increase cooperation costs at the same time. We conclude that turning the predictions of our model into testable hypotheses requires separate attention.

Methods
Two modelling variants of the effect of a harsher environment are considered, namely a production variant and a defence variant 52 . For each of these models, three types of heterogeneity are considered, namely heterogeneity in the capability of contributing to the public good, heterogeneity in the share of the public good obtained, and heterogeneity in cooperation costs. As reported in the Results section, qualitatively similar results are obtained for each of the cases. Formal descriptions of the results, and all the proofs, are contained in the Supplementary Information (Sections 3 and 4). evolutionary game. We consider an infinitely large population that reproduces asexually. In each period, with a given probability, the player is assigned the role of a strong player or of a weak player. Players are assigned to a role fully independently of the roles they may have had in the past, and the fraction of strong and weak players in the population is not subject to evolution. The population is repeatedly and randomly matched in pairs, where pairs are formed independently of the roles of the players. A strategy of a player tells the player whether to cooperate or defect in each possible subgame that may be formed, depending on the player's own type and the type of the player to whom he is matched, on the degree of adversity, and on the degree of heterogeneity. The change in the fraction of players adopting a strategy is assumed to follow the continuous replicator dynamics 77 .
Evolutionarily stable strategies and strict equilibria. Any ESS of the specified asymmetric game must be a strict, and therefore a pure-strategy equilibrium 78 . Moreover, in order to have a strict equilibrium of the entire game, players' strategies in each of the subgames that can be formed must be strict mutual best responses, so that to any ESS must correspond a strict equilibrium in each possible subgame 79 . Since our interest is in the effect of heterogeneity, Table 1 considers a subgame where an asymmetric pair is formed. The cases where a symmetric pair is formed is already analysed in the symmetric version of the model in this report 52 . production variant. The production variant may be seen as a stylised representation of cooperative hunting 53,54 , where the good produced is the prey caught. In the version of this variant with vanishing heterogeneity, if both players in a pair cooperate, they both obtain payoff V from the public good (meaning b s (C, C) = b w (C, C) = V); if both players defect they both obtain payoff 0 (meaning b s (D, D) = b w (D, D) = 0). If one player cooperates and the other one defects, both players obtain value (1 − k)V from the public good (meaning b s (C, . It is the case that ≤ ≤ k 1/2 1, where k is the degree of complementarity between the players' efforts 80 , and reflects the extent to which a second cooperating player in a pair is pivotal compared to a first cooperating player. With k = 1/2, pivotality is minimal, and a first and second cooperating player contribute the same (in this case, the game is a two-player version of the linear public-goods game 58 , with benefit of the public good equal to πrc/2, where π is the number of cooperating players in the pair and r is the multiplication factor; our model is obtained by assuming that rc = V). With k = 1 pivotality is maximal, and a second cooperating player contributes the entire value of the public good.
Heterogeneous capability to contribute to the public good. It continues to be the case that b s (C, where h measures the degree of heterogeneity. Specifically, h reflects the extent to which the players have heterogeneous capabilities of contributing to the public good, where the larger h, the more a strong player that cooperates alone contributes to the public good compared to a weak player that cooperates alone. When h = 1/2, heterogeneity vanishes; when h = 1, heterogeneity is maximal and a weak player who cooperates alone does not contribute anything. Heterogeneous shares obtained from the public good. In this case, players have the same capability of contributing to the public good, and heterogeneity h, with ≤ ≤ h 1/2 1, reflects the share of the total value of the public good that is obtained by the strong player. When h = 1/2, the case with vanishing heterogeneity is again obtained. When h = 1, heterogeneity is maximal, and e.g. when both players cooperate, of the total value that is produced for the players in the absence of heterogeneity (i.e. V for each player, or 2V in total), the strong player obtains 2V and the weak player obtains nothing.
www.nature.com/scientificreports www.nature.com/scientificreports/ Heterogeneous cooperation costs. In this case, benefits are the same as with vanishing heterogeneity, but the strong and the weak player have different cooperation costs. In particular, we assume that a strong player incurs costs c s = 2(1 − h)c, whereas a weak player incurs costs c w = 2hc, with ≤ ≤ h 1/2 1. In this manner, average cooperation costs within a heterogeneous group equal + − = hc h c c 1/2(2 ) 1/2(2(1 ) ) . As shown in the Supplementary Information, as only the level of the cooperation costs relative to benefits matters for our results, this case is analytically equivalent to a case where players have the same average cooperation costs, but have heterogeneous benefits.
Defence variant. In the defence variant, the number of players that contributes to the public good relates to the value obtained from the public good in exactly the same way as in the production model, where the degree of complementarity is now kept fixed. Yet, cooperating or defecting now relates in a stochastic way to contributing or not contributing to the public good. In particular, the defence variant represents in a stylised way a situation of circular defence 81 . Each player in a pair is positioned on one of the two sides of a common territory. Cooperating (C) means doing effort to defend one's side, defecting (D) means not doing any effort. The players face a number of random attacks A (with A ≥ 1), taking the form of sampling with replacement of the two sides of the common territory.
With probability 1/2 A , the individual player is never attacked, and with probability [1 − 1/2 A ], this player is attacked at least once. The individual player contributes to the public good when defending, but also when not defending and never being attacked. With vanishing heterogeneity, it is the case that b s (C, C) = b w (C, C) = V. Furthermore, , where 1 2 A is the probability that a non-defending player in a pair is never attacked and still contributes. The number of random attacks measures adversity in the sense that just like the variable degree of complementarity in the production variant, it makes each player's effort more pivotal, in that for a large number of random attacks a second cooperating player adds more value to the public good compared to a first cooperating player. The same three forms of heterogeneity are now considered as for the production model.
Heterogeneous capability to contribute to the public good. In this case, we have b s (C, C) = b w (C, C) = V and b s (D, . When the strong player cooperates and the weak player defects, . When the weak player cooperates and the strong player defects, . Also,  .
Heterogeneous cooperation costs. In this case benefits are the same as in the defence variant with vanishing heterogeneity, and heterogeneous cooperation costs are constructed in the same way as for the production model with heterogeneous cooperation costs.