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

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

P革命機ヴァルブレイヴ2のpythonシミュレーションコード

# -*- 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
#ヘソ振り分け
#フラグ設定
#1.電サポST70回
#2.電サポ8回ST70回
#3.時短100回
#4.電サポ8回通常 ただし潜伏は時短100回 def h_furi(): h_furir = random.random() h_dedama = 0 h_kakuhen = 0 if h_furir >= 0 and h_furir < 25/100: h_dedama += 1400 h_kakuhen = 1 elif h_furir >= 25/100 and h_furir < 38/100: h_dedama += 420 h_kakuhen = 1 elif h_furir >= 38/100 and h_furir < 50/100: h_dedama += 420 h_kakuhen = 2 elif h_furir >= 50/100 and h_furir < 89/100: h_dedama += 420 h_kakuhen = 3 elif h_furir >= 89/100 and h_furir < 100/100: h_dedama += 420 h_kakuhen = 4 return h_dedama,h_kakuhen def s_furi(): s_furir = random.random() s_dedama = 0 s_kakuhen = 0 if s_furir >= 0 and s_furir < 25/100: s_dedama += 1400 s_kakuhen = 1 elif s_furir >= 25/100 and s_furir < 38/100: s_dedama += 420 s_kakuhen = 1 elif s_furir >= 38/100 and s_furir < 50/100: s_dedama += 420 s_kakuhen = 1 elif s_furir >= 50/100 and s_furir < 89/100: s_dedama += 420 s_kakuhen = 3 elif s_furir >= 89/100 and s_furir < 100/100: s_dedama += 420 s_kakuhen = 3 return s_dedama,s_kakuhen #電サポの振り分け def d_furi(): d_furir = random.random() d_dedama = 0 d_kakuhen = 0 if d_furir >= 0 and d_furir < 2/100: d_dedama += 280 d_kakuhen = 0 elif d_furir >= 2/100 and d_furir < 4/100: d_dedama += 980 d_kakuhen = 0 elif d_furir >= 4/100 and d_furir < 6/100: d_dedama += 560 d_kakuhen = 0 elif d_furir >= 6/100 and d_furir < 13/100: d_dedama += 1400 d_kakuhen = 1 elif d_furir >= 13/100 and d_furir < 44/100: d_dedama += 980 d_kakuhen = 1 elif d_furir >= 44/100 and d_furir < 69/100: d_dedama += 560 d_kakuhen = 1 elif d_furir >= 69/100 and d_furir < 100/100: d_dedama += 560 d_kakuhen = 1 return d_dedama,d_kakuhen #連荘 def renchan(flg): ren = 0 suru = 0 st = 0 dedama = 0 rush = 0 while suru < 1: #転落抽選 #確変 r_tyusen = random.random() st += 1 if flg == 0: ren += 1 furideda,flg = d_furi() dedama += furideda st = 0 elif flg == 1: rush = 1 if r_tyusen <= (1/32.0): ren += 1 furideda,flg = d_furi() dedama += furideda st = 0 else: if st >= 70: suru += 1 elif flg == 2: if st < 12: if r_tyusen <= (1/32.0): ren += 1 furideda,flg = d_furi() dedama += furideda st = 0 else: dedama -= 25 if r_tyusen <= (1/32.0): ren += 1 furideda,flg = s_furi() dedama += furideda st = 0 else: if st >= 70: suru += 1 elif flg == 3: if r_tyusen <= (1/319.7): ren += 1 furideda,flg = d_furi() dedama += furideda st = 0 else: if st >= 104: suru += 1 else: if r_tyusen <= (1/319.7): ren += 1 furideda,flg = d_furi() dedama += furideda st = 0 else: if st >= 12: suru += 1 # print ("ren=",ren) return ren,dedama,rush sikou = 100000 #連荘回数 ren1 = [] #ラッシュの出玉数 dedama1 = [] rush1 = [] for sim in range(1,sikou+1): #初当たりの振り分け処理天井考慮 ren = 0 dedama = 0 sim3 = 0 end1 = 0 while end1 < 1: t_tyusen = random.random() sim3 += 1 if t_tyusen <= (1/319.7): h_dedama,h_kakuhen = h_furi() ren,dedama,rush = renchan(h_kakuhen) ren += 1 dedama += h_dedama end1 += 1 dedama1.append(dedama) ren1.append(ren) rush1.append(rush) #連荘平均数 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)) m3 = 250 / (m2 /319.7) print('等価ボーダ:{0:.2f}'.format(m3)) rush_bunpu = collections.Counter(rush1) print("分布=",rush_bunpu) #print('ラッシュ突入回数:',rush1.count('1')) #m4 = 1/( rush1.count('1') / sikou ) #print('ラッシュ突入分母:{0:.2f}',m4) #ラッシュ性能評価(ラッシュ入った時点からの出玉調査) sikou = 100000 #連荘回数 ren1 = [] rush1 = [] #ラッシュの出玉数 dedama1 = [] for sim in range(1,sikou+1): #初当たりの振り分け処理天井考慮 ren = 0 dedama = 0 sim3 = 0 end1 = 0 while end1 < 1: h_dedama,h_kakuhen = d_furi() ren,dedama,rush = renchan(h_kakuhen) ren += 1 dedama += 1400 end1 += 1 dedama1.append(dedama) ren1.append(ren) rush1.append(rush) #連荘平均数 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) #実戦シミュレーション sikou = 3000 i = 0 for sim in range(1,9): #初当たりの振り分け処理天井考慮 sim4 = 0 sim3 = 0 i += 1 #回転数 kaiten1 = [] #出玉推移 dedama1 = [] soudedama = 0 fig = plt.figure() fig.subplots_adjust(left=0.2) while sim4 < sikou: t_tyusen = random.random() sim4 += 1 if t_tyusen <= (1/319.7): h_dedama,h_kakuhen = h_furi() ren,dedama,rush = renchan(h_kakuhen) ren += 1 dedama += h_dedama soudedama += dedama else: soudedama = soudedama - (250 / 18) dedama1.append(soudedama) kaiten1.append(sim4) plt.plot(kaiten1,dedama1,linewidth=1) fig.savefig("%04.f"%(i)+".jpg")

