1

I'm creating a clone of "Fanduel". If you are unaware of what it is, let me explain. It is a Daily Fantasy Contest that allows you to draft players from sports such as NFL, MLB, NHL, etc. You create a fantasy team that you enter into contests for cash prizes.

What I'm having trouble with is calculating the prizes. As of now I have it to where only the top 3 winners get paid. For example, 20 people enter a contest and only the 1st, 2nd, and 3rd place entries win a prize. The issue I'm having is that I want to offer a wider range of winners, I would like to calculate prizes in the thousands for large tournaments.

I want to avoid having to enter in thousands of statements in order to achieve this. As you can see below I provided you with the code that I have come up with for the top 3 winners. I'm relatively new to coding and I'm having trouble finding information on this subject. I always refer to Stack Overflow because the advice that you provide is always on point. I haven't come across this subject here either so I apologize if this question has been answered already.

public static function calculatePrizes()
{
    $type = $_POST['type'];
    $structure = $_POST['structure'];
    $size = $_POST['size'];
    $entryFee = $_POST['entry_fee'];
    $prizes = self::$pools->calculatePrizes($type , $structure, $size,     $entryFee);

    $result = '<table style="width:100%">'
            . '<tr><td style="text-align:left">Pos</td><td style="text-align:right">Prize</td></tr>';
    $count = 0;
    foreach($prizes as $prize)
    {
        $count++;
        $place = null;
        switch ($count)
        {
            case 1:
                $place = '1st';
                break;
            case 2:
                $place = '2nd';
                break;
            case 3:
                $place = '3rd';
                break;
        }
        $result .= '<tr><td style="text-align:left">'.$place.'</td><td     style="text-align:right">$'.$prize.'</td></tr>';
    }
    $result .= '</table>';
    exit($result);
}
halfer
  • 19,824
  • 17
  • 99
  • 186
Jay Daiuto
  • 11
  • 1
  • 1
    Are you looking for advice as to the algorithm you'd use for a larger number of winners? If so, you might need to add some constraints, otherwise people will design the game in a way that suits them, but it's your game! Would your larger contest be a number of games all with 20 players, or could you have one game with as many players as you like? – halfer Apr 02 '15 at 20:27
  • Are you just looking at modiying the `switch($count)`? You can use this example of dynamically doing an ordinal contraction - http://stackoverflow.com/a/3110033/689579 – Sean Apr 02 '15 at 20:43
  • Pretty much what I'm trying to achieve is to be able to add as many people as I want to a tournament and be able to plug in the payout %'s in between 2 places/rankings... For instance, I want to run one tournament where there is 100 people and pay out the top 10% (10 people) different percentages of a prize pool. But I want to have it so where I can add any number of different number of people and be able to change the payout percentages at will – Jay Daiuto Apr 03 '15 at 20:28
  • Personally, I would like to hire someone to finish this project for me. This will be involving people's money, so it's not something I really want to experiment with. If anyone here would be interested in some freelance work, please let me know. – Jay Daiuto Apr 03 '15 at 20:36

0 Answers0