むるおか君のPythonパチンコシミュレーション

Pythonを使ってパチンコの新台解析やってます。たまに自分が処理したい作業のGUIも作ったり

P北斗無双3の天井解析プログラム

# -*- coding: utf-8 -*-
"""
Created on Wed Jul  1 10:56:29 2020

@author: HOST1191
"""
import random
import statistics 
import collections
import matplotlib.pyplot as plt
import seaborn as sns
import csv
#Pデンチュー振り分け
def d_furi():
    d_furir = random.randint(1,100)
    d_dedama =  0
    d_kakuhen =  0
    if  d_furir  >=  1  and  d_furir <= 25:
        d_dedama +=  1200
        d_kakuhen   =  1
    elif d_furir  > 26  and  d_furir  <=  50:
        d_dedama  += 810
        d_kakuhen  =  1
    else:
        d_dedama  += 420
        d_kakuhen  =  1
    return  d_dedama,d_kakuhen

#P北斗無双3ヘソの振り分け
def h_furi():
    h_furir = random.randint(1,200)
    h_dedama =  0
    h_kakuhen =  0
    if  h_furir  >=  1  and  h_furir  <= 25:
        h_dedama +=  390
        h_kakuhen   =  1
    else:
        h_dedama  +=  390
        h_kakuhen   =  0
    return  h_dedama,h_kakuhen  
#連荘
def renchan(r_kakuhen):
    wk_st    = 0
    r_dedama  =  0
    wk_dedama =  0
    wk_ren  =  0
    end  =  0
#パラメータ説明
#r_kakuhen =  0  確変ではない
#          =  1  確変
    while  end  < 1:
        r_tyusen = random.random()
        wk_st  +=  1
        wk_dedama  =  wk_dedama  -  0.5
        if r_tyusen <= (1/6.17):
            wk_ren  +=  1
            r_dedama,r_kakuhen = d_furi() 
            wk_dedama  +=  r_dedama
            wk_st  =  0
            r_kakuhen  =  1
        if  r_kakuhen  ==  1:
            if  wk_st  >=  13:
                end  +=  1
        else:
            if  wk_st  >=  4:
                end  +=  1
    return  wk_ren,wk_dedama

sikou  =  100000
#連荘回数
ren1 = []
#ラッシュの出玉数
dedama1 = []
for  sim  in  range(1,sikou+1):
#初当たりの振り分け処理天井考慮  
    sim3  =  0
    end1  =  0
    while  end1  <  1:
        t_tyusen  =  random.random()
        sim3  +=  1
        if  sim3  >=  950  and  sim3  <= 1205:
            if  t_tyusen  <=  (1/6.17):
                d_dedama,d_kakuhen  =  d_furi()
                ren,dedama  =  renchan(d_kakuhen)
                ren  +=  1
                dedama  +=  d_dedama
                end1  +=  1
        else:
            if  t_tyusen  <=  (1/319.68):
                h_dedama,h_kakuhen  =  h_furi()
                ren,dedama  =  renchan(h_kakuhen)
                ren  +=  1
                dedama  +=  h_dedama
                end1  +=  1
    dedama1.append(dedama)
    ren1.append(ren)
#連荘平均数
m1 = statistics.mean(ren1)
m2 = statistics.mean(dedama1)
#連荘と出玉の整理
ren1.sort() 
dedama1.sort() 
#print ("連荘数=",ren1)
#print ("出玉数=",dedama1)
print('天井考慮連荘平均: {0:.2f}'.format(m1))
print('天井考慮出玉平均: {0:.1f}'.format(m2))

ren_bunpu = collections.Counter(ren1)
dedama_bunpu = collections.Counter(dedama1)
print("分布=",ren_bunpu)
#print(ren_bunpu)
#出玉の円グラフ作表用定義
x1 = sum( x1 <=  1000 for x1 in dedama1)
x2 = sum(  1000 < x2 <=  5000 for x2 in dedama1) 
x3 = sum(  5000 < x3 <=  10000 for x3 in dedama1)
x4 = sum(  10000 < x4  for x4 in dedama1) 
Xgraph = ["{0:.1f}".format(x1/sikou*100),"{0:.1f}".format(x2/sikou*100),
          "{0:.1f}".format(x3/sikou*100),"{0:.1f}".format(x4/sikou*100)]
label = ["U1k","1k~5k","5k~10k","10kover"]
colors2 = ["0.3", "0.5", "0.7", "0.9", "1.1"]
plt.pie(Xgraph, labels=label, counterclock=False, startangle=90, colors=colors2,autopct="%1.1f%%")
plt.axis('equal')
xx1 = sum( xx1 <=  1000 for xx1 in dedama1)
xx2 = sum(  1000 < xx2 <=  2500 for xx2 in dedama1) 
xx3 = sum(  2500 < xx3 <=  5000 for xx3 in dedama1)
xx4 = sum(  5000 < xx4 <=  7500 for xx4 in dedama1) 
xx5 = sum(  7500 < xx5 <=  10000 for xx5 in dedama1)
xx6 = sum(  10000 < xx6 <=  20000 for xx6 in dedama1) 
xx7 = sum(  20000 < xx7 <=  30000 for xx7 in dedama1)
xx8 = sum(  30000 < xx8 <=  40000 for xx8 in dedama1) 
xx9 = sum(  40000 < xx9 <=  50000 for xx9 in dedama1)
xx10 = sum(  50000 < xx10  for xx10 in dedama1) 
print("x=",xx1,xx2,xx3,xx4,xx5,xx6,xx7,xx8,xx9,xx10)

d = list(ren_bunpu.keys())
e = list(ren_bunpu.values())
sns.set()
sns.set_style("darkgrid", {'grid.linestyle': '--'})
sns.set_context("paper", 1.0, {"lines.linewidth": 1})
sns.set_palette("winter_r", 2, 1)
sns.set('talk', 'darkgrid', 'dark', font_scale=1.0,
        rc={"lines.linewidth": 10, 'grid.linestyle': '--'})
fig, ax = plt.subplots(figsize = (10,5))
ax.set(xlabel ='ren', ylabel='occcurs', xlim=(0,30), ylim=(0,50000))
ax.bar(d,e)
plt.show()

#実戦シミュレーション
sikou  =  30000

for  sim  in  range(1,8):
#初当たりの振り分け処理天井考慮
    sim4  =  0
    sim3  =  0
#回転数
    kaiten1 = []
#出玉推移
    dedama1 = []
    soudedama  =  0
    while  sim4  <  sikou:
        t_tyusen  =  random.random()
        sim3  +=  1
        sim4  +=  1
        if  sim3  >=  950  and  sim3  <=  1205:
            if  t_tyusen  <=  (1/6.17):
                d_dedama,d_kakuhen  =  d_furi()
                ren,dedama  =  renchan(d_kakuhen)
                dedama  +=  d_dedama
                soudedama  +=  dedama
                sim3  =  0
            else:
                dedama = dedama  -  1
        else:
            if  t_tyusen  <=  (1/319.68):
                h_dedama,h_kakuhen  =  h_furi()
                ren,dedama  =  renchan(h_kakuhen)
                dedama  +=  h_dedama
                soudedama  +=  dedama
                sim3  =  0
            else:
                soudedama  =  soudedama  -   (250 / 18)
        dedama1.append(soudedama)
        kaiten1.append(sim4)
    plt.plot(kaiten1,dedama1,linewidth=1)
    plt.show()

#天井期待値の計算
#試行回数
sikou  =  100000
#千円当たりの回転数
kaitenritu =  0
#作図用
sk = []
dk = []
sim1   =  0
sim2   =  0
atari = 0
suru  = 0
for  tenzyo  in  range(0,950,50):
    for kaitenritu  in  range  (15,21):
        soudedama =  0
        for  a  in  range(1,sikou+1):
            suru  =  0
            sim1  =  0
            sim2  =  0
            while  suru  <  1: 
                t_tyusen = random.random()
    #       天井到達時点
                if  sim1  ==  tenzyo:
                    soudedama = soudedama  -  0.5
                    if  t_tyusen  <=  1/(6.17):
                        t_dedama,t_kakuhen  =  d_furi()
                        ren,dedama  =  renchan(t_kakuhen)
                        ren  +=  1
                        soudedama  +=  t_dedama
                        soudedama  +=  dedama
                        suru  +=  1
                    else:
                        sim2  +=  1
                        if  sim2  >=  255:
                            soudedama  +=  0
                            suru +=  1
                else:
                    sim1  +=  1
                    soudedama  =  soudedama  -  (250 / kaitenritu)
                    if  t_tyusen  <=  1/(319.68):
                        t_dedama,t_kakuhen  =  h_furi()
                        ren,dedama  =  renchan(t_kakuhen)
                        ren  +=  1
                        soudedama  +=  t_dedama
                        soudedama  +=  dedama
                        suru  +=  1
        sk.append(["{0:.0f}".format((soudedama/sikou)*4),tenzyo,kaitenritu])



print  ("作表用=",sk)
with open('data.csv', 'w') as file:
    writer = csv.writer(file, lineterminator='\n')
    writer.writerows(sk)
#plt.plot(atarikai,dedama1)
#plt.show()