フォルダの中の画像ファイルを別のフォルダへリネームしてコピーするpythonGUIプログラム

#! python3
# rename same folder more than 10.py - あるフォルダ内のファイル名を他のフォルダ内のファイル名にするため、forループを用いてrenameする

import tkinter as tk
from  tkinter  import messagebox
from  tkinter  import filedialog
import os
import glob
import re
import shutil
import pathlib
from PIL import Image
from PIL.ExifTags import TAGS

# 関数の定義 01
def get_exif_of_image(file):
    """Get EXIF of an image if exists.

    指定した画像のEXIFデータを取り出す関数
    @return exif_table Exif データを格納した辞書
    """
    im = Image.open(file)

    # Exif データを取得
    # 存在しなければそのまま終了 空の辞書を返す
    try:
        exif = im._getexif()
    except AttributeError:
        return {}

    # タグIDそのままでは人が読めないのでデコードして
    # テーブルに格納する
    exif_table = {}
    for tag_id, value in exif.items():
        tag = TAGS.get(tag_id, tag_id)
        exif_table[tag] = value

    return exif_table

def get_data_of_image(file):
    exif_table = get_exif_of_image(file)
    return exif_table.get("DateTimeOriginal")


def set_func(): 
    input_box.delete(0, tk.END)
    iDir = os.path.abspath(os.path.dirname(__file__))
    cfolder = filedialog.askdirectory(initialdir=iDir)
    input_box.insert(tk.END,cfolder)

def set2_func(): 
    input2_box.delete(0, tk.END)
    iDir2 = os.path.abspath(os.path.dirname(__file__))
    cfolder2 = filedialog.askdirectory(initialdir=iDir2)
    input2_box.insert(tk.END,cfolder2)

def run_func():
    cfilelist = []
    for f in  glob.glob(input_box.get() + "/**/**.jpg",recursive=True):
        if  os.path.isfile(f):
            cfilelist.append(os.path.abspath(f))
    a = 0
    for k  in cfilelist:
        a  +=  1
        shutil.copy(k,os.path.join(input2_box.get(),get_data_of_image(k) + '{0:03d}'.format(a) + '.jpg'))
    

#GUI設定
root = tk.Tk()
root.title("リネームプログラム")
root.geometry("500x200")
# Runボタン設置
run_button = tk.Button(root, text = "Run",command = run_func)
run_button.place(x = 250, y = 75)
# Setボタン設置
set1_button = tk.Button(root, text = "in フォルダ", command = set_func)
set1_button.place(x = 400, y = 10)
# Set2ボタン設置
set2_button = tk.Button(root, text = "Outフォルダ", command = set2_func)
set2_button.place(x = 400, y = 40)
# テキストボックス配置
input_box = tk.Entry(width = 60)
input_box.place(x = 10, y = 10)
# テキストボックス配置2
input2_box = tk.Entry(width = 60)
input2_box.place(x = 10, y = 40)
# ステータスバー設置
statusbar = tk.Label(root, text = " No Data!!", bd = 1, relief = tk.SUNKEN, anchor = tk.W)
statusbar.pack(side = tk.BOTTOM, fill = tk.X)


# ウインドウ状態の維持
root.mainloop()

新牙狼

 -*- 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()

Pアイドルマスターのシミュレーションプログラム

# -*- coding: utf-8 -*-
"""
Created on Fri Jan 29 11:37:47 2021

@author: HOST1191
"""
import random
import statistics 
import collections
import matplotlib.pyplot as plt
import seaborn as sns
import csv

#デンチュー振り分け
def d_furi():
    d_furir = random.random()
    d_dedama  =  0
    d_kakuhen =  0
    if  d_furir  >=  0  and  d_furir < 50/100:
        d_dedama +=  1400
        d_kakuhen   =  1
    elif d_furir  >= 50/100  and  d_furir  < 72/100:
        d_dedama +=  420
        d_kakuhen   =  1
    else:
        d_dedama +=  420
        d_kakuhen   =  0
 
    return  d_dedama,d_kakuhen

#ヘソの振り分け
def h_furi():
    h_furir = random.random()
    h_dedama  =  0
    h_kakuhen =  0
    h_jitan   =  0
    if  h_furir  >=  0  and  h_furir < 750/100:
        h_dedama +=  420
        h_kakuhen   =  0
        h_jitan  = 100
    else:
        h_dedama  += 420
        h_kakuhen  =  0
        h_jitan = 150

    return  h_dedama,h_kakuhen,h_jitan 


#連荘
def renchan(r_kakuhen,r_jitan):
    wk_st       =  0
#    wk_jitan    =  0
    r_dedama    =  0
    wk_dedama   =  0
    wk_ren      =  0
    end         =  0
#    wk_kakuhen  =  0
    wk_st2      =  0
    v_horyu     =  0
#パラメータ説明
#r_kakuhen は1見なくてよい
    while  end  < 1:
        print ("totta1")
        r_tyusen  = random.random()
        wk_st  +=  1
#       直撃大当たりの処理       
        if  r_tyusen <= (1/319.7):        
            wk_ren  +=  1
            r_dedama,r_kakuhen,r_jitan = h_furi()
            wk_dedama  +=  r_dedama
            wk_st2  +=  wk_st
            wk_st  =  0
#       終了判定
        else:
            if  wk_st  >  r_jitan:
                end  +=  1
#      デンチュー保留の抽選
    wk_st   =  0
    wk_st2  =  3.11  *  wk_st2 
    print ("totta2")
    while  end  <  2:
        r_tyusen  = random.random()
        wk_st  +=  1 
        if  r_tyusen <= (1/350):        
            v_horyu +=  1   
        if  v_horyu  >  4:
            v_horyu  =  4
        if  wk_st  >=  wk_st2:
            end  +=  1
    print ("totta3")        
    while  v_horyu  <=  0:
        print ("totta4")
        r_dedama,r_kakuhen  =  d_furi()
        wk_dedama  +=  r_dedama
        wk_ren  +=  1
        if  r_kakuhen  ==  0:
            v_horyu =  v_horyu - 1
        
    return  wk_ren,wk_dedama

sikou  =  100
#連荘回数
ren1 = []
#ラッシュの出玉数
dedama1 = []
for  sim  in  range(1,sikou+1):
#初当たりの振り分け処理天井考慮  
    sim3  =  0
    end1  =  0
    while  end1  <  1:
        t_tyusen  =  random.random()
        sim3  +=  1
        if  sim3  >=  960:
             ren,dedama  =  renchan(0,150)
        else:
            if  t_tyusen  <=  (1/319.7):
                h_dedama,h_kakuhen,h_jitan  =  h_furi()
                ren,dedama  =  renchan(h_kakuhen,h_jitan)
                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('***初当たり10回に対する平均値***')
print('天井考慮連荘平均: {0:.2f}'.format(m1))
print('天井考慮出玉平均: {0:.1f}'.format(m2))

ren_bunpu = collections.Counter(ren1)
dedama_bunpu = collections.Counter(dedama1)
#print("分布=",ren_bunpu)
#print("分布=",dedama_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"]
#plt.pie(Xgraph, counterclock=False, startangle=90, colors=colors2,autopct="%1.1f%%")
#plt.axis('equal')
#初当たり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()

#実戦シミュレーション
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  >=  960:
            ren,dedama  =  renchan(0,150)
            soudedama  +=  dedama
            sim3  =  0
        else:
            if  t_tyusen  <=  (1/319.7):
                h_dedama,h_kakuhen,h_jitan  =  h_furi()
                ren,dedama  =  renchan(h_kakuhen,h_jitan)
                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,960,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:
                    ren,dedama  =  renchan(0,150)
                    ren  +=  1
                    soudedama  +=  dedama
                    suru  +=  1
                else:
                    sim1  +=  1
                    soudedama  =  soudedama  -  (250 / kaitenritu)
                    if  t_tyusen  <=  1/(319.7):
                        t_dedama,t_kakuhen,t_jitan  =  h_furi()
                        ren,dedama  =  renchan(t_kakuhen,t_jitan)
                        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()



Pパトラッシュ5のシミュレーションプログラム

# -*- 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 < 5.2/100:
        d_dedama +=  1100
        d_kakuhen   =  1
    else:
        d_dedama  +=  330
        d_kakuhen  =  1
    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  < 45/100:
        h_dedama +=  270
        h_kakuhen   =  0
    else:
        h_dedama  +=  270
        h_kakuhen   =  1
    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:
        if  r_kakuhen  ==  1:     
            r_tyusen = random.random()
            wk_st  +=  1
            if r_tyusen <= (1/10.5):
                wk_ren  +=  1
                r_dedama,r_kakuhen = d_furi() 
                wk_dedama  +=  r_dedama
                wk_st  =  0
                r_kakuhen  =  1
            if  wk_st  >=  24:
                end  +=  1
        else:
            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  >=  500  and  sim3  <= 1000:
            if  t_tyusen  <=  (1/10.5):
                d_dedama,d_kakuhen  =  d_furi()
                ren,dedama  =  renchan(d_kakuhen)
                ren  +=  1
                dedama  +=  d_dedama
                end1  +=  1
        else:
            if  t_tyusen  <=  (1/199.8):
                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()

#実戦シミュレーション
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  and  sim3  <=  2164: 
            if  t_tyusen  <=  (1/10.5):
                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/199.8):
                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  =  300000

for  sim  in  range(1,4):
#初当たりの振り分け処理天井考慮
    sim4  =  0
    sim3  =  0
#回転数
    kaiten1 = []
#出玉推移
    dedama1 = []
    soudedama  =  0
    while  sim4  <  sikou:
        t_tyusen  =  random.random()
        sim3  +=  1
        sim4  +=  1
        if  sim3  >=  500  and  sim3  <=  1000:
            if  t_tyusen  <=  (1/10.5):
                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/199.8):
                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  =  10000
#千円当たりの回転数
kaitenritu =  0
#作図用
sk = []
dk = []
sim1   =  0
sim2   =  0
atari = 0
suru  = 0
for  tenzyo  in  range(0,500,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/(10.5):
                        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  >=  100:
                            soudedama  +=  0
                            suru +=  1
                else:
                    sim1  +=  1
                    soudedama  =  soudedama  -  (250 / kaitenritu)
                    if  t_tyusen  <=  1/(199.8):
                        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()

Pジョーズのシミュレーションプログラム

# -*- 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 < 100/100:
        d_dedama +=  1400
        d_kakuhen   =  1
    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  < 96/100:
        h_dedama +=  560
        h_kakuhen   =  0
    else:
        h_dedama  +=  1400
        h_kakuhen   =  1
    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
        if r_tyusen <= (1/7.9):
            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  >=  12:
                end  +=  1
        else:
            if  wk_st  >=  5:
                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  >=  960  and  sim3  <= 1060:
            if  t_tyusen  <=  (1/7.9):
                d_dedama,d_kakuhen  =  d_furi()
                ren,dedama  =  renchan(d_kakuhen)
                ren  +=  1
                dedama  +=  d_dedama
                end1  +=  1
        else:
            if  t_tyusen  <=  (1/319.6):
                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()

#実戦シミュレーション
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  >=  960  and  sim3  <=  1060:
            if  t_tyusen  <=  (1/7.9):
                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.6):
                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  =  300000

for  sim  in  range(1,2):
#初当たりの振り分け処理天井考慮
    sim4  =  0
    sim3  =  0
#回転数
    kaiten1 = []
#出玉推移
    dedama1 = []
    soudedama  =  0
    while  sim4  <  sikou:
        t_tyusen  =  random.random()
        sim3  +=  1
        sim4  +=  1
        if  sim3  >=  960  and  sim3  <=  1060:
            if  t_tyusen  <=  (1/7.9):
                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.6):
                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  =  10000
#千円当たりの回転数
kaitenritu =  0
#作図用
sk = []
dk = []
sim1   =  0
sim2   =  0
atari = 0
suru  = 0
for  tenzyo  in  range(0,960,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/(7.9):
                        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  >=  100:
                            soudedama  +=  0
                            suru +=  1
                else:
                    sim1  +=  1
                    soudedama  =  soudedama  -  (250 / kaitenritu)
                    if  t_tyusen  <=  1/(319.6):
                        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()

P化物語セカンドシーズンのシミュレーションプログラム

# -*- 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 < 35/100:
        d_dedama +=  920
        d_kakuhen   =  1
    elif  d_furir  >=  35  and  d_furir  <  69/100:
        d_dedama  +=  620
        d_kakuhen  =  1
    else:
        d_dedama  +=  320
        d_kakuhen  =  1
    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  < 1/100:
        h_dedama +=  1000
        h_kakuhen   =  1
    else:
        h_dedama  +=  400
        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
        if r_tyusen <= (1/7.68):
            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  >=  14:
                end  +=  1
        else:
            if  wk_st  >=  5:
                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  >=  600  and  sim3  <= 855:
            if  t_tyusen  <=  (1/7.68):
                d_dedama,d_kakuhen  =  d_furi()
                ren,dedama  =  renchan(d_kakuhen)
                ren  +=  1
                dedama  +=  d_dedama
                end1  +=  1
        else:
            if  t_tyusen  <=  (1/199.8):
                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()

#実戦シミュレーション
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  >=  600  and  sim3  <=  855:
            if  t_tyusen  <=  (1/7.68):
                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/199.8):
                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  =  300000

for  sim  in  range(1,4):
#初当たりの振り分け処理天井考慮
    sim4  =  0
    sim3  =  0
#回転数
    kaiten1 = []
#出玉推移
    dedama1 = []
    soudedama  =  0
    print("sim",sim + 17)
    while  sim4  <  sikou:
        t_tyusen  =  random.random()
        sim3  +=  1
        sim4  +=  1
        if  sim3  >=  600  and  sim3  <=  855:
            if  t_tyusen  <=  (1/7.68):
                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/199.8):
                h_dedama,h_kakuhen  =  h_furi()
                ren,dedama  =  renchan(h_kakuhen)
                dedama  +=  h_dedama
                soudedama  +=  dedama
                sim3  =  0
            else:
                soudedama  =  soudedama  -   (250 / (sim + 17))
        dedama1.append(soudedama)
        kaiten1.append(sim4)
    plt.plot(kaiten1,dedama1,linewidth=1)
    plt.show()
#天井期待値の計算
#試行回数
sikou  =  10000
#千円当たりの回転数
kaitenritu =  0
#作図用
sk = []
dk = []
sim1   =  0
sim2   =  0
atari = 0
suru  = 0
for  tenzyo  in  range(0,600,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/(7.68):
                        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  >=  100:
                            soudedama  +=  0
                            suru +=  1
                else:
                    sim1  +=  1
                    soudedama  =  soudedama  -  (250 / kaitenritu)
                    if  t_tyusen  <=  1/(199.8):
                        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()