poker/poker_pott.php

88 lines
2.3 KiB
PHP
Raw Normal View History

2017-10-31 19:16:46 +01:00
<?php
$FirstMoreThanSecond = (isset($_POST['FMTS']) && $_POST['FMTS']) ? $_POST['FMTS']:3;
$SecondMoreThanThird = (isset($_POST['FMTT']) && $_POST['FMTT']) ? $_POST['FMTT']:2;
$Stake = (isset($_POST['Stake']) && $_POST['Stake']) ? $_POST['Stake']:2;
function GetDotByPott ($Pott)
{
global $FirstMoreThanSecond;
global $SecondMoreThanThird;
$FMTS = $FirstMoreThanSecond;
$SMTT = $SecondMoreThanThird;
$a=$b=0; //1st and 2nd place
$c=$Pott; //3th starts with all the money
while (!( ($a>=($FMTS*$b)) && ($b>=$SMTT*$c) ))
{
//transport from c to b
if ($b<($SMTT*$c) && $c>0)
{
$b++;
$c--;
}
//transport from b to a
if ($a<($FMTS*$b) && $b>0)
{
$a++;
$b--;
}
}
$RetVal=array();
$RetVal[0]=0; //empty
$RetVal[1]=$a; //1st place
$RetVal[2]=$b; //2nd place
$RetVal[3]=$c; //3th place
return $RetVal;
}
$BODY.='<form action="index.php?page=poker_pott" method="post">';
$BODY.='<input type="hidden" name="page" value="poker_pott">';
$BODY.='Einsatz: ';
$BODY.='<select name="Stake">';
for ($i=1;$i<=10;$i++)
{
$BODY.='<option value="'.$i.'"'.(($Stake==$i)? "selected":"").'>'.$i.'&euro;</option>';
}
$BODY.="</select><br>";
$BODY.='Erster bekommt mindestens ';
$BODY.='<select name="FMTS">';
for ($i=1;$i<=10;$i++)
{
$BODY.='<option value="'.$i.'"'.(($FirstMoreThanSecond==$i)? "selected":"").'>'.$i.' mal</option>';
}
$BODY.="</select>mehr als der Zweite<br>";
$BODY.='Zweiter bekommt mindestens ';
$BODY.='<select name="FMTT">';
for ($i=1;$i<=10;$i++)
{
$BODY.='<option value="'.$i.'"'.(($SecondMoreThanThird==$i)? "selected":"").'>'.$i.' mal</option>';
}
$BODY.="</select>mehr als der Dritte<br>";
$BODY.='<input type="submit" value="Neu Berechnen">';
$BODY.='</form>';
$BODY.= "<table class=\"list\">";
$BODY.= "<tr>";
$BODY.= "<th>Spieler</th>";
$BODY.= "<th>Pott</th>";
$BODY.= "<th>1.Platz</th>";
$BODY.= "<th>2.Platz</th>";
$BODY.= "<th>3.Platz</th>";
$BODY.= "</tr>";
for ($i=4; $i<=20; $i++)
{
$Ret = GetDotByPott($Stake*$i);
$BODY.= "<tr>";
$BODY.= "<td>".$i."</td>";
$BODY.= "<td>".($i*$Stake)."&euro;</td>";
$BODY.= "<td><strong>".$Ret[1]."&euro;</strong></td>";
$BODY.= "<td><strong>".$Ret[2]."&euro;</strong></td>";
$BODY.= "<td><strong>".$Ret[3]."&euro;</strong></td>";
$BODY.= "</tr>";
}
$BODY.= "</table>";
?>