I have a dice pool system that awards for instance damage to the loser of an opposed roll. Players roll their pool of dice, with each player's target number being the highest number rolled by their opponent. Any roll above or equal to the target counts as one success. Players then compare their number of successes and the loser takes the difference as damage.
In the case of the players having an equal number of successes, then the player with the highest series of dice wins and deals 1 point of damage to the loser. (Starting with the highest die, the players discard matching dice until one of the players has a higher die.)
I have modelled this in AnyDice thus: Brawl Dice
function: brawl A:s vs B:s {
SA: A >= 1@B
SB: B >= 1@A
if SA-SB=0 {
result:(A > B) - (A < B)
}
result:SA-SB
}
output [brawl 3d6 vs 3d6] named "A vs B Damage"
All well and good, but my question is:
How would I model a similar situation but with Player A being able to swap his lowest dice for Player B's highest?
Also, if anyone knows how I can optimise the above code it would be appreciated. Currently I'm limited to fairly small pools.
Example #1:
Player A rolls: 4,3,3,2,1
Player B rolls: 4,4,2,2,2Player A swaps dice, exchanges his 1 result for Player B's 4 result.
Player A's final pool: 4,4,3,3,2
Player B's final pool: 4,2,2,2,1Both players' target number is 4 (taken as the highest value of the other player's pool).
Player A has two successes.
Player B has one success.
Player B takes one "damage".
Example #2:
Player A rolls: 4,3,3,2,1
Player B rolls: 6,4,2,2,2Player A swaps dice, exchanges his 1 result for Player B's 6 result.
Player A's final pool: 6,4,3,3,2
player B's final pool: 4,2,2,2,1Player A's target number is 4 (2 successes).
Player B's target number is 6 (0 successes).Player B takes two "damage".
Example #3:
Player A rolls: 4,3,2,2,1
Player B rolls: 4,4,4,3,1Player A swaps dice, exchanges his 1 result for Player B's 4 result.
Player A's final pool: 4,4,3,2,2
Player B's final pool: 4,4,3,1,1Player A's target number is 4 (2 successes).
Player B's target number is 4 (2 successes).Tiebreak!
Player A: 4,4,3,2,2
Player B: 4,4,3,1,1
Player A wins the tiebreak awarding 1 damage to player B.
If there is a Troll solution then that would also be acceptable. I have never used Troll before but I think I should be able to pick it up.
I have managed to get to the same place with Troll as with the AnyDice code above, but I'm stuck at implementing the swapping mechanic. :(
a:=5d6;
b:=5d6;
result := (count (max b) <= a)-(count (max a) <= b);
aa := sum(max(a -- b));
bb := sum(max(b -- a));
tiebreak := if aa > bb then 1
else if aa < bb then -1
else 0;
if result = 0 then tiebreak else result