Skip to content

Instantly share code, notes, and snippets.

Created January 17, 2017 00:53
Show Gist options
  • Save anonymous/f18d28cfe708b97b63f66450a0860665 to your computer and use it in GitHub Desktop.
Save anonymous/f18d28cfe708b97b63f66450a0860665 to your computer and use it in GitHub Desktop.
import random
import numpy as np
key_info = [[5, 5, 0],
[10, 5, 1],
[15, 4, 1],
[20, 3, 1],
[25, 2, 1]]
def loss(rank, stars):
if stars == 0:
if rank < 20 and rank % 5 != 0:
rank += 1
stars = key_info[int((rank-1)/5)][1]-1
else:
stars -= 1
winstreak = 0
return rank, stars, winstreak
def win(rank, stars, winstreak):
win_stars = 1
winstreak += 1
if winstreak >= 3: # and rank > 5:
win_stars = 2
stars_needed = key_info[int((rank-1)/5)][1] - stars
if stars_needed < win_stars:
rank -= 1
stars = win_stars - stars_needed
else:
stars += 1
return rank, stars, winstreak
static_win_rate_list = [0.5, 0.55, 0.60, 0.65]
dynamic_win_rate_list = [0.5, 0.55, 0.6, 0.65]
static_list = [0, 1]
for static in static_list:
for j in range(3):
static_win_rate = static_win_rate_list[j]
dynamic_win_rate = dynamic_win_rate_list[j]
game_samples = []
for i in range(100000):
rank = 25
stars = 0
winstreak = 0
games = 0
while rank > 0:
if static == 1:
if random.random() < static_win_rate:
rank, stars, winstreak = win(rank, stars, winstreak)
else:
rank, stars, winstreak = loss(rank, stars)
else:
if random.random() < dynamic_win_rate + (rank-1)/100:
rank, stars, winstreak = win(rank, stars, winstreak)
else:
rank, stars, winstreak = loss(rank, stars)
games += 1
if games > 10**6:
print("fail")
continue
game_samples.append(games)
if static == 0:
print(dynamic_win_rate + 0.25, dynamic_win_rate, np.mean(game_samples), np.std(game_samples))
if static == 1:
print(static_win_rate, static_win_rate, np.mean(game_samples), np.std(game_samples))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment