This is not necesarily PHP, but algorithm question, I am just doing it in PHP. So don't know if its the best place to post.

The problem is - I need to calculate maximum posible winning for a game, depending on bets.

We are making dogs racing game, but the algorithm would be similar to roullette. Roullette is more known in the world, so I ask how would you calculate.

For example in roulete there is bets on ODD and EVEN. And another bet is on a number lets say.

If player bets on number 36, then only bet on EVEN can win if wins bet on number 36. So there we can add those 2 values of winning.
But the player might bet huge amount lets say on ODD, and just small amounts on EVEN and 36, so maximum win amount from ODD would outghweight sum of bets on EVEN and 36.

And there can be lot of such conditions. What would be general apradch to these kind of prioblems, so it would not get to complicated.

I wrote code, but there are so many if and loops, so it gets confusing to me, so person who would need to edit it - it would be even harder for him.

Recommended Answers

All 6 Replies

HOw many times player will bet?
you can keep track using multi dimentional array for each bet
that each parent array element will keep track of each bet (in another array)

so at end we can sum up array values to know win/lose or profit/loss

HOw many times player will bet?
For one ticked one bet of same event. For example one bet for ODD, one bet for EVEN, one bet for number 36, one bet for number 35 and so on.

Hmm your solution looks something like a tree.

So for example he places bet on
Odd 30$,
even 10$
number 36 - 5$

Lets say coefficients are the same, so they dont matter. Stake amount is the win amount lets say.

So array would be:

Odd = array (
    sum_off_odd => 30
)

even = array (
    sum_off_even => 10,
    num36 = array(
         sum_of_num36 => 5
    )
)

//in this case its not needed, sum is the same, but if there is more events, for number36, which are not added in EVEN array, this is needed.

     num_36 = array (
            sum_off_num36 => 5,
            even = array(
                 sum_of_even => 10
            )
        )

So max posible win is 30.

Hmm. So something likes this you were thinking. Now I should think what if it is more events. Does this work well.

But to create such arrays I think I will need the same amout of ifs and loops. Those events I took are the simplest ones.

We loop through each event and add it to the array if it fits. But the why do we need array? Actually I was doing something similar, just adding the sum on the fly in templ variable and saving only the biggest posible.

I guess we need x fatorial actions. X is number of stakes. This time the number of types were 2. So it gets quit big loop if there is one bet for each of then number for example 36 bets on numbers [1..36] and bets on odd even. Total of 38 bets, so 38!, quite big number. Or I am thinkig of something wrong :)

Ok in rouletter the coeficioneets are the same of the numbers 1..36, but in our game they would be different.

Or maybe this problem is somehow countable using linear programming like in there:

http://www.zweigmedia.com/RealWorld/simplex.html

sometimes maybe univercity is good, because otherwise I would not have even heard about this technique. But in real life programming I have never used it so don't even if this can help for current problem.

Member Avatar for diafol

We need to know the whole types of bets possible before being able to offer a suggestion.

Roulette allows you to place bets on pairs and fours, colours, evens/odds, board thirds, board halves, columns so it can get quite complicated.

Also, the odds will be important when calculating the winnings. It's not just 'stake'.

Care to divulge more info?

OK, I will explain.

There is racing dogs game. There are running 6 dogs.

There are such bet categories:

winner-x - dog which fisnihes the first.

Finisher-x - dog which finsihes in firsts or second place.

Double-x-y - then bet where you need to guess that first dog is x and second dog is y. (Total of 6*5 = 30 variants, since sucsh as double-6-6 does not exist because same dog cannot be in first and 2nd place at the same time).

Odd (1 3 5)
Even (2 4 6)
Over (dogs numbers 4 5 6)
Under (dogs numebrs 1 2 3)

Odd, even, over, under - its a talk about dog which finsihes first.

If you need odds, you can create them randomly. Because they are not constant anyway - each betting round has differenct coeficients. For example coefincient for Under can be 1.9 and coef for over can be 1.8. The similar for other bet types.

But there is formula to get the posible win on one bet type - it is
stake * coeffiecient
So its not a problem. For this algorintm we can use just numbers saying that stake is the same for simplicity and coef differnt or vice versa. After knowing algoritm, I can replace it with this formula.

Member Avatar for diafol

Ok, so you're after an algo to cover all possible bets, which could be cumulative. That right? How do you envisage the 'player' interacting with the interface? Are you going to offer a list of bet types with options, such as dropdowns / checkboxes etc? That may affect how the data needs to be stored/queried.

data is stored in database, interface is made, everything is working. We just need extra feature - how to calculate maximum posible win :)

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.