Есть 2 футбольные команды и есть тотализатор,
необходимо принять ставки на обе команды и,
в зависимости от результата выдать 10, 5 или 0.
10 - 100% совпадение,
0 - нет совадений
5 - угадал точное кол-во голов выигрышной команды
$teamAUserRate - ставка пользователя на команду А по кол-ву забитых голов
$teamBUserRate - ставка пользователя на команду B по кол-ву забитых голов
$teamAFinalResult team A - конечный результат команды А по окончании матча по кол-ву забитых голов
$teamBFinalResult team B - конечный результат команды B по окончании матча по кол-ву забитых голов
<?
/*
* rate (ставка)
*
* @param integer $teamAUserRate team A - Users rate
* @param integer $teamBUserRate team B - Users rate
* @param integer $teamAFinalResult team A - Final rate
* @param integer $teamBFinalResult team B - Final rate
*
* return integer
*/
function rate($teamAUserRate=0, $teamBUserRate=0, $teamAFinalResult=0, $teamBFinalResult=0){
// Typable
$teamAUserRate = (int)$teamAUserRate;
$teamBUserRate = (int)$teamBUserRate;
$teamAFinalResult = (int)$teamAFinalResult;
$teamBFinalResult = (int)$teamBFinalResult;
// 100% match
if($teamAUserRate == $teamAFinalResult && $teamBUserRate == $teamBFinalResult)
return 10;
// Get winner team
$maxUserRate = ($teamAUserRate > $teamBUserRate) ? $teamAUserRate : $teamBUserRate;
$maxFinalResult = ($teamAFinalResult > $teamBFinalResult) ? $teamAFinalResult : $teamBFinalResult;
// If you guessed the winning team and bet on it
if($maxUserRate == $maxFinalResult)
return 5;
return 0;
}
// Call function rate
echo rate(3,4,3,4);
?>
|