Skip to content

Instantly share code, notes, and snippets.

@doraneko94
Created August 31, 2017 15:11
Show Gist options
  • Save doraneko94/5357ed4ac34f3b90eabe5d13f78f4b3d to your computer and use it in GitHub Desktop.
Save doraneko94/5357ed4ac34f3b90eabe5d13f78f4b3d to your computer and use it in GitHub Desktop.
randomize
shiai_num = 10000 ;shiai_numの数値と等しい回数の試合を行います。
;データ読み込み変数定義
dim b1,10
dim b2,10
dim b3,10
dim b4,10
dim st,10
dim std,10
dim bunt,10
dim fly,10
dim ball4,10
dim balld,10
dim s3,10
dim o2,10
dim o1,10
;データ読み込み
k = 1
chdir "data"
notesel data
repeat 9
noteload ""+k+".txt"
noteget buf,0
b1(k) = int(buf)
noteget buf,1
b2(k) = int(buf)
noteget buf,2
b3(k) = int(buf)
noteget buf,3
b4(k) = int(buf)
noteget buf,4
st(k) = int(buf)
noteget buf,5
std(k) = int(buf)
noteget buf,6
bunt(k) = int(buf)
noteget buf,7
fly(k) = int(buf)
noteget buf,8
ball4(k) = int(buf)
noteget buf,9
balld(k) = int(buf)
noteget buf,10
s3(k) = int(buf)
noteget buf,11
o2(k) = int(buf)
noteget buf,12
o1(k) = int(buf)
k = k + 1
loop
;結果を記録する変数の定義
sdim result
shiai = 0
*shinki ;初期化
point = 0
kai = 1
out = 0
jun = 1
first = 0 ;以下3つは塁の状況。0なら空き、1~9ならその打順の選手がいる。
second = 0
third = 0
*kaishi ;試合開始
cls
mes first
mes second
mes third
mes point
mes kai
mes shiai
if jun = 10 : jun = 1
stk = 0
ovk1 = 0
ovk2 = 0
buk = 0
flk = 0
dok = 0
;塁の埋まり方を確認。ランナーの配置・アウトカウントにより、起こりうるイベントが変わります。
if first!0 and second=0 and third=0 {
stk = 1
ovk1 = 1
buk = 1
dok = 1
}
if first=0 and second!0 and third=0 {
ovk2 = 1
}
if first=0 and second=0 and third!0 {
flk = 1
}
if first!0 and second!0 and third=0 {
ovk1 = 1
ovk2 = 1
dok = 1
}
if first!0 and second=0 and third!0 {
stk = 1
ovk1 = 1
flk = 1
dok = 1
}
if first=0 and second!0 and third!0 {
ovk2 = 1
flk = 1
}
if first!0 and second!0 and third!0 {
ovk1 = 1
ovk2 = 1
flk = 1
dok = 1
}
if out = 2 {
buk = 0
flk = 0
dok = 0
}
*steal ;盗塁をするかしないか判定。ランナー1塁かつ2塁が空いているときのみで、3盗はしません。
if stk = 1 {
rand = rnd(b1(first) + ball4(first) + balld(first))
if rand < st(first) {
second = first
first = 0
goto *kaishi
}
if rand >= st(first) and rand < st(first) + std(first) {
first = 0
out = out + 1
if out = 3 : goto *change
goto *kaishi
}
}
*dageki ;バッターの打撃。乱数で結果が決まります。
bunbo = b1(jun)+b2(jun)+b3(jun)+b4(jun)+ball4(jun)+balld(jun)+s3(jun)+o1(jun)
if buk = 1 : bunbo = bunbo + bunt(jun)
if flk = 1 : bunbo = bunbo + fly(jun)
if dok = 1 : bunbo = bunbo + o2(jun)
rand = rnd(bunbo)
*shinrui ;打撃の結果、ランナーが進みます。
if rand < b1(jun){ ;単打
if third ! 0 {
third = 0
point = point + 1
}
if second ! 0 {
if ovk2 = 1 { ;単打でも、すでに塁に出ているランナーは2つ進むことがあり、それを乱数で判定します。
rand2 = rnd(b1(second) + ball4(second) + balld(second))
if rand2 < st(second) * 3 {
point = point + 1
}
if rand2 >= st(second) * 3 and rand2 < st(second) * 3 + std(second) {
out = out + 1
if out = 3 : goto *change
}
if rand2 >= st(second) * 3 + std(second) {
third = second
}
} else {
third = second
}
second = 0
}
if first ! 0 {
if ovk1 = 1 and third = 0 {
rand3 = rnd(b1(first) + ball4(first) + balld(first))
if rand3 < st(first) * 3 {
third = first
first = 0
}
if rand3 >= st(first) * 3 and rand3 < st(first) * 3 + std(first) {
first = 0
out = out + 1
if out = 3 : goto *change
}
if rand3 >= st(first) * 3 + std(first) {
second = first
}
} else {
second = first
}
first = 0
}
first = jun
}
if rand >= b1(jun) and rand < b1(jun)+b2(jun) { ;二塁打
if third ! 0 {
third = 0
point = point + 1
}
if second ! 0 {
second = 0
point = point + 1
}
if first ! 0 {
if ovk1 = 1 {
rand2 = rnd(b1(first) + ball4(first) + balld(first))
if rand2 < st(first) * 3 {
point = point + 1
}
if rand2 >= st(first) * 3 and rand2 < st(first) * 3 + std(first) {
out = out + 1
if out = 3 : goto *change
}
if rand2 >= st(first) * 3 + std(first) {
third = first
}
} else {
third = first
}
first = 0
}
second = jun
}
if rand >= b1(jun)+b2(jun) and rand <b1(jun)+b2(jun)+b3(jun) { ;三塁打
if third ! 0 {
third = 0
point = point + 1
}
if second ! 0 {
second = 0
point = point + 1
}
if first ! 0 {
first = 0
point = point + 1
}
third = jun
}
if rand >= b1(jun)+b2(jun)+b3(jun) and rand < b1(jun)+b2(jun)+b3(jun)+b4(jun) { ;本塁打
if third ! 0 {
third = 0
point = point + 1
}
if second ! 0 {
second = 0
point = point + 1
}
if first ! 0 {
first = 0
point = point + 1
}
point = point + 1
}
if rand >= b1(jun)+b2(jun)+b3(jun)+b4(jun) and rand < b1(jun)+b2(jun)+b3(jun)+b4(jun)+ball4(jun)+balld(jun) { ;四球or死球
if first=0 and second=0 and third=0 : first=jun
if first!0 and second=0 and third=0 : second=first : first=jun
if first=0 and second!0 and third=0 : first=jun
if first=0 and second=0 and third!0 : first=jun
if first!0 and secon!0 and third=0 : third=second : second=first : first=jun
if first!0 and second=0 and third!0 : second=first : first=jun
if first=0 and second!0 and third!0 : first=jun
if first=0 and second=0 and third=0 : third=second : second=first : first=jun : point = point + 1
}
if rand >= b1(jun)+b2(jun)+b3(jun)+b4(jun)+ball4(jun)+balld(jun) and rand < b1(jun)+b2(jun)+b3(jun)+b4(jun)+ball4(jun)+balld(jun)+s3(jun) { ;三振
out = out + 1
if out = 3 :goto *change
}
if rand >= b1(jun)+b2(jun)+b3(jun)+b4(jun)+ball4(jun)+balld(jun)+s3(jun) and rand < b1(jun)+b2(jun)+b3(jun)+b4(jun)+ball4(jun)+balld(jun)+s3(jun)+o1(jun) { ;単死
out = out + 1
if out = 3 : goto *change
rand2 = rnd(5) ;アウトといっても、先行ランナーが死ぬ場合と、打者が死んで進塁打となる場合があります。
if first!0 and second=0 and third=0 {
if rand2 > 0 : first=jun
if rand2 = 0 : second=first : first=0
}
if first!0 and secon!0 and third=0 {
if rand2 = 0 : third=second : second=first : first=0
if rand2 > 0 : second=first : first=jun
}
if first!0 and second=0 and third!0 {
if rand2 = 0 : second=first : first=0
if rand2 > 0 : first=jun
}
}
if buk = 1 and flk = 0 and dok = 1 { ;以下、状況に応じて犠打、犠飛、併殺打の判定をします。
if rand >= b1(jun)+b2(jun)+b3(jun)+b4(jun)+ball4(jun)+balld(jun)+s3(jun)+o1(jun) and rand < b1(jun)+b2(jun)+b3(jun)+b4(jun)+ball4(jun)+balld(jun)+s3(jun)+o1(jun)+bunt(jun) {
second = first
out = out + 1
}
if rand >= b1(jun)+b2(jun)+b3(jun)+b4(jun)+ball4(jun)+balld(jun)+s3(jun)+o1(jun)+bunt(jun) {
first = 0
out = out + 2
if out = 3 : goto *change
}
}
if buk = 0 and flk = 0 and dok = 1 {
if rand >= b1(jun)+b2(jun)+b3(jun)+b4(jun)+ball4(jun)+balld(jun)+s3(jun)+o1(jun) {
first = 0
out = out + 2
if out = 3 : goto *change
}
}
if buk = 0 and flk = 1 and dok = 1 {
if rand >= b1(jun)+b2(jun)+b3(jun)+b4(jun)+ball4(jun)+balld(jun)+s3(jun)+o1(jun) and rand < b1(jun)+b2(jun)+b3(jun)+b4(jun)+ball4(jun)+balld(jun)+s3(jun)+o1(jun)+fly(jun) {
third = 0
out = out + 1
point = point + 1
}
if rand >= b1(jun)+b2(jun)+b3(jun)+b4(jun)+ball4(jun)+balld(jun)+s3(jun)+o1(jun)+bunt(jun)+fly(jun) {
first = 0
out = out + 2
if out = 3 : goto *change
}
}
if buk = 0 and flk = 1 and dok = 0 {
if rand >= b1(jun)+b2(jun)+b3(jun)+b4(jun)+ball4(jun)+balld(jun)+s3(jun)+o1(jun) {
third = 0
out = out + 1
point = point + 1
}
}
jun = jun + 1
goto *kaishi ;次の打者へ
*change ;3アウトでチェンジ
jun = jun + 1
kai = kai + 1
out = 0
if kai = 10 : goto *gameset ;9回が終わったら試合終了
first = 0
second = 0
third = 0
wait 1
goto *kaishi
*gameset ;結果を記録します。
notesel result
p = str(point)
noteadd p,-1
shiai = shiai + 1
if shiai < shiai_num : goto *shinki
notesave "result.txt" ;規定回数が終わればtxtに保存します。
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment