Skip to content

Instantly share code, notes, and snippets.

@dekosuke
Created November 23, 2015 16:24
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dekosuke/cbf2052b0a81c07873b2 to your computer and use it in GitHub Desktop.
Save dekosuke/cbf2052b0a81c07873b2 to your computer and use it in GitHub Desktop.
#!/usr/bin/env python
# coding:utf-8
population = 1000
num_round = 10000
mode = 1 #1: current 2:proposed
ranks = ["C-","C", "C+", "B-", "B", "B+", "A-", "A", "A+", "S", "S+"]
if mode==1:
reward_win = [(24,20,16), (18,15,12), (14,12,10), (14,12,10), (12,10,8), (12,10,8), (12,10,8), (12,10,8), (12,10,8), (5,4,4), (4,3,2)]
reward_lose = [(8,10,12), (8,10,12), (8,10,12), (8,10,12), (8,10,12), (8,10,12), (8,10,12), (8,10,12), (8,10,12), (5,5,6),(4,5,5)]
else: #mode=2
reward_win = [(20,20,20), (15,15,15), (12,12,12), (12,12,12), (10,10,10), (10,10,10), (10,10,10), (10,10,10), (10,10,10), (5,4,4), (4,3,2)]
reward_lose = [(10,10,10), (10,10,10), (10,10,10), (10,10,10), (10,10,10), (10,10,10), (10,10,10), (10,10,10), (10,10,10), (5,5,6),(4,5,5)]
#reward_win = [20, 15, 12, 12, 10, 10, 10, 10, 10, 10, 10]
#reward_lose = [10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10]
num_ranks = len(ranks)
def point_level(p):
if p<40:return 0
elif p<80: return 1
else: return 2
import random
pop_ranks = [0 for i in xrange(population)]
pop_points = [i%10 for i in xrange(population)]
for t in xrange(num_round):
for u in xrange(population):
if random.random()>0.5: #win
p = point_level(pop_points[u])
pop_points[u] += reward_win[pop_ranks[u]][p]
if pop_points[u] >= 100:
if pop_ranks[u] == num_ranks-1: #S+
pop_points[u] = 99
else:
pop_ranks[u]+=1
if mode==1:
pop_points[u]=30
else: #mode==2
if pop_ranks[u] >= num_ranks-2: #S or S+
pop_points[u]=15
else: #C- to A+
pop_points[u]=30
else: #lose
p = point_level(pop_points[u])
pop_points[u] -= reward_lose[pop_ranks[u]][p]
if (mode==1 and pop_points[u]<0) or (pop_points[u]<=0):
if pop_ranks[u] == 0: #C-
pop_points[u]=0
else:
pop_ranks[u]-=1
if mode==1:
pop_points[u]=70
else: #mode==2
if pop_ranks[u] >= num_ranks-2: #S or S+
pop_points[u]=85
else: #C- to A+
pop_points[u]=70
#print u, ranks[pop_ranks[u]],pop_points[u]
if (t%1000)==0:
for rpop in [(r,pop_ranks.count(r)) for r in range(num_ranks)]:
print "round",t,":",ranks[rpop[0]], rpop[1]
import numpy as np
import matplotlib.pyplot as plt
from matplotlib import rc
import matplotlib as mpl
import sys, os, copy, math, re
plt.figure(figsize=(9,6))
plt.subplots_adjust(left=0.15, right=0.9, top=0.9, bottom=0.15)
plt.rcParams["font.size"]=20
plt.xlabel("ranks")
plt.ylabel("users[%]")
X = range(num_ranks)
Y = [pop_ranks.count(r)*100.0/population for r in X]
plt.xticks(X, ranks)
colors = (0.6,0.6,0.8), (0.3,0.3,0.8), (0.0,0.0,0.8),\
(0.6,0.9,0.6), (0.3,0.9,0.3),(0.0,0.9,0.0),\
(0.9,0.9,0.6), (0.9,0.9,0.3),(0.9,0.9,0.0),\
(0.9,0.45,0.45),(0.9,0.0,0.0),
plt.bar(map(lambda x:x-0.4,X), Y, color=colors)
#plt.legend(loc="upper left")
plt.savefig('ranks.png')
plt.show()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment