source : アステカ
#!/usr/bin/perl
# アステカ シミュレーション
$cginame = 'azteca.cgi';
$title = 'アステカ シミュレーション';
if ($ENV{'REQUEST_METHOD'} eq 'POST') {
read (STDIN, $input, $ENV{'CONTENT_LENGTH'});
}
foreach (split(/&/,$input)) {
($name,$value) = split(/=/, $_);
push(@input, $value);
}
($s, $play, $method) = @input;
$method = 0 if !$method;
$chk[$method] = 'checked';
print "Content-Type: text/html\n\n";
# ヘッダとフォームの表示
print <<"__ FORM __";
<!DOCTYPE html PUBLIC '-//W3C//DTD HTML 4.01 Transitional//EN'>
<html lang='ja'>
<head>
<meta http-equiv='Content-Type' content="text/html; charset=shift_jis">
<title>jug7.com - cgi $title</title>
<style type="text/css"> <!--
A:hover {color:#ff0000;}
--></style>
</head>
<body text='#000000' bgcolor='#ffffff' link='#0000ff' alink='#ff0000' vlink='#0000cc'>
<div align='right'>[ <a href='../simu_data_az.html'>data</a> / <a href='azteca_memo.html'>memo</a> / <a href='azteca.html'>source</a> / <a href='../index.html'>home</a> ]</div>
<br><br>
<div align='center'><h2>$title</h2></div>
<hr width='70%'><center><form action='$cginame' method='POST'>
<table border=0>
<tr align='center'><td>設定</td><td><input type='text' size=10 name='s' value='$s'></td></tr>
<tr align='center'><td>ゲーム数</td><td><input type='text' size=10 name='play' maxlength=4 value='$play'></td></tr>
<tr align='center'><td><font size=2>CT中の<br>打ち方</font></td>
<td><input type='radio' name='method' value=0 $chk[0]><font size=2>デカチリ維持</font>
<input type='radio' name='method' value=1 $chk[1]><font size=2>サボテン維持</font></td></tr>
</table><br>
<input type='submit' value="開始">
</form></center><br><br>
__ FORM __
# エラーチェックとGET送信
if ($play > 9999) { $error = 1; $er_msg = 'プレイ数は最大9999Pまでです。'; }
if (!$s or !$play) { $error = 1; $er_msg = '記入漏れがあります。'; }
if ($s<=0 or $s>6) { $error = 1; $er_msg = '設定は1〜6までです。'; }
if (grep { /[^\d]/ } @input) { $error = 1; $er_msg = '不適切な文字が記入されています。'; };
if ($ENV{'REQUEST_METHOD'} ne 'POST') { $error = 1; $er_msg = 0; }
if ($er_msg) {
print q{<center><b><font color='red' size=4>*** ERROR !! ***</font><br><br>},"\n";
print "$er_msg</b></center>\n";
}
if ($error) {
print '<br><br><br><br><br>';
print q{<div align='right'>[ <a href='../simu_data_az.html'>data</a> / <a href='azteca_memo.html'>memo</a> / <a href='azteca.html'>source</a> / <a href='../index.html'>home</a> ]</div>};
exit;
}
# data
@gen = (103,103,103,103,104,105); # 減算値
$gen = $gen[$s-1];
$pay = $gen/256; # 払出し率
@k14 = (24,50); #/16384 14枚役, $k14[0] が低確率状態, $k14[1] が高確率状態
@k7 = (2100,2670); # 7枚役
@k2 = (4,8); # 2枚役
@high3 = (250,251,252,253,254,255); # 3枚役(設定差あり。左から設定1~6)
@low3 = (200,201,202,203,204,205);
@k3 = ($low3[$s-1], $high3[$s-1]);
$rep = 2245;
@big = (52,60,67,74,81,91);
$big = $big[$s-1]; # /16384
@bigget = (295.346, 295.348, 295.351, 295.353, 295.356, 295.359); # BIG 平均獲得枚数
$bigget = $bigget[$s-1];
print q{<table border=1 cellspacing=0 align='center'><caption>シミュレーション結果</caption>};
print q{<tr align='center' bgcolor='#ffffcc'><td><font size=2>ゲーム数</font></td><td><font size=2>当選</font></td>};
print q{<td><font size=2>トータル<br>BIG</font></td><td><font size=2>CT BIG</font></td><td><font size=2>投資</font></td>};
print q{<td><font size=2>コイン</font></td><td><font size=2>トータル<br>ゲーム数</font></td></tr>},"\n";
# 小役の乱数をあらかじめ計算
$big = $rep + $big;
@k7r = ($big+$k7[0], $big+$k7[1]);
@k3r = ($k7r[0]+$k3[0], $k7r[1]+$k3[1]);
@k14r = ($k3r[0]+$k14[0], $k3r[1]+$k14[1]);
@k2r = ($k14r[0]+$k2[0], $k14r[1]+$k2[1]);
#------------------------
# シミュレート開始
# $m=1 の時が小役高確
#------------------------
$g = $count = $bigcount = $ctbig = $ct = $out = $in = 0;
while (1) {
$g++; $count++; $in++;
if ($coin < 3) { $coin += 50; $k++; $totalk++; }
$coin -= 3;
$r = int(rand(16384)+1);
$pay2 = $out/($in*3);
$m = ($pay2 <= $pay) ? 1 : 0;
if (!$ct) { # 通常時
if ($r <= $rep) { $coin += 3; $in--; }
elsif ($r <= $big) { $out = $in = 0; $flag = 1; }
elsif ($r <= $k7r[$m]) { $coin += 7; $out += 7; }
elsif ($r <= $k3r[$m]) { $coin += 3; $out += 3; }
elsif ($r <= $k14r[$m]) { $coin += 14; $out += 14; }
elsif ($r <= $k2r[$m]) { $coin += 2; $out += 2; }
} else { # CT 中
$inc -= 3; # 純増枚数
if ($r <= $rep) { $coin += 3; $in--; $inc += 3; }
elsif ($r <= $big) { $out = $in = 0; $flag = 1; }
else { # 純増201枚にならない範囲で最高獲得の小役を取る
if ($method) { # サボテン維持
if ($inc <= 186) { $coin += 14; $out += 14; $inc += 14; }
elsif ($inc <= 193) { $coin += 7; $out += 7; $inc += 7; }
elsif ($inc <= 197) { $coin += 3; $out += 3; $inc += 3; }
} else { # デカチリ維持
if ($inc <= 186) { $coin += 14; $out += 14; $inc += 14; }
}
}
}
$ct = 0 if ($ct && $count>150); # 151P目からCT 終了
if ($flag) {
$coin += $bigget; $bigcount++; $inc = 0;
$coin_d = int($coin);
$k_d = ($k > 0) ? $k.'k' : ' ';
$opt = ($count<=100 || $ct) ? '<font color=\'blue\'><b>' : ($count >= 500) ? '<font color=\'red\'><b>' : '';
$optc = ($count<=100 || $ct) ? '</b></font>' : ($count >= 500) ? '</b></font>' : '';
if ($bigcount) {
$bigp = int($g/$bigcount+0.5);
$bigp = "<font color='blue'>$bigcount</font> (1/$bigp)";
} else { $bigp = 0; }
$ct = 0;
$r = int(rand(10)+1); # CT 抽選
if ($r <= 5) { $get = '<b>BIG</b>'; }
else { $get = '<font color=\'red\'><b>CT BIG</b></font>'; $ct = 1; $ctbig++; }
print "<tr align='center'><td>$opt $count $optc</font></td><td>$get</td><td>$bigp</td>";
print "<td>$ctbig</td><td>$k_d</td><td>$coin_d</td><td>$g</td></tr>\n";
$k = $count = $flag = 0;
}
if($g >= $play) {
$k = ($k > 0) ? $k.'k' : ' ';
$coin_d = int($coin);
if ($bigcount) {
$bigp = int($g/$bigcount+0.5);
$bigp = "<font color='blue'>$bigcount</font> (1/$bigp)";
} else { $bigp = 0; }
print "<tr align='center'><td>$count</td><td>ヤメ</td><td>$bigp</td><td>$ctbig</td>";
print "<td>$k</td><td>$coin_d</td><td>$g</td></tr>\n";
last;
}
}
# シミュデータの整理
$toushi = $totalk * 1000;
$coin = int($coin);
$kankin = $coin*20;
$shushi = $kankin - $toushi;
$opt3 = ($shushi >= 0) ? 'blue' : 'red';
$payout = ($coin-$totalk*50)/($g*3) *100+100;
$payout = &point($payout,2);
$bigp = ($bigcount) ? &point(($g/$bigcount),3) : '';
$nbig = $bigcount - $ctbig;
$nbper = &point(($nbig /$bigcount*100),2) if $bigcount; # normal-BIG のパーセンテージ
$cbper = &point(($ctbig/$bigcount*100),2) if $bigcount; # CT-BIG のパーセンテージ
# 整理したデータ、再試行ボタン、フッタの表示
print <<"__ RESULT __";
</table><br><br>
<table border=0 align='center'><tr><td colspan=2 align='center' bgcolor='#ffffcc'>
<b><font size=4 color='red'>アステカ</font> 設定 $s</b></td></tr>
<tr valign='top'><td><table border=1 align='center' cellpadding=3 cellspacing=0>
<tr><td align='center'>プレイ数</td><td align='right'> $g P</td></tr>
<tr><td align='center'><b><font size=2>トータル</font>BIG</td>
<td align='right'><b>$bigcount 回 <font color='red'>1/$bigp</font></b></td></tr>
<tr><td align='center'><b><font size=2>ノーマル</font>BIG</td>
<td align='right'><b>$nbig 回 <font color='red'>$nbper %</font></b></td></tr>
<tr><td align='center'><b><font color='red'>CT BIG</font></b></td>
<td align='right'><b>$ctbig 回 <font color='red'>$cbper %</font></b></td></tr>
</table></td><td>
<table border=1 align='center' cellpadding=3 cellspacing=0>
<tr><td align='center'>投資</td><td align='right'>$toushi 円</td></tr>
<tr><td align='center'>獲得枚数</td><td align='right'><b>$coin 枚</td></tr>
<tr><td align='center'>PAYOUT</td><td align='right'><b>$payout %</b></td></tr>
<tr><td align='center'>換金</td><td align='right'>$kankin 円</td></tr>
<tr><td align='center'>収支</td><td align='right'><b><font color='$opt3'>$shushi 円</font></b></td></tr>
</table></td></tr></table></center>
<form action='$cginame' method='POST'>
<input type='hidden' name='s' value='$s'>
<input type='hidden' name='play' value='$play'>
<input type='hidden' name='method' value='$method'>
<center><input type='submit' value="再試行"></center>
</form>
<div align='right'>[ <a href='../simu_data_az.html'>data</a> / <a href='azteca_memo.html'>memo</a> / <a href='azteca.html'>source</a> / <a href='../index.html'>home</a> ]</div>
</body></html>
__ RESULT __
exit;
# 少数を四捨五入して指定の桁にする
sub point {
my($value, $fig, $x);
($value, $fig) = @_;
$value = int($value * (10 ** $fig) + 0.5) / (10 ** $fig);
if ($value =~ /(\d+)\.(\d+)/) { $x = $2; }
elsif ($value !~ /\./) { $x =''; $value .= '.'; }
$value = $value.'0' x ( $fig - length($x) );
return $value;
}