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

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

新牙狼

 -*- 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.random()
    d_dedama =  0
    d_kakuhen =  0
    if  d_furir  >=  0  and  d_furir < 81/100:
        d_dedama +=  1400
        d_kakuhen   =  1
    else:
        d_dedama  +=  1400
        d_kakuhen   =  0
    return  d_dedama,d_kakuhen

#ヘソの振り分け
def h_furi():
    h_furir = random.random()
    h_dedama =  0
    h_kakuhen =  0
    if  h_furir  >=  0  and  h_furir  < 50/100:
        h_dedama +=  420
        h_kakuhen   =  0
    else:
        h_dedama  +=  420
        h_kakuhen   =  1
    return  h_dedama,h_kakuhen  
#連荘
def renchan(r_kakuhen):
    r_dedama  =  0
    wk_dedama =  0
    wk_ren  =  0
#パラメータ説明
#r_kakuhen =  0  確変ではない
#          =  1  確変
    while  r_kakuhen  >= 1:
        r_dedama,r_kakuhen = d_furi() 
        wk_ren  +=  1
        wk_dedama  +=  r_dedama
        
    return  wk_ren,wk_dedama

sikou  =  100000
bunbo  =  319.68
#連荘回数
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:
            d_dedama,d_kakuhen  =  d_furi()
            ren,dedama  =  renchan(d_kakuhen)
            ren  +=  1
            dedama  +=  d_dedama
            end1  +=  1
        else:
            if  t_tyusen  <=  (1/bunbo):
                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 <=  2500 for x2 in dedama1) 
x3 = sum(  2500 < x3 <=  5000 for x3 in dedama1)
x4 = sum(  5000 < x4 <=  7500 for x4 in dedama1)
x5 = sum(  7500 < x5 <=  10000 for x5 in dedama1)
x6 = sum(  10000 < x6 <=  20000 for x6 in dedama1)
x7 = sum(  20000 < x7 <=  30000 for x7 in dedama1)
x8 = sum(  30000 < x8 <=  40000 for x8 in dedama1)
x9 = sum(  40000 < x9  for x9 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),
#          "{0:.1f}".format(x5/sikou*100),"{0:.1f}".format(x6/sikou*100),
#          "{0:.1f}".format(x7/sikou*100),"{0:.1f}".format(x8/sikou*100),
#          "{0:.1f}".format(x9/sikou*100)]
#colors2 = ["0.3", "0.5", "0.7", "0.9", "1.1"]
#初当たり10万回に対する出玉別出現回数
print('***初当たり10万回に対する出玉振り分け値***')
print("x=",x1,x2,x3,x4,x5,x6,x7,x8,x9)


d = list(ren_bunpu.keys())
e = list(ren_bunpu.values())
sns.set()
sns.set_style("darkgrid", {'grid.lines1tyle': '--'})
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()

#ラッシュ突入時の出玉評価
#連荘回数
ren1 = []
#ラッシュの出玉数
dedama1 = []
for  sim  in  range(1,sikou+1):  
    end1  =  0
    while  end1  <  1:
        ren,dedama  =  renchan(1)
        ren  +=  1
        dedama  +=  420
        end1  +=  1
    dedama1.append(dedama)
    ren1.append(ren)
#連荘平均数
m1 = statistics.mean(ren1)
m2 = statistics.mean(dedama1)
print('ラッシュ突入後の連荘平均: {0:.2f}'.format(m1))
print('ラッシュ突入後の出玉平均: {0:.1f}'.format(m2))

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

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:
            d_dedama,d_kakuhen  =  d_furi()
            ren,dedama  =  renchan(d_kakuhen)
            dedama  +=  d_dedama
            soudedama  +=  dedama
            sim3  =  0
        else:
            if  t_tyusen  <=  (1/bunbo):
                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  =  1000
#千円当たりの回転数
kaitenritu =  0
#作図用
sk = []
dk = []
sim1   =  0
sim2   =  0
atari = 0
suru  = 0
for  tenzyo  in  range(0,950,100):
    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:
                    t_dedama,t_kakuhen  =  d_furi()
                    ren,dedama  =  renchan(t_kakuhen)
                    ren  +=  1
                    soudedama  +=  t_dedama
                    soudedama  +=  dedama
                    suru  +=  1
                else:
                    sim1  +=  1
                    soudedama  =  soudedama  -  (250 / kaitenritu)
                    if  t_tyusen  <=  1/(bunbo):
                        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()