Skip to content

Instantly share code, notes, and snippets.

@eIGato
Created February 20, 2022 13:34
Show Gist options
  • Save eIGato/f4224e4eee6e0c696d406b43fbcb547c to your computer and use it in GitHub Desktop.
Save eIGato/f4224e4eee6e0c696d406b43fbcb547c to your computer and use it in GitHub Desktop.
Calculate star gaining rate based on the deck win rate
# WR 45.34% is enough to keep your ground.
# WR 50% gains 0.125 stars per battle on average.
def get_streak_points(num_wins):
if num_wins < 3:
return num_wins
return num_wins * 2 - 2
def get_point_rate(win_rate):
if win_rate == 0:
return -1
if win_rate == 1:
return 2
assert 0 < win_rate < 1
lose_streak_len = 0
lose_streak_points = 0
win_streak_len = 0
win_streak_points = 0
avg_len = 0
probability = 1 # To move to next step.
while probability >= 0.0001:
lose_streak_len += 1
lose_streak_points += probability * win_rate * get_streak_points(
-lose_streak_len
)
probability *= 1 - win_rate
else:
lose_streak_points += probability * get_streak_points(
-(lose_streak_len + 1)
)
probability = 1 # To move to next step.
while probability >= 0.0001:
win_streak_len += 1
win_streak_points += probability * (1 - win_rate) * get_streak_points(
win_streak_len
)
avg_len += probability * (1 - win_rate) * win_streak_len
probability *= win_rate
else:
win_streak_points += probability * get_streak_points(
win_streak_len + 1
)
avg_len += probability * (win_streak_len + 1)
point_rate = (win_streak_points + lose_streak_points) / (
avg_len - lose_streak_points
)
print(
f'Avg lose streak {-lose_streak_points:.3f}'
f' gives {lose_streak_points:.3f} points.'
f'\nAvg win streak {avg_len:.3f} gives {win_streak_points:.3f} points.'
f'\nTotal {win_streak_points + lose_streak_points:.3f} points'
f' for {avg_len - lose_streak_points:.3f} games'
f', or {point_rate:.3f} points per game.'
)
return point_rate
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment