If B defects, A should also defect, because serving 2 years is better than serving 3. Mutual defection is the only strong Nash equilibrium in the game (i.e.the only outcome from which each player could only do worse by unilaterally changing strategy).Suppose that the two players are represented by the colors, red and blue, and that each player chooses to either "Cooperate" or "Defect".
If the number of times the game will be played is known to the players, then (by backward induction) two classically rational players will betray each other repeatedly, for the same reasons as the single-shot variant.
In an infinite or unknown length game there is no fixed optimum strategy, and prisoner's dilemma tournaments have been held to compete and test algorithms.
If both players defect, they both receive the punishment payoff P.
If Blue defects while Red cooperates, then Blue receives the temptation payoff T, while Red receives the "sucker's" payoff, S.
If X and Y contract to exchange an apple and an orange, and each fulfills their end of the deal, then each receive a payoff of b-c.