Hi,
I have a problem regarding functions. Its more of an optimisation problem as opposed to a functionality one.
The project I am working on is a bet calculator. I have all the bet types controlled through functions which have the bet details passed to them.
The problem is this:
If I have a 4 selection bet and 1 selection loses then this becomes a 3 selection bet and calls the 3 selection bet function.
Now, as I have it set up, there are if statements for every combination of winning selections and 1 losing selection.
Here is a snippet of the code:
function fourfold($odds1, $odds1a, $odds2, $odds2a, $odds3,
$odds3a, $odds4, $odds4a, $stake, $rf1='', $rf2='', $rf3='',
$rf4='', $deadheat1='', $deadheat2='', $deadheat3='',
$deadheat4='', $eachway1='', $eachway2='', $eachway3='',
$eachway4='', $status1='', $status2='', $status3='', $status4='')
{
if(
(
($status1 == "win") &&
($status2 == "win") &&
($status3 == "win") &&
(($status4 == "void") || ($status4 == "lose"))) ||
(($status1 == "placed") &&
($status2 == "placed") &&
($status3 == "placed") &&
(($status4 == "void") || ($status4 == "lose"))) &&
$eachway1 &&
$eachway2 &&
$eachway3 &&
$eachway4
)
{
return $total = treblecalc($odds1,
$odds1a, $odds2, $odds2a, $odds3, $odds3a, $stake, $rf1, $rf2,
$rf3, $deadheat1, $deadheat2, $deadheat3, $eachway1,
$eachway2, $eachway3, $status1, $status2, $status3);
$unitstake = $stake;
}
In the code above, selection 4 is void so a treblecalc function is called which passes the variables for the 3 winning selections.
Now, if selection 1 loses, I have to repat this code only instead, passing all the values for the winning selections (which would be 2, 3 and 4) This is quite a long winded way of doing it and considering I have to code every combination up to 8 selections, its going to be a lot of code!
I was wondering, is there a way that this could be done:
There is a 4 selection bet, if any 1 selection loses it calls the treblecalc and adds the variables that only relate to the winning selections. Basically, I need a function or something that will remove the need to hard code every variation of winning and losing bets.
Your help with this is appreciated. 🙂
Thanks,
Martin