|
|
1: 2: |
$cginame = 'wari.cgi'; $title = '機械割の計算'; |
1: 2: 3: 4: 5: 6: 7: 8: |
if ($ENV{'REQUEST_METHOD'} eq 'POST') {
read (STDIN, $input, $ENV{'CONTENT_LENGTH'});
}
foreach (split(/&/,$input)) {
($name,$value) = split(/=/, $_);
push(@input, $value);
}
($s, $play, $mode) = @input;
|
foreach (split(/&/,$input)) {
($key,$value) = split(/=/, $_);
$input{$key}= $value;
}
|
1: 2: 3: 4: 5: 6: 7: 8: 9: |
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> …… </center> __ FORM __ |
1: 2: 3: 4: 5: 6: 7: 8: 9: 10: 11: 12: 13: 14: 15: |
if ($play > 9999) { $error = 1; $er_msg = 'プレイ数は最大9999Pまでです。'; }
if (!$s or !$play) { $error = 1; $er_msg = '記入漏れがあります。'; }
if ($s<1 or $s>6) { $error = 1; $er_msg = '設定は 1 から 6 までです。'; }
if ($ENV{'REQUEST_METHOD'} ne 'POST') { $error = 1; $er_msg = 0; }
if ($er_msg) {
print '*** ERROR !! ***',"\n";
print "$er_msg\n";
}
if ($error) {
print '…',"\n";
exit;
}
|
1: 2: 3: 4: 5: 6: 7: 8: 9: 10: 11: 12: 13: 14: 15: 16: 17: 18: 19: 20: |
while (1) {
$g++; $count++;
if ($coin < 3) { $coin += 50; $k++; $totalk++; }
$coin -= 3;
$r = int(rand(16384)+1);
if ($r <= 68) { # BIG
$bigcount++; $coin += $bigget;
print "……";
$count = 0; $k = 0;
} elsif ($r <= 68+45) { # REG
$regcount++; $coin += $regget;
print "……";
$count = 0; $k = 0;
}
if($g >= $play) {
last; # ヤメ
}
}
|
プレイ数 当選 投資
200P BIG 7k
400P BIG 4k
のように、次の投資額は追い金の形で表示できます。
1: 2: 3: 4: 5: 6: 7: 8: 9: 10: 11: 12: 13: 14: 15: 16: 17: |
$toushi = $totalk * 1000; $kankin = $coin*20; $shushi = $kankin - $toushi; $payout = ($coin-($totalk * 50))/($g * 3)*100+100; print <<"__ RESULT __"; … 結果の表示 <form action='$cginame' method='POST'> … 再試行のフォーム </form> … </body></html> __ RESULT __ exit; |
1: 2: 3: 4: 5: 6: 7: 8: 9: 10: 11: 12: 13: 14: 15: 16: 17: 18: 19: 20: 21: 22: |
$rep = 2245; # 2245/16384 = 1/7.298
$reprt = 14316;
while (1) {
$g++; $count++;
if ($coin < 3) { $coin += 50; $k++; $totalk++; }
$coin -= 3;
$r = int(rand(16384)+1);
$repr = ($stock) ? $reprt : $rep;
if($r <= repr) { # リプレイ当選
if (!$stock) {
$coin += 3; next;
} else {
$r = int(rand(8192)+1);
if ($r <= 1294) { $coin += 3; next; }
}
} elsif( … ) {
…
}
}
|
1: 2: 3: 4: |
for (1..$s_big) { push(@bonus,"B"); }
for (1..$s_reg) { push(@bonus,"R"); }
while (@bonus) { push(@new_bonus, splice(@bonus,rand(@bonus),1)); }
@bonus = @new_bonus;
|
while (@bonus) { push(@new_bonus, splice(@bonus,rand(@bonus),1)); }
while (@bonus) { } より、ループが永久に続きそうですが、
splice は配列から要素を削除する関数です。|
splice(A, B, C) → 配列A の B の要素から C個だけ削除 例) @hoge = (0,1,2,3,4,5); splice(@hoge, 1, 3); とすると、1,2,3 の要素が削除されて、 @hoge = (0,4,5); となります。 |
1: 2: 3: 4: 5: 6: 7: 8: 9: 10: 11: 12: 13: 14: 15: 16: 17: 18: 19: 20: 21: 22: 23: |
@tbl = (11,28,34,30,16,12,20,13,8,13,0,20,14,11,13,13); # /256
@blk = (0,8,16,24,32,40,48,64,80,96,127,128,256,512,768,1024,1279); # プレイ数振り分け
$rt = &rt;
sub rt {
my($i,$x,$r,$rt);
$i = 0; $x = $tbl[0];
$r = int(rand(256)+1);
while ($r > $x) {
$i++;
$x += $tbl[$i];
}
$rt = &rtset($blk[$i], $blk[$i+1]);
return $rt;
}
sub rtset { # 引数2つの間のランダムな整数を返す
local($y,$r,$a,$b);
($a,$b) = @_;
$y = $b - $a;
$r = int(rand($y)+1) + $a;
return $r;
}
|
1: 2: 3: 4: 5: 6: 7: 8: 9: 10: 11: 12: |
$hoge = &point($hoge,3);
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;
}
|
ぐごごごごご。
$y = sprintf("%.3f", $x);
これで一発でした。終了〜。( 2004/12/8 追記 ) |